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 cooperative matrix type given the element type and
1052 /// scope and use and dimensions.
1054 unsigned NumRows, unsigned NumColumns,
1055 unsigned Use);
1056
1057 /// Build a new matrix type given the type and dependently-defined
1058 /// dimensions.
1060 Expr *ColumnExpr,
1061 SourceLocation AttributeLoc);
1062
1063 /// Build a new DependentAddressSpaceType or return the pointee
1064 /// type variable with the correct address space (retrieved from
1065 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1066 /// where the address space remains dependent.
1067 ///
1068 /// By default, performs semantic analysis when building the type with address
1069 /// space applied. Subclasses may override this routine to provide different
1070 /// behavior.
1072 Expr *AddrSpaceExpr,
1073 SourceLocation AttributeLoc);
1074
1075 /// Build a new function type.
1076 ///
1077 /// By default, performs semantic analysis when building the function type.
1078 /// Subclasses may override this routine to provide different behavior.
1080 MutableArrayRef<QualType> ParamTypes,
1082
1083 /// Build a new unprototyped function type.
1085
1086 /// Rebuild an unresolved typename type, given the decl that
1087 /// the UnresolvedUsingTypenameDecl was transformed to.
1089 NestedNameSpecifier Qualifier,
1090 SourceLocation NameLoc, Decl *D);
1091
1092 /// Build a new type found via an alias.
1095 QualType UnderlyingType) {
1096 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1097 }
1098
1099 /// Build a new typedef type.
1101 NestedNameSpecifier Qualifier,
1103 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1104 }
1105
1106 /// Build a new MacroDefined type.
1108 const IdentifierInfo *MacroII) {
1109 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1110 }
1111
1112 /// Build a new class/struct/union/enum type.
1114 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1115 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1116 /*OwnsTag=*/false);
1117 }
1119 return SemaRef.Context.getCanonicalTagType(Tag);
1120 }
1121
1122 /// Build a new typeof(expr) type.
1123 ///
1124 /// By default, performs semantic analysis when building the typeof type.
1125 /// Subclasses may override this routine to provide different behavior.
1127 TypeOfKind Kind);
1128
1129 /// Build a new typeof(type) type.
1130 ///
1131 /// By default, builds a new TypeOfType with the given underlying type.
1133
1134 /// Build a new unary transform type.
1136 UnaryTransformType::UTTKind UKind,
1137 SourceLocation Loc);
1138
1139 /// Build a new C++11 decltype type.
1140 ///
1141 /// By default, performs semantic analysis when building the decltype type.
1142 /// Subclasses may override this routine to provide different behavior.
1144
1146 SourceLocation Loc, bool FullySubstituted,
1147 ArrayRef<QualType> Expansions = {});
1148
1149 /// Build a new C++11 auto type.
1150 ///
1151 /// By default, builds a new AutoType with the given deduced type.
1154 TemplateName TypeConstraintConcept,
1155 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1156 return SemaRef.Context.getAutoType(
1157 DK, DeducedAsType, Keyword, TypeConstraintConcept, TypeConstraintArgs);
1158 }
1159
1160 /// By default, builds a new DeducedTemplateSpecializationType with the given
1161 /// deduced type.
1165 return SemaRef.Context.getDeducedTemplateSpecializationType(
1166 DK, DeducedAsType, Keyword, Template);
1167 }
1168
1169 /// Build a new template specialization type.
1170 ///
1171 /// By default, performs semantic analysis when building the template
1172 /// specialization type. Subclasses may override this routine to provide
1173 /// different behavior.
1176 SourceLocation TemplateLoc,
1178
1179 /// Build a new parenthesized type.
1180 ///
1181 /// By default, builds a new ParenType type from the inner type.
1182 /// Subclasses may override this routine to provide different behavior.
1184 return SemaRef.BuildParenType(InnerType);
1185 }
1186
1187 /// Build a new typename type that refers to an identifier.
1188 ///
1189 /// By default, performs semantic analysis when building the typename type
1190 /// (or elaborated type). Subclasses may override this routine to provide
1191 /// different behavior.
1193 SourceLocation KeywordLoc,
1194 NestedNameSpecifierLoc QualifierLoc,
1195 const IdentifierInfo *Id,
1196 SourceLocation IdLoc,
1197 bool DeducedTSTContext) {
1198 CXXScopeSpec SS;
1199 SS.Adopt(QualifierLoc);
1200
1201 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1202 // If the name is still dependent, just build a new dependent name type.
1203 if (!SemaRef.computeDeclContext(SS))
1204 return SemaRef.Context.getDependentNameType(Keyword,
1205 QualifierLoc.getNestedNameSpecifier(),
1206 Id);
1207 }
1208
1211 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1212 *Id, IdLoc, DeducedTSTContext);
1213 }
1214
1216
1217 // We had a dependent elaborated-type-specifier that has been transformed
1218 // into a non-dependent elaborated-type-specifier. Find the tag we're
1219 // referring to.
1221 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1222 if (!DC)
1223 return QualType();
1224
1225 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1226 return QualType();
1227
1228 TagDecl *Tag = nullptr;
1229 SemaRef.LookupQualifiedName(Result, DC);
1230 switch (Result.getResultKind()) {
1233 break;
1234
1236 Tag = Result.getAsSingle<TagDecl>();
1237 break;
1238
1241 llvm_unreachable("Tag lookup cannot find non-tags");
1242
1244 // Let the LookupResult structure handle ambiguities.
1245 return QualType();
1246 }
1247
1248 if (!Tag) {
1249 // Check where the name exists but isn't a tag type and use that to emit
1250 // better diagnostics.
1252 SemaRef.LookupQualifiedName(Result, DC);
1253 switch (Result.getResultKind()) {
1257 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1258 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1259 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1260 << SomeDecl << NTK << Kind;
1261 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1262 break;
1263 }
1264 default:
1265 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1266 << Kind << Id << DC << QualifierLoc.getSourceRange();
1267 break;
1268 }
1269 return QualType();
1270 }
1271 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1272 IdLoc, Id)) {
1273 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1274 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1275 return QualType();
1276 }
1277 return getDerived().RebuildTagType(
1278 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1279 }
1280
1281 /// Build a new pack expansion type.
1282 ///
1283 /// By default, builds a new PackExpansionType type from the given pattern.
1284 /// Subclasses may override this routine to provide different behavior.
1286 SourceLocation EllipsisLoc,
1287 UnsignedOrNone NumExpansions) {
1288 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1289 NumExpansions);
1290 }
1291
1292 /// Build a new atomic type given its value type.
1293 ///
1294 /// By default, performs semantic analysis when building the atomic type.
1295 /// Subclasses may override this routine to provide different behavior.
1297
1298 /// Build a new pipe type given its value type.
1300 bool isReadPipe);
1301
1302 /// Build a bit-precise int given its value type.
1303 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1304 SourceLocation Loc);
1305
1306 /// Build a dependent bit-precise int given its value type.
1307 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1308 SourceLocation Loc);
1309
1310 /// Build a new template name given a nested name specifier, a flag
1311 /// indicating whether the "template" keyword was provided, and the template
1312 /// that the template name refers to.
1313 ///
1314 /// By default, builds the new template name directly. Subclasses may override
1315 /// this routine to provide different behavior.
1317 TemplateName Name);
1318
1319 /// Build a new template name given a nested name specifier and the
1320 /// name that is referred to as a template.
1321 ///
1322 /// By default, performs semantic analysis to determine whether the name can
1323 /// be resolved to a specific template, then builds the appropriate kind of
1324 /// template name. Subclasses may override this routine to provide different
1325 /// behavior.
1327 SourceLocation TemplateKWLoc,
1328 const IdentifierInfo &Name,
1329 SourceLocation NameLoc, QualType ObjectType,
1330 bool AllowInjectedClassName);
1331
1332 /// Build a new template name given a nested name specifier and the
1333 /// overloaded operator name that is referred to as a template.
1334 ///
1335 /// By default, performs semantic analysis to determine whether the name can
1336 /// be resolved to a specific template, then builds the appropriate kind of
1337 /// template name. Subclasses may override this routine to provide different
1338 /// behavior.
1340 SourceLocation TemplateKWLoc,
1341 OverloadedOperatorKind Operator,
1342 SourceLocation NameLoc, QualType ObjectType,
1343 bool AllowInjectedClassName);
1344
1346 SourceLocation TemplateKWLoc,
1348 SourceLocation NameLoc, QualType ObjectType,
1349 bool AllowInjectedClassName);
1350
1351 /// Build a new template name given a template template parameter pack
1352 /// and the
1353 ///
1354 /// By default, performs semantic analysis to determine whether the name can
1355 /// be resolved to a specific template, then builds the appropriate kind of
1356 /// template name. Subclasses may override this routine to provide different
1357 /// behavior.
1359 Decl *AssociatedDecl, unsigned Index,
1360 bool Final) {
1362 ArgPack, AssociatedDecl, Index, Final);
1363 }
1364
1365 /// Build a new pack-index-template-name ([temp.names]).
1366 ///
1367 /// By default, performs semantic analysis to build the new template name.
1368 /// Subclasses may override this routine to provide different behavior.
1371 bool FullySubstituted,
1372 ArrayRef<TemplateName> Expansions = {}) {
1374 Pattern, IndexExpr, FullySubstituted, Expansions);
1375 }
1376
1377 /// Build a new compound statement.
1378 ///
1379 /// By default, performs semantic analysis to build the new statement.
1380 /// Subclasses may override this routine to provide different behavior.
1382 MultiStmtArg Statements,
1383 SourceLocation RBraceLoc,
1384 bool IsStmtExpr) {
1385 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1386 IsStmtExpr);
1387 }
1388
1389 /// Build a new case statement.
1390 ///
1391 /// By default, performs semantic analysis to build the new statement.
1392 /// Subclasses may override this routine to provide different behavior.
1394 Expr *LHS,
1395 SourceLocation EllipsisLoc,
1396 Expr *RHS,
1397 SourceLocation ColonLoc) {
1398 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1399 ColonLoc);
1400 }
1401
1402 /// Attach the body to a new case statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
1407 getSema().ActOnCaseStmtBody(S, Body);
1408 return S;
1409 }
1410
1411 /// Build a new default statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1416 SourceLocation ColonLoc,
1417 Stmt *SubStmt) {
1418 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1419 /*CurScope=*/nullptr);
1420 }
1421
1422 /// Build a new label statement.
1423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
1427 SourceLocation ColonLoc, Stmt *SubStmt) {
1428 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1429 }
1430
1431 /// Build a new attributed statement.
1432 ///
1433 /// By default, performs semantic analysis to build the new statement.
1434 /// Subclasses may override this routine to provide different behavior.
1437 Stmt *SubStmt) {
1438 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1439 return StmtError();
1440 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1441 }
1442
1443 /// Build a new "if" statement.
1444 ///
1445 /// By default, performs semantic analysis to build the new statement.
1446 /// Subclasses may override this routine to provide different behavior.
1448 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1449 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1450 SourceLocation ElseLoc, Stmt *Else) {
1451 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1452 Then, ElseLoc, Else);
1453 }
1454
1455 /// Start building a new switch statement.
1456 ///
1457 /// By default, performs semantic analysis to build the new statement.
1458 /// Subclasses may override this routine to provide different behavior.
1460 SourceLocation LParenLoc, Stmt *Init,
1462 SourceLocation RParenLoc) {
1463 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1464 RParenLoc);
1465 }
1466
1467 /// Attach the body to the switch statement.
1468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1472 Stmt *Switch, Stmt *Body) {
1473 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1474 }
1475
1476 /// Build a new while statement.
1477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
1482 SourceLocation RParenLoc, Stmt *Body) {
1483 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1484 }
1485
1486 /// Build a new do-while statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
1491 SourceLocation WhileLoc, SourceLocation LParenLoc,
1492 Expr *Cond, SourceLocation RParenLoc) {
1493 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1494 Cond, RParenLoc);
1495 }
1496
1497 /// Build a new for statement.
1498 ///
1499 /// By default, performs semantic analysis to build the new statement.
1500 /// Subclasses may override this routine to provide different behavior.
1503 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1504 Stmt *Body) {
1505 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1506 Inc, RParenLoc, Body);
1507 }
1508
1509 /// Build a new goto statement.
1510 ///
1511 /// By default, performs semantic analysis to build the new statement.
1512 /// Subclasses may override this routine to provide different behavior.
1514 LabelDecl *Label) {
1515 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1516 }
1517
1518 /// Build a new indirect goto statement.
1519 ///
1520 /// By default, performs semantic analysis to build the new statement.
1521 /// Subclasses may override this routine to provide different behavior.
1523 SourceLocation StarLoc,
1524 Expr *Target) {
1525 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1526 }
1527
1528 /// Build a new return statement.
1529 ///
1530 /// By default, performs semantic analysis to build the new statement.
1531 /// Subclasses may override this routine to provide different behavior.
1533 return getSema().BuildReturnStmt(ReturnLoc, Result);
1534 }
1535
1536 /// Build a new declaration statement.
1537 ///
1538 /// By default, performs semantic analysis to build the new statement.
1539 /// Subclasses may override this routine to provide different behavior.
1541 SourceLocation StartLoc, SourceLocation EndLoc) {
1543 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1544 }
1545
1546 /// Build a new inline asm statement.
1547 ///
1548 /// By default, performs semantic analysis to build the new statement.
1549 /// Subclasses may override this routine to provide different behavior.
1551 bool IsVolatile, unsigned NumOutputs,
1552 unsigned NumInputs, IdentifierInfo **Names,
1553 MultiExprArg Constraints, MultiExprArg Exprs,
1554 Expr *AsmString, MultiExprArg Clobbers,
1555 unsigned NumLabels,
1556 SourceLocation RParenLoc) {
1557 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1558 NumInputs, Names, Constraints, Exprs,
1559 AsmString, Clobbers, NumLabels, RParenLoc);
1560 }
1561
1562 /// Build a new MS style inline asm statement.
1563 ///
1564 /// By default, performs semantic analysis to build the new statement.
1565 /// Subclasses may override this routine to provide different behavior.
1567 ArrayRef<Token> AsmToks,
1568 StringRef AsmString,
1569 unsigned NumOutputs, unsigned NumInputs,
1570 ArrayRef<StringRef> Constraints,
1571 ArrayRef<StringRef> Clobbers,
1572 ArrayRef<Expr*> Exprs,
1573 SourceLocation EndLoc) {
1574 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1575 NumOutputs, NumInputs,
1576 Constraints, Clobbers, Exprs, EndLoc);
1577 }
1578
1579 /// Build a new co_return statement.
1580 ///
1581 /// By default, performs semantic analysis to build the new statement.
1582 /// Subclasses may override this routine to provide different behavior.
1584 bool IsImplicit) {
1585 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1586 }
1587
1588 /// Build a new co_await expression.
1589 ///
1590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
1593 UnresolvedLookupExpr *OpCoawaitLookup,
1594 bool IsImplicit) {
1595 // This function rebuilds a coawait-expr given its operator.
1596 // For an explicit coawait-expr, the rebuild involves the full set
1597 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1598 // including calling await_transform().
1599 // For an implicit coawait-expr, we need to rebuild the "operator
1600 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1601 // This mirrors how the implicit CoawaitExpr is originally created
1602 // in Sema::ActOnCoroutineBodyStart().
1603 if (IsImplicit) {
1605 CoawaitLoc, Operand, OpCoawaitLookup);
1606 if (Suspend.isInvalid())
1607 return ExprError();
1608 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1609 Suspend.get(), true);
1610 }
1611
1612 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1613 OpCoawaitLookup);
1614 }
1615
1616 /// Build a new co_await expression.
1617 ///
1618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
1621 Expr *Result,
1622 UnresolvedLookupExpr *Lookup) {
1623 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1624 }
1625
1626 /// Build a new co_yield expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
1631 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1632 }
1633
1637
1638 /// Build a new Objective-C \@try statement.
1639 ///
1640 /// By default, performs semantic analysis to build the new statement.
1641 /// Subclasses may override this routine to provide different behavior.
1643 Stmt *TryBody,
1644 MultiStmtArg CatchStmts,
1645 Stmt *Finally) {
1646 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1647 Finally);
1648 }
1649
1650 /// Rebuild an Objective-C exception declaration.
1651 ///
1652 /// By default, performs semantic analysis to build the new declaration.
1653 /// Subclasses may override this routine to provide different behavior.
1655 TypeSourceInfo *TInfo, QualType T) {
1657 TInfo, T, ExceptionDecl->getInnerLocStart(),
1658 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1659 }
1660
1661 /// Build a new Objective-C \@catch statement.
1662 ///
1663 /// By default, performs semantic analysis to build the new statement.
1664 /// Subclasses may override this routine to provide different behavior.
1666 SourceLocation RParenLoc,
1667 VarDecl *Var,
1668 Stmt *Body) {
1669 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1670 }
1671
1672 /// Build a new Objective-C \@finally statement.
1673 ///
1674 /// By default, performs semantic analysis to build the new statement.
1675 /// Subclasses may override this routine to provide different behavior.
1677 Stmt *Body) {
1678 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1679 }
1680
1681 /// Build a new Objective-C \@throw statement.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1686 Expr *Operand) {
1687 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1688 }
1689
1690 /// Build a new OpenMP Canonical loop.
1691 ///
1692 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1693 /// OMPCanonicalLoop.
1695 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1696 }
1697
1698 /// Build a new OpenMP executable directive.
1699 ///
1700 /// By default, performs semantic analysis to build the new statement.
1701 /// Subclasses may override this routine to provide different behavior.
1703 DeclarationNameInfo DirName,
1704 OpenMPDirectiveKind CancelRegion,
1705 ArrayRef<OMPClause *> Clauses,
1706 Stmt *AStmt, SourceLocation StartLoc,
1707 SourceLocation EndLoc) {
1708
1710 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1711 }
1712
1713 /// Build a new OpenMP metadirective.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1718 SourceLocation EndLoc,
1719 ArrayRef<OMPTraitInfo *> TraitInfos,
1720 ArrayRef<Stmt *> Variants) {
1721 return getSema().OpenMP().ActOnOpenMPMetaDirective(StartLoc, EndLoc,
1722 TraitInfos, Variants);
1723 }
1724
1725 /// Build a new OpenMP informational directive.
1727 DeclarationNameInfo DirName,
1728 ArrayRef<OMPClause *> Clauses,
1729 Stmt *AStmt,
1730 SourceLocation StartLoc,
1731 SourceLocation EndLoc) {
1732
1734 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1735 }
1736
1737 /// Build a new OpenMP 'if' clause.
1738 ///
1739 /// By default, performs semantic analysis to build the new OpenMP clause.
1740 /// Subclasses may override this routine to provide different behavior.
1742 Expr *Condition, SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation NameModifierLoc,
1745 SourceLocation ColonLoc,
1746 SourceLocation EndLoc) {
1748 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1749 EndLoc);
1750 }
1751
1752 /// Build a new OpenMP 'final' clause.
1753 ///
1754 /// By default, performs semantic analysis to build the new OpenMP clause.
1755 /// Subclasses may override this routine to provide different behavior.
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1760 LParenLoc, EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'num_threads' clause.
1764 ///
1765 /// By default, performs semantic analysis to build the new OpenMP clause.
1766 /// Subclasses may override this routine to provide different behavior.
1768 ArrayRef<Expr *> VarList,
1769 OpenMPNumThreadsClauseModifier PrescriptivenessModifier,
1770 SourceLocation PrescriptivenessModifierLoc,
1771 OpenMPNumThreadsClauseModifier DimsModifier, Expr *DimsModifierExpr,
1772 SourceLocation DimsModifierLoc, SourceLocation StartLoc,
1773 SourceLocation LParenLoc, SourceLocation EndLoc) {
1775 VarList, PrescriptivenessModifier, PrescriptivenessModifierLoc,
1776 DimsModifier, DimsModifierExpr, DimsModifierLoc, StartLoc, LParenLoc,
1777 EndLoc);
1778 }
1779
1780 /// Build a new OpenMP 'safelen' clause.
1781 ///
1782 /// By default, performs semantic analysis to build the new OpenMP clause.
1783 /// Subclasses may override this routine to provide different behavior.
1785 SourceLocation LParenLoc,
1786 SourceLocation EndLoc) {
1787 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1788 EndLoc);
1789 }
1790
1791 /// Build a new OpenMP 'simdlen' clause.
1792 ///
1793 /// By default, performs semantic analysis to build the new OpenMP clause.
1794 /// Subclasses may override this routine to provide different behavior.
1796 SourceLocation LParenLoc,
1797 SourceLocation EndLoc) {
1798 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1799 EndLoc);
1800 }
1801
1803 SourceLocation StartLoc,
1804 SourceLocation LParenLoc,
1805 SourceLocation EndLoc) {
1806 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1807 EndLoc);
1808 }
1809
1811 SourceLocation StartLoc,
1812 SourceLocation LParenLoc,
1813 SourceLocation EndLoc,
1814 std::optional<unsigned> FillIdx,
1815 SourceLocation FillLoc) {
1816 unsigned FillCount = FillIdx ? 1 : 0;
1818 Counts, StartLoc, LParenLoc, EndLoc, FillIdx, FillLoc, FillCount);
1819 }
1820
1821 /// Build a new OpenMP 'permutation' clause.
1823 SourceLocation StartLoc,
1824 SourceLocation LParenLoc,
1825 SourceLocation EndLoc) {
1826 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1827 LParenLoc, EndLoc);
1828 }
1829
1830 /// Build a new OpenMP 'full' clause.
1832 SourceLocation EndLoc) {
1833 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1834 }
1835
1836 /// Build a new OpenMP 'partial' clause.
1838 SourceLocation LParenLoc,
1839 SourceLocation EndLoc) {
1840 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1841 LParenLoc, EndLoc);
1842 }
1843
1844 /// Build a new OpenMP 'depth' clause.
1846 SourceLocation LParenLoc,
1847 SourceLocation EndLoc) {
1848 return getSema().OpenMP().ActOnOpenMPDepthClause(Depth, StartLoc, LParenLoc,
1849 EndLoc);
1850 }
1851
1852 OMPClause *
1854 SourceLocation LParenLoc, SourceLocation FirstLoc,
1855 SourceLocation CountLoc, SourceLocation EndLoc) {
1857 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1858 }
1859
1860 /// Build a new OpenMP 'allocator' clause.
1861 ///
1862 /// By default, performs semantic analysis to build the new OpenMP clause.
1863 /// Subclasses may override this routine to provide different behavior.
1865 SourceLocation LParenLoc,
1866 SourceLocation EndLoc) {
1867 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1868 EndLoc);
1869 }
1870
1871 /// Build a new OpenMP 'collapse' clause.
1872 ///
1873 /// By default, performs semantic analysis to build the new OpenMP clause.
1874 /// Subclasses may override this routine to provide different behavior.
1876 SourceLocation LParenLoc,
1877 SourceLocation EndLoc) {
1878 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1879 LParenLoc, EndLoc);
1880 }
1881
1882 /// Build a new OpenMP 'default' clause.
1883 ///
1884 /// By default, performs semantic analysis to build the new OpenMP clause.
1885 /// Subclasses may override this routine to provide different behavior.
1888 SourceLocation VCLoc,
1889 SourceLocation StartLoc,
1890 SourceLocation LParenLoc,
1891 SourceLocation EndLoc) {
1893 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1894 }
1895
1896 /// Build a new OpenMP 'proc_bind' clause.
1897 ///
1898 /// By default, performs semantic analysis to build the new OpenMP clause.
1899 /// Subclasses may override this routine to provide different behavior.
1901 SourceLocation KindKwLoc,
1902 SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1906 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1907 }
1909 SourceLocation StartLoc,
1910 SourceLocation LParenLoc,
1911 SourceLocation EndLoc) {
1913 ImpexTypeArg, StartLoc, LParenLoc, EndLoc);
1914 }
1915
1916 /// Build a new OpenMP 'schedule' clause.
1917 ///
1918 /// By default, performs semantic analysis to build the new OpenMP clause.
1919 /// Subclasses may override this routine to provide different behavior.
1922 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1923 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1924 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1926 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1927 CommaLoc, EndLoc);
1928 }
1929
1930 /// Build a new OpenMP 'ordered' clause.
1931 ///
1932 /// By default, performs semantic analysis to build the new OpenMP clause.
1933 /// Subclasses may override this routine to provide different behavior.
1935 SourceLocation EndLoc,
1936 SourceLocation LParenLoc, Expr *Num) {
1937 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1938 LParenLoc, Num);
1939 }
1940
1941 /// Build a new OpenMP 'nowait' clause.
1942 ///
1943 /// By default, performs semantic analysis to build the new OpenMP clause.
1944 /// Subclasses may override this routine to provide different behavior.
1946 SourceLocation LParenLoc,
1947 SourceLocation EndLoc) {
1948 return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc,
1949 LParenLoc, Condition);
1950 }
1951
1952 /// Build a new OpenMP 'private' clause.
1953 ///
1954 /// By default, performs semantic analysis to build the new OpenMP clause.
1955 /// Subclasses may override this routine to provide different behavior.
1957 SourceLocation StartLoc,
1958 SourceLocation LParenLoc,
1959 SourceLocation EndLoc) {
1960 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1961 LParenLoc, EndLoc);
1962 }
1963
1964 /// Build a new OpenMP 'firstprivate' clause.
1965 ///
1966 /// By default, performs semantic analysis to build the new OpenMP clause.
1967 /// Subclasses may override this routine to provide different behavior.
1969 SourceLocation StartLoc,
1970 SourceLocation LParenLoc,
1971 SourceLocation EndLoc) {
1972 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1973 LParenLoc, EndLoc);
1974 }
1975
1976 /// Build a new OpenMP 'lastprivate' clause.
1977 ///
1978 /// By default, performs semantic analysis to build the new OpenMP clause.
1979 /// Subclasses may override this routine to provide different behavior.
1982 SourceLocation LPKindLoc,
1983 SourceLocation ColonLoc,
1984 SourceLocation StartLoc,
1985 SourceLocation LParenLoc,
1986 SourceLocation EndLoc) {
1988 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1989 }
1990
1991 /// Build a new OpenMP 'shared' clause.
1992 ///
1993 /// By default, performs semantic analysis to build the new OpenMP clause.
1994 /// Subclasses may override this routine to provide different behavior.
1996 SourceLocation StartLoc,
1997 SourceLocation LParenLoc,
1998 SourceLocation EndLoc) {
1999 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
2000 LParenLoc, EndLoc);
2001 }
2002
2003 /// Build a new OpenMP 'reduction' clause.
2004 ///
2005 /// By default, performs semantic analysis to build the new statement.
2006 /// Subclasses may override this routine to provide different behavior.
2009 OpenMPOriginalSharingModifier OriginalSharingModifier,
2010 SourceLocation StartLoc, SourceLocation LParenLoc,
2011 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2012 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
2013 const DeclarationNameInfo &ReductionId,
2014 ArrayRef<Expr *> UnresolvedReductions) {
2016 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
2017 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
2018 UnresolvedReductions);
2019 }
2020
2021 /// Build a new OpenMP 'task_reduction' clause.
2022 ///
2023 /// By default, performs semantic analysis to build the new statement.
2024 /// Subclasses may override this routine to provide different behavior.
2026 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2027 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
2028 CXXScopeSpec &ReductionIdScopeSpec,
2029 const DeclarationNameInfo &ReductionId,
2030 ArrayRef<Expr *> UnresolvedReductions) {
2032 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2033 ReductionId, UnresolvedReductions);
2034 }
2035
2036 /// Build a new OpenMP 'in_reduction' clause.
2037 ///
2038 /// By default, performs semantic analysis to build the new statement.
2039 /// Subclasses may override this routine to provide different behavior.
2040 OMPClause *
2042 SourceLocation LParenLoc, SourceLocation ColonLoc,
2043 SourceLocation EndLoc,
2044 CXXScopeSpec &ReductionIdScopeSpec,
2045 const DeclarationNameInfo &ReductionId,
2046 ArrayRef<Expr *> UnresolvedReductions) {
2048 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2049 ReductionId, UnresolvedReductions);
2050 }
2051
2052 /// Build a new OpenMP 'linear' clause.
2053 ///
2054 /// By default, performs semantic analysis to build the new OpenMP clause.
2055 /// Subclasses may override this routine to provide different behavior.
2057 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
2058 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
2059 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2060 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
2062 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
2063 StepModifierLoc, EndLoc);
2064 }
2065
2066 /// Build a new OpenMP 'aligned' clause.
2067 ///
2068 /// By default, performs semantic analysis to build the new OpenMP clause.
2069 /// Subclasses may override this routine to provide different behavior.
2071 SourceLocation StartLoc,
2072 SourceLocation LParenLoc,
2073 SourceLocation ColonLoc,
2074 SourceLocation EndLoc) {
2076 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2077 }
2078
2079 /// Build a new OpenMP 'copyin' clause.
2080 ///
2081 /// By default, performs semantic analysis to build the new OpenMP clause.
2082 /// Subclasses may override this routine to provide different behavior.
2084 SourceLocation StartLoc,
2085 SourceLocation LParenLoc,
2086 SourceLocation EndLoc) {
2087 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2088 LParenLoc, EndLoc);
2089 }
2090
2091 /// Build a new OpenMP 'copyprivate' clause.
2092 ///
2093 /// By default, performs semantic analysis to build the new OpenMP clause.
2094 /// Subclasses may override this routine to provide different behavior.
2096 SourceLocation StartLoc,
2097 SourceLocation LParenLoc,
2098 SourceLocation EndLoc) {
2099 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2100 LParenLoc, EndLoc);
2101 }
2102
2103 /// Build a new OpenMP 'flush' pseudo clause.
2104 ///
2105 /// By default, performs semantic analysis to build the new OpenMP clause.
2106 /// Subclasses may override this routine to provide different behavior.
2108 SourceLocation StartLoc,
2109 SourceLocation LParenLoc,
2110 SourceLocation EndLoc) {
2111 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2112 LParenLoc, EndLoc);
2113 }
2114
2115 /// Build a new OpenMP 'depobj' pseudo clause.
2116 ///
2117 /// By default, performs semantic analysis to build the new OpenMP clause.
2118 /// Subclasses may override this routine to provide different behavior.
2120 SourceLocation LParenLoc,
2121 SourceLocation EndLoc) {
2122 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2123 LParenLoc, EndLoc);
2124 }
2125
2126 /// Build a new OpenMP 'depend' pseudo clause.
2127 ///
2128 /// By default, performs semantic analysis to build the new OpenMP clause.
2129 /// Subclasses may override this routine to provide different behavior.
2131 Expr *DepModifier, ArrayRef<Expr *> VarList,
2132 SourceLocation StartLoc,
2133 SourceLocation LParenLoc,
2134 SourceLocation EndLoc) {
2136 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2137 }
2138
2139 /// Build a new OpenMP 'device' clause.
2140 ///
2141 /// By default, performs semantic analysis to build the new statement.
2142 /// Subclasses may override this routine to provide different behavior.
2144 Expr *Device, SourceLocation StartLoc,
2145 SourceLocation LParenLoc,
2146 SourceLocation ModifierLoc,
2147 SourceLocation EndLoc) {
2149 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2150 }
2151
2152 /// Build a new OpenMP 'map' clause.
2153 ///
2154 /// By default, performs semantic analysis to build the new OpenMP clause.
2155 /// Subclasses may override this routine to provide different behavior.
2157 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2158 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2159 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2160 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2161 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2162 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2164 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2165 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2166 ColonLoc, VarList, Locs,
2167 /*NoDiagnose=*/false, UnresolvedMappers);
2168 }
2169
2170 /// Build a new OpenMP 'allocate' clause.
2171 ///
2172 /// By default, performs semantic analysis to build the new OpenMP clause.
2173 /// Subclasses may override this routine to provide different behavior.
2174 OMPClause *
2175 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2176 OpenMPAllocateClauseModifier FirstModifier,
2177 SourceLocation FirstModifierLoc,
2178 OpenMPAllocateClauseModifier SecondModifier,
2179 SourceLocation SecondModifierLoc,
2180 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2181 SourceLocation LParenLoc, SourceLocation ColonLoc,
2182 SourceLocation EndLoc) {
2184 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2185 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2186 }
2187
2188 /// Build a new OpenMP 'num_teams' clause.
2189 ///
2190 /// By default, performs semantic analysis to build the new statement.
2191 /// Subclasses may override this routine to provide different behavior.
2194 Expr *ModifierExpr, SourceLocation ModifierLoc,
2195 OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr,
2196 SourceLocation ModifierExtraLoc, SourceLocation StartLoc,
2197 SourceLocation LParenLoc, SourceLocation EndLoc) {
2199 VarList, Modifier, ModifierExpr, ModifierLoc, ModifierExtra,
2200 ModifierExtraExpr, ModifierExtraLoc, StartLoc, LParenLoc, EndLoc);
2201 }
2202
2203 /// Build a new OpenMP 'thread_limit' clause.
2204 ///
2205 /// By default, performs semantic analysis to build the new statement.
2206 /// Subclasses may override this routine to provide different behavior.
2209 Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
2210 SourceLocation LParenLoc, SourceLocation EndLoc) {
2212 VarList, Modifier, ModifierExpr, ModifierLoc, StartLoc, LParenLoc,
2213 EndLoc);
2214 }
2215
2216 /// Build a new OpenMP 'priority' clause.
2217 ///
2218 /// By default, performs semantic analysis to build the new statement.
2219 /// Subclasses may override this routine to provide different behavior.
2221 SourceLocation LParenLoc,
2222 SourceLocation EndLoc) {
2223 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2224 LParenLoc, EndLoc);
2225 }
2226
2227 /// Build a new OpenMP 'grainsize' clause.
2228 ///
2229 /// By default, performs semantic analysis to build the new statement.
2230 /// Subclasses may override this routine to provide different behavior.
2232 Expr *Device, SourceLocation StartLoc,
2233 SourceLocation LParenLoc,
2234 SourceLocation ModifierLoc,
2235 SourceLocation EndLoc) {
2237 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2238 }
2239
2240 /// Build a new OpenMP 'num_tasks' clause.
2241 ///
2242 /// By default, performs semantic analysis to build the new statement.
2243 /// Subclasses may override this routine to provide different behavior.
2245 Expr *NumTasks, SourceLocation StartLoc,
2246 SourceLocation LParenLoc,
2247 SourceLocation ModifierLoc,
2248 SourceLocation EndLoc) {
2250 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2251 }
2252
2253 /// Build a new OpenMP 'hint' clause.
2254 ///
2255 /// By default, performs semantic analysis to build the new statement.
2256 /// Subclasses may override this routine to provide different behavior.
2258 SourceLocation LParenLoc,
2259 SourceLocation EndLoc) {
2260 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2261 EndLoc);
2262 }
2263
2264 /// Build a new OpenMP 'detach' clause.
2265 ///
2266 /// By default, performs semantic analysis to build the new statement.
2267 /// Subclasses may override this routine to provide different behavior.
2269 SourceLocation LParenLoc,
2270 SourceLocation EndLoc) {
2271 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2272 EndLoc);
2273 }
2274
2275 /// Build a new OpenMP 'dist_schedule' clause.
2276 ///
2277 /// By default, performs semantic analysis to build the new OpenMP clause.
2278 /// Subclasses may override this routine to provide different behavior.
2279 OMPClause *
2281 Expr *ChunkSize, SourceLocation StartLoc,
2282 SourceLocation LParenLoc, SourceLocation KindLoc,
2283 SourceLocation CommaLoc, SourceLocation EndLoc) {
2285 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2286 }
2287
2288 /// Build a new OpenMP 'to' clause.
2289 ///
2290 /// By default, performs semantic analysis to build the new statement.
2291 /// Subclasses may override this routine to provide different behavior.
2292 OMPClause *
2294 ArrayRef<SourceLocation> MotionModifiersLoc,
2295 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2296 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2297 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2298 ArrayRef<Expr *> UnresolvedMappers) {
2300 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2301 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2302 UnresolvedMappers);
2303 }
2304
2305 /// Build a new OpenMP 'from' clause.
2306 ///
2307 /// By default, performs semantic analysis to build the new statement.
2308 /// Subclasses may override this routine to provide different behavior.
2309 OMPClause *
2311 ArrayRef<SourceLocation> MotionModifiersLoc,
2312 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2313 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2314 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2315 ArrayRef<Expr *> UnresolvedMappers) {
2317 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2318 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2319 UnresolvedMappers);
2320 }
2321
2322 /// Build a new OpenMP 'use_device_ptr' clause.
2323 ///
2324 /// By default, performs semantic analysis to build the new OpenMP clause.
2325 /// Subclasses may override this routine to provide different behavior.
2327 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2328 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
2329 SourceLocation FallbackModifierLoc) {
2331 VarList, Locs, FallbackModifier, FallbackModifierLoc);
2332 }
2333
2334 /// Build a new OpenMP 'use_device_addr' clause.
2335 ///
2336 /// By default, performs semantic analysis to build the new OpenMP clause.
2337 /// Subclasses may override this routine to provide different behavior.
2342
2343 /// Build a new OpenMP 'is_device_ptr' clause.
2344 ///
2345 /// By default, performs semantic analysis to build the new OpenMP clause.
2346 /// Subclasses may override this routine to provide different behavior.
2348 const OMPVarListLocTy &Locs) {
2349 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2350 }
2351
2352 /// Build a new OpenMP 'has_device_addr' clause.
2353 ///
2354 /// By default, performs semantic analysis to build the new OpenMP clause.
2355 /// Subclasses may override this routine to provide different behavior.
2360
2361 /// Build a new OpenMP 'defaultmap' clause.
2362 ///
2363 /// By default, performs semantic analysis to build the new OpenMP clause.
2364 /// Subclasses may override this routine to provide different behavior.
2367 SourceLocation StartLoc,
2368 SourceLocation LParenLoc,
2369 SourceLocation MLoc,
2370 SourceLocation KindLoc,
2371 SourceLocation EndLoc) {
2373 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2374 }
2375
2376 /// Build a new OpenMP 'nontemporal' clause.
2377 ///
2378 /// By default, performs semantic analysis to build the new OpenMP clause.
2379 /// Subclasses may override this routine to provide different behavior.
2381 SourceLocation StartLoc,
2382 SourceLocation LParenLoc,
2383 SourceLocation EndLoc) {
2384 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2385 LParenLoc, EndLoc);
2386 }
2387
2388 /// Build a new OpenMP 'inclusive' clause.
2389 ///
2390 /// By default, performs semantic analysis to build the new OpenMP clause.
2391 /// Subclasses may override this routine to provide different behavior.
2393 SourceLocation StartLoc,
2394 SourceLocation LParenLoc,
2395 SourceLocation EndLoc) {
2396 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2397 LParenLoc, EndLoc);
2398 }
2399
2400 /// Build a new OpenMP 'exclusive' clause.
2401 ///
2402 /// By default, performs semantic analysis to build the new OpenMP clause.
2403 /// Subclasses may override this routine to provide different behavior.
2405 SourceLocation StartLoc,
2406 SourceLocation LParenLoc,
2407 SourceLocation EndLoc) {
2408 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2409 LParenLoc, EndLoc);
2410 }
2411
2412 /// Build a new OpenMP 'uses_allocators' clause.
2413 ///
2414 /// By default, performs semantic analysis to build the new OpenMP clause.
2415 /// Subclasses may override this routine to provide different behavior.
2422
2423 /// Build a new OpenMP 'affinity' clause.
2424 ///
2425 /// By default, performs semantic analysis to build the new OpenMP clause.
2426 /// Subclasses may override this routine to provide different behavior.
2428 SourceLocation LParenLoc,
2429 SourceLocation ColonLoc,
2430 SourceLocation EndLoc, Expr *Modifier,
2431 ArrayRef<Expr *> Locators) {
2433 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2434 }
2435
2436 /// Build a new OpenMP 'order' clause.
2437 ///
2438 /// By default, performs semantic analysis to build the new OpenMP clause.
2439 /// Subclasses may override this routine to provide different behavior.
2441 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2442 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2443 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2445 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2446 }
2447
2448 /// Build a new OpenMP 'init' clause.
2449 ///
2450 /// By default, performs semantic analysis to build the new OpenMP clause.
2451 /// Subclasses may override this routine to provide different behavior.
2453 SourceLocation StartLoc,
2454 SourceLocation LParenLoc,
2455 SourceLocation VarLoc,
2456 SourceLocation EndLoc) {
2458 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2459 }
2460
2461 /// Build a new OpenMP 'use' clause.
2462 ///
2463 /// By default, performs semantic analysis to build the new OpenMP clause.
2464 /// Subclasses may override this routine to provide different behavior.
2466 SourceLocation LParenLoc,
2467 SourceLocation VarLoc, SourceLocation EndLoc) {
2468 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2469 LParenLoc, VarLoc, EndLoc);
2470 }
2471
2472 /// Build a new OpenMP 'destroy' clause.
2473 ///
2474 /// By default, performs semantic analysis to build the new OpenMP clause.
2475 /// Subclasses may override this routine to provide different behavior.
2477 SourceLocation LParenLoc,
2478 SourceLocation VarLoc,
2479 SourceLocation EndLoc) {
2481 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2482 }
2483
2484 /// Build a new OpenMP 'novariants' clause.
2485 ///
2486 /// By default, performs semantic analysis to build the new OpenMP clause.
2487 /// Subclasses may override this routine to provide different behavior.
2489 SourceLocation StartLoc,
2490 SourceLocation LParenLoc,
2491 SourceLocation EndLoc) {
2493 LParenLoc, EndLoc);
2494 }
2495
2496 /// Build a new OpenMP 'nocontext' clause.
2497 ///
2498 /// By default, performs semantic analysis to build the new OpenMP clause.
2499 /// Subclasses may override this routine to provide different behavior.
2501 SourceLocation LParenLoc,
2502 SourceLocation EndLoc) {
2504 LParenLoc, EndLoc);
2505 }
2506
2507 /// Build a new OpenMP 'filter' clause.
2508 ///
2509 /// By default, performs semantic analysis to build the new OpenMP clause.
2510 /// Subclasses may override this routine to provide different behavior.
2512 SourceLocation LParenLoc,
2513 SourceLocation EndLoc) {
2514 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2515 LParenLoc, EndLoc);
2516 }
2517
2518 /// Build a new OpenMP 'bind' clause.
2519 ///
2520 /// By default, performs semantic analysis to build the new OpenMP clause.
2521 /// Subclasses may override this routine to provide different behavior.
2523 SourceLocation KindLoc,
2524 SourceLocation StartLoc,
2525 SourceLocation LParenLoc,
2526 SourceLocation EndLoc) {
2527 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2528 LParenLoc, EndLoc);
2529 }
2530
2531 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2532 ///
2533 /// By default, performs semantic analysis to build the new OpenMP clause.
2534 /// Subclasses may override this routine to provide different behavior.
2536 SourceLocation LParenLoc,
2537 SourceLocation EndLoc) {
2538 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2539 LParenLoc, EndLoc);
2540 }
2541
2542 /// Build a new OpenMP 'dyn_groupprivate' clause.
2543 ///
2544 /// By default, performs semantic analysis to build the new OpenMP clause.
2545 /// Subclasses may override this routine to provide different behavior.
2549 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
2550 SourceLocation M2Loc, SourceLocation EndLoc) {
2552 M1, M2, Size, StartLoc, LParenLoc, M1Loc, M2Loc, EndLoc);
2553 }
2554
2555 /// Build a new OpenMP 'ompx_attribute' clause.
2556 ///
2557 /// By default, performs semantic analysis to build the new OpenMP clause.
2558 /// Subclasses may override this routine to provide different behavior.
2560 SourceLocation StartLoc,
2561 SourceLocation LParenLoc,
2562 SourceLocation EndLoc) {
2563 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2564 LParenLoc, EndLoc);
2565 }
2566
2567 /// Build a new OpenMP 'ompx_bare' clause.
2568 ///
2569 /// By default, performs semantic analysis to build the new OpenMP clause.
2570 /// Subclasses may override this routine to provide different behavior.
2572 SourceLocation EndLoc) {
2573 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2574 }
2575
2576 /// Build a new OpenMP 'align' clause.
2577 ///
2578 /// By default, performs semantic analysis to build the new OpenMP clause.
2579 /// Subclasses may override this routine to provide different behavior.
2581 SourceLocation LParenLoc,
2582 SourceLocation EndLoc) {
2583 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2584 EndLoc);
2585 }
2586
2587 /// Build a new OpenMP 'at' clause.
2588 ///
2589 /// By default, performs semantic analysis to build the new OpenMP clause.
2590 /// Subclasses may override this routine to provide different behavior.
2592 SourceLocation StartLoc,
2593 SourceLocation LParenLoc,
2594 SourceLocation EndLoc) {
2595 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2596 LParenLoc, EndLoc);
2597 }
2598
2599 /// Build a new OpenMP 'severity' clause.
2600 ///
2601 /// By default, performs semantic analysis to build the new OpenMP clause.
2602 /// Subclasses may override this routine to provide different behavior.
2604 SourceLocation KwLoc,
2605 SourceLocation StartLoc,
2606 SourceLocation LParenLoc,
2607 SourceLocation EndLoc) {
2608 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2609 LParenLoc, EndLoc);
2610 }
2611
2612 /// Build a new OpenMP 'message' clause.
2613 ///
2614 /// By default, performs semantic analysis to build the new OpenMP clause.
2615 /// Subclasses may override this routine to provide different behavior.
2617 SourceLocation LParenLoc,
2618 SourceLocation EndLoc) {
2619 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2620 EndLoc);
2621 }
2622
2623 /// Build a new OpenMP 'doacross' clause.
2624 ///
2625 /// By default, performs semantic analysis to build the new OpenMP clause.
2626 /// Subclasses may override this routine to provide different behavior.
2627 OMPClause *
2629 SourceLocation DepLoc, SourceLocation ColonLoc,
2630 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2631 SourceLocation LParenLoc, SourceLocation EndLoc) {
2633 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2634 }
2635
2636 /// Build a new OpenMP 'holds' clause.
2638 SourceLocation LParenLoc,
2639 SourceLocation EndLoc) {
2640 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2641 EndLoc);
2642 }
2643
2644 /// Rebuild the operand to an Objective-C \@synchronized statement.
2645 ///
2646 /// By default, performs semantic analysis to build the new statement.
2647 /// Subclasses may override this routine to provide different behavior.
2652
2653 /// Build a new Objective-C \@synchronized statement.
2654 ///
2655 /// By default, performs semantic analysis to build the new statement.
2656 /// Subclasses may override this routine to provide different behavior.
2661
2662 /// Build a new Objective-C \@autoreleasepool statement.
2663 ///
2664 /// By default, performs semantic analysis to build the new statement.
2665 /// Subclasses may override this routine to provide different behavior.
2670
2671 /// Build a new Objective-C fast enumeration statement.
2672 ///
2673 /// By default, performs semantic analysis to build the new statement.
2674 /// Subclasses may override this routine to provide different behavior.
2676 Stmt *Element,
2677 Expr *Collection,
2678 SourceLocation RParenLoc,
2679 Stmt *Body) {
2681 ForLoc, Element, Collection, RParenLoc);
2682 if (ForEachStmt.isInvalid())
2683 return StmtError();
2684
2685 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2686 Body);
2687 }
2688
2689 /// Build a new C++ exception declaration.
2690 ///
2691 /// By default, performs semantic analysis to build the new decaration.
2692 /// Subclasses may override this routine to provide different behavior.
2695 SourceLocation StartLoc,
2696 SourceLocation IdLoc,
2697 IdentifierInfo *Id) {
2699 StartLoc, IdLoc, Id);
2700 if (Var)
2701 getSema().CurContext->addDecl(Var);
2702 return Var;
2703 }
2704
2705 /// Build a new C++ catch statement.
2706 ///
2707 /// By default, performs semantic analysis to build the new statement.
2708 /// Subclasses may override this routine to provide different behavior.
2710 VarDecl *ExceptionDecl,
2711 Stmt *Handler) {
2712 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2713 Handler));
2714 }
2715
2716 /// Build a new C++ try statement.
2717 ///
2718 /// By default, performs semantic analysis to build the new statement.
2719 /// Subclasses may override this routine to provide different behavior.
2721 ArrayRef<Stmt *> Handlers) {
2722 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2723 }
2724
2725 /// Build a new C++0x range-based for statement.
2726 ///
2727 /// By default, performs semantic analysis to build the new statement.
2728 /// Subclasses may override this routine to provide different behavior.
2730 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2731 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2732 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2733 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2734 // If we've just learned that the range is actually an Objective-C
2735 // collection, treat this as an Objective-C fast enumeration loop.
2736 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2737 if (RangeStmt->isSingleDecl()) {
2738 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2739 if (RangeVar->isInvalidDecl())
2740 return StmtError();
2741
2742 Expr *RangeExpr = RangeVar->getInit();
2743 if (!RangeExpr->isTypeDependent() &&
2744 RangeExpr->getType()->isObjCObjectPointerType()) {
2745 // FIXME: Support init-statements in Objective-C++20 ranged for
2746 // statement.
2747 if (Init) {
2748 return SemaRef.Diag(Init->getBeginLoc(),
2749 diag::err_objc_for_range_init_stmt)
2750 << Init->getSourceRange();
2751 }
2753 ForLoc, LoopVar, RangeExpr, RParenLoc);
2754 }
2755 }
2756 }
2757 }
2758
2760 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2761 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2762 }
2763
2764 /// Build a new C++0x range-based for statement.
2765 ///
2766 /// By default, performs semantic analysis to build the new statement.
2767 /// Subclasses may override this routine to provide different behavior.
2769 bool IsIfExists,
2770 NestedNameSpecifierLoc QualifierLoc,
2771 DeclarationNameInfo NameInfo,
2772 Stmt *Nested) {
2773 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2774 QualifierLoc, NameInfo, Nested);
2775 }
2776
2777 /// Attach body to a C++0x range-based for statement.
2778 ///
2779 /// By default, performs semantic analysis to finish the new statement.
2780 /// Subclasses may override this routine to provide different behavior.
2782 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2783 }
2784
2786 Stmt *TryBlock, Stmt *Handler) {
2787 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2788 }
2789
2791 Stmt *Block) {
2792 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2793 }
2794
2796 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2797 }
2798
2800 SourceLocation LParen,
2801 SourceLocation RParen,
2802 TypeSourceInfo *TSI) {
2803 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2804 TSI);
2805 }
2806
2807 /// Build a new predefined expression.
2808 ///
2809 /// By default, performs semantic analysis to build the new expression.
2810 /// Subclasses may override this routine to provide different behavior.
2814
2815 /// Build a new expression that references a declaration.
2816 ///
2817 /// By default, performs semantic analysis to build the new expression.
2818 /// Subclasses may override this routine to provide different behavior.
2820 LookupResult &R,
2821 bool RequiresADL) {
2822 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2823 }
2824
2825
2826 /// Build a new expression that references a declaration.
2827 ///
2828 /// By default, performs semantic analysis to build the new expression.
2829 /// Subclasses may override this routine to provide different behavior.
2831 ValueDecl *VD,
2832 const DeclarationNameInfo &NameInfo,
2834 TemplateArgumentListInfo *TemplateArgs) {
2835 CXXScopeSpec SS;
2836 SS.Adopt(QualifierLoc);
2837 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2838 TemplateArgs);
2839 }
2840
2841 /// Build a new expression in parentheses.
2842 ///
2843 /// By default, performs semantic analysis to build the new expression.
2844 /// Subclasses may override this routine to provide different behavior.
2846 SourceLocation RParen) {
2847 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2848 }
2849
2850 /// Build a new pseudo-destructor expression.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2855 SourceLocation OperatorLoc,
2856 bool isArrow,
2857 CXXScopeSpec &SS,
2858 TypeSourceInfo *ScopeType,
2859 SourceLocation CCLoc,
2860 SourceLocation TildeLoc,
2861 PseudoDestructorTypeStorage Destroyed);
2862
2863 /// Build a new unary operator expression.
2864 ///
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
2869 Expr *SubExpr) {
2870 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2871 }
2872
2873 /// Build a new builtin offsetof expression.
2874 ///
2875 /// By default, performs semantic analysis to build the new expression.
2876 /// Subclasses may override this routine to provide different behavior.
2878 TypeSourceInfo *Type, const Designation &Desig,
2879 SourceLocation RParenLoc) {
2880 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Desig, RParenLoc);
2881 }
2882
2883 /// Build a new sizeof, alignof or vec_step expression with a
2884 /// type argument.
2885 ///
2886 /// By default, performs semantic analysis to build the new expression.
2887 /// Subclasses may override this routine to provide different behavior.
2889 SourceLocation OpLoc,
2890 UnaryExprOrTypeTrait ExprKind,
2891 SourceRange R) {
2892 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2893 }
2894
2895 /// Build a new sizeof, alignof or vec step expression with an
2896 /// expression argument.
2897 ///
2898 /// By default, performs semantic analysis to build the new expression.
2899 /// Subclasses may override this routine to provide different behavior.
2901 UnaryExprOrTypeTrait ExprKind,
2902 SourceRange R) {
2904 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2905 if (Result.isInvalid())
2906 return ExprError();
2907
2908 return Result;
2909 }
2910
2911 /// Build a new array subscript expression.
2912 ///
2913 /// By default, performs semantic analysis to build the new expression.
2914 /// Subclasses may override this routine to provide different behavior.
2916 SourceLocation LBracketLoc,
2917 Expr *RHS,
2918 SourceLocation RBracketLoc) {
2919 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2920 LBracketLoc, RHS,
2921 RBracketLoc);
2922 }
2923
2924 /// Build a new matrix single subscript expression.
2925 ///
2926 /// By default, performs semantic analysis to build the new expression.
2927 /// Subclasses may override this routine to provide different behavior.
2929 SourceLocation RBracketLoc) {
2931 RBracketLoc);
2932 }
2933
2934 /// Build a new matrix subscript expression.
2935 ///
2936 /// By default, performs semantic analysis to build the new expression.
2937 /// Subclasses may override this routine to provide different behavior.
2939 Expr *ColumnIdx,
2940 SourceLocation RBracketLoc) {
2941 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2942 RBracketLoc);
2943 }
2944
2945 /// Build a new array section expression.
2946 ///
2947 /// By default, performs semantic analysis to build the new expression.
2948 /// Subclasses may override this routine to provide different behavior.
2950 SourceLocation LBracketLoc,
2951 Expr *LowerBound,
2952 SourceLocation ColonLocFirst,
2953 SourceLocation ColonLocSecond,
2954 Expr *Length, Expr *Stride,
2955 SourceLocation RBracketLoc) {
2956 if (IsOMPArraySection)
2958 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2959 Stride, RBracketLoc);
2960
2961 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2962 "Stride/second colon not allowed for OpenACC");
2963
2965 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2966 }
2967
2968 /// Build a new array shaping expression.
2969 ///
2970 /// By default, performs semantic analysis to build the new expression.
2971 /// Subclasses may override this routine to provide different behavior.
2973 SourceLocation RParenLoc,
2974 ArrayRef<Expr *> Dims,
2975 ArrayRef<SourceRange> BracketsRanges) {
2977 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2978 }
2979
2980 /// Build a new iterator expression.
2981 ///
2982 /// By default, performs semantic analysis to build the new expression.
2983 /// Subclasses may override this routine to provide different behavior.
2986 SourceLocation RLoc,
2989 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2990 }
2991
2992 /// Build a new call expression.
2993 ///
2994 /// By default, performs semantic analysis to build the new expression.
2995 /// Subclasses may override this routine to provide different behavior.
2997 MultiExprArg Args,
2998 SourceLocation RParenLoc,
2999 Expr *ExecConfig = nullptr) {
3000 return getSema().ActOnCallExpr(
3001 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
3002 }
3003
3005 MultiExprArg Args,
3006 SourceLocation RParenLoc) {
3008 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
3009 }
3010
3011 /// Build a new member access expression.
3012 ///
3013 /// By default, performs semantic analysis to build the new expression.
3014 /// Subclasses may override this routine to provide different behavior.
3016 bool isArrow,
3017 NestedNameSpecifierLoc QualifierLoc,
3018 SourceLocation TemplateKWLoc,
3019 const DeclarationNameInfo &MemberNameInfo,
3021 NamedDecl *FoundDecl,
3022 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3023 NamedDecl *FirstQualifierInScope) {
3025 isArrow);
3026 if (!Member->getDeclName()) {
3027 // We have a reference to an unnamed field. This is always the
3028 // base of an anonymous struct/union member access, i.e. the
3029 // field is always of record type.
3030 assert(Member->getType()->isRecordType() &&
3031 "unnamed member not of record type?");
3032
3033 BaseResult =
3035 QualifierLoc.getNestedNameSpecifier(),
3036 FoundDecl, Member);
3037 if (BaseResult.isInvalid())
3038 return ExprError();
3039 Base = BaseResult.get();
3040
3041 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
3042 // from the AST, so we need to re-insert them if needed (since
3043 // `BuildFieldRefereneExpr()` doesn't do this).
3044 if (!isArrow && Base->isPRValue()) {
3046 if (BaseResult.isInvalid())
3047 return ExprError();
3048 Base = BaseResult.get();
3049 }
3050
3051 CXXScopeSpec EmptySS;
3053 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
3054 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
3055 MemberNameInfo);
3056 }
3057
3058 CXXScopeSpec SS;
3059 SS.Adopt(QualifierLoc);
3060
3061 Base = BaseResult.get();
3062 if (Base->containsErrors())
3063 return ExprError();
3064
3065 QualType BaseType = Base->getType();
3066
3067 if (isArrow && !BaseType->isPointerType())
3068 return ExprError();
3069
3070 // FIXME: this involves duplicating earlier analysis in a lot of
3071 // cases; we should avoid this when possible.
3072 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
3073 R.addDecl(FoundDecl);
3074 R.resolveKind();
3075
3076 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
3078 if (auto *ThisClass = cast<CXXThisExpr>(Base)
3079 ->getType()
3080 ->getPointeeType()
3081 ->getAsCXXRecordDecl()) {
3082 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
3083 // In unevaluated contexts, an expression supposed to be a member access
3084 // might reference a member in an unrelated class.
3085 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
3086 return getSema().BuildDeclRefExpr(Member, Member->getType(),
3087 VK_LValue, Member->getLocation());
3088 }
3089 }
3090
3091 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
3092 SS, TemplateKWLoc,
3093 FirstQualifierInScope,
3094 R, ExplicitTemplateArgs,
3095 /*S*/nullptr);
3096 }
3097
3098 /// Build a new binary operator expression.
3099 ///
3100 /// By default, performs semantic analysis to build the new expression.
3101 /// Subclasses may override this routine to provide different behavior.
3103 Expr *LHS, Expr *RHS,
3104 bool ForFoldExpression = false) {
3105 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
3106 ForFoldExpression);
3107 }
3108
3109 /// Build a new rewritten operator expression.
3110 ///
3111 /// By default, performs semantic analysis to build the new expression.
3112 /// Subclasses may override this routine to provide different behavior.
3114 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3115 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3116 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3117 RHS, /*RequiresADL*/false);
3118 }
3119
3120 /// Build a new conditional operator expression.
3121 ///
3122 /// By default, performs semantic analysis to build the new expression.
3123 /// Subclasses may override this routine to provide different behavior.
3125 SourceLocation QuestionLoc,
3126 Expr *LHS,
3127 SourceLocation ColonLoc,
3128 Expr *RHS) {
3129 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3130 LHS, RHS);
3131 }
3132
3133 /// Build a new C-style cast expression.
3134 ///
3135 /// By default, performs semantic analysis to build the new expression.
3136 /// Subclasses may override this routine to provide different behavior.
3138 TypeSourceInfo *TInfo,
3139 SourceLocation RParenLoc,
3140 Expr *SubExpr) {
3141 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3142 SubExpr);
3143 }
3144
3145 /// Build a new compound literal expression.
3146 ///
3147 /// By default, performs semantic analysis to build the new expression.
3148 /// Subclasses may override this routine to provide different behavior.
3150 TypeSourceInfo *TInfo,
3151 SourceLocation RParenLoc,
3152 Expr *Init) {
3153 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3154 Init);
3155 }
3156
3157 /// Build a new extended vector or matrix element access expression.
3158 ///
3159 /// By default, performs semantic analysis to build the new expression.
3160 /// Subclasses may override this routine to provide different behavior.
3162 SourceLocation OpLoc,
3163 bool IsArrow,
3164 SourceLocation AccessorLoc,
3165 IdentifierInfo &Accessor) {
3166
3167 CXXScopeSpec SS;
3168 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3170 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3171 /*FirstQualifierInScope*/ nullptr, NameInfo,
3172 /* TemplateArgs */ nullptr,
3173 /*S*/ nullptr);
3174 }
3175
3176 /// Build a new initializer list expression.
3177 ///
3178 /// By default, performs semantic analysis to build the new expression.
3179 /// Subclasses may override this routine to provide different behavior.
3181 SourceLocation RBraceLoc, bool IsExplicit) {
3182 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc, IsExplicit);
3183 }
3184
3185 /// Build a new designated initializer expression.
3186 ///
3187 /// By default, performs semantic analysis to build the new expression.
3188 /// Subclasses may override this routine to provide different behavior.
3190 MultiExprArg ArrayExprs,
3191 SourceLocation EqualOrColonLoc,
3192 bool GNUSyntax,
3193 Expr *Init) {
3195 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3196 Init);
3197 if (Result.isInvalid())
3198 return ExprError();
3199
3200 return Result;
3201 }
3202
3203 /// Build a new value-initialized expression.
3204 ///
3205 /// By default, builds the implicit value initialization without performing
3206 /// any semantic analysis. Subclasses may override this routine to provide
3207 /// different behavior.
3211
3212 /// Build a new \c va_arg expression.
3213 ///
3214 /// By default, performs semantic analysis to build the new expression.
3215 /// Subclasses may override this routine to provide different behavior.
3217 Expr *SubExpr, TypeSourceInfo *TInfo,
3218 SourceLocation RParenLoc) {
3219 return getSema().BuildVAArgExpr(BuiltinLoc,
3220 SubExpr, TInfo,
3221 RParenLoc);
3222 }
3223
3224 /// Build a new expression list in parentheses.
3225 ///
3226 /// By default, performs semantic analysis to build the new expression.
3227 /// Subclasses may override this routine to provide different behavior.
3229 MultiExprArg SubExprs,
3230 SourceLocation RParenLoc) {
3231 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3232 }
3233
3235 unsigned NumUserSpecifiedExprs,
3236 SourceLocation InitLoc,
3237 SourceLocation LParenLoc,
3238 SourceLocation RParenLoc) {
3239 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3240 InitLoc, LParenLoc, RParenLoc);
3241 }
3242
3243 /// Build a new address-of-label expression.
3244 ///
3245 /// By default, performs semantic analysis, using the name of the label
3246 /// rather than attempting to map the label statement itself.
3247 /// Subclasses may override this routine to provide different behavior.
3249 SourceLocation LabelLoc, LabelDecl *Label) {
3250 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3251 }
3252
3253 /// Build a new GNU statement expression.
3254 ///
3255 /// By default, performs semantic analysis to build the new expression.
3256 /// Subclasses may override this routine to provide different behavior.
3258 SourceLocation RParenLoc, unsigned TemplateDepth,
3259 bool HasResult) {
3260 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc, TemplateDepth,
3261 HasResult);
3262 }
3263
3264 /// Build a new __builtin_choose_expr expression.
3265 ///
3266 /// By default, performs semantic analysis to build the new expression.
3267 /// Subclasses may override this routine to provide different behavior.
3269 Expr *Cond, Expr *LHS, Expr *RHS,
3270 SourceLocation RParenLoc) {
3271 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3272 Cond, LHS, RHS,
3273 RParenLoc);
3274 }
3275
3276 /// Build a new generic selection expression with an expression predicate.
3277 ///
3278 /// By default, performs semantic analysis to build the new expression.
3279 /// Subclasses may override this routine to provide different behavior.
3281 SourceLocation DefaultLoc,
3282 SourceLocation RParenLoc,
3283 Expr *ControllingExpr,
3285 ArrayRef<Expr *> Exprs) {
3286 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3287 /*PredicateIsExpr=*/true,
3288 ControllingExpr, Types, Exprs);
3289 }
3290
3291 /// Build a new generic selection expression with a type predicate.
3292 ///
3293 /// By default, performs semantic analysis to build the new expression.
3294 /// Subclasses may override this routine to provide different behavior.
3296 SourceLocation DefaultLoc,
3297 SourceLocation RParenLoc,
3298 TypeSourceInfo *ControllingType,
3300 ArrayRef<Expr *> Exprs) {
3301 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3302 /*PredicateIsExpr=*/false,
3303 ControllingType, Types, Exprs);
3304 }
3305
3306 /// Build a new overloaded operator call expression.
3307 ///
3308 /// By default, performs semantic analysis to build the new expression.
3309 /// The semantic analysis provides the behavior of template instantiation,
3310 /// copying with transformations that turn what looks like an overloaded
3311 /// operator call into a use of a builtin operator, performing
3312 /// argument-dependent lookup, etc. Subclasses may override this routine to
3313 /// provide different behavior.
3315 SourceLocation OpLoc,
3316 SourceLocation CalleeLoc,
3317 bool RequiresADL,
3318 const UnresolvedSetImpl &Functions,
3319 Expr *First, Expr *Second);
3320
3321 /// Build a new C++ "named" cast expression, such as static_cast or
3322 /// reinterpret_cast.
3323 ///
3324 /// By default, this routine dispatches to one of the more-specific routines
3325 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3326 /// Subclasses may override this routine to provide different behavior.
3329 SourceLocation LAngleLoc,
3330 TypeSourceInfo *TInfo,
3331 SourceLocation RAngleLoc,
3332 SourceLocation LParenLoc,
3333 Expr *SubExpr,
3334 SourceLocation RParenLoc) {
3335 switch (Class) {
3336 case Stmt::CXXStaticCastExprClass:
3337 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3338 RAngleLoc, LParenLoc,
3339 SubExpr, RParenLoc);
3340
3341 case Stmt::CXXDynamicCastExprClass:
3342 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3343 RAngleLoc, LParenLoc,
3344 SubExpr, RParenLoc);
3345
3346 case Stmt::CXXReinterpretCastExprClass:
3347 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3348 RAngleLoc, LParenLoc,
3349 SubExpr,
3350 RParenLoc);
3351
3352 case Stmt::CXXConstCastExprClass:
3353 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3354 RAngleLoc, LParenLoc,
3355 SubExpr, RParenLoc);
3356
3357 case Stmt::CXXAddrspaceCastExprClass:
3358 return getDerived().RebuildCXXAddrspaceCastExpr(
3359 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3360
3361 default:
3362 llvm_unreachable("Invalid C++ named cast");
3363 }
3364 }
3365
3366 /// Build a new C++ static_cast expression.
3367 ///
3368 /// By default, performs semantic analysis to build the new expression.
3369 /// Subclasses may override this routine to provide different behavior.
3371 SourceLocation LAngleLoc,
3372 TypeSourceInfo *TInfo,
3373 SourceLocation RAngleLoc,
3374 SourceLocation LParenLoc,
3375 Expr *SubExpr,
3376 SourceLocation RParenLoc) {
3377 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3378 TInfo, SubExpr,
3379 SourceRange(LAngleLoc, RAngleLoc),
3380 SourceRange(LParenLoc, RParenLoc));
3381 }
3382
3383 /// Build a new C++ dynamic_cast expression.
3384 ///
3385 /// By default, performs semantic analysis to build the new expression.
3386 /// Subclasses may override this routine to provide different behavior.
3388 SourceLocation LAngleLoc,
3389 TypeSourceInfo *TInfo,
3390 SourceLocation RAngleLoc,
3391 SourceLocation LParenLoc,
3392 Expr *SubExpr,
3393 SourceLocation RParenLoc) {
3394 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3395 TInfo, SubExpr,
3396 SourceRange(LAngleLoc, RAngleLoc),
3397 SourceRange(LParenLoc, RParenLoc));
3398 }
3399
3400 /// Build a new C++ reinterpret_cast expression.
3401 ///
3402 /// By default, performs semantic analysis to build the new expression.
3403 /// Subclasses may override this routine to provide different behavior.
3405 SourceLocation LAngleLoc,
3406 TypeSourceInfo *TInfo,
3407 SourceLocation RAngleLoc,
3408 SourceLocation LParenLoc,
3409 Expr *SubExpr,
3410 SourceLocation RParenLoc) {
3411 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3412 TInfo, SubExpr,
3413 SourceRange(LAngleLoc, RAngleLoc),
3414 SourceRange(LParenLoc, RParenLoc));
3415 }
3416
3417 /// Build a new C++ const_cast expression.
3418 ///
3419 /// By default, performs semantic analysis to build the new expression.
3420 /// Subclasses may override this routine to provide different behavior.
3422 SourceLocation LAngleLoc,
3423 TypeSourceInfo *TInfo,
3424 SourceLocation RAngleLoc,
3425 SourceLocation LParenLoc,
3426 Expr *SubExpr,
3427 SourceLocation RParenLoc) {
3428 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3429 TInfo, SubExpr,
3430 SourceRange(LAngleLoc, RAngleLoc),
3431 SourceRange(LParenLoc, RParenLoc));
3432 }
3433
3436 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3437 SourceLocation LParenLoc, Expr *SubExpr,
3438 SourceLocation RParenLoc) {
3439 return getSema().BuildCXXNamedCast(
3440 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3441 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3442 }
3443
3444 /// Build a new C++ functional-style cast expression.
3445 ///
3446 /// By default, performs semantic analysis to build the new expression.
3447 /// Subclasses may override this routine to provide different behavior.
3449 SourceLocation LParenLoc,
3450 Expr *Sub,
3451 SourceLocation RParenLoc,
3452 bool ListInitialization) {
3453 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3454 // CXXParenListInitExpr. Pass its expanded arguments so that the
3455 // CXXParenListInitExpr can be rebuilt.
3456 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3458 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3459 RParenLoc, ListInitialization);
3460
3461 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3463 TInfo, LParenLoc, PLE->getUserSpecifiedInitExprs(), RParenLoc,
3464 ListInitialization);
3465
3466 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3467 MultiExprArg(&Sub, 1), RParenLoc,
3468 ListInitialization);
3469 }
3470
3471 /// Build a new C++ __builtin_bit_cast expression.
3472 ///
3473 /// By default, performs semantic analysis to build the new expression.
3474 /// Subclasses may override this routine to provide different behavior.
3476 TypeSourceInfo *TSI, Expr *Sub,
3477 SourceLocation RParenLoc) {
3478 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3479 }
3480
3481 /// Build a new C++ typeid(type) expression.
3482 ///
3483 /// By default, performs semantic analysis to build the new expression.
3484 /// Subclasses may override this routine to provide different behavior.
3486 SourceLocation TypeidLoc,
3487 TypeSourceInfo *Operand,
3488 SourceLocation RParenLoc) {
3489 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3490 RParenLoc);
3491 }
3492
3493
3494 /// Build a new C++ typeid(expr) expression.
3495 ///
3496 /// By default, performs semantic analysis to build the new expression.
3497 /// Subclasses may override this routine to provide different behavior.
3499 SourceLocation TypeidLoc,
3500 Expr *Operand,
3501 SourceLocation RParenLoc) {
3502 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3503 RParenLoc);
3504 }
3505
3506 /// Build a new C++ __uuidof(type) expression.
3507 ///
3508 /// By default, performs semantic analysis to build the new expression.
3509 /// Subclasses may override this routine to provide different behavior.
3511 TypeSourceInfo *Operand,
3512 SourceLocation RParenLoc) {
3513 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3514 }
3515
3516 /// Build a new C++ __uuidof(expr) expression.
3517 ///
3518 /// By default, performs semantic analysis to build the new expression.
3519 /// Subclasses may override this routine to provide different behavior.
3521 Expr *Operand, SourceLocation RParenLoc) {
3522 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3523 }
3524
3525 /// Build a new C++ "this" expression.
3526 ///
3527 /// By default, performs semantic analysis to build a new "this" expression.
3528 /// Subclasses may override this routine to provide different behavior.
3530 QualType ThisType,
3531 bool isImplicit) {
3532 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3533 return ExprError();
3534 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3535 }
3536
3537 /// Build a new C++ throw expression.
3538 ///
3539 /// By default, performs semantic analysis to build the new expression.
3540 /// Subclasses may override this routine to provide different behavior.
3542 bool IsThrownVariableInScope) {
3543 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3544 }
3545
3546 /// Build a new C++ default-argument expression.
3547 ///
3548 /// By default, builds a new default-argument expression, which does not
3549 /// require any semantic analysis. Subclasses may override this routine to
3550 /// provide different behavior.
3552 Expr *RewrittenExpr) {
3553 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3554 RewrittenExpr, getSema().CurContext);
3555 }
3556
3557 /// Build a new C++11 default-initialization expression.
3558 ///
3559 /// By default, builds a new default field initialization expression, which
3560 /// does not require any semantic analysis. Subclasses may override this
3561 /// routine to provide different behavior.
3563 Expr *RewrittenInit) {
3564 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
3565 getSema().CurContext, RewrittenInit);
3566 }
3567
3568 /// Build a new C++ zero-initialization expression.
3569 ///
3570 /// By default, performs semantic analysis to build the new expression.
3571 /// Subclasses may override this routine to provide different behavior.
3573 SourceLocation LParenLoc,
3574 SourceLocation RParenLoc) {
3575 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3576 /*ListInitialization=*/false);
3577 }
3578
3579 /// Build a new C++ "new" expression.
3580 ///
3581 /// By default, performs semantic analysis to build the new expression.
3582 /// Subclasses may override this routine to provide different behavior.
3584 SourceLocation PlacementLParen,
3585 MultiExprArg PlacementArgs,
3586 SourceLocation PlacementRParen,
3587 SourceRange TypeIdParens, QualType AllocatedType,
3588 TypeSourceInfo *AllocatedTypeInfo,
3589 std::optional<Expr *> ArraySize,
3590 SourceRange DirectInitRange, Expr *Initializer) {
3591 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3592 PlacementLParen,
3593 PlacementArgs,
3594 PlacementRParen,
3595 TypeIdParens,
3596 AllocatedType,
3597 AllocatedTypeInfo,
3598 ArraySize,
3599 DirectInitRange,
3600 Initializer);
3601 }
3602
3603 /// Build a new C++ "delete" expression.
3604 ///
3605 /// By default, performs semantic analysis to build the new expression.
3606 /// Subclasses may override this routine to provide different behavior.
3608 bool IsGlobalDelete,
3609 bool IsArrayForm,
3610 Expr *Operand) {
3611 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3612 Operand);
3613 }
3614
3615 /// Build a new type trait expression.
3616 ///
3617 /// By default, performs semantic analysis to build the new expression.
3618 /// Subclasses may override this routine to provide different behavior.
3620 SourceLocation StartLoc,
3622 SourceLocation RParenLoc) {
3623 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3624 }
3625
3626 /// Build a new array type trait expression.
3627 ///
3628 /// By default, performs semantic analysis to build the new expression.
3629 /// Subclasses may override this routine to provide different behavior.
3630 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
3631 SourceLocation StartLoc,
3632 TypeSourceInfo *TSInfo,
3633 Expr *DimExpr,
3634 SourceLocation RParenLoc) {
3635 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3636 }
3637
3638 /// Build a new expression trait expression.
3639 ///
3640 /// By default, performs semantic analysis to build the new expression.
3641 /// Subclasses may override this routine to provide different behavior.
3642 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
3643 SourceLocation StartLoc,
3644 Expr *Queried,
3645 SourceLocation RParenLoc) {
3646 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3647 }
3648
3649 /// Build a new (previously unresolved) declaration reference
3650 /// expression.
3651 ///
3652 /// By default, performs semantic analysis to build the new expression.
3653 /// Subclasses may override this routine to provide different behavior.
3655 NestedNameSpecifierLoc QualifierLoc,
3656 SourceLocation TemplateKWLoc,
3657 const DeclarationNameInfo &NameInfo,
3658 const TemplateArgumentListInfo *TemplateArgs,
3659 bool IsAddressOfOperand,
3660 TypeSourceInfo **RecoveryTSI) {
3661 CXXScopeSpec SS;
3662 SS.Adopt(QualifierLoc);
3663
3664 if (TemplateArgs || TemplateKWLoc.isValid())
3666 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3667
3669 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3670 }
3671
3672 /// Build a new template-id expression.
3673 ///
3674 /// By default, performs semantic analysis to build the new expression.
3675 /// Subclasses may override this routine to provide different behavior.
3677 SourceLocation TemplateKWLoc,
3678 LookupResult &R,
3679 bool RequiresADL,
3680 const TemplateArgumentListInfo *TemplateArgs) {
3681 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3682 TemplateArgs);
3683 }
3684
3685 /// Build a new object-construction expression.
3686 ///
3687 /// By default, performs semantic analysis to build the new expression.
3688 /// Subclasses may override this routine to provide different behavior.
3691 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3692 bool ListInitialization, bool StdInitListInitialization,
3693 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3694 SourceRange ParenRange) {
3695 // Reconstruct the constructor we originally found, which might be
3696 // different if this is a call to an inherited constructor.
3697 CXXConstructorDecl *FoundCtor = Constructor;
3698 if (Constructor->isInheritingConstructor())
3699 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3700
3701 SmallVector<Expr *, 8> ConvertedArgs;
3702 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3703 ConvertedArgs))
3704 return ExprError();
3705
3706 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3707 IsElidable,
3708 ConvertedArgs,
3709 HadMultipleCandidates,
3710 ListInitialization,
3711 StdInitListInitialization,
3712 RequiresZeroInit, ConstructKind,
3713 ParenRange);
3714 }
3715
3716 /// Build a new implicit construction via inherited constructor
3717 /// expression.
3720 bool ConstructsVBase,
3721 bool InheritedFromVBase) {
3723 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3724 }
3725
3726 /// Build a new object-construction expression.
3727 ///
3728 /// By default, performs semantic analysis to build the new expression.
3729 /// Subclasses may override this routine to provide different behavior.
3731 SourceLocation LParenOrBraceLoc,
3732 MultiExprArg Args,
3733 SourceLocation RParenOrBraceLoc,
3734 bool ListInitialization) {
3736 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3737 }
3738
3739 /// Build a new object-construction expression.
3740 ///
3741 /// By default, performs semantic analysis to build the new expression.
3742 /// Subclasses may override this routine to provide different behavior.
3744 SourceLocation LParenLoc,
3745 MultiExprArg Args,
3746 SourceLocation RParenLoc,
3747 bool ListInitialization) {
3748 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3749 RParenLoc, ListInitialization);
3750 }
3751
3752 /// Build a new member reference expression.
3753 ///
3754 /// By default, performs semantic analysis to build the new expression.
3755 /// Subclasses may override this routine to provide different behavior.
3757 QualType BaseType,
3758 bool IsArrow,
3759 SourceLocation OperatorLoc,
3760 NestedNameSpecifierLoc QualifierLoc,
3761 SourceLocation TemplateKWLoc,
3762 NamedDecl *FirstQualifierInScope,
3763 const DeclarationNameInfo &MemberNameInfo,
3764 const TemplateArgumentListInfo *TemplateArgs) {
3765 CXXScopeSpec SS;
3766 SS.Adopt(QualifierLoc);
3767
3768 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3769 OperatorLoc, IsArrow,
3770 SS, TemplateKWLoc,
3771 FirstQualifierInScope,
3772 MemberNameInfo,
3773 TemplateArgs, /*S*/nullptr);
3774 }
3775
3776 /// Build a new member reference expression.
3777 ///
3778 /// By default, performs semantic analysis to build the new expression.
3779 /// Subclasses may override this routine to provide different behavior.
3781 SourceLocation OperatorLoc,
3782 bool IsArrow,
3783 NestedNameSpecifierLoc QualifierLoc,
3784 SourceLocation TemplateKWLoc,
3785 NamedDecl *FirstQualifierInScope,
3786 LookupResult &R,
3787 const TemplateArgumentListInfo *TemplateArgs) {
3788 CXXScopeSpec SS;
3789 SS.Adopt(QualifierLoc);
3790
3791 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3792 OperatorLoc, IsArrow,
3793 SS, TemplateKWLoc,
3794 FirstQualifierInScope,
3795 R, TemplateArgs, /*S*/nullptr);
3796 }
3797
3798 /// Build a new noexcept expression.
3799 ///
3800 /// By default, performs semantic analysis to build the new expression.
3801 /// Subclasses may override this routine to provide different behavior.
3803 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3804 }
3805
3808
3809 /// Build a new expression to compute the length of a parameter pack.
3811 SourceLocation PackLoc,
3812 SourceLocation RParenLoc,
3813 UnsignedOrNone Length,
3814 ArrayRef<TemplateArgument> PartialArgs) {
3815 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3816 RParenLoc, Length, PartialArgs);
3817 }
3818
3820 SourceLocation RSquareLoc,
3821 Expr *PackIdExpression, Expr *IndexExpr,
3822 ArrayRef<Expr *> ExpandedExprs,
3823 bool FullySubstituted = false) {
3824 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3825 IndexExpr, RSquareLoc, ExpandedExprs,
3826 FullySubstituted);
3827 }
3828
3829 /// Build a new expression representing a call to a source location
3830 /// builtin.
3831 ///
3832 /// By default, performs semantic analysis to build the new expression.
3833 /// Subclasses may override this routine to provide different behavior.
3835 SourceLocation BuiltinLoc,
3836 SourceLocation RPLoc,
3837 DeclContext *ParentContext) {
3838 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3839 ParentContext);
3840 }
3841
3843 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3844 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3846 CXXScopeSpec SS;
3847 SS.Adopt(NNS);
3848 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3849 ConceptNameInfo,
3850 FoundDecl,
3851 NamedConcept, TALI);
3852 if (Result.isInvalid())
3853 return ExprError();
3854 return Result;
3855 }
3856
3857 /// \brief Build a new requires expression.
3858 ///
3859 /// By default, performs semantic analysis to build the new expression.
3860 /// Subclasses may override this routine to provide different behavior.
3863 SourceLocation LParenLoc,
3864 ArrayRef<ParmVarDecl *> LocalParameters,
3865 SourceLocation RParenLoc,
3867 SourceLocation ClosingBraceLoc) {
3868 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3869 LocalParameters, RParenLoc, Requirements,
3870 ClosingBraceLoc);
3871 }
3872
3876 return SemaRef.BuildTypeRequirement(SubstDiag);
3877 }
3878
3880 return SemaRef.BuildTypeRequirement(T);
3881 }
3882
3885 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3886 SourceLocation NoexceptLoc,
3888 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3889 std::move(Ret));
3890 }
3891
3893 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3895 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3896 std::move(Ret));
3897 }
3898
3900 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3901 const ASTConstraintSatisfaction &Satisfaction) {
3902 return new (getSema().Context)
3903 concepts::NestedRequirement(InvalidConstraintEntity, &Satisfaction);
3904 }
3905
3907 return SemaRef.BuildNestedRequirement(Constraint);
3908 }
3909
3910 /// \brief Build a new Objective-C boxed expression.
3911 ///
3912 /// By default, performs semantic analysis to build the new expression.
3913 /// Subclasses may override this routine to provide different behavior.
3915 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3916 }
3917
3918 /// Build a new Objective-C array literal.
3919 ///
3920 /// By default, performs semantic analysis to build the new expression.
3921 /// Subclasses may override this routine to provide different behavior.
3923 Expr **Elements, unsigned NumElements) {
3925 Range, MultiExprArg(Elements, NumElements));
3926 }
3927
3929 Expr *Base, Expr *Key,
3930 ObjCMethodDecl *getterMethod,
3931 ObjCMethodDecl *setterMethod) {
3933 RB, Base, Key, getterMethod, setterMethod);
3934 }
3935
3936 /// Build a new Objective-C dictionary literal.
3937 ///
3938 /// By default, performs semantic analysis to build the new expression.
3939 /// Subclasses may override this routine to provide different behavior.
3944
3945 /// Build a new Objective-C \@encode expression.
3946 ///
3947 /// By default, performs semantic analysis to build the new expression.
3948 /// Subclasses may override this routine to provide different behavior.
3950 TypeSourceInfo *EncodeTypeInfo,
3951 SourceLocation RParenLoc) {
3952 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3953 RParenLoc);
3954 }
3955
3956 /// Build a new Objective-C class message.
3958 Selector Sel,
3959 ArrayRef<SourceLocation> SelectorLocs,
3961 SourceLocation LBracLoc,
3962 MultiExprArg Args,
3963 SourceLocation RBracLoc) {
3964 return SemaRef.ObjC().BuildClassMessage(
3965 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3966 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3967 RBracLoc, Args);
3968 }
3969
3970 /// Build a new Objective-C instance message.
3972 Selector Sel,
3973 ArrayRef<SourceLocation> SelectorLocs,
3975 SourceLocation LBracLoc,
3976 MultiExprArg Args,
3977 SourceLocation RBracLoc) {
3978 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3979 /*SuperLoc=*/SourceLocation(),
3980 Sel, Method, LBracLoc,
3981 SelectorLocs, RBracLoc, Args);
3982 }
3983
3984 /// Build a new Objective-C instance/class message to 'super'.
3986 Selector Sel,
3987 ArrayRef<SourceLocation> SelectorLocs,
3988 QualType SuperType,
3990 SourceLocation LBracLoc,
3991 MultiExprArg Args,
3992 SourceLocation RBracLoc) {
3993 return Method->isInstanceMethod()
3994 ? SemaRef.ObjC().BuildInstanceMessage(
3995 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3996 SelectorLocs, RBracLoc, Args)
3997 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3998 Sel, Method, LBracLoc,
3999 SelectorLocs, RBracLoc, Args);
4000 }
4001
4002 /// Build a new Objective-C ivar reference expression.
4003 ///
4004 /// By default, performs semantic analysis to build the new expression.
4005 /// Subclasses may override this routine to provide different behavior.
4007 SourceLocation IvarLoc,
4008 bool IsArrow, bool IsFreeIvar) {
4009 CXXScopeSpec SS;
4010 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
4012 BaseArg, BaseArg->getType(),
4013 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
4014 /*FirstQualifierInScope=*/nullptr, NameInfo,
4015 /*TemplateArgs=*/nullptr,
4016 /*S=*/nullptr);
4017 if (IsFreeIvar && Result.isUsable())
4018 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
4019 return Result;
4020 }
4021
4022 /// Build a new Objective-C property reference expression.
4023 ///
4024 /// By default, performs semantic analysis to build the new expression.
4025 /// Subclasses may override this routine to provide different behavior.
4028 SourceLocation PropertyLoc) {
4029 CXXScopeSpec SS;
4030 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
4031 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4032 /*FIXME:*/PropertyLoc,
4033 /*IsArrow=*/false,
4034 SS, SourceLocation(),
4035 /*FirstQualifierInScope=*/nullptr,
4036 NameInfo,
4037 /*TemplateArgs=*/nullptr,
4038 /*S=*/nullptr);
4039 }
4040
4041 /// Build a new Objective-C property reference expression.
4042 ///
4043 /// By default, performs semantic analysis to build the new expression.
4044 /// Subclasses may override this routine to provide different behavior.
4046 ObjCMethodDecl *Getter,
4047 ObjCMethodDecl *Setter,
4048 SourceLocation PropertyLoc) {
4049 // Since these expressions can only be value-dependent, we do not
4050 // need to perform semantic analysis again.
4051 return Owned(
4052 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
4054 PropertyLoc, Base));
4055 }
4056
4057 /// Build a new Objective-C "isa" expression.
4058 ///
4059 /// By default, performs semantic analysis to build the new expression.
4060 /// Subclasses may override this routine to provide different behavior.
4062 SourceLocation OpLoc, bool IsArrow) {
4063 CXXScopeSpec SS;
4064 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
4065 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4066 OpLoc, IsArrow,
4067 SS, SourceLocation(),
4068 /*FirstQualifierInScope=*/nullptr,
4069 NameInfo,
4070 /*TemplateArgs=*/nullptr,
4071 /*S=*/nullptr);
4072 }
4073
4074 /// Build a new shuffle vector expression.
4075 ///
4076 /// By default, performs semantic analysis to build the new expression.
4077 /// Subclasses may override this routine to provide different behavior.
4079 MultiExprArg SubExprs,
4080 SourceLocation RParenLoc) {
4081 // Find the declaration for __builtin_shufflevector
4082 const IdentifierInfo &Name
4083 = SemaRef.Context.Idents.get("__builtin_shufflevector");
4084 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
4085 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
4086 assert(!Lookup.empty() && "No __builtin_shufflevector?");
4087
4088 // Build a reference to the __builtin_shufflevector builtin
4090 Expr *Callee = new (SemaRef.Context)
4091 DeclRefExpr(SemaRef.Context, Builtin, false,
4092 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
4093 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
4094 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
4095 CK_BuiltinFnToFnPtr).get();
4096
4097 // Build the CallExpr
4098 ExprResult TheCall = CallExpr::Create(
4099 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
4100 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
4102
4103 // Type-check the __builtin_shufflevector expression.
4104 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
4105 }
4106
4107 /// Build a new convert vector expression.
4109 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4110 SourceLocation RParenLoc) {
4111 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4112 }
4113
4114 /// Build a new template argument pack expansion.
4115 ///
4116 /// By default, performs semantic analysis to build a new pack expansion
4117 /// for a template argument. Subclasses may override this routine to provide
4118 /// different behavior.
4120 SourceLocation EllipsisLoc,
4121 UnsignedOrNone NumExpansions) {
4122 switch (Pattern.getArgument().getKind()) {
4126 EllipsisLoc, NumExpansions);
4127 if (Result.isInvalid())
4128 return TemplateArgumentLoc();
4129
4131 /*IsCanonical=*/false),
4132 Result.get());
4133 }
4134
4136 return TemplateArgumentLoc(
4137 SemaRef.Context,
4139 NumExpansions),
4140 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4141 Pattern.getTemplateNameLoc(), EllipsisLoc);
4142
4150 llvm_unreachable("Pack expansion pattern has no parameter packs");
4151
4153 if (TypeSourceInfo *Expansion
4154 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4155 EllipsisLoc,
4156 NumExpansions))
4157 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4158 Expansion);
4159 break;
4160 }
4161
4162 return TemplateArgumentLoc();
4163 }
4164
4165 /// Build a new expression pack expansion.
4166 ///
4167 /// By default, performs semantic analysis to build a new pack expansion
4168 /// for an expression. Subclasses may override this routine to provide
4169 /// different behavior.
4171 UnsignedOrNone NumExpansions) {
4172 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4173 }
4174
4175 /// Build a new C++1z fold-expression.
4176 ///
4177 /// By default, performs semantic analysis in order to build a new fold
4178 /// expression.
4180 SourceLocation LParenLoc, Expr *LHS,
4181 BinaryOperatorKind Operator,
4182 SourceLocation EllipsisLoc, Expr *RHS,
4183 SourceLocation RParenLoc,
4184 UnsignedOrNone NumExpansions) {
4185 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4186 EllipsisLoc, RHS, RParenLoc,
4187 NumExpansions);
4188 }
4189
4191 LambdaScopeInfo *LSI) {
4192 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4193 if (Expr *Init = PVD->getInit())
4195 Init->containsUnexpandedParameterPack();
4196 else if (PVD->hasUninstantiatedDefaultArg())
4198 PVD->getUninstantiatedDefaultArg()
4199 ->containsUnexpandedParameterPack();
4200 }
4201 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4202 }
4203
4204 /// Build an empty C++1z fold-expression with the given operator.
4205 ///
4206 /// By default, produces the fallback value for the fold-expression, or
4207 /// produce an error if there is no fallback value.
4209 BinaryOperatorKind Operator) {
4210 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4211 }
4212
4213 /// Build a new atomic operation expression.
4214 ///
4215 /// By default, performs semantic analysis to build the new expression.
4216 /// Subclasses may override this routine to provide different behavior.
4219 SourceLocation RParenLoc) {
4220 // Use this for all of the locations, since we don't know the difference
4221 // between the call and the expr at this point.
4222 SourceRange Range{BuiltinLoc, RParenLoc};
4223 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4225 }
4226
4228 ArrayRef<Expr *> SubExprs, QualType Type) {
4229 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4230 }
4231
4233 SourceLocation BeginLoc,
4234 SourceLocation DirLoc,
4235 SourceLocation EndLoc,
4237 StmtResult StrBlock) {
4239 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4240 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4241 }
4242
4253
4255 SourceLocation BeginLoc,
4256 SourceLocation DirLoc,
4257 SourceLocation EndLoc,
4259 StmtResult Loop) {
4261 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4262 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4263 }
4264
4266 SourceLocation DirLoc,
4267 SourceLocation EndLoc,
4269 StmtResult StrBlock) {
4271 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4273 Clauses, StrBlock);
4274 }
4275
4285
4295
4297 SourceLocation DirLoc,
4298 SourceLocation EndLoc,
4300 StmtResult StrBlock) {
4304 Clauses, StrBlock);
4305 }
4306
4308 SourceLocation DirLoc,
4309 SourceLocation EndLoc,
4310 ArrayRef<OpenACCClause *> Clauses) {
4312 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4314 Clauses, {});
4315 }
4316
4326
4328 SourceLocation DirLoc,
4329 SourceLocation EndLoc,
4330 ArrayRef<OpenACCClause *> Clauses) {
4332 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4334 Clauses, {});
4335 }
4336
4338 SourceLocation DirLoc,
4339 SourceLocation EndLoc,
4340 ArrayRef<OpenACCClause *> Clauses) {
4342 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4344 Clauses, {});
4345 }
4346
4348 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4349 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4350 SourceLocation RParenLoc, SourceLocation EndLoc,
4351 ArrayRef<OpenACCClause *> Clauses) {
4353 Exprs.push_back(DevNumExpr);
4354 llvm::append_range(Exprs, QueueIdExprs);
4356 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4357 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4358 }
4359
4361 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4362 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4363 SourceLocation RParenLoc, SourceLocation EndLoc) {
4365 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4366 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4367 }
4368
4370 SourceLocation DirLoc,
4371 OpenACCAtomicKind AtKind,
4372 SourceLocation EndLoc,
4374 StmtResult AssociatedStmt) {
4376 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4377 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4378 AssociatedStmt);
4379 }
4380
4384
4386 RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index,
4387 QualType ParamType, SourceLocation Loc,
4388 TemplateArgument Arg,
4389 UnsignedOrNone PackIndex, bool Final) {
4391 AssociatedDecl, Index, ParamType, Loc, Arg, PackIndex, Final);
4392 }
4393
4395 SourceLocation StartLoc,
4396 SourceLocation LParenLoc,
4397 SourceLocation EndLoc) {
4398 return getSema().OpenMP().ActOnOpenMPTransparentClause(ImpexType, StartLoc,
4399 LParenLoc, EndLoc);
4400 }
4401
4402private:
4403 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4404 QualType ObjectType,
4405 NamedDecl *FirstQualifierInScope);
4406
4407 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4408 QualType ObjectType,
4409 NamedDecl *FirstQualifierInScope) {
4410 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4411 return TSInfo;
4412
4413 TypeLocBuilder TLB;
4414 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4415 ObjectType, FirstQualifierInScope);
4416 if (T.isNull())
4417 return nullptr;
4418 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4419 }
4420
4421 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4422 DependentNameTypeLoc TL,
4423 bool DeducibleTSTContext,
4424 QualType ObjectType = QualType(),
4425 NamedDecl *UnqualLookup = nullptr);
4426
4428 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4430
4431 OpenACCClause *
4432 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4433 OpenACCDirectiveKind DirKind,
4434 const OpenACCClause *OldClause);
4435};
4436
4437template <typename Derived>
4439 if (!S)
4440 return S;
4441
4442 switch (S->getStmtClass()) {
4443 case Stmt::NoStmtClass: break;
4444
4445 // Transform individual statement nodes
4446 // Pass SDK into statements that can produce a value
4447#define STMT(Node, Parent) \
4448 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4449#define VALUESTMT(Node, Parent) \
4450 case Stmt::Node##Class: \
4451 return getDerived().Transform##Node(cast<Node>(S), SDK);
4452#define ABSTRACT_STMT(Node)
4453#define EXPR(Node, Parent)
4454#include "clang/AST/StmtNodes.inc"
4455
4456 // Transform expressions by calling TransformExpr.
4457#define STMT(Node, Parent)
4458#define ABSTRACT_STMT(Stmt)
4459#define EXPR(Node, Parent) case Stmt::Node##Class:
4460#include "clang/AST/StmtNodes.inc"
4461 {
4462 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4463
4465 E = getSema().ActOnStmtExprResult(E);
4466 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4467 }
4468 }
4469
4470 return S;
4471}
4472
4473template<typename Derived>
4475 if (!S)
4476 return S;
4477
4478 switch (S->getClauseKind()) {
4479 default: break;
4480 // Transform individual clause nodes
4481#define GEN_CLANG_CLAUSE_CLASS
4482#define CLAUSE_CLASS(Enum, Str, Class) \
4483 case Enum: \
4484 return getDerived().Transform##Class(cast<Class>(S));
4485#include "llvm/Frontend/OpenMP/OMP.inc"
4486 }
4487
4488 return S;
4489}
4490
4491
4492template<typename Derived>
4494 if (!E)
4495 return E;
4496
4497 switch (E->getStmtClass()) {
4498 case Stmt::NoStmtClass: break;
4499#define STMT(Node, Parent) case Stmt::Node##Class: break;
4500#define ABSTRACT_STMT(Stmt)
4501#define EXPR(Node, Parent) \
4502 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4503#include "clang/AST/StmtNodes.inc"
4504 }
4505
4506 return E;
4507}
4508
4509template<typename Derived>
4511 bool NotCopyInit) {
4512 // Initializers are instantiated like expressions, except that various outer
4513 // layers are stripped.
4514 if (!Init)
4515 return Init;
4516
4517 if (auto *FE = dyn_cast<FullExpr>(Init))
4518 Init = FE->getSubExpr();
4519
4520 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4521 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4522 Init = OVE->getSourceExpr();
4523 }
4524
4525 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4526 Init = MTE->getSubExpr();
4527
4528 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4529 Init = Binder->getSubExpr();
4530
4531 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4532 Init = ICE->getSubExprAsWritten();
4533
4534 if (CXXStdInitializerListExpr *ILE =
4535 dyn_cast<CXXStdInitializerListExpr>(Init))
4536 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4537
4538 // If this is copy-initialization, we only need to reconstruct
4539 // InitListExprs. Other forms of copy-initialization will be a no-op if
4540 // the initializer is already the right type.
4541 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4542 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4543 return getDerived().TransformExpr(Init);
4544
4545 // Revert value-initialization back to empty parens.
4546 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4547 SourceRange Parens = VIE->getSourceRange();
4548 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4549 Parens.getEnd());
4550 }
4551
4552 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4554 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4555 SourceLocation());
4556
4557 // Revert initialization by constructor back to a parenthesized or braced list
4558 // of expressions. Any other form of initializer can just be reused directly.
4559 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4560 return getDerived().TransformExpr(Init);
4561
4562 // If the initialization implicitly converted an initializer list to a
4563 // std::initializer_list object, unwrap the std::initializer_list too.
4564 if (Construct && Construct->isStdInitListInitialization())
4565 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4566
4567 // Enter a list-init context if this was list initialization.
4570 Construct->isListInitialization());
4571
4572 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4573 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4574 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4575 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4576 SmallVector<Expr*, 8> NewArgs;
4577 bool ArgChanged = false;
4578 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4579 /*IsCall*/true, NewArgs, &ArgChanged))
4580 return ExprError();
4581
4582 // If this was list initialization, revert to syntactic list form.
4583 if (Construct->isListInitialization())
4584 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4585 Construct->getEndLoc(),
4586 /*IsExplicit=*/true);
4587
4588 // Build a ParenListExpr to represent anything else.
4590 if (Parens.isInvalid()) {
4591 // This was a variable declaration's initialization for which no initializer
4592 // was specified.
4593 assert(NewArgs.empty() &&
4594 "no parens or braces but have direct init with arguments?");
4595 return ExprEmpty();
4596 }
4597 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4598 Parens.getEnd());
4599}
4600
4601template<typename Derived>
4603 unsigned NumInputs,
4604 bool IsCall,
4605 SmallVectorImpl<Expr *> &Outputs,
4606 bool *ArgChanged) {
4607 for (unsigned I = 0; I != NumInputs; ++I) {
4608 // If requested, drop call arguments that need to be dropped.
4609 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4610 if (ArgChanged)
4611 *ArgChanged = true;
4612
4613 break;
4614 }
4615
4616 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4617 Expr *Pattern = Expansion->getPattern();
4618
4620 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4621 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4622
4623 // Determine whether the set of unexpanded parameter packs can and should
4624 // be expanded.
4625 bool Expand = true;
4626 bool RetainExpansion = false;
4627 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4628 UnsignedOrNone NumExpansions = OrigNumExpansions;
4630 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4631 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4632 RetainExpansion, NumExpansions))
4633 return true;
4634
4635 if (!Expand) {
4636 // The transform has determined that we should perform a simple
4637 // transformation on the pack expansion, producing another pack
4638 // expansion.
4639 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4640 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4641 if (OutPattern.isInvalid())
4642 return true;
4643
4644 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4645 Expansion->getEllipsisLoc(),
4646 NumExpansions);
4647 if (Out.isInvalid())
4648 return true;
4649
4650 if (ArgChanged)
4651 *ArgChanged = true;
4652 Outputs.push_back(Out.get());
4653 continue;
4654 }
4655
4656 // Record right away that the argument was changed. This needs
4657 // to happen even if the array expands to nothing.
4658 if (ArgChanged) *ArgChanged = true;
4659
4660 // The transform has determined that we should perform an elementwise
4661 // expansion of the pattern. Do so.
4662 for (unsigned I = 0; I != *NumExpansions; ++I) {
4663 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4664 ExprResult Out = getDerived().TransformExpr(Pattern);
4665 if (Out.isInvalid())
4666 return true;
4667
4668 if (Out.get()->containsUnexpandedParameterPack()) {
4669 Out = getDerived().RebuildPackExpansion(
4670 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4671 if (Out.isInvalid())
4672 return true;
4673 }
4674
4675 Outputs.push_back(Out.get());
4676 }
4677
4678 // If we're supposed to retain a pack expansion, do so by temporarily
4679 // forgetting the partially-substituted parameter pack.
4680 if (RetainExpansion) {
4681 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4682
4683 ExprResult Out = getDerived().TransformExpr(Pattern);
4684 if (Out.isInvalid())
4685 return true;
4686
4687 Out = getDerived().RebuildPackExpansion(
4688 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4689 if (Out.isInvalid())
4690 return true;
4691
4692 Outputs.push_back(Out.get());
4693 }
4694
4695 continue;
4696 }
4697
4699 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4700 : getDerived().TransformExpr(Inputs[I]);
4701 if (Result.isInvalid())
4702 return true;
4703
4704 if (Result.get() != Inputs[I] && ArgChanged)
4705 *ArgChanged = true;
4706
4707 Outputs.push_back(Result.get());
4708 }
4709
4710 return false;
4711}
4712
4713template <typename Derived>
4716
4719 /*LambdaContextDecl=*/nullptr,
4721 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4722
4723 if (Var) {
4724 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4726
4727 if (!ConditionVar)
4728 return Sema::ConditionError();
4729
4730 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4731 }
4732
4733 if (Expr) {
4734 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4735
4736 if (CondExpr.isInvalid())
4737 return Sema::ConditionError();
4738
4739 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4740 /*MissingOK=*/true);
4741 }
4742
4743 return Sema::ConditionResult();
4744}
4745
4746template <typename Derived>
4748 NestedNameSpecifierLoc NNS, QualType ObjectType,
4749 NamedDecl *FirstQualifierInScope) {
4751
4752 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4753 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4754 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4755 Qualifiers.push_back(Qualifier);
4756 };
4757 insertNNS(NNS);
4758
4759 CXXScopeSpec SS;
4760 while (!Qualifiers.empty()) {
4761 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4763
4764 switch (QNNS.getKind()) {
4766 llvm_unreachable("unexpected null nested name specifier");
4767
4770 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4772 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4773 break;
4774 }
4775
4777 // There is no meaningful transformation that one could perform on the
4778 // global scope.
4779 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4780 break;
4781
4783 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4785 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4786 Q.getEndLoc());
4787 break;
4788 }
4789
4791 assert(SS.isEmpty());
4792 TypeLoc TL = Q.castAsTypeLoc();
4793
4794 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4795 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4796 if (QualifierLoc) {
4797 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4798 QualifierLoc, ObjectType, FirstQualifierInScope);
4799 if (!QualifierLoc)
4800 return NestedNameSpecifierLoc();
4801 ObjectType = QualType();
4802 FirstQualifierInScope = nullptr;
4803 }
4804 SS.Adopt(QualifierLoc);
4806 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4807 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4808 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4809 false, SS,
4810 FirstQualifierInScope, false))
4811 return NestedNameSpecifierLoc();
4812 return SS.getWithLocInContext(SemaRef.Context);
4813 }
4814
4815 QualType T = TL.getType();
4816 TypeLocBuilder TLB;
4817 if (!getDerived().AlreadyTransformed(T)) {
4818 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4819 FirstQualifierInScope);
4820 if (T.isNull())
4821 return NestedNameSpecifierLoc();
4822 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4823 }
4824
4825 if (T->isDependentType() || T->isRecordType() ||
4826 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4827 if (T->isEnumeralType())
4828 SemaRef.Diag(TL.getBeginLoc(),
4829 diag::warn_cxx98_compat_enum_nested_name_spec);
4830 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4831 break;
4832 }
4833 // If the nested-name-specifier is an invalid type def, don't emit an
4834 // error because a previous error should have already been emitted.
4836 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4837 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4838 << T << SS.getRange();
4839 }
4840 return NestedNameSpecifierLoc();
4841 }
4842 }
4843 }
4844
4845 // Don't rebuild the nested-name-specifier if we don't have to.
4846 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4848 return NNS;
4849
4850 // If we can re-use the source-location data from the original
4851 // nested-name-specifier, do so.
4852 if (SS.location_size() == NNS.getDataLength() &&
4853 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4855
4856 // Allocate new nested-name-specifier location information.
4857 return SS.getWithLocInContext(SemaRef.Context);
4858}
4859
4860template<typename Derived>
4864 DeclarationName Name = NameInfo.getName();
4865 if (!Name)
4866 return DeclarationNameInfo();
4867
4868 switch (Name.getNameKind()) {
4876 return NameInfo;
4877
4879 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4880 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4881 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4882 if (!NewTemplate)
4883 return DeclarationNameInfo();
4884
4885 DeclarationNameInfo NewNameInfo(NameInfo);
4886 NewNameInfo.setName(
4887 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4888 return NewNameInfo;
4889 }
4890
4894 TypeSourceInfo *NewTInfo;
4895 CanQualType NewCanTy;
4896 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4897 NewTInfo = getDerived().TransformType(OldTInfo);
4898 if (!NewTInfo)
4899 return DeclarationNameInfo();
4900 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4901 }
4902 else {
4903 NewTInfo = nullptr;
4904 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4905 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4906 if (NewT.isNull())
4907 return DeclarationNameInfo();
4908 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4909 }
4910
4911 DeclarationName NewName
4912 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4913 NewCanTy);
4914 DeclarationNameInfo NewNameInfo(NameInfo);
4915 NewNameInfo.setName(NewName);
4916 NewNameInfo.setNamedTypeInfo(NewTInfo);
4917 return NewNameInfo;
4918 }
4919 }
4920
4921 llvm_unreachable("Unknown name kind.");
4922}
4923
4924template <typename Derived>
4926 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4928 QualType ObjectType, bool AllowInjectedClassName) {
4929 if (const IdentifierInfo *II = IO.getIdentifier())
4930 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4931 ObjectType, AllowInjectedClassName);
4932 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4933 NameLoc, ObjectType,
4934 AllowInjectedClassName);
4935}
4936
4937template <typename Derived>
4939 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4940 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4941 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4943 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4944
4945 if (QualifierLoc) {
4946 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4947 QualifierLoc, ObjectType, FirstQualifierInScope);
4948 if (!QualifierLoc)
4949 return TemplateName();
4950 }
4951
4952 NestedNameSpecifierLoc UnderlyingQualifier;
4953 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4954 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4955 FirstQualifierInScope, AllowInjectedClassName);
4956 if (NewUnderlyingName.isNull())
4957 return TemplateName();
4958 assert(!UnderlyingQualifier && "unexpected qualifier");
4959
4960 if (!getDerived().AlwaysRebuild() &&
4961 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4962 NewUnderlyingName == UnderlyingName)
4963 return Name;
4964 CXXScopeSpec SS;
4965 SS.Adopt(QualifierLoc);
4966 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4967 NewUnderlyingName);
4968 }
4969
4971 if (QualifierLoc) {
4972 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4973 QualifierLoc, ObjectType, FirstQualifierInScope);
4974 if (!QualifierLoc)
4975 return TemplateName();
4976 // The qualifier-in-scope and object type only apply to the leftmost
4977 // entity.
4978 ObjectType = QualType();
4979 }
4980
4981 if (!getDerived().AlwaysRebuild() &&
4982 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4983 ObjectType.isNull())
4984 return Name;
4985
4986 CXXScopeSpec SS;
4987 SS.Adopt(QualifierLoc);
4988 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4989 NameLoc, ObjectType,
4990 AllowInjectedClassName);
4991 }
4992
4995 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4996
4997 NestedNameSpecifierLoc ReplacementQualifierLoc;
4998 TemplateName ReplacementName = S->getReplacement();
4999 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
5001 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
5002 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
5003 }
5004
5005 TemplateName NewName = getDerived().TransformTemplateName(
5006 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
5007 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
5008 if (NewName.isNull())
5009 return TemplateName();
5010 Decl *AssociatedDecl =
5011 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
5012 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
5013 AssociatedDecl == S->getAssociatedDecl())
5014 return Name;
5015 return SemaRef.Context.getSubstTemplateTemplateParm(
5016 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
5017 S->getFinal());
5018 }
5019
5021 assert(!QualifierLoc && "Unexpected qualified pack-index-template-name");
5022
5023 ExprResult IndexExpr;
5024 {
5025 EnterExpressionEvaluationContext ConstantContext(
5027 IndexExpr = getDerived().TransformExpr(PI->getIndexExpr());
5028 if (IndexExpr.isInvalid())
5029 return TemplateName();
5030 }
5031
5032 auto TransformOne = [&](TemplateName N) {
5033 NestedNameSpecifierLoc NoQualifier;
5034 return getDerived().TransformTemplateName(
5035 NoQualifier, TemplateKWLoc, N, NameLoc, ObjectType,
5036 FirstQualifierInScope, AllowInjectedClassName);
5037 };
5038
5039 TemplateName Pattern = PI->getPattern();
5040 SmallVector<TemplateName, 4> SubstitutedNames;
5041 ArrayRef<TemplateName> Names = PI->getExpansions();
5042
5043 bool NotYetExpanded = Names.empty();
5044 bool FullySubstituted = true;
5045
5046 if (Names.empty() && !PI->expandsToEmptyPack())
5047 Names = ArrayRef(&Pattern, 1);
5048
5049 for (TemplateName N : Names) {
5050 if (!N.containsUnexpandedParameterPack()) {
5051 TemplateName Transformed = TransformOne(N);
5052 if (Transformed.isNull())
5053 return TemplateName();
5054 SubstitutedNames.push_back(Transformed);
5055 continue;
5056 }
5057
5059 getSema().collectUnexpandedParameterPacks(N, Unexpanded);
5060 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5061
5062 bool ShouldExpand = true;
5063 bool RetainExpansion = false;
5064 UnsignedOrNone NumExpansions = std::nullopt;
5066 NameLoc, SourceRange(), Unexpanded,
5067 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
5068 RetainExpansion, NumExpansions))
5069 return TemplateName();
5070
5071 if (!ShouldExpand) {
5072 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
5073 TemplateName Pack = TransformOne(N);
5074 if (Pack.isNull())
5075 return TemplateName();
5076 if (NotYetExpanded) {
5077 FullySubstituted = false;
5078 return getDerived().RebuildPackIndexingTemplateName(
5079 Pack, IndexExpr.get(), FullySubstituted);
5080 }
5081 SubstitutedNames.push_back(Pack);
5082 continue;
5083 }
5084
5085 for (unsigned I = 0; I != *NumExpansions; ++I) {
5086 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5087 TemplateName Out = TransformOne(N);
5088 if (Out.isNull())
5089 return TemplateName();
5090 SubstitutedNames.push_back(Out);
5091 FullySubstituted &= !Out.containsUnexpandedParameterPack();
5092 }
5093
5094 // If we're supposed to retain a pack expansion, do so by temporarily
5095 // forgetting the partially-substituted parameter pack.
5096 if (RetainExpansion) {
5097 FullySubstituted = false;
5098 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5099 TemplateName Out = TransformOne(N);
5100 if (Out.isNull())
5101 return TemplateName();
5102 SubstitutedNames.push_back(Out);
5103 }
5104 }
5105
5106 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
5107 TemplateName NewPattern = TransformOne(Pattern);
5108 if (NewPattern.isNull())
5109 return TemplateName();
5110
5111 return getDerived().RebuildPackIndexingTemplateName(
5112 NewPattern, IndexExpr.get(), FullySubstituted, SubstitutedNames);
5113 }
5114
5115 assert(!Name.getAsDeducedTemplateName() &&
5116 "DeducedTemplateName should not escape partial ordering");
5117
5118 // FIXME: Preserve UsingTemplateName.
5119 if (auto *Template = Name.getAsTemplateDecl()) {
5120 assert(!QualifierLoc && "Unexpected qualifier");
5121 return TemplateName(cast_or_null<TemplateDecl>(
5122 getDerived().TransformDecl(NameLoc, Template)));
5123 }
5124
5127 assert(!QualifierLoc &&
5128 "Unexpected qualified SubstTemplateTemplateParmPack");
5129 return getDerived().RebuildTemplateName(
5130 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
5131 SubstPack->getIndex(), SubstPack->getFinal());
5132 }
5133
5134 // These should be getting filtered out before they reach the AST.
5135 llvm_unreachable("overloaded function decl survived to here");
5136}
5137
5138template <typename Derived>
5141 SourceLocation NameLoc) {
5142 NestedNameSpecifierLoc QualifierLoc;
5143 return getDerived().TransformTemplateName(
5144 QualifierLoc, /*TemplateKWLoc=*/SourceLocation(), Name, NameLoc);
5145}
5146
5147template <typename Derived>
5149 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
5150 TemplateName Name, SourceLocation NameLoc) {
5151 TemplateName TN = getDerived().TransformTemplateName(
5152 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
5153 if (TN.isNull())
5154 return TemplateArgument();
5155 return TemplateArgument(TN);
5156}
5157
5158template<typename Derived>
5160 const TemplateArgument &Arg,
5161 TemplateArgumentLoc &Output) {
5162 Output = getSema().getTrivialTemplateArgumentLoc(
5163 Arg, QualType(), getDerived().getBaseLocation());
5164}
5165
5166template <typename Derived>
5168 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
5169 bool Uneval) {
5170 const TemplateArgument &Arg = Input.getArgument();
5171 switch (Arg.getKind()) {
5174 llvm_unreachable("Unexpected TemplateArgument");
5175
5180 // Transform a resolved template argument straight to a resolved template
5181 // argument. We get here when substituting into an already-substituted
5182 // template type argument during concept satisfaction checking.
5184 QualType NewT = getDerived().TransformType(T);
5185 if (NewT.isNull())
5186 return true;
5187
5189 ? Arg.getAsDecl()
5190 : nullptr;
5191 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
5193 : nullptr;
5194 if (D && !NewD)
5195 return true;
5196
5197 if (NewT == T && D == NewD)
5198 Output = Input;
5199 else if (Arg.getKind() == TemplateArgument::Integral)
5200 Output = TemplateArgumentLoc(
5201 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
5203 else if (Arg.getKind() == TemplateArgument::NullPtr)
5204 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
5206 else if (Arg.getKind() == TemplateArgument::Declaration)
5207 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
5210 Output = TemplateArgumentLoc(
5211 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
5213 else
5214 llvm_unreachable("unexpected template argument kind");
5215
5216 return false;
5217 }
5218
5220 TypeSourceInfo *TSI = Input.getTypeSourceInfo();
5221 if (!TSI)
5222 TSI = InventTypeSourceInfo(Input.getArgument().getAsType());
5223
5224 TSI = getDerived().TransformType(TSI);
5225 if (!TSI)
5226 return true;
5227
5228 Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI);
5229 return false;
5230 }
5231
5233 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5234
5235 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5236 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5237 Input.getTemplateNameLoc());
5238 if (Out.isNull())
5239 return true;
5240 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5241 QualifierLoc, Input.getTemplateNameLoc());
5242 return false;
5243 }
5244
5246 llvm_unreachable("Caller should expand pack expansions");
5247
5249 // Template argument expressions are constant expressions.
5251 getSema(),
5254 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5256
5257 Expr *InputExpr = Input.getSourceExpression();
5258 if (!InputExpr)
5259 InputExpr = Input.getArgument().getAsExpr();
5260
5261 ExprResult E = getDerived().TransformExpr(InputExpr);
5262 E = SemaRef.ActOnConstantExpression(E);
5263 if (E.isInvalid())
5264 return true;
5265 Output = TemplateArgumentLoc(
5266 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5267 return false;
5268 }
5269 }
5270
5271 // Work around bogus GCC warning
5272 return true;
5273}
5274
5275/// Iterator adaptor that invents template argument location information
5276/// for each of the template arguments in its underlying iterator.
5277template<typename Derived, typename InputIterator>
5280 InputIterator Iter;
5281
5282public:
5285 typedef typename std::iterator_traits<InputIterator>::difference_type
5287 typedef std::input_iterator_tag iterator_category;
5288
5289 class pointer {
5291
5292 public:
5293 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5294
5295 const TemplateArgumentLoc *operator->() const { return &Arg; }
5296 };
5297
5299 InputIterator Iter)
5300 : Self(Self), Iter(Iter) { }
5301
5303 ++Iter;
5304 return *this;
5305 }
5306
5309 ++(*this);
5310 return Old;
5311 }
5312
5315 Self.InventTemplateArgumentLoc(*Iter, Result);
5316 return Result;
5317 }
5318
5319 pointer operator->() const { return pointer(**this); }
5320
5323 return X.Iter == Y.Iter;
5324 }
5325
5328 return X.Iter != Y.Iter;
5329 }
5330};
5331
5332template<typename Derived>
5333template<typename InputIterator>
5335 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5336 bool Uneval) {
5337 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5339 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5340 // Unpack argument packs, which we translate them into separate
5341 // arguments.
5342 // FIXME: We could do much better if we could guarantee that the
5343 // TemplateArgumentLocInfo for the pack expansion would be usable for
5344 // all of the template arguments in the argument pack.
5345 typedef TemplateArgumentLocInventIterator<Derived,
5347 PackLocIterator;
5348
5349 TemplateArgumentListInfo *PackOutput = &Outputs;
5350
5352 PackLocIterator(*this, In.getArgument().pack_begin()),
5353 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5354 Uneval))
5355 return true;
5356
5357 continue;
5358 }
5359
5360 if (In.getArgument().isPackExpansion()) {
5361 UnexpandedInfo Info;
5362 TemplateArgumentLoc Prepared;
5363 if (getDerived().PreparePackForExpansion(In, Uneval, Prepared, Info))
5364 return true;
5365 if (!Info.Expand) {
5366 Outputs.addArgument(Prepared);
5367 continue;
5368 }
5369
5370 // The transform has determined that we should perform an elementwise
5371 // expansion of the pattern. Do so.
5372 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5374 ForgetSubst.emplace(getDerived());
5375 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5376 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5377
5379 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5380 return true;
5381
5382 if (Out.getArgument().containsUnexpandedParameterPack()) {
5383 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5384 Info.OrigNumExpansions);
5385 if (Out.getArgument().isNull())
5386 return true;
5387 }
5388
5389 Outputs.addArgument(Out);
5390 }
5391
5392 // If we're supposed to retain a pack expansion, do so by temporarily
5393 // forgetting the partially-substituted parameter pack.
5394 if (Info.RetainExpansion) {
5395 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5396
5398 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5399 return true;
5400
5401 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5402 Info.OrigNumExpansions);
5403 if (Out.getArgument().isNull())
5404 return true;
5405
5406 Outputs.addArgument(Out);
5407 }
5408
5409 continue;
5410 }
5411
5412 // The simple case:
5413 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5414 return true;
5415
5416 Outputs.addArgument(Out);
5417 }
5418
5419 return false;
5420}
5421
5422template <typename Derived>
5423template <typename InputIterator>
5425 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5426 bool Uneval) {
5427
5428 // [C++26][temp.constr.normal]
5429 // any non-dependent concept template argument
5430 // is substituted into the constraint-expression of C.
5431 auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) {
5432 return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter();
5433 };
5434
5435 for (; First != Last; ++First) {
5438
5439 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5440 typedef TemplateArgumentLocInventIterator<Derived,
5442 PackLocIterator;
5444 PackLocIterator(*this, In.getArgument().pack_begin()),
5445 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5446 Uneval))
5447 return true;
5448 continue;
5449 }
5450
5451 if (!isNonDependentConceptArgument(In.getArgument())) {
5452 Outputs.addArgument(In);
5453 continue;
5454 }
5455
5456 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5457 return true;
5458
5459 Outputs.addArgument(Out);
5460 }
5461
5462 return false;
5463}
5464
5465// FIXME: Find ways to reduce code duplication for pack expansions.
5466template <typename Derived>
5468 bool Uneval,
5470 UnexpandedInfo &Info) {
5471 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5472 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5473 TemplateArgumentLoc &Pattern) {
5474 assert(Arg.getArgument().isPackExpansion());
5475 // We have a pack expansion, for which we will be substituting into the
5476 // pattern.
5477 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5478 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5480 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5481 if (IsLateExpansionAttempt) {
5482 // Request expansion only when there is an opportunity to expand a pack
5483 // that required a substituion first.
5484 bool SawPackTypes =
5485 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5487 });
5488 if (!SawPackTypes) {
5489 Info.Expand = false;
5490 return false;
5491 }
5492 }
5493 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5494
5495 // Determine whether the set of unexpanded parameter packs can and
5496 // should be expanded.
5497 Info.Expand = true;
5498 Info.RetainExpansion = false;
5499 Info.NumExpansions = Info.OrigNumExpansions;
5500 return getDerived().TryExpandParameterPacks(
5501 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5502 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5503 Info.RetainExpansion, Info.NumExpansions);
5504 };
5505
5506 TemplateArgumentLoc Pattern;
5507 if (ComputeInfo(In, false, Info, Pattern))
5508 return true;
5509
5510 if (Info.Expand) {
5511 Out = Pattern;
5512 return false;
5513 }
5514
5515 // The transform has determined that we should perform a simple
5516 // transformation on the pack expansion, producing another pack
5517 // expansion.
5518 TemplateArgumentLoc OutPattern;
5519 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5520 std::in_place, getSema(), std::nullopt);
5521 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5522 return true;
5523
5524 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5525 Info.NumExpansions);
5526 if (Out.getArgument().isNull())
5527 return true;
5528 SubstIndex.reset();
5529
5530 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5531 return false;
5532
5533 // Some packs will learn their length after substitution, e.g.
5534 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5535 // value of `T`.
5536 //
5537 // We only expand after we know sizes of all packs, check if this is the case
5538 // or not. However, we avoid a full template substitution and only do
5539 // expanstions after this point.
5540
5541 // E.g. when substituting template arguments of tuple with {T -> int} in the
5542 // following example:
5543 // template <class T>
5544 // struct TupleWithInt {
5545 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5546 // };
5547 // TupleWithInt<int>::type y;
5548 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5549 // length and run `ComputeInfo()` to provide the necessary information to our
5550 // caller.
5551 //
5552 // Note that we may still have situations where builtin is not going to be
5553 // expanded. For example:
5554 // template <class T>
5555 // struct Foo {
5556 // template <class U> using tuple_with_t =
5557 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5558 // tuple_with_t<short>;
5559 // }
5560 // Because the substitution into `type` happens in dependent context, `type`
5561 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5562 // and the caller will not be able to expand it.
5563 ForgetSubstitutionRAII ForgetSubst(getDerived());
5564 if (ComputeInfo(Out, true, Info, OutPattern))
5565 return true;
5566 if (!Info.Expand)
5567 return false;
5568 Out = OutPattern;
5569 Info.ExpandUnderForgetSubstitions = true;
5570 return false;
5571}
5572
5573//===----------------------------------------------------------------------===//
5574// Type transformation
5575//===----------------------------------------------------------------------===//
5576
5577template<typename Derived>
5580 return T;
5581
5582 // Temporary workaround. All of these transformations should
5583 // eventually turn into transformations on TypeLocs.
5584 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5586
5587 TypeSourceInfo *NewTSI = getDerived().TransformType(TSI);
5588
5589 if (!NewTSI)
5590 return QualType();
5591
5592 return NewTSI->getType();
5593}
5594
5595template <typename Derived>
5597 // Refine the base location to the type's location.
5598 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5601 return TSI;
5602
5603 TypeLocBuilder TLB;
5604
5605 TypeLoc TL = TSI->getTypeLoc();
5606 TLB.reserve(TL.getFullDataSize());
5607
5608 QualType Result = getDerived().TransformType(TLB, TL);
5609 if (Result.isNull())
5610 return nullptr;
5611
5612 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5613}
5614
5615template<typename Derived>
5618 switch (T.getTypeLocClass()) {
5619#define ABSTRACT_TYPELOC(CLASS, PARENT)
5620#define TYPELOC(CLASS, PARENT) \
5621 case TypeLoc::CLASS: \
5622 return getDerived().Transform##CLASS##Type(TLB, \
5623 T.castAs<CLASS##TypeLoc>());
5624#include "clang/AST/TypeLocNodes.def"
5625 }
5626
5627 llvm_unreachable("unhandled type loc!");
5628}
5629
5630template<typename Derived>
5632 if (!isa<DependentNameType>(T))
5633 return TransformType(T);
5634
5636 return T;
5637 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5639 TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI);
5640 return NewTSI ? NewTSI->getType() : QualType();
5641}
5642
5643template <typename Derived>
5646 if (!isa<DependentNameType>(TSI->getType()))
5647 return TransformType(TSI);
5648
5649 // Refine the base location to the type's location.
5650 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5653 return TSI;
5654
5655 TypeLocBuilder TLB;
5656
5657 TypeLoc TL = TSI->getTypeLoc();
5658 TLB.reserve(TL.getFullDataSize());
5659
5660 auto QTL = TL.getAs<QualifiedTypeLoc>();
5661 if (QTL)
5662 TL = QTL.getUnqualifiedLoc();
5663
5664 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5665
5666 QualType Result = getDerived().TransformDependentNameType(
5667 TLB, DNTL, /*DeducedTSTContext*/true);
5668 if (Result.isNull())
5669 return nullptr;
5670
5671 if (QTL) {
5672 Result = getDerived().RebuildQualifiedType(Result, QTL);
5673 if (Result.isNull())
5674 return nullptr;
5676 }
5677
5678 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5679}
5680
5681template<typename Derived>
5684 QualifiedTypeLoc T) {
5686 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5687 auto SuppressObjCLifetime =
5689 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5690 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5691 SuppressObjCLifetime);
5692 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5693 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5694 TLB, STTP, SuppressObjCLifetime);
5695 } else {
5696 Result = getDerived().TransformType(TLB, UnqualTL);
5697 }
5698
5699 if (Result.isNull())
5700 return QualType();
5701
5702 Result = getDerived().RebuildQualifiedType(Result, T);
5703
5704 if (Result.isNull())
5705 return QualType();
5706
5707 // RebuildQualifiedType might have updated the type, but not in a way
5708 // that invalidates the TypeLoc. (There's no location information for
5709 // qualifiers.)
5711
5712 return Result;
5713}
5714
5715template <typename Derived>
5717 QualifiedTypeLoc TL) {
5718
5719 SourceLocation Loc = TL.getBeginLoc();
5720 Qualifiers Quals = TL.getType().getLocalQualifiers();
5721
5722 if ((T.getAddressSpace() != LangAS::Default &&
5723 Quals.getAddressSpace() != LangAS::Default) &&
5724 T.getAddressSpace() != Quals.getAddressSpace()) {
5725 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5726 << TL.getType() << T;
5727 return QualType();
5728 }
5729
5730 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5731 if (LocalPointerAuth.isPresent()) {
5732 if (T.getPointerAuth().isPresent()) {
5733 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5734 return QualType();
5735 }
5736 if (!T->isDependentType()) {
5737 if (!T->isSignableType(SemaRef.getASTContext())) {
5738 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5739 return QualType();
5740 }
5741 }
5742 }
5743 // C++ [dcl.fct]p7:
5744 // [When] adding cv-qualifications on top of the function type [...] the
5745 // cv-qualifiers are ignored.
5746 if (T->isFunctionType()) {
5747 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5748 Quals.getAddressSpace());
5749 return T;
5750 }
5751
5752 // C++ [dcl.ref]p1:
5753 // when the cv-qualifiers are introduced through the use of a typedef-name
5754 // or decltype-specifier [...] the cv-qualifiers are ignored.
5755 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5756 // applied to a reference type.
5757 if (T->isReferenceType()) {
5758 // The only qualifier that applies to a reference type is restrict.
5759 if (!Quals.hasRestrict())
5760 return T;
5762 }
5763
5764 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5765 // resulting type.
5766 if (Quals.hasObjCLifetime()) {
5767 if (!T->isObjCLifetimeType() && !T->isDependentType())
5768 Quals.removeObjCLifetime();
5769 else if (T.getObjCLifetime()) {
5770 // Objective-C ARC:
5771 // A lifetime qualifier applied to a substituted template parameter
5772 // overrides the lifetime qualifier from the template argument.
5773 const AutoType *AutoTy;
5774 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5775 // 'auto' types behave the same way as template parameters.
5776 QualType Deduced = AutoTy->getDeducedType();
5777 Qualifiers Qs = Deduced.getQualifiers();
5778 Qs.removeObjCLifetime();
5779 Deduced =
5780 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5781 T = SemaRef.Context.getAutoType(AutoTy->getDeducedKind(), Deduced,
5782 AutoTy->getKeyword(),
5783 AutoTy->getTypeConstraintConcept(),
5784 AutoTy->getTypeConstraintArguments());
5785 } else {
5786 // Otherwise, complain about the addition of a qualifier to an
5787 // already-qualified type.
5788 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5789 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5790 Quals.removeObjCLifetime();
5791 }
5792 }
5793 }
5794
5795 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5796}
5797
5798template <typename Derived>
5799QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5800 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5801 NamedDecl *FirstQualifierInScope) {
5802 assert(!getDerived().AlreadyTransformed(TL.getType()));
5803
5804 switch (TL.getTypeLocClass()) {
5805 case TypeLoc::TemplateSpecialization:
5806 return getDerived().TransformTemplateSpecializationType(
5807 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5808 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5809 case TypeLoc::DependentName:
5810 return getDerived().TransformDependentNameType(
5811 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5812 ObjectType, FirstQualifierInScope);
5813 default:
5814 // Any dependent canonical type can appear here, through type alias
5815 // templates.
5816 return getDerived().TransformType(TLB, TL);
5817 }
5818}
5819
5820template <class TyLoc> static inline
5822 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5823 NewT.setNameLoc(T.getNameLoc());
5824 return T.getType();
5825}
5826
5827template<typename Derived>
5828QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5829 BuiltinTypeLoc T) {
5830 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5831 NewT.setBuiltinLoc(T.getBuiltinLoc());
5832 if (T.needsExtraLocalData())
5833 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5834 return T.getType();
5835}
5836
5837template<typename Derived>
5839 ComplexTypeLoc T) {
5840 // FIXME: recurse?
5841 return TransformTypeSpecType(TLB, T);
5842}
5843
5844template <typename Derived>
5846 AdjustedTypeLoc TL) {
5847 // Adjustments applied during transformation are handled elsewhere.
5848 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5849}
5850
5851template<typename Derived>
5853 DecayedTypeLoc TL) {
5854 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5855 if (OriginalType.isNull())
5856 return QualType();
5857
5858 QualType Result = TL.getType();
5859 if (getDerived().AlwaysRebuild() ||
5860 OriginalType != TL.getOriginalLoc().getType())
5861 Result = SemaRef.Context.getDecayedType(OriginalType);
5862 TLB.push<DecayedTypeLoc>(Result);
5863 // Nothing to set for DecayedTypeLoc.
5864 return Result;
5865}
5866
5867template <typename Derived>
5871 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5872 if (OriginalType.isNull())
5873 return QualType();
5874
5875 QualType Result = TL.getType();
5876 if (getDerived().AlwaysRebuild() ||
5877 OriginalType != TL.getElementLoc().getType())
5878 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5879 TLB.push<ArrayParameterTypeLoc>(Result);
5880 // Nothing to set for ArrayParameterTypeLoc.
5881 return Result;
5882}
5883
5884template<typename Derived>
5886 PointerTypeLoc TL) {
5887 QualType PointeeType
5888 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5889 if (PointeeType.isNull())
5890 return QualType();
5891
5892 QualType Result = TL.getType();
5893 if (PointeeType->getAs<ObjCObjectType>()) {
5894 // A dependent pointer type 'T *' has is being transformed such
5895 // that an Objective-C class type is being replaced for 'T'. The
5896 // resulting pointer type is an ObjCObjectPointerType, not a
5897 // PointerType.
5898 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5899
5901 NewT.setStarLoc(TL.getStarLoc());
5902 return Result;
5903 }
5904
5905 if (getDerived().AlwaysRebuild() ||
5906 PointeeType != TL.getPointeeLoc().getType()) {
5907 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5908 if (Result.isNull())
5909 return QualType();
5910 }
5911
5912 // Objective-C ARC can add lifetime qualifiers to the type that we're
5913 // pointing to.
5914 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5915
5916 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5917 NewT.setSigilLoc(TL.getSigilLoc());
5918 return Result;
5919}
5920
5921template<typename Derived>
5925 QualType PointeeType
5926 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5927 if (PointeeType.isNull())
5928 return QualType();
5929
5930 QualType Result = TL.getType();
5931 if (getDerived().AlwaysRebuild() ||
5932 PointeeType != TL.getPointeeLoc().getType()) {
5933 Result = getDerived().RebuildBlockPointerType(PointeeType,
5934 TL.getSigilLoc());
5935 if (Result.isNull())
5936 return QualType();
5937 }
5938
5940 NewT.setSigilLoc(TL.getSigilLoc());
5941 return Result;
5942}
5943
5944/// Transforms a reference type. Note that somewhat paradoxically we
5945/// don't care whether the type itself is an l-value type or an r-value
5946/// type; we only care if the type was *written* as an l-value type
5947/// or an r-value type.
5948template<typename Derived>
5951 ReferenceTypeLoc TL) {
5952 const ReferenceType *T = TL.getTypePtr();
5953
5954 // Note that this works with the pointee-as-written.
5955 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5956 if (PointeeType.isNull())
5957 return QualType();
5958
5959 QualType Result = TL.getType();
5960 if (getDerived().AlwaysRebuild() ||
5961 PointeeType != T->getPointeeTypeAsWritten()) {
5962 Result = getDerived().RebuildReferenceType(PointeeType,
5963 T->isSpelledAsLValue(),
5964 TL.getSigilLoc());
5965 if (Result.isNull())
5966 return QualType();
5967 }
5968
5969 // Objective-C ARC can add lifetime qualifiers to the type that we're
5970 // referring to.
5973
5974 // r-value references can be rebuilt as l-value references.
5975 ReferenceTypeLoc NewTL;
5977 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5978 else
5979 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5980 NewTL.setSigilLoc(TL.getSigilLoc());
5981
5982 return Result;
5983}
5984
5985template<typename Derived>
5989 return TransformReferenceType(TLB, TL);
5990}
5991
5992template<typename Derived>
5993QualType
5994TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5995 RValueReferenceTypeLoc TL) {
5996 return TransformReferenceType(TLB, TL);
5997}
5998
5999template<typename Derived>
6003 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6004 if (PointeeType.isNull())
6005 return QualType();
6006
6007 const MemberPointerType *T = TL.getTypePtr();
6008
6009 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
6010 NestedNameSpecifierLoc NewQualifierLoc =
6011 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
6012 if (!NewQualifierLoc)
6013 return QualType();
6014
6015 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
6016 if (OldCls) {
6017 NewCls = cast_or_null<CXXRecordDecl>(
6018 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
6019 if (!NewCls)
6020 return QualType();
6021 }
6022
6023 QualType Result = TL.getType();
6024 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
6025 NewQualifierLoc.getNestedNameSpecifier() !=
6026 OldQualifierLoc.getNestedNameSpecifier() ||
6027 NewCls != OldCls) {
6028 CXXScopeSpec SS;
6029 SS.Adopt(NewQualifierLoc);
6030 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
6031 TL.getStarLoc());
6032 if (Result.isNull())
6033 return QualType();
6034 }
6035
6036 // If we had to adjust the pointee type when building a member pointer, make
6037 // sure to push TypeLoc info for it.
6038 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
6039 if (MPT && PointeeType != MPT->getPointeeType()) {
6040 assert(isa<AdjustedType>(MPT->getPointeeType()));
6041 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
6042 }
6043
6045 NewTL.setSigilLoc(TL.getSigilLoc());
6046 NewTL.setQualifierLoc(NewQualifierLoc);
6047
6048 return Result;
6049}
6050
6051template<typename Derived>
6055 const ConstantArrayType *T = TL.getTypePtr();
6056 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6057 if (ElementType.isNull())
6058 return QualType();
6059
6060 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6061 Expr *OldSize = TL.getSizeExpr();
6062 if (!OldSize)
6063 OldSize = const_cast<Expr*>(T->getSizeExpr());
6064 Expr *NewSize = nullptr;
6065 if (OldSize) {
6068 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
6069 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
6070 }
6071
6072 QualType Result = TL.getType();
6073 if (getDerived().AlwaysRebuild() ||
6074 ElementType != T->getElementType() ||
6075 (T->getSizeExpr() && NewSize != OldSize)) {
6076 Result = getDerived().RebuildConstantArrayType(ElementType,
6077 T->getSizeModifier(),
6078 T->getSize(), NewSize,
6079 T->getIndexTypeCVRQualifiers(),
6080 TL.getBracketsRange());
6081 if (Result.isNull())
6082 return QualType();
6083 }
6084
6085 // We might have either a ConstantArrayType or a VariableArrayType now:
6086 // a ConstantArrayType is allowed to have an element type which is a
6087 // VariableArrayType if the type is dependent. Fortunately, all array
6088 // types have the same location layout.
6089 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6090 NewTL.setLBracketLoc(TL.getLBracketLoc());
6091 NewTL.setRBracketLoc(TL.getRBracketLoc());
6092 NewTL.setSizeExpr(NewSize);
6093
6094 return Result;
6095}
6096
6097template<typename Derived>
6099 TypeLocBuilder &TLB,
6101 const IncompleteArrayType *T = TL.getTypePtr();
6102 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6103 if (ElementType.isNull())
6104 return QualType();
6105
6106 QualType Result = TL.getType();
6107 if (getDerived().AlwaysRebuild() ||
6108 ElementType != T->getElementType()) {
6109 Result = getDerived().RebuildIncompleteArrayType(ElementType,
6110 T->getSizeModifier(),
6111 T->getIndexTypeCVRQualifiers(),
6112 TL.getBracketsRange());
6113 if (Result.isNull())
6114 return QualType();
6115 }
6116
6118 NewTL.setLBracketLoc(TL.getLBracketLoc());
6119 NewTL.setRBracketLoc(TL.getRBracketLoc());
6120 NewTL.setSizeExpr(nullptr);
6121
6122 return Result;
6123}
6124
6125template<typename Derived>
6129 const VariableArrayType *T = TL.getTypePtr();
6130 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6131 if (ElementType.isNull())
6132 return QualType();
6133
6134 ExprResult SizeResult;
6135 {
6138 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
6139 }
6140 if (SizeResult.isInvalid())
6141 return QualType();
6142 SizeResult =
6143 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
6144 if (SizeResult.isInvalid())
6145 return QualType();
6146
6147 Expr *Size = SizeResult.get();
6148
6149 QualType Result = TL.getType();
6150 if (getDerived().AlwaysRebuild() ||
6151 ElementType != T->getElementType() ||
6152 Size != T->getSizeExpr()) {
6153 Result = getDerived().RebuildVariableArrayType(ElementType,
6154 T->getSizeModifier(),
6155 Size,
6156 T->getIndexTypeCVRQualifiers(),
6157 TL.getBracketsRange());
6158 if (Result.isNull())
6159 return QualType();
6160 }
6161
6162 // We might have constant size array now, but fortunately it has the same
6163 // location layout.
6164 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6165 NewTL.setLBracketLoc(TL.getLBracketLoc());
6166 NewTL.setRBracketLoc(TL.getRBracketLoc());
6167 NewTL.setSizeExpr(Size);
6168
6169 return Result;
6170}
6171
6172template<typename Derived>
6176 const DependentSizedArrayType *T = TL.getTypePtr();
6177 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6178 if (ElementType.isNull())
6179 return QualType();
6180
6181 // Array bounds are constant expressions.
6184
6185 // If we have a VLA then it won't be a constant.
6186 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
6187
6188 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6189 Expr *origSize = TL.getSizeExpr();
6190 if (!origSize) origSize = T->getSizeExpr();
6191
6192 ExprResult sizeResult
6193 = getDerived().TransformExpr(origSize);
6194 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
6195 if (sizeResult.isInvalid())
6196 return QualType();
6197
6198 Expr *size = sizeResult.get();
6199
6200 QualType Result = TL.getType();
6201 if (getDerived().AlwaysRebuild() ||
6202 ElementType != T->getElementType() ||
6203 size != origSize) {
6204 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
6205 T->getSizeModifier(),
6206 size,
6207 T->getIndexTypeCVRQualifiers(),
6208 TL.getBracketsRange());
6209 if (Result.isNull())
6210 return QualType();
6211 }
6212
6213 // We might have any sort of array type now, but fortunately they
6214 // all have the same location layout.
6215 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6216 NewTL.setLBracketLoc(TL.getLBracketLoc());
6217 NewTL.setRBracketLoc(TL.getRBracketLoc());
6218 NewTL.setSizeExpr(size);
6219
6220 return Result;
6221}
6222
6223template <typename Derived>
6226 const DependentVectorType *T = TL.getTypePtr();
6227 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6228 if (ElementType.isNull())
6229 return QualType();
6230
6233
6234 Expr *OrigSize = TL.getSizeExpr();
6235 ExprResult Size = getDerived().TransformExpr(OrigSize);
6236 Size = SemaRef.ActOnConstantExpression(Size);
6237 if (Size.isInvalid())
6238 return QualType();
6239
6240 QualType Result = TL.getType();
6241 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6242 Size.get() != OrigSize) {
6243 Result = getDerived().RebuildDependentVectorType(
6244 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
6245 if (Result.isNull())
6246 return QualType();
6247 }
6248
6249 // Result might be dependent or not.
6252 TLB.push<DependentVectorTypeLoc>(Result);
6253 NewTL.setNameLoc(TL.getNameLoc());
6254 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6255 NewTL.setSizeExpr(Size.get());
6256 } else {
6257 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6258 NewTL.setNameLoc(TL.getNameLoc());
6259 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6260 NewTL.setSizeExpr(Size.get());
6261 }
6262
6263 return Result;
6264}
6265
6266template<typename Derived>
6268 TypeLocBuilder &TLB,
6270 const DependentSizedExtVectorType *T = TL.getTypePtr();
6271
6272 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6273 if (ElementType.isNull())
6274 return QualType();
6275
6276 // Vector sizes are constant expressions.
6279
6280 Expr *OrigSize = TL.getSizeExpr();
6281 ExprResult Size = getDerived().TransformExpr(OrigSize);
6282 Size = SemaRef.ActOnConstantExpression(Size);
6283 if (Size.isInvalid())
6284 return QualType();
6285
6286 QualType Result = TL.getType();
6287 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6288 Size.get() != OrigSize) {
6289 Result = getDerived().RebuildDependentSizedExtVectorType(
6290 ElementType, Size.get(), T->getAttributeLoc());
6291 if (Result.isNull())
6292 return QualType();
6293 }
6294
6295 // Result might be dependent or not.
6299 NewTL.setNameLoc(TL.getNameLoc());
6300 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6301 NewTL.setSizeExpr(Size.get());
6302 } else {
6303 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6304 NewTL.setNameLoc(TL.getNameLoc());
6305 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6306 NewTL.setSizeExpr(Size.get());
6307 }
6308
6309 return Result;
6310}
6311
6312template <typename Derived>
6316 const ConstantMatrixType *T = TL.getTypePtr();
6317 QualType ElementType = getDerived().TransformType(T->getElementType());
6318 if (ElementType.isNull())
6319 return QualType();
6320
6321 QualType Result = TL.getType();
6322 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6323 Result = getDerived().RebuildConstantMatrixType(
6324 ElementType, T->getNumRows(), T->getNumColumns(), TL.getAttrNameLoc());
6325 if (Result.isNull())
6326 return QualType();
6327 }
6328
6330 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6331 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6332 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6333 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6334
6335 return Result;
6336}
6337
6338template <typename Derived>
6341 const CooperativeMatrixType *T = TL.getTypePtr();
6342 QualType ElementType = getDerived().TransformType(T->getElementType());
6343 if (ElementType.isNull())
6344 return QualType();
6345
6346 QualType Result = TL.getType();
6347 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6348 Result = getDerived().RebuildCooperativeMatrixType(
6349 ElementType, T->getScope(), T->getNumRows(), T->getNumColumns(),
6350 T->getUse());
6351 if (Result.isNull())
6352 return QualType();
6353 }
6354
6356 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6357 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6358 NewTL.setAttrScopeOperand(TL.getAttrScopeOperand());
6359 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6360 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6361 NewTL.setAttrUseOperand(TL.getAttrUseOperand());
6362
6363 return Result;
6364}
6365
6366template <typename Derived>
6369 const DependentSizedMatrixType *T = TL.getTypePtr();
6370
6371 QualType ElementType = getDerived().TransformType(T->getElementType());
6372 if (ElementType.isNull()) {
6373 return QualType();
6374 }
6375
6376 // Matrix dimensions are constant expressions.
6379
6380 Expr *origRows = TL.getAttrRowOperand();
6381 if (!origRows)
6382 origRows = T->getRowExpr();
6383 Expr *origColumns = TL.getAttrColumnOperand();
6384 if (!origColumns)
6385 origColumns = T->getColumnExpr();
6386
6387 ExprResult rowResult = getDerived().TransformExpr(origRows);
6388 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6389 if (rowResult.isInvalid())
6390 return QualType();
6391
6392 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6393 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6394 if (columnResult.isInvalid())
6395 return QualType();
6396
6397 Expr *rows = rowResult.get();
6398 Expr *columns = columnResult.get();
6399
6400 QualType Result = TL.getType();
6401 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6402 rows != origRows || columns != origColumns) {
6403 Result = getDerived().RebuildDependentSizedMatrixType(
6404 ElementType, rows, columns, T->getAttributeLoc());
6405
6406 if (Result.isNull())
6407 return QualType();
6408 }
6409
6410 // We might have any sort of matrix type now, but fortunately they
6411 // all have the same location layout.
6412 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6413 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6414 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6415 NewTL.setAttrRowOperand(rows);
6416 NewTL.setAttrColumnOperand(columns);
6417 return Result;
6418}
6419
6420template <typename Derived>
6423 const DependentAddressSpaceType *T = TL.getTypePtr();
6424
6426 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6427
6428 if (pointeeType.isNull())
6429 return QualType();
6430
6431 // Address spaces are constant expressions.
6434
6435 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6436 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6437 if (AddrSpace.isInvalid())
6438 return QualType();
6439
6440 QualType Result = TL.getType();
6441 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6442 AddrSpace.get() != T->getAddrSpaceExpr()) {
6443 Result = getDerived().RebuildDependentAddressSpaceType(
6444 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6445 if (Result.isNull())
6446 return QualType();
6447 }
6448
6449 // Result might be dependent or not.
6453
6454 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6455 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6456 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6457
6458 } else {
6459 TLB.TypeWasModifiedSafely(Result);
6460 }
6461
6462 return Result;
6463}
6464
6465template <typename Derived>
6467 VectorTypeLoc TL) {
6468 const VectorType *T = TL.getTypePtr();
6469 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6470 if (ElementType.isNull())
6471 return QualType();
6472
6473 QualType Result = TL.getType();
6474 if (getDerived().AlwaysRebuild() ||
6475 ElementType != T->getElementType()) {
6476 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6477 T->getVectorKind());
6478 if (Result.isNull())
6479 return QualType();
6480 }
6481
6482 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6483 NewTL.setNameLoc(TL.getNameLoc());
6484 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6485 NewTL.setSizeExpr(TL.getSizeExpr());
6486
6487 return Result;
6488}
6489
6490template<typename Derived>
6492 ExtVectorTypeLoc TL) {
6493 const VectorType *T = TL.getTypePtr();
6494 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6495 if (ElementType.isNull())
6496 return QualType();
6497
6498 QualType Result = TL.getType();
6499 if (getDerived().AlwaysRebuild() ||
6500 ElementType != T->getElementType()) {
6501 Result = getDerived().RebuildExtVectorType(ElementType, T->getNumElements(),
6502 TL.getAttrNameLoc());
6503 if (Result.isNull())
6504 return QualType();
6505 }
6506
6507 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6508 NewTL.setNameLoc(TL.getNameLoc());
6509 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6510 NewTL.setSizeExpr(TL.getSizeExpr());
6511
6512 return Result;
6513}
6514
6515template <typename Derived>
6517 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6518 bool ExpectParameterPack) {
6519 TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo();
6520 TypeSourceInfo *NewTSI = nullptr;
6521
6522 if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) {
6523 // If we're substituting into a pack expansion type and we know the
6524 // length we want to expand to, just substitute for the pattern.
6525 TypeLoc OldTL = OldTSI->getTypeLoc();
6526 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6527
6528 TypeLocBuilder TLB;
6529 TypeLoc NewTL = OldTSI->getTypeLoc();
6530 TLB.reserve(NewTL.getFullDataSize());
6531
6532 QualType Result = getDerived().TransformType(TLB,
6533 OldExpansionTL.getPatternLoc());
6534 if (Result.isNull())
6535 return nullptr;
6536
6538 OldExpansionTL.getPatternLoc().getSourceRange(),
6539 OldExpansionTL.getEllipsisLoc(),
6540 NumExpansions);
6541 if (Result.isNull())
6542 return nullptr;
6543
6544 PackExpansionTypeLoc NewExpansionTL
6545 = TLB.push<PackExpansionTypeLoc>(Result);
6546 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6547 NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6548 } else
6549 NewTSI = getDerived().TransformType(OldTSI);
6550 if (!NewTSI)
6551 return nullptr;
6552
6553 if (NewTSI == OldTSI && indexAdjustment == 0)
6554 return OldParm;
6555
6557 SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(),
6558 OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(),
6559 NewTSI, OldParm->getStorageClass(),
6560 /* DefArg */ nullptr);
6561 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6562 OldParm->getFunctionScopeIndex() + indexAdjustment);
6563 getDerived().transformedLocalDecl(OldParm, {newParm});
6564 return newParm;
6565}
6566
6567template <typename Derived>
6570 const QualType *ParamTypes,
6571 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6572 SmallVectorImpl<QualType> &OutParamTypes,
6575 unsigned *LastParamTransformed) {
6576 int indexAdjustment = 0;
6577
6578 unsigned NumParams = Params.size();
6579 for (unsigned i = 0; i != NumParams; ++i) {
6580 if (LastParamTransformed)
6581 *LastParamTransformed = i;
6582 if (ParmVarDecl *OldParm = Params[i]) {
6583 assert(OldParm->getFunctionScopeIndex() == i);
6584
6585 UnsignedOrNone NumExpansions = std::nullopt;
6586 ParmVarDecl *NewParm = nullptr;
6587 if (OldParm->isParameterPack()) {
6588 // We have a function parameter pack that may need to be expanded.
6590
6591 // Find the parameter packs that could be expanded.
6592 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6594 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6595 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6596
6597 // Determine whether we should expand the parameter packs.
6598 bool ShouldExpand = false;
6599 bool RetainExpansion = false;
6600 UnsignedOrNone OrigNumExpansions = std::nullopt;
6601 if (Unexpanded.size() > 0) {
6602 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6603 NumExpansions = OrigNumExpansions;
6605 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6606 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6607 ShouldExpand, RetainExpansion, NumExpansions)) {
6608 return true;
6609 }
6610 } else {
6611#ifndef NDEBUG
6612 const AutoType *AT =
6613 Pattern.getType().getTypePtr()->getContainedAutoType();
6614 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6615 "Could not find parameter packs or undeduced auto type!");
6616#endif
6617 }
6618
6619 if (ShouldExpand) {
6620 // Expand the function parameter pack into multiple, separate
6621 // parameters.
6622 getDerived().ExpandingFunctionParameterPack(OldParm);
6623 for (unsigned I = 0; I != *NumExpansions; ++I) {
6624 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6625 ParmVarDecl *NewParm
6626 = getDerived().TransformFunctionTypeParam(OldParm,
6627 indexAdjustment++,
6628 OrigNumExpansions,
6629 /*ExpectParameterPack=*/false);
6630 if (!NewParm)
6631 return true;
6632
6633 if (ParamInfos)
6634 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6635 OutParamTypes.push_back(NewParm->getType());
6636 if (PVars)
6637 PVars->push_back(NewParm);
6638 }
6639
6640 // If we're supposed to retain a pack expansion, do so by temporarily
6641 // forgetting the partially-substituted parameter pack.
6642 if (RetainExpansion) {
6643 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6644 ParmVarDecl *NewParm
6645 = getDerived().TransformFunctionTypeParam(OldParm,
6646 indexAdjustment++,
6647 OrigNumExpansions,
6648 /*ExpectParameterPack=*/false);
6649 if (!NewParm)
6650 return true;
6651
6652 if (ParamInfos)
6653 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6654 OutParamTypes.push_back(NewParm->getType());
6655 if (PVars)
6656 PVars->push_back(NewParm);
6657 }
6658
6659 // The next parameter should have the same adjustment as the
6660 // last thing we pushed, but we post-incremented indexAdjustment
6661 // on every push. Also, if we push nothing, the adjustment should
6662 // go down by one.
6663 indexAdjustment--;
6664
6665 // We're done with the pack expansion.
6666 continue;
6667 }
6668
6669 // We'll substitute the parameter now without expanding the pack
6670 // expansion.
6671 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6672 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6673 indexAdjustment,
6674 NumExpansions,
6675 /*ExpectParameterPack=*/true);
6676 assert(NewParm->isParameterPack() &&
6677 "Parameter pack no longer a parameter pack after "
6678 "transformation.");
6679 } else {
6680 NewParm = getDerived().TransformFunctionTypeParam(
6681 OldParm, indexAdjustment, std::nullopt,
6682 /*ExpectParameterPack=*/false);
6683 }
6684
6685 if (!NewParm)
6686 return true;
6687
6688 if (ParamInfos)
6689 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6690 OutParamTypes.push_back(NewParm->getType());
6691 if (PVars)
6692 PVars->push_back(NewParm);
6693 continue;
6694 }
6695
6696 // Deal with the possibility that we don't have a parameter
6697 // declaration for this parameter.
6698 assert(ParamTypes);
6699 QualType OldType = ParamTypes[i];
6700 bool IsPackExpansion = false;
6701 UnsignedOrNone NumExpansions = std::nullopt;
6702 QualType NewType;
6703 if (const PackExpansionType *Expansion
6704 = dyn_cast<PackExpansionType>(OldType)) {
6705 // We have a function parameter pack that may need to be expanded.
6706 QualType Pattern = Expansion->getPattern();
6708 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6709
6710 // Determine whether we should expand the parameter packs.
6711 bool ShouldExpand = false;
6712 bool RetainExpansion = false;
6714 Loc, SourceRange(), Unexpanded,
6715 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6716 RetainExpansion, NumExpansions)) {
6717 return true;
6718 }
6719
6720 if (ShouldExpand) {
6721 // Expand the function parameter pack into multiple, separate
6722 // parameters.
6723 for (unsigned I = 0; I != *NumExpansions; ++I) {
6724 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6725 QualType NewType = getDerived().TransformType(Pattern);
6726 if (NewType.isNull())
6727 return true;
6728
6729 if (NewType->containsUnexpandedParameterPack()) {
6730 NewType = getSema().getASTContext().getPackExpansionType(
6731 NewType, std::nullopt);
6732
6733 if (NewType.isNull())
6734 return true;
6735 }
6736
6737 if (ParamInfos)
6738 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6739 OutParamTypes.push_back(NewType);
6740 if (PVars)
6741 PVars->push_back(nullptr);
6742 }
6743
6744 // We're done with the pack expansion.
6745 continue;
6746 }
6747
6748 // If we're supposed to retain a pack expansion, do so by temporarily
6749 // forgetting the partially-substituted parameter pack.
6750 if (RetainExpansion) {
6751 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6752 QualType NewType = getDerived().TransformType(Pattern);
6753 if (NewType.isNull())
6754 return true;
6755
6756 if (ParamInfos)
6757 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6758 OutParamTypes.push_back(NewType);
6759 if (PVars)
6760 PVars->push_back(nullptr);
6761 }
6762
6763 // We'll substitute the parameter now without expanding the pack
6764 // expansion.
6765 OldType = Expansion->getPattern();
6766 IsPackExpansion = true;
6767 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6768 NewType = getDerived().TransformType(OldType);
6769 } else {
6770 NewType = getDerived().TransformType(OldType);
6771 }
6772
6773 if (NewType.isNull())
6774 return true;
6775
6776 if (IsPackExpansion)
6777 NewType = getSema().Context.getPackExpansionType(NewType,
6778 NumExpansions);
6779
6780 if (ParamInfos)
6781 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6782 OutParamTypes.push_back(NewType);
6783 if (PVars)
6784 PVars->push_back(nullptr);
6785 }
6786
6787#ifndef NDEBUG
6788 if (PVars) {
6789 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6790 if (ParmVarDecl *parm = (*PVars)[i])
6791 assert(parm->getFunctionScopeIndex() == i);
6792 }
6793#endif
6794
6795 return false;
6796}
6797
6798template<typename Derived>
6802 SmallVector<QualType, 4> ExceptionStorage;
6803 return getDerived().TransformFunctionProtoType(
6804 TLB, TL, nullptr, Qualifiers(),
6805 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6806 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6807 ExceptionStorage, Changed);
6808 });
6809}
6810
6811template<typename Derived> template<typename Fn>
6813 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6814 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6815
6816 // Transform the parameters and return type.
6817 //
6818 // We are required to instantiate the params and return type in source order.
6819 // When the function has a trailing return type, we instantiate the
6820 // parameters before the return type, since the return type can then refer
6821 // to the parameters themselves (via decltype, sizeof, etc.).
6822 //
6823 SmallVector<QualType, 4> ParamTypes;
6825 Sema::ExtParameterInfoBuilder ExtParamInfos;
6826 const FunctionProtoType *T = TL.getTypePtr();
6827
6828 QualType ResultType;
6829
6830 if (T->hasTrailingReturn()) {
6832 TL.getBeginLoc(), TL.getParams(),
6834 T->getExtParameterInfosOrNull(),
6835 ParamTypes, &ParamDecls, ExtParamInfos))
6836 return QualType();
6837
6838 {
6839 // C++11 [expr.prim.general]p3:
6840 // If a declaration declares a member function or member function
6841 // template of a class X, the expression this is a prvalue of type
6842 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6843 // and the end of the function-definition, member-declarator, or
6844 // declarator.
6845 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6846 Sema::CXXThisScopeRAII ThisScope(
6847 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6848
6849 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6850 if (ResultType.isNull())
6851 return QualType();
6852 }
6853 }
6854 else {
6855 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6856 if (ResultType.isNull())
6857 return QualType();
6858
6860 TL.getBeginLoc(), TL.getParams(),
6862 T->getExtParameterInfosOrNull(),
6863 ParamTypes, &ParamDecls, ExtParamInfos))
6864 return QualType();
6865 }
6866
6867 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6868
6869 bool EPIChanged = false;
6870 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6871 return QualType();
6872
6873 // Handle extended parameter information.
6874 if (auto NewExtParamInfos =
6875 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6876 if (!EPI.ExtParameterInfos ||
6878 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6879 EPIChanged = true;
6880 }
6881 EPI.ExtParameterInfos = NewExtParamInfos;
6882 } else if (EPI.ExtParameterInfos) {
6883 EPIChanged = true;
6884 EPI.ExtParameterInfos = nullptr;
6885 }
6886
6887 // Transform any function effects with unevaluated conditions.
6888 // Hold this set in a local for the rest of this function, since EPI
6889 // may need to hold a FunctionEffectsRef pointing into it.
6890 std::optional<FunctionEffectSet> NewFX;
6891 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6892 NewFX.emplace();
6895
6896 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6897 FunctionEffectWithCondition NewEC = PrevEC;
6898 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6899 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6900 if (NewExpr.isInvalid())
6901 return QualType();
6902 std::optional<FunctionEffectMode> Mode =
6903 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6904 if (!Mode)
6905 return QualType();
6906
6907 // The condition expression has been transformed, and re-evaluated.
6908 // It may or may not have become constant.
6909 switch (*Mode) {
6911 NewEC.Cond = {};
6912 break;
6914 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6915 NewEC.Cond = {};
6916 break;
6918 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6919 break;
6921 llvm_unreachable(
6922 "FunctionEffectMode::None shouldn't be possible here");
6923 }
6924 }
6925 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6926 TL.getBeginLoc())) {
6928 NewFX->insert(NewEC, Errs);
6929 assert(Errs.empty());
6930 }
6931 }
6932 EPI.FunctionEffects = *NewFX;
6933 EPIChanged = true;
6934 }
6935
6936 QualType Result = TL.getType();
6937 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6938 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6939 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6940 if (Result.isNull())
6941 return QualType();
6942 }
6943
6946 NewTL.setLParenLoc(TL.getLParenLoc());
6947 NewTL.setRParenLoc(TL.getRParenLoc());
6950 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6951 NewTL.setParam(i, ParamDecls[i]);
6952
6953 return Result;
6954}
6955
6956template<typename Derived>
6959 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6960 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6961
6962 // Instantiate a dynamic noexcept expression, if any.
6963 if (isComputedNoexcept(ESI.Type)) {
6964 // Update this scrope because ContextDecl in Sema will be used in
6965 // TransformExpr.
6966 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6967 Sema::CXXThisScopeRAII ThisScope(
6968 SemaRef, Method ? Method->getParent() : nullptr,
6969 Method ? Method->getMethodQualifiers() : Qualifiers{},
6970 Method != nullptr);
6973 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6974 if (NoexceptExpr.isInvalid())
6975 return true;
6976
6978 NoexceptExpr =
6979 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6980 if (NoexceptExpr.isInvalid())
6981 return true;
6982
6983 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6984 Changed = true;
6985 ESI.NoexceptExpr = NoexceptExpr.get();
6986 ESI.Type = EST;
6987 }
6988
6989 if (ESI.Type != EST_Dynamic)
6990 return false;
6991
6992 // Instantiate a dynamic exception specification's type.
6993 for (QualType T : ESI.Exceptions) {
6994 if (const PackExpansionType *PackExpansion =
6995 T->getAs<PackExpansionType>()) {
6996 Changed = true;
6997
6998 // We have a pack expansion. Instantiate it.
7000 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7001 Unexpanded);
7002 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7003
7004 // Determine whether the set of unexpanded parameter packs can and
7005 // should
7006 // be expanded.
7007 bool Expand = false;
7008 bool RetainExpansion = false;
7009 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7010 // FIXME: Track the location of the ellipsis (and track source location
7011 // information for the types in the exception specification in general).
7013 Loc, SourceRange(), Unexpanded,
7014 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
7015 NumExpansions))
7016 return true;
7017
7018 if (!Expand) {
7019 // We can't expand this pack expansion into separate arguments yet;
7020 // just substitute into the pattern and create a new pack expansion
7021 // type.
7022 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7023 QualType U = getDerived().TransformType(PackExpansion->getPattern());
7024 if (U.isNull())
7025 return true;
7026
7027 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
7028 Exceptions.push_back(U);
7029 continue;
7030 }
7031
7032 // Substitute into the pack expansion pattern for each slice of the
7033 // pack.
7034 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7035 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
7036
7037 QualType U = getDerived().TransformType(PackExpansion->getPattern());
7038 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
7039 return true;
7040
7041 Exceptions.push_back(U);
7042 }
7043 } else {
7044 QualType U = getDerived().TransformType(T);
7045 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
7046 return true;
7047 if (T != U)
7048 Changed = true;
7049
7050 Exceptions.push_back(U);
7051 }
7052 }
7053
7054 ESI.Exceptions = Exceptions;
7055 if (ESI.Exceptions.empty())
7056 ESI.Type = EST_DynamicNone;
7057 return false;
7058}
7059
7060template<typename Derived>
7062 TypeLocBuilder &TLB,
7064 const FunctionNoProtoType *T = TL.getTypePtr();
7065 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
7066 if (ResultType.isNull())
7067 return QualType();
7068
7069 QualType Result = TL.getType();
7070 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
7071 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
7072
7075 NewTL.setLParenLoc(TL.getLParenLoc());
7076 NewTL.setRParenLoc(TL.getRParenLoc());
7078
7079 return Result;
7080}
7081
7082template <typename Derived>
7083QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
7084 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
7085
7086 const UnresolvedUsingType *T = TL.getTypePtr();
7087 bool Changed = false;
7088
7089 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7090 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7091 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7092 if (!QualifierLoc)
7093 return QualType();
7094 Changed |= QualifierLoc != OldQualifierLoc;
7095 }
7096
7097 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
7098 if (!D)
7099 return QualType();
7100 Changed |= D != T->getDecl();
7101
7102 QualType Result = TL.getType();
7103 if (getDerived().AlwaysRebuild() || Changed) {
7104 Result = getDerived().RebuildUnresolvedUsingType(
7105 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
7106 D);
7107 if (Result.isNull())
7108 return QualType();
7109 }
7110
7112 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7113 QualifierLoc, TL.getNameLoc());
7114 else
7115 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7116 QualifierLoc, TL.getNameLoc());
7117 return Result;
7118}
7119
7120template <typename Derived>
7122 UsingTypeLoc TL) {
7123 const UsingType *T = TL.getTypePtr();
7124 bool Changed = false;
7125
7126 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7127 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7128 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7129 if (!QualifierLoc)
7130 return QualType();
7131 Changed |= QualifierLoc != OldQualifierLoc;
7132 }
7133
7134 auto *D = cast_or_null<UsingShadowDecl>(
7135 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7136 if (!D)
7137 return QualType();
7138 Changed |= D != T->getDecl();
7139
7140 QualType UnderlyingType = getDerived().TransformType(T->desugar());
7141 if (UnderlyingType.isNull())
7142 return QualType();
7143 Changed |= UnderlyingType != T->desugar();
7144
7145 QualType Result = TL.getType();
7146 if (getDerived().AlwaysRebuild() || Changed) {
7147 Result = getDerived().RebuildUsingType(
7148 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
7149 UnderlyingType);
7150 if (Result.isNull())
7151 return QualType();
7152 }
7153 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
7154 TL.getNameLoc());
7155 return Result;
7156}
7157
7158template<typename Derived>
7160 TypedefTypeLoc TL) {
7161 const TypedefType *T = TL.getTypePtr();
7162 bool Changed = false;
7163
7164 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7165 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7166 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7167 if (!QualifierLoc)
7168 return QualType();
7169 Changed |= QualifierLoc != OldQualifierLoc;
7170 }
7171
7172 auto *Typedef = cast_or_null<TypedefNameDecl>(
7173 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7174 if (!Typedef)
7175 return QualType();
7176 Changed |= Typedef != T->getDecl();
7177
7178 // FIXME: Transform the UnderlyingType if different from decl.
7179
7180 QualType Result = TL.getType();
7181 if (getDerived().AlwaysRebuild() || Changed) {
7182 Result = getDerived().RebuildTypedefType(
7183 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
7184 if (Result.isNull())
7185 return QualType();
7186 }
7187
7188 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7189 QualifierLoc, TL.getNameLoc());
7190 return Result;
7191}
7192
7193template<typename Derived>
7195 TypeOfExprTypeLoc TL) {
7196 // typeof expressions are not potentially evaluated contexts
7200
7201 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
7202 if (E.isInvalid())
7203 return QualType();
7204
7205 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
7206 if (E.isInvalid())
7207 return QualType();
7208
7209 QualType Result = TL.getType();
7211 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
7212 Result =
7213 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
7214 if (Result.isNull())
7215 return QualType();
7216 }
7217
7218 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
7219 NewTL.setTypeofLoc(TL.getTypeofLoc());
7220 NewTL.setLParenLoc(TL.getLParenLoc());
7221 NewTL.setRParenLoc(TL.getRParenLoc());
7222
7223 return Result;
7224}
7225
7226template<typename Derived>
7228 TypeOfTypeLoc TL) {
7229 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
7230 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
7231 if (!New_Under_TI)
7232 return QualType();
7233
7234 QualType Result = TL.getType();
7235 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
7236 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
7237 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
7238 if (Result.isNull())
7239 return QualType();
7240 }
7241
7242 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
7243 NewTL.setTypeofLoc(TL.getTypeofLoc());
7244 NewTL.setLParenLoc(TL.getLParenLoc());
7245 NewTL.setRParenLoc(TL.getRParenLoc());
7246 NewTL.setUnmodifiedTInfo(New_Under_TI);
7247
7248 return Result;
7249}
7250
7251template<typename Derived>
7253 DecltypeTypeLoc TL) {
7254 const DecltypeType *T = TL.getTypePtr();
7255
7256 // decltype expressions are not potentially evaluated contexts
7260
7261 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
7262 if (E.isInvalid())
7263 return QualType();
7264
7265 E = getSema().ActOnDecltypeExpression(E.get());
7266 if (E.isInvalid())
7267 return QualType();
7268
7269 QualType Result = TL.getType();
7270 if (getDerived().AlwaysRebuild() ||
7271 E.get() != T->getUnderlyingExpr()) {
7272 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
7273 if (Result.isNull())
7274 return QualType();
7275 }
7276 else E.get();
7277
7278 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
7279 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
7280 NewTL.setRParenLoc(TL.getRParenLoc());
7281 return Result;
7282}
7283
7284template <typename Derived>
7288 // Transform the index
7289 ExprResult IndexExpr;
7290 {
7291 EnterExpressionEvaluationContext ConstantContext(
7293
7294 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
7295 if (IndexExpr.isInvalid())
7296 return QualType();
7297 }
7298 QualType Pattern = TL.getPattern();
7299
7300 const PackIndexingType *PIT = TL.getTypePtr();
7301 SmallVector<QualType, 5> SubtitutedTypes;
7302 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
7303
7304 bool NotYetExpanded = Types.empty();
7305 bool FullySubstituted = true;
7306
7307 if (Types.empty() && !PIT->expandsToEmptyPack())
7308 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7309
7310 for (QualType T : Types) {
7311 if (!T->containsUnexpandedParameterPack()) {
7312 QualType Transformed = getDerived().TransformType(T);
7313 if (Transformed.isNull())
7314 return QualType();
7315 SubtitutedTypes.push_back(Transformed);
7316 continue;
7317 }
7318
7320 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7321 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7322 // Determine whether the set of unexpanded parameter packs can and should
7323 // be expanded.
7324 bool ShouldExpand = true;
7325 bool RetainExpansion = false;
7326 UnsignedOrNone NumExpansions = std::nullopt;
7327 if (getDerived().TryExpandParameterPacks(
7328 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7329 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7330 RetainExpansion, NumExpansions))
7331 return QualType();
7332 if (!ShouldExpand) {
7333 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7334 // FIXME: should we keep TypeLoc for individual expansions in
7335 // PackIndexingTypeLoc?
7336 TypeSourceInfo *TI =
7337 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7338 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7339 if (Pack.isNull())
7340 return QualType();
7341 if (NotYetExpanded) {
7342 FullySubstituted = false;
7343 QualType Out = getDerived().RebuildPackIndexingType(
7344 Pack, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted);
7345 if (Out.isNull())
7346 return QualType();
7347
7349 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7350 return Out;
7351 }
7352 SubtitutedTypes.push_back(Pack);
7353 continue;
7354 }
7355 for (unsigned I = 0; I != *NumExpansions; ++I) {
7356 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7357 QualType Out = getDerived().TransformType(T);
7358 if (Out.isNull())
7359 return QualType();
7360 SubtitutedTypes.push_back(Out);
7361 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7362 }
7363 // If we're supposed to retain a pack expansion, do so by temporarily
7364 // forgetting the partially-substituted parameter pack.
7365 if (RetainExpansion) {
7366 FullySubstituted = false;
7367 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7368 QualType Out = getDerived().TransformType(T);
7369 if (Out.isNull())
7370 return QualType();
7371 SubtitutedTypes.push_back(Out);
7372 }
7373 }
7374
7375 // A pack indexing type can appear in a larger pack expansion,
7376 // e.g. `Pack...[pack_of_indexes]...`
7377 // so we need to temporarily disable substitution of pack elements
7378 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7379 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7380
7381 QualType Out = getDerived().RebuildPackIndexingType(
7382 Result, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted,
7383 SubtitutedTypes);
7384 if (Out.isNull())
7385 return Out;
7386
7388 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7389 return Out;
7390}
7391
7392template<typename Derived>
7394 TypeLocBuilder &TLB,
7396 QualType Result = TL.getType();
7397 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7398 if (Result->isDependentType()) {
7399 const UnaryTransformType *T = TL.getTypePtr();
7400
7401 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7402 if (!NewBaseTSI)
7403 return QualType();
7404 QualType NewBase = NewBaseTSI->getType();
7405
7406 Result = getDerived().RebuildUnaryTransformType(NewBase,
7407 T->getUTTKind(),
7408 TL.getKWLoc());
7409 if (Result.isNull())
7410 return QualType();
7411 }
7412
7414 NewTL.setKWLoc(TL.getKWLoc());
7415 NewTL.setParensRange(TL.getParensRange());
7416 NewTL.setUnderlyingTInfo(NewBaseTSI);
7417 return Result;
7418}
7419
7420template<typename Derived>
7423 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7424
7425 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7426 TemplateName TemplateName = getDerived().TransformTemplateName(
7427 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7428 TL.getTemplateNameLoc());
7429 if (TemplateName.isNull())
7430 return QualType();
7431
7432 QualType OldDeduced = T->getDeducedType();
7433 QualType NewDeduced;
7434 if (!OldDeduced.isNull()) {
7435 NewDeduced = getDerived().TransformType(OldDeduced);
7436 if (NewDeduced.isNull())
7437 return QualType();
7438 }
7439
7440 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7441 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7442 NewDeduced, T->getKeyword(), TemplateName);
7443 if (Result.isNull())
7444 return QualType();
7445
7446 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7447 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7448 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7449 NewTL.setQualifierLoc(QualifierLoc);
7450 return Result;
7451}
7452
7453template <typename Derived>
7455 TagTypeLoc TL) {
7456 const TagType *T = TL.getTypePtr();
7457
7458 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7459 if (QualifierLoc) {
7460 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7461 if (!QualifierLoc)
7462 return QualType();
7463 }
7464
7465 auto *TD = cast_or_null<TagDecl>(
7466 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7467 if (!TD)
7468 return QualType();
7469
7470 QualType Result = TL.getType();
7471 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7472 TD != T->getDecl()) {
7473 if (T->isCanonicalUnqualified())
7474 Result = getDerived().RebuildCanonicalTagType(TD);
7475 else
7476 Result = getDerived().RebuildTagType(
7477 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7478 if (Result.isNull())
7479 return QualType();
7480 }
7481
7482 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7484 NewTL.setQualifierLoc(QualifierLoc);
7485 NewTL.setNameLoc(TL.getNameLoc());
7486
7487 return Result;
7488}
7489
7490template <typename Derived>
7492 EnumTypeLoc TL) {
7493 return getDerived().TransformTagType(TLB, TL);
7494}
7495
7496template <typename Derived>
7497QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7498 RecordTypeLoc TL) {
7499 return getDerived().TransformTagType(TLB, TL);
7500}
7501
7502template<typename Derived>
7504 TypeLocBuilder &TLB,
7506 return getDerived().TransformTagType(TLB, TL);
7507}
7508
7509template<typename Derived>
7511 TypeLocBuilder &TLB,
7513 return getDerived().TransformTemplateTypeParmType(
7514 TLB, TL,
7515 /*SuppressObjCLifetime=*/false);
7516}
7517
7518template <typename Derived>
7520 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7521 return TransformTypeSpecType(TLB, TL);
7522}
7523
7524template<typename Derived>
7525QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7526 TypeLocBuilder &TLB,
7527 SubstTemplateTypeParmTypeLoc TL) {
7528 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7529
7530 Decl *NewReplaced =
7531 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7532
7533 // Substitute into the replacement type, which itself might involve something
7534 // that needs to be transformed. This only tends to occur with default
7535 // template arguments of template template parameters.
7536 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7537 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7538 if (Replacement.isNull())
7539 return QualType();
7540
7541 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7542 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7543 T->getFinal());
7544
7545 // Propagate type-source information.
7546 SubstTemplateTypeParmTypeLoc NewTL
7547 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7548 NewTL.setNameLoc(TL.getNameLoc());
7549 return Result;
7550
7551}
7552template <typename Derived>
7555 return TransformTypeSpecType(TLB, TL);
7556}
7557
7558template<typename Derived>
7560 TypeLocBuilder &TLB,
7562 return getDerived().TransformSubstTemplateTypeParmPackType(
7563 TLB, TL, /*SuppressObjCLifetime=*/false);
7564}
7565
7566template <typename Derived>
7569 return TransformTypeSpecType(TLB, TL);
7570}
7571
7572template<typename Derived>
7573QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7574 AtomicTypeLoc TL) {
7575 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7576 if (ValueType.isNull())
7577 return QualType();
7578
7579 QualType Result = TL.getType();
7580 if (getDerived().AlwaysRebuild() ||
7581 ValueType != TL.getValueLoc().getType()) {
7582 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7583 if (Result.isNull())
7584 return QualType();
7585 }
7586
7587 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7588 NewTL.setKWLoc(TL.getKWLoc());
7589 NewTL.setLParenLoc(TL.getLParenLoc());
7590 NewTL.setRParenLoc(TL.getRParenLoc());
7591
7592 return Result;
7593}
7594
7595template <typename Derived>
7597 PipeTypeLoc TL) {
7598 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7599 if (ValueType.isNull())
7600 return QualType();
7601
7602 QualType Result = TL.getType();
7603 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7604 const PipeType *PT = Result->castAs<PipeType>();
7605 bool isReadPipe = PT->isReadOnly();
7606 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7607 if (Result.isNull())
7608 return QualType();
7609 }
7610
7611 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7612 NewTL.setKWLoc(TL.getKWLoc());
7613
7614 return Result;
7615}
7616
7617template <typename Derived>
7619 BitIntTypeLoc TL) {
7620 const BitIntType *EIT = TL.getTypePtr();
7621 QualType Result = TL.getType();
7622
7623 if (getDerived().AlwaysRebuild()) {
7624 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7625 EIT->getNumBits(), TL.getNameLoc());
7626 if (Result.isNull())
7627 return QualType();
7628 }
7629
7630 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7631 NewTL.setNameLoc(TL.getNameLoc());
7632 return Result;
7633}
7634
7635template <typename Derived>
7638 const DependentBitIntType *EIT = TL.getTypePtr();
7639
7642 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7643 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7644
7645 if (BitsExpr.isInvalid())
7646 return QualType();
7647
7648 QualType Result = TL.getType();
7649
7650 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7651 Result = getDerived().RebuildDependentBitIntType(
7652 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7653
7654 if (Result.isNull())
7655 return QualType();
7656 }
7657
7660 NewTL.setNameLoc(TL.getNameLoc());
7661 } else {
7662 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7663 NewTL.setNameLoc(TL.getNameLoc());
7664 }
7665 return Result;
7666}
7667
7668template <typename Derived>
7671 llvm_unreachable("This type does not need to be transformed.");
7672}
7673
7674 /// Simple iterator that traverses the template arguments in a
7675 /// container that provides a \c getArgLoc() member function.
7676 ///
7677 /// This iterator is intended to be used with the iterator form of
7678 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7679 template<typename ArgLocContainer>
7681 ArgLocContainer *Container;
7682 unsigned Index;
7683
7684 public:
7687 typedef int difference_type;
7688 typedef std::input_iterator_tag iterator_category;
7689
7690 class pointer {
7692
7693 public:
7694 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7695
7697 return &Arg;
7698 }
7699 };
7700
7701
7703
7704 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7705 unsigned Index)
7706 : Container(&Container), Index(Index) { }
7707
7709 ++Index;
7710 return *this;
7711 }
7712
7715 ++(*this);
7716 return Old;
7717 }
7718
7720 return Container->getArgLoc(Index);
7721 }
7722
7724 return pointer(Container->getArgLoc(Index));
7725 }
7726
7729 return X.Container == Y.Container && X.Index == Y.Index;
7730 }
7731
7734 return !(X == Y);
7735 }
7736 };
7737
7738template<typename Derived>
7739QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7740 AutoTypeLoc TL) {
7741 const AutoType *T = TL.getTypePtr();
7742 QualType OldDeduced = T->getDeducedType();
7743 QualType NewDeduced;
7744 if (!OldDeduced.isNull()) {
7745 NewDeduced = getDerived().TransformType(OldDeduced);
7746 if (NewDeduced.isNull())
7747 return QualType();
7748 }
7749
7750 TemplateName NewCD;
7751 TemplateArgumentListInfo NewTemplateArgs;
7752 NestedNameSpecifierLoc NewNestedNameSpec;
7753 if (T->isConstrained()) {
7754 assert(TL.getConceptReference());
7755 NewCD = getDerived().TransformConceptTemplateName(
7756 T->getTypeConstraintConcept(), TL.getConceptNameLoc());
7757 if (NewCD.isNull())
7758 return QualType();
7759
7760 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7761 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7763 if (getDerived().TransformTemplateArguments(
7764 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7765 NewTemplateArgs))
7766 return QualType();
7767
7768 if (TL.getNestedNameSpecifierLoc()) {
7769 NewNestedNameSpec
7770 = getDerived().TransformNestedNameSpecifierLoc(
7771 TL.getNestedNameSpecifierLoc());
7772 if (!NewNestedNameSpec)
7773 return QualType();
7774 }
7775 }
7776
7777 QualType Result = TL.getType();
7778 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7779 T->isDependentType() || T->isConstrained()) {
7780 // FIXME: Maybe don't rebuild if all template arguments are the same.
7782 NewArgList.reserve(NewTemplateArgs.size());
7783 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7784 NewArgList.push_back(ArgLoc.getArgument());
7785 Result = getDerived().RebuildAutoType(
7786 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7787 NewDeduced, T->getKeyword(), NewCD, NewArgList);
7788 if (Result.isNull())
7789 return QualType();
7790 }
7791
7792 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7793 NewTL.setNameLoc(TL.getNameLoc());
7794 NewTL.setRParenLoc(TL.getRParenLoc());
7795 NewTL.setConceptReference(nullptr);
7796
7797 if (T->isConstrained()) {
7798 DeclarationName ConceptName =
7799 SemaRef.Context
7800 .getNameForTemplate(TL.getTypePtr()->getTypeConstraintConcept(),
7801 TL.getConceptNameLoc())
7802 .getName();
7804 DeclarationNameInfo(ConceptName, TL.getConceptNameLoc(), ConceptName);
7805 auto *CR = ConceptReference::Create(
7806 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7807 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7808 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7809 NewTL.setConceptReference(CR);
7810 }
7811
7812 return Result;
7813}
7814
7815template <typename Derived>
7818 return getDerived().TransformTemplateSpecializationType(
7819 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7820 /*AllowInjectedClassName=*/false);
7821}
7822
7823template <typename Derived>
7826 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7827 const TemplateSpecializationType *T = TL.getTypePtr();
7828
7829 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7830 TemplateName Template = getDerived().TransformTemplateName(
7831 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7832 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7833 AllowInjectedClassName);
7834 if (Template.isNull())
7835 return QualType();
7836
7837 TemplateArgumentListInfo NewTemplateArgs;
7838 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7839 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7841 ArgIterator;
7842 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7843 ArgIterator(TL, TL.getNumArgs()),
7844 NewTemplateArgs))
7845 return QualType();
7846
7847 // This needs to be rebuilt if either the arguments changed, or if the
7848 // original template changed. If the template changed, and even if the
7849 // arguments didn't change, these arguments might not correspond to their
7850 // respective parameters, therefore needing conversions.
7851 QualType Result = getDerived().RebuildTemplateSpecializationType(
7852 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7853 NewTemplateArgs);
7854
7855 if (!Result.isNull()) {
7857 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7858 TL.getTemplateNameLoc(), NewTemplateArgs);
7859 }
7860
7861 return Result;
7862}
7863
7864template <typename Derived>
7866 AttributedTypeLoc TL) {
7867 const AttributedType *oldType = TL.getTypePtr();
7868 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7869 if (modifiedType.isNull())
7870 return QualType();
7871
7872 // HLSL: re-validate matrix-layout markers after substitution. If the
7873 // post-substitution type is no longer a matrix, diagnose now.
7874 if (SemaRef.getLangOpts().HLSL &&
7876 oldType->getAttrKind(), modifiedType,
7877 TL.getAttr() ? TL.getAttr()->getLocation()
7878 : TL.getModifiedLoc().getBeginLoc()))
7879 return QualType();
7880
7881 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7882 const Attr *oldAttr = TL.getAttr();
7883 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7884 if (oldAttr && !newAttr)
7885 return QualType();
7886
7887 QualType result = TL.getType();
7888
7889 // FIXME: dependent operand expressions?
7890 if (getDerived().AlwaysRebuild() ||
7891 modifiedType != oldType->getModifiedType()) {
7892 // If the equivalent type is equal to the modified type, we don't want to
7893 // transform it as well because:
7894 //
7895 // 1. The transformation would yield the same result and is therefore
7896 // superfluous, and
7897 //
7898 // 2. Transforming the same type twice can cause problems, e.g. if it
7899 // is a FunctionProtoType, we may end up instantiating the function
7900 // parameters twice, which causes an assertion since the parameters
7901 // are already bound to their counterparts in the template for this
7902 // instantiation.
7903 //
7904 QualType equivalentType = modifiedType;
7905 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7906 TypeLocBuilder AuxiliaryTLB;
7907 AuxiliaryTLB.reserve(TL.getFullDataSize());
7908 equivalentType =
7909 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7910 if (equivalentType.isNull())
7911 return QualType();
7912 }
7913
7914 if (SemaRef.getLangOpts().HLSL) {
7915 if (oldType->getAttrKind() == attr::HLSLRowMajor)
7916 equivalentType = SemaRef.Context.getMatrixTypeWithLayout(
7917 equivalentType, MatrixType::LayoutKind::RowMajor);
7918 else if (oldType->getAttrKind() == attr::HLSLColumnMajor)
7919 equivalentType = SemaRef.Context.getMatrixTypeWithLayout(
7920 equivalentType, MatrixType::LayoutKind::ColumnMajor);
7921 }
7922
7923 // Check whether we can add nullability; it is only represented as
7924 // type sugar, and therefore cannot be diagnosed in any other way.
7925 if (auto nullability = oldType->getImmediateNullability()) {
7926 if (!modifiedType->canHaveNullability()) {
7927 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7928 : TL.getModifiedLoc().getBeginLoc()),
7929 diag::err_nullability_nonpointer)
7930 << DiagNullabilityKind(*nullability, false) << modifiedType;
7931 return QualType();
7932 }
7933 }
7934
7935 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7936 modifiedType,
7937 equivalentType,
7938 TL.getAttr());
7939 }
7940
7941 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7942 newTL.setAttr(newAttr);
7943 return result;
7944}
7945
7946template <typename Derived>
7949 const CountAttributedType *OldTy = TL.getTypePtr();
7950 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7951 if (InnerTy.isNull())
7952 return QualType();
7953
7954 Expr *OldCount = TL.getCountExpr();
7955 Expr *NewCount = nullptr;
7956 if (OldCount) {
7957 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7958 if (CountResult.isInvalid())
7959 return QualType();
7960 NewCount = CountResult.get();
7961 }
7962
7963 QualType Result = TL.getType();
7964 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7965 OldCount != NewCount) {
7966 // Currently, CountAttributedType can only wrap incomplete array types.
7968 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7969 }
7970
7971 TLB.push<CountAttributedTypeLoc>(Result);
7972 return Result;
7973}
7974
7975template <typename Derived>
7979 const LateParsedAttrType *OldTy = TL.getTypePtr();
7980 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7981 if (InnerTy.isNull())
7982 return QualType();
7983
7984 QualType Result = TL.getType();
7985 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getWrappedType()) {
7987 InnerTy, OldTy->getLateParsedAttribute());
7988 }
7989
7991 newTL.setAttrNameLoc(TL.getAttrNameLoc());
7992 return Result;
7993}
7994
7995template <typename Derived>
7998 // The BTFTagAttributedType is available for C only.
7999 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
8000}
8001
8002template <typename Derived>
8005 const OverflowBehaviorType *OldTy = TL.getTypePtr();
8006 QualType InnerTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
8007 if (InnerTy.isNull())
8008 return QualType();
8009
8010 QualType Result = TL.getType();
8011 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getUnderlyingType()) {
8012 Result = SemaRef.Context.getOverflowBehaviorType(OldTy->getBehaviorKind(),
8013 InnerTy);
8014 if (Result.isNull())
8015 return QualType();
8016 }
8017
8019 NewTL.initializeLocal(SemaRef.Context, TL.getAttrLoc());
8020 return Result;
8021}
8022
8023template <typename Derived>
8026
8027 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
8028
8029 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
8030 if (WrappedTy.isNull())
8031 return QualType();
8032
8033 QualType ContainedTy = QualType();
8034 QualType OldContainedTy = oldType->getContainedType();
8035 TypeSourceInfo *ContainedTSI = nullptr;
8036 if (!OldContainedTy.isNull()) {
8037 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
8038 if (!oldContainedTSI)
8039 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
8040 OldContainedTy, SourceLocation());
8041 ContainedTSI = getDerived().TransformType(oldContainedTSI);
8042 if (!ContainedTSI)
8043 return QualType();
8044 ContainedTy = ContainedTSI->getType();
8045 }
8046
8047 HLSLAttributedResourceType::Attributes Attrs = oldType->getAttrs();
8048 if (Attrs.SampleCountExpr) {
8049 ExprResult SampleCountResult =
8050 getDerived().TransformExpr(Attrs.SampleCountExpr);
8051 if (SampleCountResult.isInvalid())
8052 return QualType();
8053 Attrs.SampleCountExpr = SampleCountResult.get();
8054 }
8055
8056 QualType Result = TL.getType();
8057 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
8058 ContainedTy != oldType->getContainedType() ||
8059 Attrs.SampleCountExpr != oldType->getSampleCountExpr()) {
8060 Result = SemaRef.Context.getHLSLAttributedResourceType(WrappedTy,
8061 ContainedTy, Attrs);
8062 }
8063
8066 NewTL.setSourceRange(TL.getLocalSourceRange());
8067 NewTL.setContainedTypeSourceInfo(ContainedTSI);
8068 return Result;
8069}
8070
8071template <typename Derived>
8074 // No transformations needed.
8075 return TL.getType();
8076}
8077
8078template<typename Derived>
8081 ParenTypeLoc TL) {
8082 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
8083 if (Inner.isNull())
8084 return QualType();
8085
8086 QualType Result = TL.getType();
8087 if (getDerived().AlwaysRebuild() ||
8088 Inner != TL.getInnerLoc().getType()) {
8089 Result = getDerived().RebuildParenType(Inner);
8090 if (Result.isNull())
8091 return QualType();
8092 }
8093
8094 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
8095 NewTL.setLParenLoc(TL.getLParenLoc());
8096 NewTL.setRParenLoc(TL.getRParenLoc());
8097 return Result;
8098}
8099
8100template <typename Derived>
8104 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
8105 if (Inner.isNull())
8106 return QualType();
8107
8108 QualType Result = TL.getType();
8109 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
8110 Result =
8111 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
8112 if (Result.isNull())
8113 return QualType();
8114 }
8115
8117 NewTL.setExpansionLoc(TL.getExpansionLoc());
8118 return Result;
8119}
8120
8121template<typename Derived>
8122QualType TreeTransform<Derived>::TransformDependentNameType(
8124 return TransformDependentNameType(TLB, TL, false);
8125}
8126
8127template <typename Derived>
8128QualType TreeTransform<Derived>::TransformDependentNameType(
8129 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
8130 QualType ObjectType, NamedDecl *UnqualLookup) {
8131 const DependentNameType *T = TL.getTypePtr();
8132
8133 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
8134 if (QualifierLoc) {
8135 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
8136 QualifierLoc, ObjectType, UnqualLookup);
8137 if (!QualifierLoc)
8138 return QualType();
8139 } else {
8140 assert((ObjectType.isNull() && !UnqualLookup) &&
8141 "must be transformed by TransformNestedNameSpecifierLoc");
8142 }
8143
8145 = getDerived().RebuildDependentNameType(T->getKeyword(),
8146 TL.getElaboratedKeywordLoc(),
8147 QualifierLoc,
8148 T->getIdentifier(),
8149 TL.getNameLoc(),
8150 DeducedTSTContext);
8151 if (Result.isNull())
8152 return QualType();
8153
8154 if (isa<TagType>(Result)) {
8155 auto NewTL = TLB.push<TagTypeLoc>(Result);
8156 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8157 NewTL.setQualifierLoc(QualifierLoc);
8158 NewTL.setNameLoc(TL.getNameLoc());
8160 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
8161 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8162 NewTL.setTemplateNameLoc(TL.getNameLoc());
8163 NewTL.setQualifierLoc(QualifierLoc);
8164 } else if (isa<TypedefType>(Result)) {
8165 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
8166 QualifierLoc, TL.getNameLoc());
8167 } else if (isa<UnresolvedUsingType>(Result)) {
8168 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
8169 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
8170 } else {
8171 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
8172 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8173 NewTL.setQualifierLoc(QualifierLoc);
8174 NewTL.setNameLoc(TL.getNameLoc());
8175 }
8176 return Result;
8177}
8178
8179template<typename Derived>
8182 QualType Pattern
8183 = getDerived().TransformType(TLB, TL.getPatternLoc());
8184 if (Pattern.isNull())
8185 return QualType();
8186
8187 QualType Result = TL.getType();
8188 if (getDerived().AlwaysRebuild() ||
8189 Pattern != TL.getPatternLoc().getType()) {
8190 Result = getDerived().RebuildPackExpansionType(Pattern,
8191 TL.getPatternLoc().getSourceRange(),
8192 TL.getEllipsisLoc(),
8193 TL.getTypePtr()->getNumExpansions());
8194 if (Result.isNull())
8195 return QualType();
8196 }
8197
8199 NewT.setEllipsisLoc(TL.getEllipsisLoc());
8200 return Result;
8201}
8202
8203template<typename Derived>
8207 // ObjCInterfaceType is never dependent.
8208 TLB.pushFullCopy(TL);
8209 return TL.getType();
8210}
8211
8212template<typename Derived>
8216 const ObjCTypeParamType *T = TL.getTypePtr();
8217 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
8218 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
8219 if (!OTP)
8220 return QualType();
8221
8222 QualType Result = TL.getType();
8223 if (getDerived().AlwaysRebuild() ||
8224 OTP != T->getDecl()) {
8225 Result = getDerived().RebuildObjCTypeParamType(
8226 OTP, TL.getProtocolLAngleLoc(),
8227 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8228 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8229 if (Result.isNull())
8230 return QualType();
8231 }
8232
8234 if (TL.getNumProtocols()) {
8235 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8236 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8237 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
8238 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8239 }
8240 return Result;
8241}
8242
8243template<typename Derived>
8246 ObjCObjectTypeLoc TL) {
8247 // Transform base type.
8248 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
8249 if (BaseType.isNull())
8250 return QualType();
8251
8252 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
8253
8254 // Transform type arguments.
8255 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
8256 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
8257 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
8258 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
8259 QualType TypeArg = TypeArgInfo->getType();
8260 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
8261 AnyChanged = true;
8262
8263 // We have a pack expansion. Instantiate it.
8264 const auto *PackExpansion = PackExpansionLoc.getType()
8265 ->castAs<PackExpansionType>();
8267 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
8268 Unexpanded);
8269 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8270
8271 // Determine whether the set of unexpanded parameter packs can
8272 // and should be expanded.
8273 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
8274 bool Expand = false;
8275 bool RetainExpansion = false;
8276 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
8277 if (getDerived().TryExpandParameterPacks(
8278 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
8279 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
8280 RetainExpansion, NumExpansions))
8281 return QualType();
8282
8283 if (!Expand) {
8284 // We can't expand this pack expansion into separate arguments yet;
8285 // just substitute into the pattern and create a new pack expansion
8286 // type.
8287 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
8288
8289 TypeLocBuilder TypeArgBuilder;
8290 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8291 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
8292 PatternLoc);
8293 if (NewPatternType.isNull())
8294 return QualType();
8295
8296 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
8297 NewPatternType, NumExpansions);
8298 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
8299 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
8300 NewTypeArgInfos.push_back(
8301 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
8302 continue;
8303 }
8304
8305 // Substitute into the pack expansion pattern for each slice of the
8306 // pack.
8307 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
8308 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
8309
8310 TypeLocBuilder TypeArgBuilder;
8311 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8312
8313 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
8314 PatternLoc);
8315 if (NewTypeArg.isNull())
8316 return QualType();
8317
8318 NewTypeArgInfos.push_back(
8319 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8320 }
8321
8322 continue;
8323 }
8324
8325 TypeLocBuilder TypeArgBuilder;
8326 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
8327 QualType NewTypeArg =
8328 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
8329 if (NewTypeArg.isNull())
8330 return QualType();
8331
8332 // If nothing changed, just keep the old TypeSourceInfo.
8333 if (NewTypeArg == TypeArg) {
8334 NewTypeArgInfos.push_back(TypeArgInfo);
8335 continue;
8336 }
8337
8338 NewTypeArgInfos.push_back(
8339 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8340 AnyChanged = true;
8341 }
8342
8343 QualType Result = TL.getType();
8344 if (getDerived().AlwaysRebuild() || AnyChanged) {
8345 // Rebuild the type.
8346 Result = getDerived().RebuildObjCObjectType(
8347 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8348 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8349 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8350 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8351
8352 if (Result.isNull())
8353 return QualType();
8354 }
8355
8356 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8357 NewT.setHasBaseTypeAsWritten(true);
8358 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8359 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8360 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8361 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8362 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8363 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8364 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8365 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8366 return Result;
8367}
8368
8369template<typename Derived>
8373 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8374 if (PointeeType.isNull())
8375 return QualType();
8376
8377 QualType Result = TL.getType();
8378 if (getDerived().AlwaysRebuild() ||
8379 PointeeType != TL.getPointeeLoc().getType()) {
8380 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8381 TL.getStarLoc());
8382 if (Result.isNull())
8383 return QualType();
8384 }
8385
8387 NewT.setStarLoc(TL.getStarLoc());
8388 return Result;
8389}
8390
8391//===----------------------------------------------------------------------===//
8392// Statement transformation
8393//===----------------------------------------------------------------------===//
8394template<typename Derived>
8397 return S;
8398}
8399
8400template<typename Derived>
8403 return getDerived().TransformCompoundStmt(S, false);
8404}
8405
8406template<typename Derived>
8409 bool IsStmtExpr) {
8410 Sema::CompoundScopeRAII CompoundScope(getSema());
8411 Sema::FPFeaturesStateRAII FPSave(getSema());
8412 if (S->hasStoredFPFeatures())
8413 getSema().resetFPOptions(
8414 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8415
8416 bool SubStmtInvalid = false;
8417 bool SubStmtChanged = false;
8418 SmallVector<Stmt*, 8> Statements;
8419 for (auto *B : S->body()) {
8420 StmtResult Result = getDerived().TransformStmt(
8421 B, IsStmtExpr && B == S->body_back() ? StmtDiscardKind::StmtExprResult
8422 : StmtDiscardKind::Discarded);
8423
8424 if (Result.isInvalid()) {
8425 // Immediately fail if this was a DeclStmt, since it's very
8426 // likely that this will cause problems for future statements.
8427 if (isa<DeclStmt>(B))
8428 return StmtError();
8429
8430 // Otherwise, just keep processing substatements and fail later.
8431 SubStmtInvalid = true;
8432 continue;
8433 }
8434
8435 SubStmtChanged = SubStmtChanged || Result.get() != B;
8436 Statements.push_back(Result.getAs<Stmt>());
8437 }
8438
8439 if (SubStmtInvalid)
8440 return StmtError();
8441
8442 if (!getDerived().AlwaysRebuild() &&
8443 !SubStmtChanged)
8444 return S;
8445
8446 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8447 Statements,
8448 S->getRBracLoc(),
8449 IsStmtExpr);
8450}
8451
8452template<typename Derived>
8455 ExprResult LHS, RHS;
8456 {
8459
8460 // Transform the left-hand case value.
8461 LHS = getDerived().TransformExpr(S->getLHS());
8462 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8463 if (LHS.isInvalid())
8464 return StmtError();
8465
8466 // Transform the right-hand case value (for the GNU case-range extension).
8467 RHS = getDerived().TransformExpr(S->getRHS());
8468 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8469 if (RHS.isInvalid())
8470 return StmtError();
8471 }
8472
8473 // Build the case statement.
8474 // Case statements are always rebuilt so that they will attached to their
8475 // transformed switch statement.
8476 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8477 LHS.get(),
8478 S->getEllipsisLoc(),
8479 RHS.get(),
8480 S->getColonLoc());
8481 if (Case.isInvalid())
8482 return StmtError();
8483
8484 // Transform the statement following the case
8485 StmtResult SubStmt =
8486 getDerived().TransformStmt(S->getSubStmt());
8487 if (SubStmt.isInvalid())
8488 return StmtError();
8489
8490 // Attach the body to the case statement
8491 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8492}
8493
8494template <typename Derived>
8496 // Transform the statement following the default case
8497 StmtResult SubStmt =
8498 getDerived().TransformStmt(S->getSubStmt());
8499 if (SubStmt.isInvalid())
8500 return StmtError();
8501
8502 // Default statements are always rebuilt
8503 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8504 SubStmt.get());
8505}
8506
8507template<typename Derived>
8510 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8511 if (SubStmt.isInvalid())
8512 return StmtError();
8513
8514 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8515 S->getDecl());
8516 if (!LD)
8517 return StmtError();
8518
8519 // If we're transforming "in-place" (we're not creating new local
8520 // declarations), assume we're replacing the old label statement
8521 // and clear out the reference to it.
8522 if (LD == S->getDecl())
8523 S->getDecl()->setStmt(nullptr);
8524
8525 // FIXME: Pass the real colon location in.
8526 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8528 SubStmt.get());
8529}
8530
8531template <typename Derived>
8533 if (!R)
8534 return R;
8535
8536 switch (R->getKind()) {
8537// Transform attributes by calling TransformXXXAttr.
8538#define ATTR(X) \
8539 case attr::X: \
8540 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8541#include "clang/Basic/AttrList.inc"
8542 }
8543 return R;
8544}
8545
8546template <typename Derived>
8548 const Stmt *InstS,
8549 const Attr *R) {
8550 if (!R)
8551 return R;
8552
8553 switch (R->getKind()) {
8554// Transform attributes by calling TransformStmtXXXAttr.
8555#define ATTR(X) \
8556 case attr::X: \
8557 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8558#include "clang/Basic/AttrList.inc"
8559 }
8560 return TransformAttr(R);
8561}
8562
8563template <typename Derived>
8566 StmtDiscardKind SDK) {
8567 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8568 if (SubStmt.isInvalid())
8569 return StmtError();
8570
8571 bool AttrsChanged = false;
8573
8574 // Visit attributes and keep track if any are transformed.
8575 for (const auto *I : S->getAttrs()) {
8576 const Attr *R =
8577 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8578 AttrsChanged |= (I != R);
8579 if (R)
8580 Attrs.push_back(R);
8581 }
8582
8583 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8584 return S;
8585
8586 // If transforming the attributes failed for all of the attributes in the
8587 // statement, don't make an AttributedStmt without attributes.
8588 if (Attrs.empty())
8589 return SubStmt;
8590
8591 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8592 SubStmt.get());
8593}
8594
8595template<typename Derived>
8598 // Transform the initialization statement
8599 StmtResult Init = getDerived().TransformStmt(S->getInit());
8600 if (Init.isInvalid())
8601 return StmtError();
8602
8604 if (!S->isConsteval()) {
8605 // Transform the condition
8606 Cond = getDerived().TransformCondition(
8607 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8608 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8610 if (Cond.isInvalid())
8611 return StmtError();
8612 }
8613
8614 // If this is a constexpr if, determine which arm we should instantiate.
8615 std::optional<bool> ConstexprConditionValue;
8616 if (S->isConstexpr())
8617 ConstexprConditionValue = Cond.getKnownValue();
8618
8619 // Transform the "then" branch.
8620 StmtResult Then;
8621 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8625 S->isNonNegatedConsteval());
8626
8627 Then = getDerived().TransformStmt(S->getThen());
8628 if (Then.isInvalid())
8629 return StmtError();
8630 } else {
8631 // Discarded branch is replaced with empty CompoundStmt so we can keep
8632 // proper source location for start and end of original branch, so
8633 // subsequent transformations like CoverageMapping work properly
8634 Then = new (getSema().Context)
8635 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8636 }
8637
8638 // Transform the "else" branch.
8639 StmtResult Else;
8640 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8644 S->isNegatedConsteval());
8645
8646 Else = getDerived().TransformStmt(S->getElse());
8647 if (Else.isInvalid())
8648 return StmtError();
8649 } else if (S->getElse() && ConstexprConditionValue &&
8650 *ConstexprConditionValue) {
8651 // Same thing here as with <then> branch, we are discarding it, we can't
8652 // replace it with NULL nor NullStmt as we need to keep for source location
8653 // range, for CoverageMapping
8654 Else = new (getSema().Context)
8655 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8656 }
8657
8658 if (!getDerived().AlwaysRebuild() &&
8659 Init.get() == S->getInit() &&
8660 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8661 Then.get() == S->getThen() &&
8662 Else.get() == S->getElse())
8663 return S;
8664
8665 return getDerived().RebuildIfStmt(
8666 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8667 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8668}
8669
8670template<typename Derived>
8673 // Transform the initialization statement
8674 StmtResult Init = getDerived().TransformStmt(S->getInit());
8675 if (Init.isInvalid())
8676 return StmtError();
8677
8678 // Transform the condition.
8679 Sema::ConditionResult Cond = getDerived().TransformCondition(
8680 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8682 if (Cond.isInvalid())
8683 return StmtError();
8684
8685 // Rebuild the switch statement.
8687 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8688 Init.get(), Cond, S->getRParenLoc());
8689 if (Switch.isInvalid())
8690 return StmtError();
8691
8692 // Transform the body of the switch statement.
8693 StmtResult Body = getDerived().TransformStmt(S->getBody());
8694
8695 // Complete the switch statement.
8696 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8697 Body.get());
8698}
8699
8700template<typename Derived>
8703 // Transform the condition
8704 Sema::ConditionResult Cond = getDerived().TransformCondition(
8705 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8707 if (Cond.isInvalid())
8708 return StmtError();
8709
8710 // OpenACC Restricts a while-loop inside of certain construct/clause
8711 // combinations, so diagnose that here in OpenACC mode.
8713 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8714
8715 // Transform the body
8716 StmtResult Body = getDerived().TransformStmt(S->getBody());
8717 if (Body.isInvalid())
8718 return StmtError();
8719
8720 if (!getDerived().AlwaysRebuild() &&
8721 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8722 Body.get() == S->getBody())
8723 return Owned(S);
8724
8725 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8726 Cond, S->getRParenLoc(), Body.get());
8727}
8728
8729template<typename Derived>
8732 // OpenACC Restricts a do-loop inside of certain construct/clause
8733 // combinations, so diagnose that here in OpenACC mode.
8735 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8736
8737 // Transform the body
8738 StmtResult Body = getDerived().TransformStmt(S->getBody());
8739 if (Body.isInvalid())
8740 return StmtError();
8741
8742 // Transform the condition
8743 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8744 if (Cond.isInvalid())
8745 return StmtError();
8746
8747 if (!getDerived().AlwaysRebuild() &&
8748 Cond.get() == S->getCond() &&
8749 Body.get() == S->getBody())
8750 return S;
8751
8752 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8753 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8754 S->getRParenLoc());
8755}
8756
8757template<typename Derived>
8760 if (getSema().getLangOpts().getOpenMPVersion())
8761 getSema().OpenMP().startOpenMPLoop();
8762
8763 // Transform the initialization statement
8764 StmtResult Init = getDerived().TransformStmt(S->getInit());
8765 if (Init.isInvalid())
8766 return StmtError();
8767
8768 // In OpenMP loop region loop control variable must be captured and be
8769 // private. Perform analysis of first part (if any).
8770 if (getSema().getLangOpts().getOpenMPVersion() && Init.isUsable())
8771 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8772 Init.get());
8773
8774 // Transform the condition
8775 Sema::ConditionResult Cond = getDerived().TransformCondition(
8776 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8778 if (Cond.isInvalid())
8779 return StmtError();
8780
8781 // Transform the increment
8782 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8783 if (Inc.isInvalid())
8784 return StmtError();
8785
8786 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8787 if (S->getInc() && !FullInc.get())
8788 return StmtError();
8789
8790 // OpenACC Restricts a for-loop inside of certain construct/clause
8791 // combinations, so diagnose that here in OpenACC mode.
8793 SemaRef.OpenACC().ActOnForStmtBegin(
8794 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8795 Cond.get().second, S->getInc(), Inc.get());
8796
8797 // Transform the body
8798 StmtResult Body = getDerived().TransformStmt(S->getBody());
8799 if (Body.isInvalid())
8800 return StmtError();
8801
8802 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8803
8804 if (!getDerived().AlwaysRebuild() &&
8805 Init.get() == S->getInit() &&
8806 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8807 Inc.get() == S->getInc() &&
8808 Body.get() == S->getBody())
8809 return S;
8810
8811 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8812 Init.get(), Cond, FullInc,
8813 S->getRParenLoc(), Body.get());
8814}
8815
8816template<typename Derived>
8819 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8820 S->getLabel());
8821 if (!LD)
8822 return StmtError();
8823
8824 // Goto statements must always be rebuilt, to resolve the label.
8825 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8826 cast<LabelDecl>(LD));
8827}
8828
8829template<typename Derived>
8832 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8833 if (Target.isInvalid())
8834 return StmtError();
8835 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8836
8837 if (!getDerived().AlwaysRebuild() &&
8838 Target.get() == S->getTarget())
8839 return S;
8840
8841 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8842 Target.get());
8843}
8844
8845template<typename Derived>
8848 if (!S->isNamed())
8849 return S;
8850
8851 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8852 S->getLabelDecl());
8853 if (!LD)
8854 return StmtError();
8855
8856 return new (SemaRef.Context)
8857 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8858}
8859
8860template<typename Derived>
8863 if (!S->isNamed())
8864 return S;
8865
8866 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8867 S->getLabelDecl());
8868 if (!LD)
8869 return StmtError();
8870
8871 return new (SemaRef.Context)
8872 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8873}
8874
8875template <typename Derived>
8877 StmtResult Result = getDerived().TransformStmt(S->getBody());
8878 if (!Result.isUsable())
8879 return StmtError();
8880 return DeferStmt::Create(getSema().Context, S->getDeferLoc(), Result.get());
8881}
8882
8883template<typename Derived>
8886 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8887 /*NotCopyInit*/false);
8888 if (Result.isInvalid())
8889 return StmtError();
8890
8891 // FIXME: We always rebuild the return statement because there is no way
8892 // to tell whether the return type of the function has changed.
8893 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8894}
8895
8896template<typename Derived>
8899 bool DeclChanged = false;
8901 LambdaScopeInfo *LSI = getSema().getCurLambda();
8902 for (auto *D : S->decls()) {
8903 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8904 if (!Transformed)
8905 return StmtError();
8906
8907 if (Transformed != D)
8908 DeclChanged = true;
8909
8910 if (LSI) {
8911 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8912 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8913 LSI->ContainsUnexpandedParameterPack |=
8914 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8915 } else {
8916 LSI->ContainsUnexpandedParameterPack |=
8917 getSema()
8918 .getASTContext()
8919 .getTypeDeclType(TD)
8920 ->containsUnexpandedParameterPack();
8921 }
8922 }
8923 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8924 LSI->ContainsUnexpandedParameterPack |=
8925 VD->getType()->containsUnexpandedParameterPack();
8926 }
8927
8928 Decls.push_back(Transformed);
8929 }
8930
8931 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8932 return S;
8933
8934 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8935}
8936
8937template<typename Derived>
8940
8941 SmallVector<Expr*, 8> Constraints;
8944
8945 SmallVector<Expr*, 8> Clobbers;
8946
8947 bool ExprsChanged = false;
8948
8949 auto RebuildString = [&](Expr *E) {
8950 ExprResult Result = getDerived().TransformExpr(E);
8951 if (!Result.isUsable())
8952 return Result;
8953 if (Result.get() != E) {
8954 ExprsChanged = true;
8955 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8956 }
8957 return Result;
8958 };
8959
8960 // Go through the outputs.
8961 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8962 Names.push_back(S->getOutputIdentifier(I));
8963
8964 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8965 if (Result.isInvalid())
8966 return StmtError();
8967
8968 Constraints.push_back(Result.get());
8969
8970 // Transform the output expr.
8971 Expr *OutputExpr = S->getOutputExpr(I);
8972 Result = getDerived().TransformExpr(OutputExpr);
8973 if (Result.isInvalid())
8974 return StmtError();
8975
8976 ExprsChanged |= Result.get() != OutputExpr;
8977
8978 Exprs.push_back(Result.get());
8979 }
8980
8981 // Go through the inputs.
8982 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8983 Names.push_back(S->getInputIdentifier(I));
8984
8985 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8986 if (Result.isInvalid())
8987 return StmtError();
8988
8989 Constraints.push_back(Result.get());
8990
8991 // Transform the input expr.
8992 Expr *InputExpr = S->getInputExpr(I);
8993 Result = getDerived().TransformExpr(InputExpr);
8994 if (Result.isInvalid())
8995 return StmtError();
8996
8997 ExprsChanged |= Result.get() != InputExpr;
8998
8999 Exprs.push_back(Result.get());
9000 }
9001
9002 // Go through the Labels.
9003 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
9004 Names.push_back(S->getLabelIdentifier(I));
9005
9006 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
9007 if (Result.isInvalid())
9008 return StmtError();
9009 ExprsChanged |= Result.get() != S->getLabelExpr(I);
9010 Exprs.push_back(Result.get());
9011 }
9012
9013 // Go through the clobbers.
9014 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
9015 ExprResult Result = RebuildString(S->getClobberExpr(I));
9016 if (Result.isInvalid())
9017 return StmtError();
9018 Clobbers.push_back(Result.get());
9019 }
9020
9021 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
9022 if (AsmString.isInvalid())
9023 return StmtError();
9024
9025 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
9026 return S;
9027
9028 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
9029 S->isVolatile(), S->getNumOutputs(),
9030 S->getNumInputs(), Names.data(),
9031 Constraints, Exprs, AsmString.get(),
9032 Clobbers, S->getNumLabels(),
9033 S->getRParenLoc());
9034}
9035
9036template<typename Derived>
9039 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
9040
9041 bool HadError = false, HadChange = false;
9042
9043 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
9044 SmallVector<Expr*, 8> TransformedExprs;
9045 TransformedExprs.reserve(SrcExprs.size());
9046 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
9047 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
9048 if (!Result.isUsable()) {
9049 HadError = true;
9050 } else {
9051 HadChange |= (Result.get() != SrcExprs[i]);
9052 TransformedExprs.push_back(Result.get());
9053 }
9054 }
9055
9056 if (HadError) return StmtError();
9057 if (!HadChange && !getDerived().AlwaysRebuild())
9058 return Owned(S);
9059
9060 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
9061 AsmToks, S->getAsmString(),
9062 S->getNumOutputs(), S->getNumInputs(),
9063 S->getAllConstraints(), S->getClobbers(),
9064 TransformedExprs, S->getEndLoc());
9065}
9066
9067// C++ Coroutines
9068template<typename Derived>
9071 auto *ScopeInfo = SemaRef.getCurFunction();
9072 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
9073 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
9074 ScopeInfo->NeedsCoroutineSuspends &&
9075 ScopeInfo->CoroutineSuspends.first == nullptr &&
9076 ScopeInfo->CoroutineSuspends.second == nullptr &&
9077 "expected clean scope info");
9078
9079 // Set that we have (possibly-invalid) suspend points before we do anything
9080 // that may fail.
9081 ScopeInfo->setNeedsCoroutineSuspends(false);
9082
9083 // We re-build the coroutine promise object (and the coroutine parameters its
9084 // type and constructor depend on) based on the types used in our current
9085 // function. We must do so, and set it on the current FunctionScopeInfo,
9086 // before attempting to transform the other parts of the coroutine body
9087 // statement, such as the implicit suspend statements (because those
9088 // statements reference the FunctionScopeInfo::CoroutinePromise).
9089 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
9090 return StmtError();
9091 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
9092 if (!Promise)
9093 return StmtError();
9094 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
9095 ScopeInfo->CoroutinePromise = Promise;
9096
9097 // Transform the implicit coroutine statements constructed using dependent
9098 // types during the previous parse: initial and final suspensions, the return
9099 // object, and others. We also transform the coroutine function's body.
9100 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
9101 if (InitSuspend.isInvalid())
9102 return StmtError();
9103 StmtResult FinalSuspend =
9104 getDerived().TransformStmt(S->getFinalSuspendStmt());
9105 if (FinalSuspend.isInvalid() ||
9106 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
9107 return StmtError();
9108 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
9109 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
9110
9111 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
9112 if (BodyRes.isInvalid())
9113 return StmtError();
9114
9115 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
9116 if (Builder.isInvalid())
9117 return StmtError();
9118
9119 Expr *ReturnObject = S->getReturnValueInit();
9120 assert(ReturnObject && "the return object is expected to be valid");
9121 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
9122 /*NoCopyInit*/ false);
9123 if (Res.isInvalid())
9124 return StmtError();
9125 Builder.ReturnValue = Res.get();
9126
9127 // If during the previous parse the coroutine still had a dependent promise
9128 // statement, we may need to build some implicit coroutine statements
9129 // (such as exception and fallthrough handlers) for the first time.
9130 if (S->hasDependentPromiseType()) {
9131 // We can only build these statements, however, if the current promise type
9132 // is not dependent.
9133 if (!Promise->getType()->isDependentType()) {
9134 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
9135 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
9136 "these nodes should not have been built yet");
9137 if (!Builder.buildDependentStatements())
9138 return StmtError();
9139 }
9140 } else {
9141 if (auto *OnFallthrough = S->getFallthroughHandler()) {
9142 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
9143 if (Res.isInvalid())
9144 return StmtError();
9145 Builder.OnFallthrough = Res.get();
9146 }
9147
9148 if (auto *OnException = S->getExceptionHandler()) {
9149 StmtResult Res = getDerived().TransformStmt(OnException);
9150 if (Res.isInvalid())
9151 return StmtError();
9152 Builder.OnException = Res.get();
9153 }
9154
9155 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
9156 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
9157 if (Res.isInvalid())
9158 return StmtError();
9159 Builder.ReturnStmtOnAllocFailure = Res.get();
9160 }
9161
9162 // Transform any additional statements we may have already built
9163 assert(S->getAllocate() && S->getDeallocate() &&
9164 "allocation and deallocation calls must already be built");
9165 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
9166 if (AllocRes.isInvalid())
9167 return StmtError();
9168 Builder.Allocate = AllocRes.get();
9169
9170 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
9171 if (DeallocRes.isInvalid())
9172 return StmtError();
9173 Builder.Deallocate = DeallocRes.get();
9174
9175 if (auto *ResultDecl = S->getResultDecl()) {
9176 StmtResult Res = getDerived().TransformStmt(ResultDecl);
9177 if (Res.isInvalid())
9178 return StmtError();
9179 Builder.ResultDecl = Res.get();
9180 }
9181
9182 if (auto *ReturnStmt = S->getReturnStmt()) {
9183 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
9184 if (Res.isInvalid())
9185 return StmtError();
9186 Builder.ReturnStmt = Res.get();
9187 }
9188 }
9189
9190 return getDerived().RebuildCoroutineBodyStmt(Builder);
9191}
9192
9193template<typename Derived>
9196 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
9197 /*NotCopyInit*/false);
9198 if (Result.isInvalid())
9199 return StmtError();
9200
9201 // Always rebuild; we don't know if this needs to be injected into a new
9202 // context or if the promise type has changed.
9203 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
9204 S->isImplicit());
9205}
9206
9207template <typename Derived>
9209 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
9210 /*NotCopyInit*/ false);
9211 if (Operand.isInvalid())
9212 return ExprError();
9213
9214 // Rebuild the common-expr from the operand rather than transforming it
9215 // separately.
9216
9217 // FIXME: getCurScope() should not be used during template instantiation.
9218 // We should pick up the set of unqualified lookup results for operator
9219 // co_await during the initial parse.
9220 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
9221 getSema().getCurScope(), E->getKeywordLoc());
9222
9223 // Always rebuild; we don't know if this needs to be injected into a new
9224 // context or if the promise type has changed.
9225 return getDerived().RebuildCoawaitExpr(
9226 E->getKeywordLoc(), Operand.get(),
9227 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
9228}
9229
9230template <typename Derived>
9233 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
9234 /*NotCopyInit*/ false);
9235 if (OperandResult.isInvalid())
9236 return ExprError();
9237
9238 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
9239 E->getOperatorCoawaitLookup());
9240
9241 if (LookupResult.isInvalid())
9242 return ExprError();
9243
9244 // Always rebuild; we don't know if this needs to be injected into a new
9245 // context or if the promise type has changed.
9246 return getDerived().RebuildDependentCoawaitExpr(
9247 E->getKeywordLoc(), OperandResult.get(),
9249}
9250
9251template<typename Derived>
9254 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
9255 /*NotCopyInit*/false);
9256 if (Result.isInvalid())
9257 return ExprError();
9258
9259 // Always rebuild; we don't know if this needs to be injected into a new
9260 // context or if the promise type has changed.
9261 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
9262}
9263
9264// Objective-C Statements.
9265
9266template<typename Derived>
9269 // Transform the body of the @try.
9270 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
9271 if (TryBody.isInvalid())
9272 return StmtError();
9273
9274 // Transform the @catch statements (if present).
9275 bool AnyCatchChanged = false;
9276 SmallVector<Stmt*, 8> CatchStmts;
9277 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
9278 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
9279 if (Catch.isInvalid())
9280 return StmtError();
9281 if (Catch.get() != S->getCatchStmt(I))
9282 AnyCatchChanged = true;
9283 CatchStmts.push_back(Catch.get());
9284 }
9285
9286 // Transform the @finally statement (if present).
9287 StmtResult Finally;
9288 if (S->getFinallyStmt()) {
9289 Finally = getDerived().TransformStmt(S->getFinallyStmt());
9290 if (Finally.isInvalid())
9291 return StmtError();
9292 }
9293
9294 // If nothing changed, just retain this statement.
9295 if (!getDerived().AlwaysRebuild() &&
9296 TryBody.get() == S->getTryBody() &&
9297 !AnyCatchChanged &&
9298 Finally.get() == S->getFinallyStmt())
9299 return S;
9300
9301 // Build a new statement.
9302 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
9303 CatchStmts, Finally.get());
9304}
9305
9306template<typename Derived>
9309 // Transform the @catch parameter, if there is one.
9310 VarDecl *Var = nullptr;
9311 if (VarDecl *FromVar = S->getCatchParamDecl()) {
9312 TypeSourceInfo *TSInfo = nullptr;
9313 if (FromVar->getTypeSourceInfo()) {
9314 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
9315 if (!TSInfo)
9316 return StmtError();
9317 }
9318
9319 QualType T;
9320 if (TSInfo)
9321 T = TSInfo->getType();
9322 else {
9323 T = getDerived().TransformType(FromVar->getType());
9324 if (T.isNull())
9325 return StmtError();
9326 }
9327
9328 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
9329 if (!Var)
9330 return StmtError();
9331 }
9332
9333 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
9334 if (Body.isInvalid())
9335 return StmtError();
9336
9337 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9338 S->getRParenLoc(),
9339 Var, Body.get());
9340}
9341
9342template<typename Derived>
9345 // Transform the body.
9346 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9347 if (Body.isInvalid())
9348 return StmtError();
9349
9350 // If nothing changed, just retain this statement.
9351 if (!getDerived().AlwaysRebuild() &&
9352 Body.get() == S->getFinallyBody())
9353 return S;
9354
9355 // Build a new statement.
9356 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9357 Body.get());
9358}
9359
9360template<typename Derived>
9364 if (S->getThrowExpr()) {
9365 Operand = getDerived().TransformExpr(S->getThrowExpr());
9366 if (Operand.isInvalid())
9367 return StmtError();
9368 }
9369
9370 if (!getDerived().AlwaysRebuild() &&
9371 Operand.get() == S->getThrowExpr())
9372 return S;
9373
9374 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9375}
9376
9377template<typename Derived>
9381 // Transform the object we are locking.
9382 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9383 if (Object.isInvalid())
9384 return StmtError();
9385 Object =
9386 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9387 Object.get());
9388 if (Object.isInvalid())
9389 return StmtError();
9390
9391 // Transform the body.
9392 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9393 if (Body.isInvalid())
9394 return StmtError();
9395
9396 // If nothing change, just retain the current statement.
9397 if (!getDerived().AlwaysRebuild() &&
9398 Object.get() == S->getSynchExpr() &&
9399 Body.get() == S->getSynchBody())
9400 return S;
9401
9402 // Build a new statement.
9403 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9404 Object.get(), Body.get());
9405}
9406
9407template<typename Derived>
9411 // Transform the body.
9412 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9413 if (Body.isInvalid())
9414 return StmtError();
9415
9416 // If nothing changed, just retain this statement.
9417 if (!getDerived().AlwaysRebuild() &&
9418 Body.get() == S->getSubStmt())
9419 return S;
9420
9421 // Build a new statement.
9422 return getDerived().RebuildObjCAutoreleasePoolStmt(
9423 S->getAtLoc(), Body.get());
9424}
9425
9426template<typename Derived>
9430 // Transform the element statement.
9431 StmtResult Element = getDerived().TransformStmt(
9432 S->getElement(), StmtDiscardKind::NotDiscarded);
9433 if (Element.isInvalid())
9434 return StmtError();
9435
9436 // Transform the collection expression.
9437 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9438 if (Collection.isInvalid())
9439 return StmtError();
9440
9441 // Transform the body.
9442 StmtResult Body = getDerived().TransformStmt(S->getBody());
9443 if (Body.isInvalid())
9444 return StmtError();
9445
9446 // If nothing changed, just retain this statement.
9447 if (!getDerived().AlwaysRebuild() &&
9448 Element.get() == S->getElement() &&
9449 Collection.get() == S->getCollection() &&
9450 Body.get() == S->getBody())
9451 return S;
9452
9453 // Build a new statement.
9454 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9455 Element.get(),
9456 Collection.get(),
9457 S->getRParenLoc(),
9458 Body.get());
9459}
9460
9461template <typename Derived>
9463 // Transform the exception declaration, if any.
9464 VarDecl *Var = nullptr;
9465 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9466 TypeSourceInfo *T =
9467 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9468 if (!T)
9469 return StmtError();
9470
9471 Var = getDerived().RebuildExceptionDecl(
9472 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9473 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9474 if (!Var || Var->isInvalidDecl())
9475 return StmtError();
9476 }
9477
9478 // Transform the actual exception handler.
9479 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9480 if (Handler.isInvalid())
9481 return StmtError();
9482
9483 if (!getDerived().AlwaysRebuild() && !Var &&
9484 Handler.get() == S->getHandlerBlock())
9485 return S;
9486
9487 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9488}
9489
9490template <typename Derived>
9492 // Transform the try block itself.
9493 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9494 if (TryBlock.isInvalid())
9495 return StmtError();
9496
9497 // Transform the handlers.
9498 bool HandlerChanged = false;
9499 SmallVector<Stmt *, 8> Handlers;
9500 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9501 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9502 if (Handler.isInvalid())
9503 return StmtError();
9504
9505 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9506 Handlers.push_back(Handler.getAs<Stmt>());
9507 }
9508
9509 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9510
9511 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9512 !HandlerChanged)
9513 return S;
9514
9515 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9516 Handlers);
9517}
9518
9519template<typename Derived>
9522 EnterExpressionEvaluationContext ForRangeInitContext(
9524 /*LambdaContextDecl=*/nullptr,
9526 getSema().getLangOpts().CPlusPlus23);
9527
9528 // P2718R0 - Lifetime extension in range-based for loops.
9529 if (getSema().getLangOpts().CPlusPlus23) {
9530 auto &LastRecord = getSema().currentEvaluationContext();
9531 LastRecord.InLifetimeExtendingContext = true;
9532 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9533 }
9535 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9536 if (Init.isInvalid())
9537 return StmtError();
9538
9539 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9540 if (Range.isInvalid())
9541 return StmtError();
9542
9543 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9544 assert(getSema().getLangOpts().CPlusPlus23 ||
9545 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9546 auto ForRangeLifetimeExtendTemps =
9547 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9548
9549 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9550 if (Begin.isInvalid())
9551 return StmtError();
9552 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9553 if (End.isInvalid())
9554 return StmtError();
9555
9556 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9557 if (Cond.isInvalid())
9558 return StmtError();
9559 if (Cond.get())
9560 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9561 if (Cond.isInvalid())
9562 return StmtError();
9563 if (Cond.get())
9564 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9565
9566 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9567 if (Inc.isInvalid())
9568 return StmtError();
9569 if (Inc.get())
9570 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9571
9572 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9573 if (LoopVar.isInvalid())
9574 return StmtError();
9575
9576 StmtResult NewStmt = S;
9577 if (getDerived().AlwaysRebuild() ||
9578 Init.get() != S->getInit() ||
9579 Range.get() != S->getRangeStmt() ||
9580 Begin.get() != S->getBeginStmt() ||
9581 End.get() != S->getEndStmt() ||
9582 Cond.get() != S->getCond() ||
9583 Inc.get() != S->getInc() ||
9584 LoopVar.get() != S->getLoopVarStmt()) {
9585 NewStmt = getDerived().RebuildCXXForRangeStmt(
9586 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9587 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9588 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9589 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9590 // Might not have attached any initializer to the loop variable.
9591 getSema().ActOnInitializerError(
9592 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9593 return StmtError();
9594 }
9595 }
9596
9597 // OpenACC Restricts a while-loop inside of certain construct/clause
9598 // combinations, so diagnose that here in OpenACC mode.
9600 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9601
9602 StmtResult Body = getDerived().TransformStmt(S->getBody());
9603 if (Body.isInvalid())
9604 return StmtError();
9605
9606 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9607
9608 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9609 // it now so we have a new statement to attach the body to.
9610 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9611 NewStmt = getDerived().RebuildCXXForRangeStmt(
9612 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9613 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9614 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9615 if (NewStmt.isInvalid())
9616 return StmtError();
9617 }
9618
9619 if (NewStmt.get() == S)
9620 return S;
9621
9622 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9623}
9624
9625template <typename Derived>
9628 assert(SemaRef.CurContext->isExpansionStmt());
9629
9630 Decl *ESD =
9631 getDerived().TransformDecl(S->getDecl()->getLocation(), S->getDecl());
9632 if (!ESD || ESD->isInvalidDecl())
9633 return StmtError();
9635
9636 // This is required because some parts of an expansion statement (e.g. the
9637 // init-statement) are not in a dependent context and must thus be transformed
9638 // in the parent context.
9639 auto TransformStmtInParentContext = [&](Stmt *SubStmt) -> StmtResult {
9640 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9641 /*NewThis=*/false);
9642 return getDerived().TransformStmt(SubStmt);
9643 };
9644
9645 Stmt *Init = S->getInit();
9646 if (Init) {
9647 StmtResult SR = TransformStmtInParentContext(Init);
9648 if (SR.isInvalid())
9649 return StmtError();
9650 Init = SR.get();
9651 }
9652
9653 // Collect lifetime-extended temporaries in case this ends up being a
9654 // destructuring or iterating expansion statement.
9655 //
9656 // CWG 3140: Additionally, for iterating expansions statements, we need to
9657 // apply lifetime extension to the initializer of the range.
9658 ExprResult ExpansionInitializer;
9661 if (S->isDependent() || S->isIterating()) {
9663 SemaRef, SemaRef.currentEvaluationContext().Context);
9666
9667 if (S->isDependent()) {
9668 // The expansion initializer should not be in the context of the expansion
9669 // statement because it isn't instantiated when the expansion statement is
9670 // expanded.
9671 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9672 /*NewThis=*/false);
9673 ExpansionInitializer =
9674 getDerived().TransformExpr(S->getExpansionInitializer());
9675 if (ExpansionInitializer.isInvalid())
9676 return StmtError();
9677 } else if (S->isIterating()) {
9678 Range = TransformStmtInParentContext(S->getRangeVarStmt());
9679 if (Range.isInvalid())
9680 return StmtError();
9681 }
9682
9683 ExpansionInitializer =
9684 SemaRef.MaybeCreateExprWithCleanups(ExpansionInitializer);
9685
9686 LifetimeExtendTemps =
9688 }
9689
9690 CXXExpansionStmtPattern *NewPattern = nullptr;
9691 if (S->isEnumerating()) {
9692 StmtResult ExpansionVar =
9693 getDerived().TransformStmt(S->getExpansionVarStmt());
9694 if (ExpansionVar.isInvalid())
9695 return StmtError();
9696
9698 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9699 S->getLParenLoc(), S->getColonLoc(), S->getRParenLoc());
9700 } else if (S->isIterating()) {
9701 StmtResult Begin = TransformStmtInParentContext(S->getBeginVarStmt());
9702 StmtResult Iter = TransformStmtInParentContext(S->getIterVarStmt());
9703 if (Begin.isInvalid() || Iter.isInvalid())
9704 return StmtError();
9705
9706 // The expansion variable is part of the pattern only and never ends
9707 // up in the instantiations, so keep it in the expansion statement's
9708 // DeclContext.
9709 StmtResult ExpansionVar =
9710 getDerived().TransformStmt(S->getExpansionVarStmt());
9711 if (ExpansionVar.isInvalid())
9712 return StmtError();
9713
9715 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9716 Range.getAs<DeclStmt>(), Begin.getAs<DeclStmt>(),
9717 Iter.getAs<DeclStmt>(), S->getLParenLoc(), S->getColonLoc(),
9718 S->getRParenLoc());
9719
9721 NewPattern->getRangeVar(), LifetimeExtendTemps);
9722 } else if (S->isDependent()) {
9723 StmtResult ExpansionVar =
9724 getDerived().TransformStmt(S->getExpansionVarStmt());
9725 if (ExpansionVar.isInvalid())
9726 return StmtError();
9727
9729 NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9730 ExpansionInitializer.get(), S->getLParenLoc(), S->getColonLoc(),
9731 S->getRParenLoc(), LifetimeExtendTemps);
9732
9733 if (Res.isInvalid())
9734 return StmtError();
9735
9736 NewPattern = cast<CXXExpansionStmtPattern>(Res.get());
9737 } else {
9738 // The only time we instantiate an expansion statement is if its expansion
9739 // size is dependent (otherwise, we only instantiate the expansions and
9740 // leave the underlying CXXExpansionStmtPattern as-is). Since destructuring
9741 // expansion statements never have a dependent size, we should never get
9742 // here.
9743 llvm_unreachable("destructuring pattern should never be instantiated");
9744 }
9745
9746 StmtResult Body = getDerived().TransformStmt(S->getBody());
9747 if (Body.isInvalid())
9748 return StmtError();
9749
9750 return SemaRef.FinishCXXExpansionStmt(NewPattern, Body.get());
9751}
9752
9753template <typename Derived>
9756 bool SubStmtChanged = false;
9757 auto TransformStmts = [&](SmallVectorImpl<Stmt *> &NewStmts,
9758 ArrayRef<Stmt *> OldStmts) {
9759 for (Stmt *OldDS : OldStmts) {
9760 StmtResult NewDS = getDerived().TransformStmt(OldDS);
9761 if (NewDS.isInvalid())
9762 return true;
9763
9764 SubStmtChanged |= NewDS.get() != OldDS;
9765 NewStmts.push_back(NewDS.get());
9766 }
9767
9768 return false;
9769 };
9770
9771 Decl *ESD =
9772 getDerived().TransformDecl(S->getParent()->getLocation(), S->getParent());
9773 if (!ESD || ESD->isInvalidDecl())
9774 return StmtError();
9776
9777 SmallVector<Stmt *> PreambleStmts;
9778 SmallVector<Stmt *> Instantiations;
9779
9780 // Apply lifetime extension to the preamble statements if this was a
9781 // destructuring expansion statement.
9782 {
9784 SemaRef, SemaRef.currentEvaluationContext().Context);
9787 if (TransformStmts(PreambleStmts, S->getPreambleStmts()))
9788 return StmtError();
9789
9790 if (S->shouldApplyLifetimeExtensionToPreamble()) {
9791 auto *VD =
9792 cast<VarDecl>(cast<DeclStmt>(PreambleStmts.front())->getSingleDecl());
9795 }
9796 }
9797
9798 if (TransformStmts(Instantiations, S->getInstantiations()))
9799 return StmtError();
9800
9801 if (!getDerived().AlwaysRebuild() && !SubStmtChanged)
9802 return S;
9803
9805 SemaRef.Context, NewESD, Instantiations, PreambleStmts,
9806 S->shouldApplyLifetimeExtensionToPreamble());
9807}
9808
9809template <typename Derived>
9812 ExprResult Range = getDerived().TransformExpr(E->getRangeExpr());
9813 ExprResult Idx = getDerived().TransformExpr(E->getIndexExpr());
9814 if (Range.isInvalid() || Idx.isInvalid())
9815 return ExprError();
9816
9817 if (!getDerived().AlwaysRebuild() && Range.get() == E->getRangeExpr() &&
9818 Idx.get() == E->getIndexExpr())
9819 return E;
9820
9821 return SemaRef.BuildCXXExpansionSelectExpr(Range.getAs<InitListExpr>(),
9822 Idx.get());
9823}
9824
9825template<typename Derived>
9829 // Transform the nested-name-specifier, if any.
9830 NestedNameSpecifierLoc QualifierLoc;
9831 if (S->getQualifierLoc()) {
9832 QualifierLoc
9833 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9834 if (!QualifierLoc)
9835 return StmtError();
9836 }
9837
9838 // Transform the declaration name.
9839 DeclarationNameInfo NameInfo = S->getNameInfo();
9840 if (NameInfo.getName()) {
9841 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9842 if (!NameInfo.getName())
9843 return StmtError();
9844 }
9845
9846 // Check whether anything changed.
9847 if (!getDerived().AlwaysRebuild() &&
9848 QualifierLoc == S->getQualifierLoc() &&
9849 NameInfo.getName() == S->getNameInfo().getName())
9850 return S;
9851
9852 // Determine whether this name exists, if we can.
9853 CXXScopeSpec SS;
9854 SS.Adopt(QualifierLoc);
9855 bool Dependent = false;
9856 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9858 if (S->isIfExists())
9859 break;
9860
9861 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9862
9864 if (S->isIfNotExists())
9865 break;
9866
9867 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9868
9870 Dependent = true;
9871 break;
9872
9874 return StmtError();
9875 }
9876
9877 // We need to continue with the instantiation, so do so now.
9878 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9879 if (SubStmt.isInvalid())
9880 return StmtError();
9881
9882 // If we have resolved the name, just transform to the substatement.
9883 if (!Dependent)
9884 return SubStmt;
9885
9886 // The name is still dependent, so build a dependent expression again.
9887 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9888 S->isIfExists(),
9889 QualifierLoc,
9890 NameInfo,
9891 SubStmt.get());
9892}
9893
9894template<typename Derived>
9897 NestedNameSpecifierLoc QualifierLoc;
9898 if (E->getQualifierLoc()) {
9899 QualifierLoc
9900 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9901 if (!QualifierLoc)
9902 return ExprError();
9903 }
9904
9905 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9906 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9907 if (!PD)
9908 return ExprError();
9909
9910 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9911 if (Base.isInvalid())
9912 return ExprError();
9913
9914 return new (SemaRef.getASTContext())
9915 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9917 QualifierLoc, E->getMemberLoc());
9918}
9919
9920template <typename Derived>
9923 auto BaseRes = getDerived().TransformExpr(E->getBase());
9924 if (BaseRes.isInvalid())
9925 return ExprError();
9926 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9927 if (IdxRes.isInvalid())
9928 return ExprError();
9929
9930 if (!getDerived().AlwaysRebuild() &&
9931 BaseRes.get() == E->getBase() &&
9932 IdxRes.get() == E->getIdx())
9933 return E;
9934
9935 return getDerived().RebuildArraySubscriptExpr(
9936 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9937}
9938
9939template <typename Derived>
9941 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9942 if (TryBlock.isInvalid())
9943 return StmtError();
9944
9945 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9946 if (Handler.isInvalid())
9947 return StmtError();
9948
9949 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9950 Handler.get() == S->getHandler())
9951 return S;
9952
9953 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9954 TryBlock.get(), Handler.get());
9955}
9956
9957template <typename Derived>
9959 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9960 if (Block.isInvalid())
9961 return StmtError();
9962
9963 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9964}
9965
9966template <typename Derived>
9968 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9969 if (FilterExpr.isInvalid())
9970 return StmtError();
9971
9972 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9973 if (Block.isInvalid())
9974 return StmtError();
9975
9976 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9977 Block.get());
9978}
9979
9980template <typename Derived>
9982 if (isa<SEHFinallyStmt>(Handler))
9983 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9984 else
9985 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9986}
9987
9988template<typename Derived>
9991 return S;
9992}
9993
9994//===----------------------------------------------------------------------===//
9995// OpenMP directive transformation
9996//===----------------------------------------------------------------------===//
9997
9998template <typename Derived>
9999StmtResult
10000TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
10001 // OMPCanonicalLoops are eliminated during transformation, since they will be
10002 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
10003 // after transformation.
10004 return getDerived().TransformStmt(L->getLoopStmt());
10005}
10006
10007template <typename Derived>
10010
10011 // Transform the clauses
10013 ArrayRef<OMPClause *> Clauses = D->clauses();
10014 TClauses.reserve(Clauses.size());
10015 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
10016 I != E; ++I) {
10017 if (*I) {
10018 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
10019 OMPClause *Clause = getDerived().TransformOMPClause(*I);
10020 getDerived().getSema().OpenMP().EndOpenMPClause();
10021 if (Clause)
10022 TClauses.push_back(Clause);
10023 } else {
10024 TClauses.push_back(nullptr);
10025 }
10026 }
10027 StmtResult AssociatedStmt;
10028 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
10029 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
10030 D->getDirectiveKind(),
10031 /*CurScope=*/nullptr);
10032 StmtResult Body;
10033 {
10034 Sema::CompoundScopeRAII CompoundScope(getSema());
10035 Stmt *CS;
10036 if (D->getDirectiveKind() == OMPD_atomic ||
10037 D->getDirectiveKind() == OMPD_critical ||
10038 D->getDirectiveKind() == OMPD_section ||
10039 D->getDirectiveKind() == OMPD_master)
10040 CS = D->getAssociatedStmt();
10041 else
10042 CS = D->getRawStmt();
10043 Body = getDerived().TransformStmt(CS);
10044 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
10045 getSema().getLangOpts().OpenMPIRBuilder)
10046 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
10047 }
10048 AssociatedStmt =
10049 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
10050 if (AssociatedStmt.isInvalid()) {
10051 return StmtError();
10052 }
10053 }
10054 if (TClauses.size() != Clauses.size()) {
10055 return StmtError();
10056 }
10057
10058 // Transform directive name for 'omp critical' directive.
10059 DeclarationNameInfo DirName;
10060 if (D->getDirectiveKind() == OMPD_critical) {
10061 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
10062 DirName = getDerived().TransformDeclarationNameInfo(DirName);
10063 }
10064 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
10065 if (D->getDirectiveKind() == OMPD_cancellation_point) {
10066 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
10067 } else if (D->getDirectiveKind() == OMPD_cancel) {
10068 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
10069 }
10070
10071 return getDerived().RebuildOMPExecutableDirective(
10072 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
10073 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
10074}
10075
10076/// This is mostly the same as above, but allows 'informational' class
10077/// directives when rebuilding the stmt. It still takes an
10078/// OMPExecutableDirective-type argument because we're reusing that as the
10079/// superclass for the 'assume' directive at present, instead of defining a
10080/// mostly-identical OMPInformationalDirective parent class.
10081template <typename Derived>
10084
10085 // Transform the clauses
10087 ArrayRef<OMPClause *> Clauses = D->clauses();
10088 TClauses.reserve(Clauses.size());
10089 for (OMPClause *C : Clauses) {
10090 if (C) {
10091 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
10092 OMPClause *Clause = getDerived().TransformOMPClause(C);
10093 getDerived().getSema().OpenMP().EndOpenMPClause();
10094 if (Clause)
10095 TClauses.push_back(Clause);
10096 } else {
10097 TClauses.push_back(nullptr);
10098 }
10099 }
10100 StmtResult AssociatedStmt;
10101 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
10102 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
10103 D->getDirectiveKind(),
10104 /*CurScope=*/nullptr);
10105 StmtResult Body;
10106 {
10107 Sema::CompoundScopeRAII CompoundScope(getSema());
10108 assert(D->getDirectiveKind() == OMPD_assume &&
10109 "Unexpected informational directive");
10110 Stmt *CS = D->getAssociatedStmt();
10111 Body = getDerived().TransformStmt(CS);
10112 }
10113 AssociatedStmt =
10114 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
10115 if (AssociatedStmt.isInvalid())
10116 return StmtError();
10117 }
10118 if (TClauses.size() != Clauses.size())
10119 return StmtError();
10120
10121 DeclarationNameInfo DirName;
10122
10123 return getDerived().RebuildOMPInformationalDirective(
10124 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
10125 D->getBeginLoc(), D->getEndLoc());
10126}
10127
10128template <typename Derived>
10131 // Every variant is a complete directive (or the plain associated statement),
10132 // so it is transformed on its own.
10133 SmallVector<Stmt *, 4> Variants;
10134 for (Stmt *V : D->variants()) {
10135 StmtResult NewV = getDerived().TransformStmt(V);
10136 if (NewV.isInvalid())
10137 return StmtError();
10138 Variants.push_back(NewV.get());
10139 }
10140
10141 // Copy the trait infos and transform their score and condition expressions.
10142 // The implicit 'otherwise' trait info is added back by Sema.
10143 ArrayRef<OMPTraitInfo *> OldTraitInfos = D->traitInfos();
10144 if (D->hasImplicitOtherwise())
10145 OldTraitInfos = OldTraitInfos.drop_back();
10147 for (const OMPTraitInfo *OldTI : OldTraitInfos) {
10148 OMPTraitInfo &TI = getSema().getASTContext().getNewOMPTraitInfo();
10149 TI = *OldTI;
10150 auto TransformScoreOrCondition = [&](Expr *&E, bool IsScore) {
10151 if (!E)
10152 return false;
10153 EnterExpressionEvaluationContext Ctx(
10154 getSema(),
10157 ExprResult ER = getDerived().TransformExpr(E);
10158 if (!ER.isUsable())
10159 return true;
10160 E = ER.get();
10161 return false;
10162 };
10163 if (TI.anyScoreOrCondition(TransformScoreOrCondition))
10164 return StmtError();
10165 TraitInfos.push_back(&TI);
10166 }
10167
10168 return getDerived().RebuildOMPMetaDirective(D->getBeginLoc(), D->getEndLoc(),
10169 TraitInfos, Variants);
10170}
10171
10172template <typename Derived>
10175 DeclarationNameInfo DirName;
10176 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10177 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
10178 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10179 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10180 return Res;
10181}
10182
10183template <typename Derived>
10186 DeclarationNameInfo DirName;
10187 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10188 OMPD_simd, DirName, nullptr, D->getBeginLoc());
10189 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10190 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10191 return Res;
10192}
10193
10194template <typename Derived>
10197 DeclarationNameInfo DirName;
10198 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10199 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10200 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10201 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10202 return Res;
10203}
10204
10205template <typename Derived>
10208 DeclarationNameInfo DirName;
10209 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10210 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10211 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10212 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10213 return Res;
10214}
10215
10216template <typename Derived>
10219 DeclarationNameInfo DirName;
10220 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10221 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10222 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10223 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10224 return Res;
10225}
10226
10227template <typename Derived>
10230 DeclarationNameInfo DirName;
10231 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10232 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10233 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10234 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10235 return Res;
10236}
10237
10238template <typename Derived>
10240 OMPInterchangeDirective *D) {
10241 DeclarationNameInfo DirName;
10242 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10243 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10244 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10245 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10246 return Res;
10247}
10248
10249template <typename Derived>
10252 DeclarationNameInfo DirName;
10253 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10254 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10255 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10256 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10257 return Res;
10258}
10259
10260template <typename Derived>
10263 DeclarationNameInfo DirName;
10264 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10265 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10266 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10267 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10268 return Res;
10269}
10270
10271template <typename Derived>
10274 DeclarationNameInfo DirName;
10275 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10276 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10278 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10279 return Res;
10280}
10281
10282template <typename Derived>
10285 DeclarationNameInfo DirName;
10286 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10287 OMPD_for, DirName, nullptr, D->getBeginLoc());
10288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10289 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10290 return Res;
10291}
10292
10293template <typename Derived>
10296 DeclarationNameInfo DirName;
10297 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10298 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
10299 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10300 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10301 return Res;
10302}
10303
10304template <typename Derived>
10307 DeclarationNameInfo DirName;
10308 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10309 OMPD_sections, DirName, nullptr, D->getBeginLoc());
10310 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10311 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10312 return Res;
10313}
10314
10315template <typename Derived>
10318 DeclarationNameInfo DirName;
10319 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10320 OMPD_section, DirName, nullptr, D->getBeginLoc());
10321 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10322 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10323 return Res;
10324}
10325
10326template <typename Derived>
10329 DeclarationNameInfo DirName;
10330 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10331 OMPD_scope, DirName, nullptr, D->getBeginLoc());
10332 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10333 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10334 return Res;
10335}
10336
10337template <typename Derived>
10340 DeclarationNameInfo DirName;
10341 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10342 OMPD_single, DirName, nullptr, D->getBeginLoc());
10343 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10344 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10345 return Res;
10346}
10347
10348template <typename Derived>
10351 DeclarationNameInfo DirName;
10352 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10353 OMPD_master, DirName, nullptr, D->getBeginLoc());
10354 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10355 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10356 return Res;
10357}
10358
10359template <typename Derived>
10362 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10363 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
10364 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10365 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10366 return Res;
10367}
10368
10369template <typename Derived>
10371 OMPParallelForDirective *D) {
10372 DeclarationNameInfo DirName;
10373 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10374 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
10375 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10376 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10377 return Res;
10378}
10379
10380template <typename Derived>
10382 OMPParallelForSimdDirective *D) {
10383 DeclarationNameInfo DirName;
10384 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10385 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10386 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10387 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10388 return Res;
10389}
10390
10391template <typename Derived>
10393 OMPParallelMasterDirective *D) {
10394 DeclarationNameInfo DirName;
10395 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10396 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
10397 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10398 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10399 return Res;
10400}
10401
10402template <typename Derived>
10404 OMPParallelMaskedDirective *D) {
10405 DeclarationNameInfo DirName;
10406 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10407 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
10408 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10409 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10410 return Res;
10411}
10412
10413template <typename Derived>
10415 OMPParallelSectionsDirective *D) {
10416 DeclarationNameInfo DirName;
10417 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10418 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
10419 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10420 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10421 return Res;
10422}
10423
10424template <typename Derived>
10427 DeclarationNameInfo DirName;
10428 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10429 OMPD_task, DirName, nullptr, D->getBeginLoc());
10430 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10431 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10432 return Res;
10433}
10434
10435template <typename Derived>
10437 OMPTaskyieldDirective *D) {
10438 DeclarationNameInfo DirName;
10439 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10440 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
10441 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10442 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10443 return Res;
10444}
10445
10446template <typename Derived>
10449 DeclarationNameInfo DirName;
10450 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10451 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
10452 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10453 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10454 return Res;
10455}
10456
10457template <typename Derived>
10460 DeclarationNameInfo DirName;
10461 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10462 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
10463 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10464 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10465 return Res;
10466}
10467
10468template <typename Derived>
10471 DeclarationNameInfo DirName;
10472 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10473 OMPD_assume, DirName, nullptr, D->getBeginLoc());
10474 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
10475 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10476 return Res;
10477}
10478
10479template <typename Derived>
10482 DeclarationNameInfo DirName;
10483 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10484 OMPD_error, DirName, nullptr, D->getBeginLoc());
10485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10486 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10487 return Res;
10488}
10489
10490template <typename Derived>
10492 OMPTaskgroupDirective *D) {
10493 DeclarationNameInfo DirName;
10494 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10495 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
10496 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10497 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10498 return Res;
10499}
10500
10501template <typename Derived>
10504 DeclarationNameInfo DirName;
10505 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10506 OMPD_flush, DirName, nullptr, D->getBeginLoc());
10507 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10508 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10509 return Res;
10510}
10511
10512template <typename Derived>
10515 DeclarationNameInfo DirName;
10516 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10517 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
10518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10519 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10520 return Res;
10521}
10522
10523template <typename Derived>
10526 DeclarationNameInfo DirName;
10527 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10528 OMPD_scan, DirName, nullptr, D->getBeginLoc());
10529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10530 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10531 return Res;
10532}
10533
10534template <typename Derived>
10536 OMPOrderedStandaloneDirective *D) {
10537 DeclarationNameInfo DirName;
10538 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10539 OMPD_ordered_standalone, DirName, nullptr, D->getBeginLoc());
10540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10541 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10542 return Res;
10543}
10544
10545template <typename Derived>
10547 OMPOrderedBlockAssocDirective *D) {
10548 DeclarationNameInfo DirName;
10549 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10550 OMPD_ordered_blockassoc, DirName, nullptr, D->getBeginLoc());
10551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10552 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10553 return Res;
10554}
10555
10556template <typename Derived>
10559 DeclarationNameInfo DirName;
10560 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10561 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
10562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10563 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10564 return Res;
10565}
10566
10567template <typename Derived>
10570 DeclarationNameInfo DirName;
10571 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10572 OMPD_target, DirName, nullptr, D->getBeginLoc());
10573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10574 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10575 return Res;
10576}
10577
10578template <typename Derived>
10580 OMPTargetDataDirective *D) {
10581 DeclarationNameInfo DirName;
10582 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10583 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
10584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10585 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10586 return Res;
10587}
10588
10589template <typename Derived>
10591 OMPTargetEnterDataDirective *D) {
10592 DeclarationNameInfo DirName;
10593 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10594 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
10595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10596 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10597 return Res;
10598}
10599
10600template <typename Derived>
10602 OMPTargetExitDataDirective *D) {
10603 DeclarationNameInfo DirName;
10604 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10605 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
10606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10607 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10608 return Res;
10609}
10610
10611template <typename Derived>
10613 OMPTargetParallelDirective *D) {
10614 DeclarationNameInfo DirName;
10615 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10616 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10618 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10619 return Res;
10620}
10621
10622template <typename Derived>
10624 OMPTargetParallelForDirective *D) {
10625 DeclarationNameInfo DirName;
10626 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10627 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10629 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10630 return Res;
10631}
10632
10633template <typename Derived>
10635 OMPTargetUpdateDirective *D) {
10636 DeclarationNameInfo DirName;
10637 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10638 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10640 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10641 return Res;
10642}
10643
10644template <typename Derived>
10647 DeclarationNameInfo DirName;
10648 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10649 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10651 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10652 return Res;
10653}
10654
10655template <typename Derived>
10657 OMPCancellationPointDirective *D) {
10658 DeclarationNameInfo DirName;
10659 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10660 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10661 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10662 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10663 return Res;
10664}
10665
10666template <typename Derived>
10669 DeclarationNameInfo DirName;
10670 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10671 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10672 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10673 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10674 return Res;
10675}
10676
10677template <typename Derived>
10680 DeclarationNameInfo DirName;
10681 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10682 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10683 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10684 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10685 return Res;
10686}
10687
10688template <typename Derived>
10690 OMPTaskLoopSimdDirective *D) {
10691 DeclarationNameInfo DirName;
10692 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10693 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10694 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10695 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10696 return Res;
10697}
10698
10699template <typename Derived>
10701 OMPMasterTaskLoopDirective *D) {
10702 DeclarationNameInfo DirName;
10703 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10704 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10705 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10706 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10707 return Res;
10708}
10709
10710template <typename Derived>
10712 OMPMaskedTaskLoopDirective *D) {
10713 DeclarationNameInfo DirName;
10714 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10715 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10716 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10717 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10718 return Res;
10719}
10720
10721template <typename Derived>
10723 OMPMasterTaskLoopSimdDirective *D) {
10724 DeclarationNameInfo DirName;
10725 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10726 OMPD_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>
10734 OMPMaskedTaskLoopSimdDirective *D) {
10735 DeclarationNameInfo DirName;
10736 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10737 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10738 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10739 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10740 return Res;
10741}
10742
10743template <typename Derived>
10745 OMPParallelMasterTaskLoopDirective *D) {
10746 DeclarationNameInfo DirName;
10747 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10748 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10749 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10750 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10751 return Res;
10752}
10753
10754template <typename Derived>
10756 OMPParallelMaskedTaskLoopDirective *D) {
10757 DeclarationNameInfo DirName;
10758 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10759 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10760 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10761 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10762 return Res;
10763}
10764
10765template <typename Derived>
10768 OMPParallelMasterTaskLoopSimdDirective *D) {
10769 DeclarationNameInfo DirName;
10770 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10771 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10772 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10773 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10774 return Res;
10775}
10776
10777template <typename Derived>
10780 OMPParallelMaskedTaskLoopSimdDirective *D) {
10781 DeclarationNameInfo DirName;
10782 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10783 OMPD_parallel_masked_taskloop_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 OMPDistributeDirective *D) {
10792 DeclarationNameInfo DirName;
10793 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10794 OMPD_distribute, 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 OMPDistributeParallelForDirective *D) {
10803 DeclarationNameInfo DirName;
10804 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10805 OMPD_distribute_parallel_for, 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>
10814 OMPDistributeParallelForSimdDirective *D) {
10815 DeclarationNameInfo DirName;
10816 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10817 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10818 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10819 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10820 return Res;
10821}
10822
10823template <typename Derived>
10825 OMPDistributeSimdDirective *D) {
10826 DeclarationNameInfo DirName;
10827 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10828 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10829 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10830 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10831 return Res;
10832}
10833
10834template <typename Derived>
10836 OMPTargetParallelForSimdDirective *D) {
10837 DeclarationNameInfo DirName;
10838 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10839 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10841 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10842 return Res;
10843}
10844
10845template <typename Derived>
10847 OMPTargetSimdDirective *D) {
10848 DeclarationNameInfo DirName;
10849 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10850 OMPD_target_simd, 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 OMPTeamsDistributeDirective *D) {
10859 DeclarationNameInfo DirName;
10860 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10861 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10862 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10863 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10864 return Res;
10865}
10866
10867template <typename Derived>
10869 OMPTeamsDistributeSimdDirective *D) {
10870 DeclarationNameInfo DirName;
10871 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10872 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10873 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10874 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10875 return Res;
10876}
10877
10878template <typename Derived>
10880 OMPTeamsDistributeParallelForSimdDirective *D) {
10881 DeclarationNameInfo DirName;
10882 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10883 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10884 D->getBeginLoc());
10885 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10886 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10887 return Res;
10888}
10889
10890template <typename Derived>
10892 OMPTeamsDistributeParallelForDirective *D) {
10893 DeclarationNameInfo DirName;
10894 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10895 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10896 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10897 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10898 return Res;
10899}
10900
10901template <typename Derived>
10903 OMPTargetTeamsDirective *D) {
10904 DeclarationNameInfo DirName;
10905 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10906 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10907 auto Res = getDerived().TransformOMPExecutableDirective(D);
10908 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10909 return Res;
10910}
10911
10912template <typename Derived>
10914 OMPTargetTeamsDistributeDirective *D) {
10915 DeclarationNameInfo DirName;
10916 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10917 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10918 auto Res = getDerived().TransformOMPExecutableDirective(D);
10919 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10920 return Res;
10921}
10922
10923template <typename Derived>
10926 OMPTargetTeamsDistributeParallelForDirective *D) {
10927 DeclarationNameInfo DirName;
10928 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10929 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10930 D->getBeginLoc());
10931 auto Res = getDerived().TransformOMPExecutableDirective(D);
10932 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10933 return Res;
10934}
10935
10936template <typename Derived>
10939 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10940 DeclarationNameInfo DirName;
10941 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10942 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10943 D->getBeginLoc());
10944 auto Res = getDerived().TransformOMPExecutableDirective(D);
10945 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10946 return Res;
10947}
10948
10949template <typename Derived>
10952 OMPTargetTeamsDistributeSimdDirective *D) {
10953 DeclarationNameInfo DirName;
10954 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10955 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10956 auto Res = getDerived().TransformOMPExecutableDirective(D);
10957 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10958 return Res;
10959}
10960
10961template <typename Derived>
10964 DeclarationNameInfo DirName;
10965 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10966 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10968 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10969 return Res;
10970}
10971
10972template <typename Derived>
10975 DeclarationNameInfo DirName;
10976 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10977 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10979 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10980 return Res;
10981}
10982
10983template <typename Derived>
10986 DeclarationNameInfo DirName;
10987 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10988 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10990 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10991 return Res;
10992}
10993
10994template <typename Derived>
10996 OMPGenericLoopDirective *D) {
10997 DeclarationNameInfo DirName;
10998 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10999 OMPD_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 OMPTeamsGenericLoopDirective *D) {
11008 DeclarationNameInfo DirName;
11009 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11010 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
11011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11012 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11013 return Res;
11014}
11015
11016template <typename Derived>
11018 OMPTargetTeamsGenericLoopDirective *D) {
11019 DeclarationNameInfo DirName;
11020 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11021 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
11022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11023 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11024 return Res;
11025}
11026
11027template <typename Derived>
11029 OMPParallelGenericLoopDirective *D) {
11030 DeclarationNameInfo DirName;
11031 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11032 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
11033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11034 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11035 return Res;
11036}
11037
11038template <typename Derived>
11041 OMPTargetParallelGenericLoopDirective *D) {
11042 DeclarationNameInfo DirName;
11043 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11044 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
11045 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11046 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11047 return Res;
11048}
11049
11050template <typename Derived>
11052 OMPTargetGenericLoopDirective *D) {
11053 DeclarationNameInfo DirName;
11054 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11055 OMPD_target_loop, DirName, nullptr, D->getBeginLoc());
11056 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11057 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11058 return Res;
11059}
11060
11061//===----------------------------------------------------------------------===//
11062// OpenMP clause transformation
11063//===----------------------------------------------------------------------===//
11064template <typename Derived>
11066 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11067 if (Cond.isInvalid())
11068 return nullptr;
11069 return getDerived().RebuildOMPIfClause(
11070 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
11071 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
11072}
11073
11074template <typename Derived>
11076 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11077 if (Cond.isInvalid())
11078 return nullptr;
11079 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
11080 C->getLParenLoc(), C->getEndLoc());
11081}
11082
11083template <typename Derived>
11084OMPClause *
11087 Vars.reserve(C->varlist_size());
11088 for (auto *VE : C->varlist()) {
11089 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11090 if (EVar.isInvalid())
11091 return nullptr;
11092 Vars.push_back(EVar.get());
11093 }
11094 Expr *DimsModifierExpr = C->getDimsModifierExpr();
11095 if (DimsModifierExpr) {
11096 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(DimsModifierExpr));
11097 if (EVar.isInvalid())
11098 return nullptr;
11099 DimsModifierExpr = EVar.get();
11100 }
11101 return getDerived().RebuildOMPNumThreadsClause(
11102 Vars, C->getPrescriptivenessModifier(),
11103 C->getPrescriptivenessModifierLoc(), C->getDimsModifier(),
11104 DimsModifierExpr, C->getDimsModifierLoc(), C->getBeginLoc(),
11105 C->getLParenLoc(), C->getEndLoc());
11106}
11107
11108template <typename Derived>
11109OMPClause *
11111 ExprResult E = getDerived().TransformExpr(C->getSafelen());
11112 if (E.isInvalid())
11113 return nullptr;
11114 return getDerived().RebuildOMPSafelenClause(
11115 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11116}
11117
11118template <typename Derived>
11119OMPClause *
11121 ExprResult E = getDerived().TransformExpr(C->getAllocator());
11122 if (E.isInvalid())
11123 return nullptr;
11124 return getDerived().RebuildOMPAllocatorClause(
11125 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11126}
11127
11128template <typename Derived>
11129OMPClause *
11131 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
11132 if (E.isInvalid())
11133 return nullptr;
11134 return getDerived().RebuildOMPSimdlenClause(
11135 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11136}
11137
11138template <typename Derived>
11140 SmallVector<Expr *, 4> TransformedSizes;
11141 TransformedSizes.reserve(C->getNumSizes());
11142 bool Changed = false;
11143 for (Expr *E : C->getSizesRefs()) {
11144 if (!E) {
11145 TransformedSizes.push_back(nullptr);
11146 continue;
11147 }
11148
11149 ExprResult T = getDerived().TransformExpr(E);
11150 if (T.isInvalid())
11151 return nullptr;
11152 if (E != T.get())
11153 Changed = true;
11154 TransformedSizes.push_back(T.get());
11155 }
11156
11157 if (!Changed && !getDerived().AlwaysRebuild())
11158 return C;
11159 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
11160 C->getLParenLoc(), C->getEndLoc());
11161}
11162
11163template <typename Derived>
11164OMPClause *
11166 SmallVector<Expr *, 4> TransformedCounts;
11167 TransformedCounts.reserve(C->getNumCounts());
11168 for (Expr *E : C->getCountsRefs()) {
11169 if (!E) {
11170 TransformedCounts.push_back(nullptr);
11171 continue;
11172 }
11173
11174 ExprResult T = getDerived().TransformExpr(E);
11175 if (T.isInvalid())
11176 return nullptr;
11177 TransformedCounts.push_back(T.get());
11178 }
11179
11180 return RebuildOMPCountsClause(TransformedCounts, C->getBeginLoc(),
11181 C->getLParenLoc(), C->getEndLoc(),
11182 C->getOmpFillIndex(), C->getOmpFillLoc());
11183}
11184
11185template <typename Derived>
11186OMPClause *
11188 SmallVector<Expr *> TransformedArgs;
11189 TransformedArgs.reserve(C->getNumLoops());
11190 bool Changed = false;
11191 for (Expr *E : C->getArgsRefs()) {
11192 if (!E) {
11193 TransformedArgs.push_back(nullptr);
11194 continue;
11195 }
11196
11197 ExprResult T = getDerived().TransformExpr(E);
11198 if (T.isInvalid())
11199 return nullptr;
11200 if (E != T.get())
11201 Changed = true;
11202 TransformedArgs.push_back(T.get());
11203 }
11204
11205 if (!Changed && !getDerived().AlwaysRebuild())
11206 return C;
11207 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
11208 C->getLParenLoc(), C->getEndLoc());
11209}
11210
11211template <typename Derived>
11213 if (!getDerived().AlwaysRebuild())
11214 return C;
11215 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
11216}
11217
11218template <typename Derived>
11219OMPClause *
11221 ExprResult T = getDerived().TransformExpr(C->getFactor());
11222 if (T.isInvalid())
11223 return nullptr;
11224 Expr *Factor = T.get();
11225 bool Changed = Factor != C->getFactor();
11226
11227 if (!Changed && !getDerived().AlwaysRebuild())
11228 return C;
11229 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
11230 C->getEndLoc());
11231}
11232
11233template <typename Derived>
11235 ExprResult T = getDerived().TransformExpr(C->getDepth());
11236 if (T.isInvalid())
11237 return nullptr;
11238 Expr *Depth = T.get();
11239 bool Changed = Depth != C->getDepth();
11240
11241 if (!Changed && !getDerived().AlwaysRebuild())
11242 return C;
11243 return RebuildOMPDepthClause(Depth, C->getBeginLoc(), C->getLParenLoc(),
11244 C->getEndLoc());
11245}
11246
11247template <typename Derived>
11248OMPClause *
11250 ExprResult F = getDerived().TransformExpr(C->getFirst());
11251 if (F.isInvalid())
11252 return nullptr;
11253
11254 ExprResult Cn = getDerived().TransformExpr(C->getCount());
11255 if (Cn.isInvalid())
11256 return nullptr;
11257
11258 Expr *First = F.get();
11259 Expr *Count = Cn.get();
11260
11261 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
11262
11263 // If no changes and AlwaysRebuild() is false, return the original clause
11264 if (!Changed && !getDerived().AlwaysRebuild())
11265 return C;
11266
11267 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
11268 C->getLParenLoc(), C->getFirstLoc(),
11269 C->getCountLoc(), C->getEndLoc());
11270}
11271
11272template <typename Derived>
11273OMPClause *
11275 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
11276 if (E.isInvalid())
11277 return nullptr;
11278 return getDerived().RebuildOMPCollapseClause(
11279 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11280}
11281
11282template <typename Derived>
11283OMPClause *
11285 return getDerived().RebuildOMPDefaultClause(
11286 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
11287 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
11288 C->getEndLoc());
11289}
11290
11291template <typename Derived>
11292OMPClause *
11294 // No need to rebuild this clause, no template-dependent parameters.
11295 return C;
11296}
11297
11298template <typename Derived>
11299OMPClause *
11301 Expr *Impex = C->getImpexType();
11302 ExprResult TransformedImpex = getDerived().TransformExpr(Impex);
11303
11304 if (TransformedImpex.isInvalid())
11305 return nullptr;
11306
11307 return getDerived().RebuildOMPTransparentClause(
11308 TransformedImpex.get(), C->getBeginLoc(), C->getLParenLoc(),
11309 C->getEndLoc());
11310}
11311
11312template <typename Derived>
11313OMPClause *
11315 return getDerived().RebuildOMPProcBindClause(
11316 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
11317 C->getLParenLoc(), C->getEndLoc());
11318}
11319
11320template <typename Derived>
11321OMPClause *
11323 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11324 if (E.isInvalid())
11325 return nullptr;
11326 return getDerived().RebuildOMPScheduleClause(
11327 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
11328 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11329 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
11330 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11331}
11332
11333template <typename Derived>
11334OMPClause *
11336 ExprResult E;
11337 if (auto *Num = C->getNumForLoops()) {
11338 E = getDerived().TransformExpr(Num);
11339 if (E.isInvalid())
11340 return nullptr;
11341 }
11342 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
11343 C->getLParenLoc(), E.get());
11344}
11345
11346template <typename Derived>
11347OMPClause *
11349 ExprResult E;
11350 if (Expr *Evt = C->getEventHandler()) {
11351 E = getDerived().TransformExpr(Evt);
11352 if (E.isInvalid())
11353 return nullptr;
11354 }
11355 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
11356 C->getLParenLoc(), C->getEndLoc());
11357}
11358
11359template <typename Derived>
11360OMPClause *
11362 ExprResult Cond;
11363 if (auto *Condition = C->getCondition()) {
11364 Cond = getDerived().TransformExpr(Condition);
11365 if (Cond.isInvalid())
11366 return nullptr;
11367 }
11368 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
11369 C->getLParenLoc(), C->getEndLoc());
11370}
11371
11372template <typename Derived>
11373OMPClause *
11375 // No need to rebuild this clause, no template-dependent parameters.
11376 return C;
11377}
11378
11379template <typename Derived>
11380OMPClause *
11382 // No need to rebuild this clause, no template-dependent parameters.
11383 return C;
11384}
11385
11386template <typename Derived>
11388 // No need to rebuild this clause, no template-dependent parameters.
11389 return C;
11390}
11391
11392template <typename Derived>
11394 // No need to rebuild this clause, no template-dependent parameters.
11395 return C;
11396}
11397
11398template <typename Derived>
11399OMPClause *
11401 // No need to rebuild this clause, no template-dependent parameters.
11402 return C;
11403}
11404
11405template <typename Derived>
11407 OMPUpdateDependObjectsClause *C) {
11408 // No need to rebuild this clause, no template-dependent parameters.
11409 return C;
11410}
11411
11412template <typename Derived>
11413OMPClause *
11415 // No need to rebuild this clause, no template-dependent parameters.
11416 return C;
11417}
11418
11419template <typename Derived>
11420OMPClause *
11422 // No need to rebuild this clause, no template-dependent parameters.
11423 return C;
11424}
11425
11426template <typename Derived>
11428 // No need to rebuild this clause, no template-dependent parameters.
11429 return C;
11430}
11431
11432template <typename Derived>
11433OMPClause *
11435 return C;
11436}
11437
11438template <typename Derived>
11440 ExprResult E = getDerived().TransformExpr(C->getExpr());
11441 if (E.isInvalid())
11442 return nullptr;
11443 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
11444 C->getLParenLoc(), C->getEndLoc());
11445}
11446
11447template <typename Derived>
11448OMPClause *
11450 return C;
11451}
11452
11453template <typename Derived>
11454OMPClause *
11456 return C;
11457}
11458template <typename Derived>
11460 OMPNoOpenMPRoutinesClause *C) {
11461 return C;
11462}
11463template <typename Derived>
11465 OMPNoOpenMPConstructsClause *C) {
11466 return C;
11467}
11468template <typename Derived>
11470 OMPNoParallelismClause *C) {
11471 return C;
11472}
11473
11474template <typename Derived>
11475OMPClause *
11477 // No need to rebuild this clause, no template-dependent parameters.
11478 return C;
11479}
11480
11481template <typename Derived>
11482OMPClause *
11484 // No need to rebuild this clause, no template-dependent parameters.
11485 return C;
11486}
11487
11488template <typename Derived>
11489OMPClause *
11491 // No need to rebuild this clause, no template-dependent parameters.
11492 return C;
11493}
11494
11495template <typename Derived>
11496OMPClause *
11498 // No need to rebuild this clause, no template-dependent parameters.
11499 return C;
11500}
11501
11502template <typename Derived>
11503OMPClause *
11505 // No need to rebuild this clause, no template-dependent parameters.
11506 return C;
11507}
11508
11509template <typename Derived>
11511 // No need to rebuild this clause, no template-dependent parameters.
11512 return C;
11513}
11514
11515template <typename Derived>
11516OMPClause *
11518 // No need to rebuild this clause, no template-dependent parameters.
11519 return C;
11520}
11521
11522template <typename Derived>
11524 // No need to rebuild this clause, no template-dependent parameters.
11525 return C;
11526}
11527
11528template <typename Derived>
11529OMPClause *
11531 // No need to rebuild this clause, no template-dependent parameters.
11532 return C;
11533}
11534
11535template <typename Derived>
11537 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
11538 if (IVR.isInvalid())
11539 return nullptr;
11540
11541 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
11542 for (OMPInitClause::PrefView P : C->prefs()) {
11543 Expr *NewFr = nullptr;
11544 if (P.Fr) {
11545 ExprResult ER = getDerived().TransformExpr(P.Fr);
11546 if (ER.isInvalid())
11547 return nullptr;
11548 NewFr = ER.get();
11549 }
11550 SmallVector<Expr *, 2> NewAttrs;
11551 NewAttrs.reserve(P.Attrs.size());
11552 for (Expr *A : P.Attrs) {
11553 ExprResult ER = getDerived().TransformExpr(A);
11554 if (ER.isInvalid())
11555 return nullptr;
11556 NewAttrs.push_back(ER.get());
11557 }
11558 InteropInfo.Prefs.emplace_back(NewFr, std::move(NewAttrs));
11559 }
11560 InteropInfo.HasPreferAttrs = C->hasPreferAttrs();
11561 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
11562 C->getBeginLoc(), C->getLParenLoc(),
11563 C->getVarLoc(), C->getEndLoc());
11564}
11565
11566template <typename Derived>
11568 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
11569 if (ER.isInvalid())
11570 return nullptr;
11571 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
11572 C->getLParenLoc(), C->getVarLoc(),
11573 C->getEndLoc());
11574}
11575
11576template <typename Derived>
11577OMPClause *
11579 ExprResult ER;
11580 if (Expr *IV = C->getInteropVar()) {
11581 ER = getDerived().TransformExpr(IV);
11582 if (ER.isInvalid())
11583 return nullptr;
11584 }
11585 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
11586 C->getLParenLoc(), C->getVarLoc(),
11587 C->getEndLoc());
11588}
11589
11590template <typename Derived>
11591OMPClause *
11593 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11594 if (Cond.isInvalid())
11595 return nullptr;
11596 return getDerived().RebuildOMPNovariantsClause(
11597 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11598}
11599
11600template <typename Derived>
11601OMPClause *
11603 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11604 if (Cond.isInvalid())
11605 return nullptr;
11606 return getDerived().RebuildOMPNocontextClause(
11607 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11608}
11609
11610template <typename Derived>
11611OMPClause *
11613 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
11614 if (ThreadID.isInvalid())
11615 return nullptr;
11616 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
11617 C->getLParenLoc(), C->getEndLoc());
11618}
11619
11620template <typename Derived>
11622 ExprResult E = getDerived().TransformExpr(C->getAlignment());
11623 if (E.isInvalid())
11624 return nullptr;
11625 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
11626 C->getLParenLoc(), C->getEndLoc());
11627}
11628
11629template <typename Derived>
11631 OMPUnifiedAddressClause *C) {
11632 llvm_unreachable("unified_address clause cannot appear in dependent context");
11633}
11634
11635template <typename Derived>
11637 OMPUnifiedSharedMemoryClause *C) {
11638 llvm_unreachable(
11639 "unified_shared_memory clause cannot appear in dependent context");
11640}
11641
11642template <typename Derived>
11644 OMPReverseOffloadClause *C) {
11645 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
11646}
11647
11648template <typename Derived>
11650 OMPDynamicAllocatorsClause *C) {
11651 llvm_unreachable(
11652 "dynamic_allocators clause cannot appear in dependent context");
11653}
11654
11655template <typename Derived>
11657 OMPAtomicDefaultMemOrderClause *C) {
11658 llvm_unreachable(
11659 "atomic_default_mem_order clause cannot appear in dependent context");
11660}
11661
11662template <typename Derived>
11663OMPClause *
11665 llvm_unreachable("self_maps clause cannot appear in dependent context");
11666}
11667
11668template <typename Derived>
11670 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
11671 C->getBeginLoc(), C->getLParenLoc(),
11672 C->getEndLoc());
11673}
11674
11675template <typename Derived>
11676OMPClause *
11678 return getDerived().RebuildOMPSeverityClause(
11679 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
11680 C->getLParenLoc(), C->getEndLoc());
11681}
11682
11683template <typename Derived>
11684OMPClause *
11686 ExprResult E = getDerived().TransformExpr(C->getMessageString());
11687 if (E.isInvalid())
11688 return nullptr;
11689 return getDerived().RebuildOMPMessageClause(
11690 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11691}
11692
11693template <typename Derived>
11694OMPClause *
11697 Vars.reserve(C->varlist_size());
11698 for (auto *VE : C->varlist()) {
11699 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11700 if (EVar.isInvalid())
11701 return nullptr;
11702 Vars.push_back(EVar.get());
11703 }
11704 return getDerived().RebuildOMPPrivateClause(
11705 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11706}
11707
11708template <typename Derived>
11710 OMPFirstprivateClause *C) {
11712 Vars.reserve(C->varlist_size());
11713 for (auto *VE : C->varlist()) {
11714 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11715 if (EVar.isInvalid())
11716 return nullptr;
11717 Vars.push_back(EVar.get());
11718 }
11719 return getDerived().RebuildOMPFirstprivateClause(
11720 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11721}
11722
11723template <typename Derived>
11724OMPClause *
11727 Vars.reserve(C->varlist_size());
11728 for (auto *VE : C->varlist()) {
11729 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11730 if (EVar.isInvalid())
11731 return nullptr;
11732 Vars.push_back(EVar.get());
11733 }
11734 return getDerived().RebuildOMPLastprivateClause(
11735 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11736 C->getLParenLoc(), C->getEndLoc());
11737}
11738
11739template <typename Derived>
11740OMPClause *
11743 Vars.reserve(C->varlist_size());
11744 for (auto *VE : C->varlist()) {
11745 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11746 if (EVar.isInvalid())
11747 return nullptr;
11748 Vars.push_back(EVar.get());
11749 }
11750 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11751 C->getLParenLoc(), C->getEndLoc());
11752}
11753
11754template <typename Derived>
11755OMPClause *
11758 Vars.reserve(C->varlist_size());
11759 for (auto *VE : C->varlist()) {
11760 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11761 if (EVar.isInvalid())
11762 return nullptr;
11763 Vars.push_back(EVar.get());
11764 }
11765 CXXScopeSpec ReductionIdScopeSpec;
11766 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11767
11768 DeclarationNameInfo NameInfo = C->getNameInfo();
11769 if (NameInfo.getName()) {
11770 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11771 if (!NameInfo.getName())
11772 return nullptr;
11773 }
11774 // Build a list of all UDR decls with the same names ranged by the Scopes.
11775 // The Scope boundary is a duplication of the previous decl.
11776 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11777 for (auto *E : C->reduction_ops()) {
11778 // Transform all the decls.
11779 if (E) {
11780 auto *ULE = cast<UnresolvedLookupExpr>(E);
11781 UnresolvedSet<8> Decls;
11782 for (auto *D : ULE->decls()) {
11783 NamedDecl *InstD =
11784 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11785 Decls.addDecl(InstD, InstD->getAccess());
11786 }
11787 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11788 SemaRef.Context, /*NamingClass=*/nullptr,
11789 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11790 /*ADL=*/true, Decls.begin(), Decls.end(),
11791 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11792 } else
11793 UnresolvedReductions.push_back(nullptr);
11794 }
11795 return getDerived().RebuildOMPReductionClause(
11796 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11797 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11798 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11799}
11800
11801template <typename Derived>
11803 OMPTaskReductionClause *C) {
11805 Vars.reserve(C->varlist_size());
11806 for (auto *VE : C->varlist()) {
11807 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11808 if (EVar.isInvalid())
11809 return nullptr;
11810 Vars.push_back(EVar.get());
11811 }
11812 CXXScopeSpec ReductionIdScopeSpec;
11813 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11814
11815 DeclarationNameInfo NameInfo = C->getNameInfo();
11816 if (NameInfo.getName()) {
11817 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11818 if (!NameInfo.getName())
11819 return nullptr;
11820 }
11821 // Build a list of all UDR decls with the same names ranged by the Scopes.
11822 // The Scope boundary is a duplication of the previous decl.
11823 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11824 for (auto *E : C->reduction_ops()) {
11825 // Transform all the decls.
11826 if (E) {
11827 auto *ULE = cast<UnresolvedLookupExpr>(E);
11828 UnresolvedSet<8> Decls;
11829 for (auto *D : ULE->decls()) {
11830 NamedDecl *InstD =
11831 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11832 Decls.addDecl(InstD, InstD->getAccess());
11833 }
11834 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11835 SemaRef.Context, /*NamingClass=*/nullptr,
11836 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11837 /*ADL=*/true, Decls.begin(), Decls.end(),
11838 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11839 } else
11840 UnresolvedReductions.push_back(nullptr);
11841 }
11842 return getDerived().RebuildOMPTaskReductionClause(
11843 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11844 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11845}
11846
11847template <typename Derived>
11848OMPClause *
11851 Vars.reserve(C->varlist_size());
11852 for (auto *VE : C->varlist()) {
11853 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11854 if (EVar.isInvalid())
11855 return nullptr;
11856 Vars.push_back(EVar.get());
11857 }
11858 CXXScopeSpec ReductionIdScopeSpec;
11859 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11860
11861 DeclarationNameInfo NameInfo = C->getNameInfo();
11862 if (NameInfo.getName()) {
11863 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11864 if (!NameInfo.getName())
11865 return nullptr;
11866 }
11867 // Build a list of all UDR decls with the same names ranged by the Scopes.
11868 // The Scope boundary is a duplication of the previous decl.
11869 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11870 for (auto *E : C->reduction_ops()) {
11871 // Transform all the decls.
11872 if (E) {
11873 auto *ULE = cast<UnresolvedLookupExpr>(E);
11874 UnresolvedSet<8> Decls;
11875 for (auto *D : ULE->decls()) {
11876 NamedDecl *InstD =
11877 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11878 Decls.addDecl(InstD, InstD->getAccess());
11879 }
11880 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11881 SemaRef.Context, /*NamingClass=*/nullptr,
11882 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11883 /*ADL=*/true, Decls.begin(), Decls.end(),
11884 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11885 } else
11886 UnresolvedReductions.push_back(nullptr);
11887 }
11888 return getDerived().RebuildOMPInReductionClause(
11889 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11890 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11891}
11892
11893template <typename Derived>
11894OMPClause *
11897 Vars.reserve(C->varlist_size());
11898 for (auto *VE : C->varlist()) {
11899 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11900 if (EVar.isInvalid())
11901 return nullptr;
11902 Vars.push_back(EVar.get());
11903 }
11904 ExprResult Step = getDerived().TransformExpr(C->getStep());
11905 if (Step.isInvalid())
11906 return nullptr;
11907 return getDerived().RebuildOMPLinearClause(
11908 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11909 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11910 C->getEndLoc());
11911}
11912
11913template <typename Derived>
11914OMPClause *
11917 Vars.reserve(C->varlist_size());
11918 for (auto *VE : C->varlist()) {
11919 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11920 if (EVar.isInvalid())
11921 return nullptr;
11922 Vars.push_back(EVar.get());
11923 }
11924 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11925 if (Alignment.isInvalid())
11926 return nullptr;
11927 return getDerived().RebuildOMPAlignedClause(
11928 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11929 C->getColonLoc(), C->getEndLoc());
11930}
11931
11932template <typename Derived>
11933OMPClause *
11936 Vars.reserve(C->varlist_size());
11937 for (auto *VE : C->varlist()) {
11938 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11939 if (EVar.isInvalid())
11940 return nullptr;
11941 Vars.push_back(EVar.get());
11942 }
11943 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11944 C->getLParenLoc(), C->getEndLoc());
11945}
11946
11947template <typename Derived>
11948OMPClause *
11951 Vars.reserve(C->varlist_size());
11952 for (auto *VE : C->varlist()) {
11953 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11954 if (EVar.isInvalid())
11955 return nullptr;
11956 Vars.push_back(EVar.get());
11957 }
11958 return getDerived().RebuildOMPCopyprivateClause(
11959 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11960}
11961
11962template <typename Derived>
11965 Vars.reserve(C->varlist_size());
11966 for (auto *VE : C->varlist()) {
11967 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11968 if (EVar.isInvalid())
11969 return nullptr;
11970 Vars.push_back(EVar.get());
11971 }
11972 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11973 C->getLParenLoc(), C->getEndLoc());
11974}
11975
11976template <typename Derived>
11977OMPClause *
11979 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11980 if (E.isInvalid())
11981 return nullptr;
11982 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11983 C->getLParenLoc(), C->getEndLoc());
11984}
11985
11986template <typename Derived>
11987OMPClause *
11990 Expr *DepModifier = C->getModifier();
11991 if (DepModifier) {
11992 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11993 if (DepModRes.isInvalid())
11994 return nullptr;
11995 DepModifier = DepModRes.get();
11996 }
11997 Vars.reserve(C->varlist_size());
11998 for (auto *VE : C->varlist()) {
11999 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12000 if (EVar.isInvalid())
12001 return nullptr;
12002 Vars.push_back(EVar.get());
12003 }
12004 return getDerived().RebuildOMPDependClause(
12005 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
12006 C->getOmpAllMemoryLoc()},
12007 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12008}
12009
12010template <typename Derived>
12011OMPClause *
12013 ExprResult E = getDerived().TransformExpr(C->getDevice());
12014 if (E.isInvalid())
12015 return nullptr;
12016 return getDerived().RebuildOMPDeviceClause(
12017 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12018 C->getModifierLoc(), C->getEndLoc());
12019}
12020
12021template <typename Derived, class T>
12024 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
12025 DeclarationNameInfo &MapperIdInfo,
12026 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
12027 // Transform expressions in the list.
12028 Vars.reserve(C->varlist_size());
12029 for (auto *VE : C->varlist()) {
12030 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
12031 if (EVar.isInvalid())
12032 return true;
12033 Vars.push_back(EVar.get());
12034 }
12035 // Transform mapper scope specifier and identifier.
12036 NestedNameSpecifierLoc QualifierLoc;
12037 if (C->getMapperQualifierLoc()) {
12038 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
12039 C->getMapperQualifierLoc());
12040 if (!QualifierLoc)
12041 return true;
12042 }
12043 MapperIdScopeSpec.Adopt(QualifierLoc);
12044 MapperIdInfo = C->getMapperIdInfo();
12045 if (MapperIdInfo.getName()) {
12046 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
12047 if (!MapperIdInfo.getName())
12048 return true;
12049 }
12050 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
12051 // the previous user-defined mapper lookup in dependent environment.
12052 for (auto *E : C->mapperlists()) {
12053 // Transform all the decls.
12054 if (E) {
12055 auto *ULE = cast<UnresolvedLookupExpr>(E);
12056 UnresolvedSet<8> Decls;
12057 for (auto *D : ULE->decls()) {
12058 NamedDecl *InstD =
12059 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
12060 Decls.addDecl(InstD, InstD->getAccess());
12061 }
12062 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
12063 TT.getSema().Context, /*NamingClass=*/nullptr,
12064 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
12065 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
12066 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
12067 } else {
12068 UnresolvedMappers.push_back(nullptr);
12069 }
12070 }
12071 return false;
12072}
12073
12074template <typename Derived>
12075OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
12076 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12078 Expr *IteratorModifier = C->getIteratorModifier();
12079 if (IteratorModifier) {
12080 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12081 if (MapModRes.isInvalid())
12082 return nullptr;
12083 IteratorModifier = MapModRes.get();
12084 }
12085 CXXScopeSpec MapperIdScopeSpec;
12086 DeclarationNameInfo MapperIdInfo;
12087 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12089 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12090 return nullptr;
12091 return getDerived().RebuildOMPMapClause(
12092 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
12093 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
12094 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
12095}
12096
12097template <typename Derived>
12098OMPClause *
12100 Expr *Allocator = C->getAllocator();
12101 if (Allocator) {
12102 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
12103 if (AllocatorRes.isInvalid())
12104 return nullptr;
12105 Allocator = AllocatorRes.get();
12106 }
12107 Expr *Alignment = C->getAlignment();
12108 if (Alignment) {
12109 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
12110 if (AlignmentRes.isInvalid())
12111 return nullptr;
12112 Alignment = AlignmentRes.get();
12113 }
12115 Vars.reserve(C->varlist_size());
12116 for (auto *VE : C->varlist()) {
12117 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12118 if (EVar.isInvalid())
12119 return nullptr;
12120 Vars.push_back(EVar.get());
12121 }
12122 return getDerived().RebuildOMPAllocateClause(
12123 Allocator, Alignment, C->getFirstAllocateModifier(),
12124 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
12125 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
12126 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
12127}
12128
12129template <typename Derived>
12130OMPClause *
12133 Vars.reserve(C->varlist_size());
12134 for (auto *VE : C->varlist()) {
12135 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12136 if (EVar.isInvalid())
12137 return nullptr;
12138 Vars.push_back(EVar.get());
12139 }
12140 Expr *ModifierExpr = C->getModifierExpr();
12141 if (ModifierExpr) {
12142 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
12143 if (EVar.isInvalid())
12144 return nullptr;
12145 ModifierExpr = EVar.get();
12146 }
12147 return getDerived().RebuildOMPNumTeamsClause(
12148 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
12149 OMPC_NUMTEAMS_unknown, nullptr, SourceLocation(), C->getBeginLoc(),
12150 C->getLParenLoc(), C->getEndLoc());
12151}
12152
12153template <typename Derived>
12154OMPClause *
12157 Vars.reserve(C->varlist_size());
12158 for (auto *VE : C->varlist()) {
12159 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12160 if (EVar.isInvalid())
12161 return nullptr;
12162 Vars.push_back(EVar.get());
12163 }
12164 Expr *ModifierExpr = C->getModifierExpr();
12165 if (ModifierExpr) {
12166 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
12167 if (EVar.isInvalid())
12168 return nullptr;
12169 ModifierExpr = EVar.get();
12170 }
12171 return getDerived().RebuildOMPThreadLimitClause(
12172 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
12173 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12174}
12175
12176template <typename Derived>
12177OMPClause *
12179 ExprResult E = getDerived().TransformExpr(C->getPriority());
12180 if (E.isInvalid())
12181 return nullptr;
12182 return getDerived().RebuildOMPPriorityClause(
12183 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12184}
12185
12186template <typename Derived>
12187OMPClause *
12189 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
12190 if (E.isInvalid())
12191 return nullptr;
12192 return getDerived().RebuildOMPGrainsizeClause(
12193 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12194 C->getModifierLoc(), C->getEndLoc());
12195}
12196
12197template <typename Derived>
12198OMPClause *
12200 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
12201 if (E.isInvalid())
12202 return nullptr;
12203 return getDerived().RebuildOMPNumTasksClause(
12204 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12205 C->getModifierLoc(), C->getEndLoc());
12206}
12207
12208template <typename Derived>
12210 ExprResult E = getDerived().TransformExpr(C->getHint());
12211 if (E.isInvalid())
12212 return nullptr;
12213 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
12214 C->getLParenLoc(), C->getEndLoc());
12215}
12216
12217template <typename Derived>
12219 OMPDistScheduleClause *C) {
12220 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
12221 if (E.isInvalid())
12222 return nullptr;
12223 return getDerived().RebuildOMPDistScheduleClause(
12224 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12225 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
12226}
12227
12228template <typename Derived>
12229OMPClause *
12231 // Rebuild Defaultmap Clause since we need to invoke the checking of
12232 // defaultmap(none:variable-category) after template initialization.
12233 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
12234 C->getDefaultmapKind(),
12235 C->getBeginLoc(),
12236 C->getLParenLoc(),
12237 C->getDefaultmapModifierLoc(),
12238 C->getDefaultmapKindLoc(),
12239 C->getEndLoc());
12240}
12241
12242template <typename Derived>
12244 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12246 Expr *IteratorModifier = C->getIteratorModifier();
12247 if (IteratorModifier) {
12248 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12249 if (MapModRes.isInvalid())
12250 return nullptr;
12251 IteratorModifier = MapModRes.get();
12252 }
12253 CXXScopeSpec MapperIdScopeSpec;
12254 DeclarationNameInfo MapperIdInfo;
12255 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12257 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12258 return nullptr;
12259 return getDerived().RebuildOMPToClause(
12260 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
12261 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
12262 UnresolvedMappers);
12263}
12264
12265template <typename Derived>
12267 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12269 Expr *IteratorModifier = C->getIteratorModifier();
12270 if (IteratorModifier) {
12271 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12272 if (MapModRes.isInvalid())
12273 return nullptr;
12274 IteratorModifier = MapModRes.get();
12275 }
12276 CXXScopeSpec MapperIdScopeSpec;
12277 DeclarationNameInfo MapperIdInfo;
12278 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12280 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12281 return nullptr;
12282 return getDerived().RebuildOMPFromClause(
12283 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
12284 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
12285 UnresolvedMappers);
12286}
12287
12288template <typename Derived>
12290 OMPUseDevicePtrClause *C) {
12292 Vars.reserve(C->varlist_size());
12293 for (auto *VE : C->varlist()) {
12294 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12295 if (EVar.isInvalid())
12296 return nullptr;
12297 Vars.push_back(EVar.get());
12298 }
12299 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12300 return getDerived().RebuildOMPUseDevicePtrClause(
12301 Vars, Locs, C->getFallbackModifier(), C->getFallbackModifierLoc());
12302}
12303
12304template <typename Derived>
12306 OMPUseDeviceAddrClause *C) {
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 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12316 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
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 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12331 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
12332}
12333
12334template <typename Derived>
12336 OMPHasDeviceAddrClause *C) {
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 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12346 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
12347}
12348
12349template <typename Derived>
12350OMPClause *
12353 Vars.reserve(C->varlist_size());
12354 for (auto *VE : C->varlist()) {
12355 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12356 if (EVar.isInvalid())
12357 return nullptr;
12358 Vars.push_back(EVar.get());
12359 }
12360 return getDerived().RebuildOMPNontemporalClause(
12361 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12362}
12363
12364template <typename Derived>
12365OMPClause *
12368 Vars.reserve(C->varlist_size());
12369 for (auto *VE : C->varlist()) {
12370 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12371 if (EVar.isInvalid())
12372 return nullptr;
12373 Vars.push_back(EVar.get());
12374 }
12375 return getDerived().RebuildOMPInclusiveClause(
12376 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12377}
12378
12379template <typename Derived>
12380OMPClause *
12383 Vars.reserve(C->varlist_size());
12384 for (auto *VE : C->varlist()) {
12385 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12386 if (EVar.isInvalid())
12387 return nullptr;
12388 Vars.push_back(EVar.get());
12389 }
12390 return getDerived().RebuildOMPExclusiveClause(
12391 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12392}
12393
12394template <typename Derived>
12396 OMPUsesAllocatorsClause *C) {
12398 Data.reserve(C->getNumberOfAllocators());
12399 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
12400 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
12401 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
12402 if (Allocator.isInvalid())
12403 continue;
12404 ExprResult AllocatorTraits;
12405 if (Expr *AT = D.AllocatorTraits) {
12406 AllocatorTraits = getDerived().TransformExpr(AT);
12407 if (AllocatorTraits.isInvalid())
12408 continue;
12409 }
12410 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
12411 NewD.Allocator = Allocator.get();
12412 NewD.AllocatorTraits = AllocatorTraits.get();
12413 NewD.LParenLoc = D.LParenLoc;
12414 NewD.RParenLoc = D.RParenLoc;
12415 }
12416 return getDerived().RebuildOMPUsesAllocatorsClause(
12417 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12418}
12419
12420template <typename Derived>
12421OMPClause *
12423 SmallVector<Expr *, 4> Locators;
12424 Locators.reserve(C->varlist_size());
12425 ExprResult ModifierRes;
12426 if (Expr *Modifier = C->getModifier()) {
12427 ModifierRes = getDerived().TransformExpr(Modifier);
12428 if (ModifierRes.isInvalid())
12429 return nullptr;
12430 }
12431 for (Expr *E : C->varlist()) {
12432 ExprResult Locator = getDerived().TransformExpr(E);
12433 if (Locator.isInvalid())
12434 continue;
12435 Locators.push_back(Locator.get());
12436 }
12437 return getDerived().RebuildOMPAffinityClause(
12438 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
12439 ModifierRes.get(), Locators);
12440}
12441
12442template <typename Derived>
12444 return getDerived().RebuildOMPOrderClause(
12445 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
12446 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
12447}
12448
12449template <typename Derived>
12451 return getDerived().RebuildOMPBindClause(
12452 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
12453 C->getLParenLoc(), C->getEndLoc());
12454}
12455
12456template <typename Derived>
12458 OMPXDynCGroupMemClause *C) {
12459 ExprResult Size = getDerived().TransformExpr(C->getSize());
12460 if (Size.isInvalid())
12461 return nullptr;
12462 return getDerived().RebuildOMPXDynCGroupMemClause(
12463 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12464}
12465
12466template <typename Derived>
12468 OMPDynGroupprivateClause *C) {
12469 ExprResult Size = getDerived().TransformExpr(C->getSize());
12470 if (Size.isInvalid())
12471 return nullptr;
12472 return getDerived().RebuildOMPDynGroupprivateClause(
12473 C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(),
12474 Size.get(), C->getBeginLoc(), C->getLParenLoc(),
12475 C->getDynGroupprivateModifierLoc(),
12476 C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc());
12477}
12478
12479template <typename Derived>
12480OMPClause *
12483 Vars.reserve(C->varlist_size());
12484 for (auto *VE : C->varlist()) {
12485 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12486 if (EVar.isInvalid())
12487 return nullptr;
12488 Vars.push_back(EVar.get());
12489 }
12490 return getDerived().RebuildOMPDoacrossClause(
12491 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
12492 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12493}
12494
12495template <typename Derived>
12496OMPClause *
12499 for (auto *A : C->getAttrs())
12500 NewAttrs.push_back(getDerived().TransformAttr(A));
12501 return getDerived().RebuildOMPXAttributeClause(
12502 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12503}
12504
12505template <typename Derived>
12507 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
12508}
12509
12510//===----------------------------------------------------------------------===//
12511// OpenACC transformation
12512//===----------------------------------------------------------------------===//
12513namespace {
12514template <typename Derived>
12515class OpenACCClauseTransform final
12516 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
12517 TreeTransform<Derived> &Self;
12518 ArrayRef<const OpenACCClause *> ExistingClauses;
12519 SemaOpenACC::OpenACCParsedClause &ParsedClause;
12520 OpenACCClause *NewClause = nullptr;
12521
12522 ExprResult VisitVar(Expr *VarRef) {
12523 ExprResult Res = Self.TransformExpr(VarRef);
12524
12525 if (!Res.isUsable())
12526 return Res;
12527
12528 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12529 ParsedClause.getClauseKind(),
12530 Res.get());
12531
12532 return Res;
12533 }
12534
12535 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
12536 llvm::SmallVector<Expr *> InstantiatedVarList;
12537 for (Expr *CurVar : VarList) {
12538 ExprResult VarRef = VisitVar(CurVar);
12539
12540 if (VarRef.isUsable())
12541 InstantiatedVarList.push_back(VarRef.get());
12542 }
12543
12544 return InstantiatedVarList;
12545 }
12546
12547public:
12548 OpenACCClauseTransform(TreeTransform<Derived> &Self,
12549 ArrayRef<const OpenACCClause *> ExistingClauses,
12550 SemaOpenACC::OpenACCParsedClause &PC)
12551 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
12552
12553 OpenACCClause *CreatedClause() const { return NewClause; }
12554
12555#define VISIT_CLAUSE(CLAUSE_NAME) \
12556 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
12557#include "clang/Basic/OpenACCClauses.def"
12558};
12559
12560template <typename Derived>
12561void OpenACCClauseTransform<Derived>::VisitDefaultClause(
12562 const OpenACCDefaultClause &C) {
12563 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
12564
12565 NewClause = OpenACCDefaultClause::Create(
12566 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
12567 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12568 ParsedClause.getEndLoc());
12569}
12570
12571template <typename Derived>
12572void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
12573 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12574 assert(Cond && "If constructed with invalid Condition");
12575 Sema::ConditionResult Res = Self.TransformCondition(
12576 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
12577
12578 if (Res.isInvalid() || !Res.get().second)
12579 return;
12580
12581 ParsedClause.setConditionDetails(Res.get().second);
12582
12583 NewClause = OpenACCIfClause::Create(
12584 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12585 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12586 ParsedClause.getEndLoc());
12587}
12588
12589template <typename Derived>
12590void OpenACCClauseTransform<Derived>::VisitSelfClause(
12591 const OpenACCSelfClause &C) {
12592
12593 // If this is an 'update' 'self' clause, this is actually a var list instead.
12594 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
12595 llvm::SmallVector<Expr *> InstantiatedVarList;
12596 for (Expr *CurVar : C.getVarList()) {
12597 ExprResult Res = Self.TransformExpr(CurVar);
12598
12599 if (!Res.isUsable())
12600 continue;
12601
12602 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12603 ParsedClause.getClauseKind(),
12604 Res.get());
12605
12606 if (Res.isUsable())
12607 InstantiatedVarList.push_back(Res.get());
12608 }
12609
12610 ParsedClause.setVarListDetails(InstantiatedVarList,
12612
12613 NewClause = OpenACCSelfClause::Create(
12614 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12615 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12616 ParsedClause.getEndLoc());
12617 } else {
12618
12619 if (C.hasConditionExpr()) {
12620 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12622 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
12624
12625 if (Res.isInvalid() || !Res.get().second)
12626 return;
12627
12628 ParsedClause.setConditionDetails(Res.get().second);
12629 }
12630
12631 NewClause = OpenACCSelfClause::Create(
12632 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12633 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12634 ParsedClause.getEndLoc());
12635 }
12636}
12637
12638template <typename Derived>
12639void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
12640 const OpenACCNumGangsClause &C) {
12641 llvm::SmallVector<Expr *> InstantiatedIntExprs;
12642
12643 for (Expr *CurIntExpr : C.getIntExprs()) {
12644 ExprResult Res = Self.TransformExpr(CurIntExpr);
12645
12646 if (!Res.isUsable())
12647 return;
12648
12649 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12650 C.getClauseKind(),
12651 C.getBeginLoc(), Res.get());
12652 if (!Res.isUsable())
12653 return;
12654
12655 InstantiatedIntExprs.push_back(Res.get());
12656 }
12657
12658 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
12660 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12661 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12662 ParsedClause.getEndLoc());
12663}
12664
12665template <typename Derived>
12666void OpenACCClauseTransform<Derived>::VisitPrivateClause(
12667 const OpenACCPrivateClause &C) {
12668 llvm::SmallVector<Expr *> InstantiatedVarList;
12670
12671 for (const auto [RefExpr, InitRecipe] :
12672 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12673 ExprResult VarRef = VisitVar(RefExpr);
12674
12675 if (VarRef.isUsable()) {
12676 InstantiatedVarList.push_back(VarRef.get());
12677
12678 // We only have to create a new one if it is dependent, and Sema won't
12679 // make one of these unless the type is non-dependent.
12680 if (InitRecipe.isSet())
12681 InitRecipes.push_back(InitRecipe);
12682 else
12683 InitRecipes.push_back(
12684 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
12685 }
12686 }
12687 ParsedClause.setVarListDetails(InstantiatedVarList,
12689
12690 NewClause = OpenACCPrivateClause::Create(
12691 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12692 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12693 ParsedClause.getEndLoc());
12694}
12695
12696template <typename Derived>
12697void OpenACCClauseTransform<Derived>::VisitHostClause(
12698 const OpenACCHostClause &C) {
12699 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12701
12702 NewClause = OpenACCHostClause::Create(
12703 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12704 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12705 ParsedClause.getEndLoc());
12706}
12707
12708template <typename Derived>
12709void OpenACCClauseTransform<Derived>::VisitDeviceClause(
12710 const OpenACCDeviceClause &C) {
12711 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12713
12714 NewClause = OpenACCDeviceClause::Create(
12715 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12716 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12717 ParsedClause.getEndLoc());
12718}
12719
12720template <typename Derived>
12721void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
12723 llvm::SmallVector<Expr *> InstantiatedVarList;
12725
12726 for (const auto [RefExpr, InitRecipe] :
12727 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12728 ExprResult VarRef = VisitVar(RefExpr);
12729
12730 if (VarRef.isUsable()) {
12731 InstantiatedVarList.push_back(VarRef.get());
12732
12733 // We only have to create a new one if it is dependent, and Sema won't
12734 // make one of these unless the type is non-dependent.
12735 if (InitRecipe.isSet())
12736 InitRecipes.push_back(InitRecipe);
12737 else
12738 InitRecipes.push_back(
12739 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
12740 VarRef.get()));
12741 }
12742 }
12743 ParsedClause.setVarListDetails(InstantiatedVarList,
12745
12747 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12748 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12749 ParsedClause.getEndLoc());
12750}
12751
12752template <typename Derived>
12753void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12754 const OpenACCNoCreateClause &C) {
12755 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12757
12759 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12760 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12761 ParsedClause.getEndLoc());
12762}
12763
12764template <typename Derived>
12765void OpenACCClauseTransform<Derived>::VisitPresentClause(
12766 const OpenACCPresentClause &C) {
12767 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12769
12770 NewClause = OpenACCPresentClause::Create(
12771 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12772 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12773 ParsedClause.getEndLoc());
12774}
12775
12776template <typename Derived>
12777void OpenACCClauseTransform<Derived>::VisitCopyClause(
12778 const OpenACCCopyClause &C) {
12779 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12780 C.getModifierList());
12781
12782 NewClause = OpenACCCopyClause::Create(
12783 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12784 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12785 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12786 ParsedClause.getEndLoc());
12787}
12788
12789template <typename Derived>
12790void OpenACCClauseTransform<Derived>::VisitLinkClause(
12791 const OpenACCLinkClause &C) {
12792 llvm_unreachable("link clause not valid unless a decl transform");
12793}
12794
12795template <typename Derived>
12796void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12798 llvm_unreachable("device_resident clause not valid unless a decl transform");
12799}
12800template <typename Derived>
12801void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12802 const OpenACCNoHostClause &C) {
12803 llvm_unreachable("nohost clause not valid unless a decl transform");
12804}
12805template <typename Derived>
12806void OpenACCClauseTransform<Derived>::VisitBindClause(
12807 const OpenACCBindClause &C) {
12808 llvm_unreachable("bind clause not valid unless a decl transform");
12809}
12810
12811template <typename Derived>
12812void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12813 const OpenACCCopyInClause &C) {
12814 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12815 C.getModifierList());
12816
12817 NewClause = OpenACCCopyInClause::Create(
12818 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12819 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12820 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12821 ParsedClause.getEndLoc());
12822}
12823
12824template <typename Derived>
12825void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12826 const OpenACCCopyOutClause &C) {
12827 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12828 C.getModifierList());
12829
12830 NewClause = OpenACCCopyOutClause::Create(
12831 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12832 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12833 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12834 ParsedClause.getEndLoc());
12835}
12836
12837template <typename Derived>
12838void OpenACCClauseTransform<Derived>::VisitCreateClause(
12839 const OpenACCCreateClause &C) {
12840 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12841 C.getModifierList());
12842
12843 NewClause = OpenACCCreateClause::Create(
12844 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12845 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12846 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12847 ParsedClause.getEndLoc());
12848}
12849template <typename Derived>
12850void OpenACCClauseTransform<Derived>::VisitAttachClause(
12851 const OpenACCAttachClause &C) {
12852 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12853
12854 // Ensure each var is a pointer type.
12855 llvm::erase_if(VarList, [&](Expr *E) {
12856 return Self.getSema().OpenACC().CheckVarIsPointerType(
12858 });
12859
12860 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12861 NewClause = OpenACCAttachClause::Create(
12862 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12863 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12864 ParsedClause.getEndLoc());
12865}
12866
12867template <typename Derived>
12868void OpenACCClauseTransform<Derived>::VisitDetachClause(
12869 const OpenACCDetachClause &C) {
12870 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12871
12872 // Ensure each var is a pointer type.
12873 llvm::erase_if(VarList, [&](Expr *E) {
12874 return Self.getSema().OpenACC().CheckVarIsPointerType(
12876 });
12877
12878 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12879 NewClause = OpenACCDetachClause::Create(
12880 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12881 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12882 ParsedClause.getEndLoc());
12883}
12884
12885template <typename Derived>
12886void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12887 const OpenACCDeleteClause &C) {
12888 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12890 NewClause = OpenACCDeleteClause::Create(
12891 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12892 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12893 ParsedClause.getEndLoc());
12894}
12895
12896template <typename Derived>
12897void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12898 const OpenACCUseDeviceClause &C) {
12899 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12902 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12903 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12904 ParsedClause.getEndLoc());
12905}
12906
12907template <typename Derived>
12908void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12909 const OpenACCDevicePtrClause &C) {
12910 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12911
12912 // Ensure each var is a pointer type.
12913 llvm::erase_if(VarList, [&](Expr *E) {
12914 return Self.getSema().OpenACC().CheckVarIsPointerType(
12916 });
12917
12918 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12920 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12921 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12922 ParsedClause.getEndLoc());
12923}
12924
12925template <typename Derived>
12926void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12927 const OpenACCNumWorkersClause &C) {
12928 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12929 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12930
12931 ExprResult Res = Self.TransformExpr(IntExpr);
12932 if (!Res.isUsable())
12933 return;
12934
12935 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12936 C.getClauseKind(),
12937 C.getBeginLoc(), Res.get());
12938 if (!Res.isUsable())
12939 return;
12940
12941 ParsedClause.setIntExprDetails(Res.get());
12943 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12944 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12945 ParsedClause.getEndLoc());
12946}
12947
12948template <typename Derived>
12949void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12950 const OpenACCDeviceNumClause &C) {
12951 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12952 assert(IntExpr && "device_num clause constructed with invalid int expr");
12953
12954 ExprResult Res = Self.TransformExpr(IntExpr);
12955 if (!Res.isUsable())
12956 return;
12957
12958 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12959 C.getClauseKind(),
12960 C.getBeginLoc(), Res.get());
12961 if (!Res.isUsable())
12962 return;
12963
12964 ParsedClause.setIntExprDetails(Res.get());
12966 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12967 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12968 ParsedClause.getEndLoc());
12969}
12970
12971template <typename Derived>
12972void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12974 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12975 assert(IntExpr && "default_async clause constructed with invalid int expr");
12976
12977 ExprResult Res = Self.TransformExpr(IntExpr);
12978 if (!Res.isUsable())
12979 return;
12980
12981 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12982 C.getClauseKind(),
12983 C.getBeginLoc(), Res.get());
12984 if (!Res.isUsable())
12985 return;
12986
12987 ParsedClause.setIntExprDetails(Res.get());
12989 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12990 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12991 ParsedClause.getEndLoc());
12992}
12993
12994template <typename Derived>
12995void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12997 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12998 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12999
13000 ExprResult Res = Self.TransformExpr(IntExpr);
13001 if (!Res.isUsable())
13002 return;
13003
13004 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13005 C.getClauseKind(),
13006 C.getBeginLoc(), Res.get());
13007 if (!Res.isUsable())
13008 return;
13009
13010 ParsedClause.setIntExprDetails(Res.get());
13012 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13013 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
13014 ParsedClause.getEndLoc());
13015}
13016
13017template <typename Derived>
13018void OpenACCClauseTransform<Derived>::VisitAsyncClause(
13019 const OpenACCAsyncClause &C) {
13020 if (C.hasIntExpr()) {
13021 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
13022 if (!Res.isUsable())
13023 return;
13024
13025 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13026 C.getClauseKind(),
13027 C.getBeginLoc(), Res.get());
13028 if (!Res.isUsable())
13029 return;
13030 ParsedClause.setIntExprDetails(Res.get());
13031 }
13032
13033 NewClause = OpenACCAsyncClause::Create(
13034 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13035 ParsedClause.getLParenLoc(),
13036 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
13037 : nullptr,
13038 ParsedClause.getEndLoc());
13039}
13040
13041template <typename Derived>
13042void OpenACCClauseTransform<Derived>::VisitWorkerClause(
13043 const OpenACCWorkerClause &C) {
13044 if (C.hasIntExpr()) {
13045 // restrictions on this expression are all "does it exist in certain
13046 // situations" that are not possible to be dependent, so the only check we
13047 // have is that it transforms, and is an int expression.
13048 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
13049 if (!Res.isUsable())
13050 return;
13051
13052 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13053 C.getClauseKind(),
13054 C.getBeginLoc(), Res.get());
13055 if (!Res.isUsable())
13056 return;
13057 ParsedClause.setIntExprDetails(Res.get());
13058 }
13059
13060 NewClause = OpenACCWorkerClause::Create(
13061 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13062 ParsedClause.getLParenLoc(),
13063 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
13064 : nullptr,
13065 ParsedClause.getEndLoc());
13066}
13067
13068template <typename Derived>
13069void OpenACCClauseTransform<Derived>::VisitVectorClause(
13070 const OpenACCVectorClause &C) {
13071 if (C.hasIntExpr()) {
13072 // restrictions on this expression are all "does it exist in certain
13073 // situations" that are not possible to be dependent, so the only check we
13074 // have is that it transforms, and is an int expression.
13075 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
13076 if (!Res.isUsable())
13077 return;
13078
13079 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13080 C.getClauseKind(),
13081 C.getBeginLoc(), Res.get());
13082 if (!Res.isUsable())
13083 return;
13084 ParsedClause.setIntExprDetails(Res.get());
13085 }
13086
13087 NewClause = OpenACCVectorClause::Create(
13088 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13089 ParsedClause.getLParenLoc(),
13090 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
13091 : nullptr,
13092 ParsedClause.getEndLoc());
13093}
13094
13095template <typename Derived>
13096void OpenACCClauseTransform<Derived>::VisitWaitClause(
13097 const OpenACCWaitClause &C) {
13098 if (C.hasExprs()) {
13099 Expr *DevNumExpr = nullptr;
13100 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
13101
13102 // Instantiate devnum expr if it exists.
13103 if (C.getDevNumExpr()) {
13104 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
13105 if (!Res.isUsable())
13106 return;
13107 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13108 C.getClauseKind(),
13109 C.getBeginLoc(), Res.get());
13110 if (!Res.isUsable())
13111 return;
13112
13113 DevNumExpr = Res.get();
13114 }
13115
13116 // Instantiate queue ids.
13117 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
13118 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
13119 if (!Res.isUsable())
13120 return;
13121 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13122 C.getClauseKind(),
13123 C.getBeginLoc(), Res.get());
13124 if (!Res.isUsable())
13125 return;
13126
13127 InstantiatedQueueIdExprs.push_back(Res.get());
13128 }
13129
13130 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
13131 std::move(InstantiatedQueueIdExprs));
13132 }
13133
13134 NewClause = OpenACCWaitClause::Create(
13135 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13136 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
13137 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
13138 ParsedClause.getEndLoc());
13139}
13140
13141template <typename Derived>
13142void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
13143 const OpenACCDeviceTypeClause &C) {
13144 // Nothing to transform here, just create a new version of 'C'.
13146 Self.getSema().getASTContext(), C.getClauseKind(),
13147 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13148 C.getArchitectures(), ParsedClause.getEndLoc());
13149}
13150
13151template <typename Derived>
13152void OpenACCClauseTransform<Derived>::VisitAutoClause(
13153 const OpenACCAutoClause &C) {
13154 // Nothing to do, so just create a new node.
13155 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
13156 ParsedClause.getBeginLoc(),
13157 ParsedClause.getEndLoc());
13158}
13159
13160template <typename Derived>
13161void OpenACCClauseTransform<Derived>::VisitIndependentClause(
13162 const OpenACCIndependentClause &C) {
13163 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
13164 ParsedClause.getBeginLoc(),
13165 ParsedClause.getEndLoc());
13166}
13167
13168template <typename Derived>
13169void OpenACCClauseTransform<Derived>::VisitSeqClause(
13170 const OpenACCSeqClause &C) {
13171 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
13172 ParsedClause.getBeginLoc(),
13173 ParsedClause.getEndLoc());
13174}
13175template <typename Derived>
13176void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
13177 const OpenACCFinalizeClause &C) {
13178 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
13179 ParsedClause.getBeginLoc(),
13180 ParsedClause.getEndLoc());
13181}
13182
13183template <typename Derived>
13184void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
13185 const OpenACCIfPresentClause &C) {
13186 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
13187 ParsedClause.getBeginLoc(),
13188 ParsedClause.getEndLoc());
13189}
13190
13191template <typename Derived>
13192void OpenACCClauseTransform<Derived>::VisitReductionClause(
13193 const OpenACCReductionClause &C) {
13194 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
13195 SmallVector<Expr *> ValidVars;
13197
13198 for (const auto [Var, OrigRecipe] :
13199 llvm::zip(TransformedVars, C.getRecipes())) {
13200 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
13201 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
13202 if (Res.isUsable()) {
13203 ValidVars.push_back(Res.get());
13204
13205 if (OrigRecipe.isSet())
13206 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
13207 else
13208 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
13209 C.getReductionOp(), Res.get()));
13210 }
13211 }
13212
13213 NewClause = Self.getSema().OpenACC().CheckReductionClause(
13214 ExistingClauses, ParsedClause.getDirectiveKind(),
13215 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13216 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
13217}
13218
13219template <typename Derived>
13220void OpenACCClauseTransform<Derived>::VisitCollapseClause(
13221 const OpenACCCollapseClause &C) {
13222 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
13223 assert(LoopCount && "collapse clause constructed with invalid loop count");
13224
13225 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
13226
13227 if (!NewLoopCount.isUsable())
13228 return;
13229
13230 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
13231 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
13232 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
13233
13234 // FIXME: It isn't clear whether this is properly tested here, we should
13235 // probably see if we can come up with a test for this.
13236 if (!NewLoopCount.isUsable())
13237 return;
13238
13239 NewLoopCount =
13240 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
13241
13242 // FIXME: It isn't clear whether this is properly tested here, we should
13243 // probably see if we can come up with a test for this.
13244 if (!NewLoopCount.isUsable())
13245 return;
13246
13247 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
13249 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13250 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
13251 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
13252}
13253
13254template <typename Derived>
13255void OpenACCClauseTransform<Derived>::VisitTileClause(
13256 const OpenACCTileClause &C) {
13257
13258 llvm::SmallVector<Expr *> TransformedExprs;
13259
13260 for (Expr *E : C.getSizeExprs()) {
13261 ExprResult NewSizeExpr = Self.TransformExpr(E);
13262
13263 if (!NewSizeExpr.isUsable())
13264 return;
13265
13266 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
13267 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
13268 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
13269
13270 // FIXME: It isn't clear whether this is properly tested here, we should
13271 // probably see if we can come up with a test for this.
13272 if (!NewSizeExpr.isUsable())
13273 return;
13274
13275 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
13276
13277 if (!NewSizeExpr.isUsable())
13278 return;
13279 TransformedExprs.push_back(NewSizeExpr.get());
13280 }
13281
13282 ParsedClause.setIntExprDetails(TransformedExprs);
13283 NewClause = OpenACCTileClause::Create(
13284 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13285 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
13286 ParsedClause.getEndLoc());
13287}
13288template <typename Derived>
13289void OpenACCClauseTransform<Derived>::VisitGangClause(
13290 const OpenACCGangClause &C) {
13291 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
13292 llvm::SmallVector<Expr *> TransformedIntExprs;
13293
13294 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
13295 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
13296 if (!ER.isUsable())
13297 continue;
13298
13299 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
13300 ParsedClause.getDirectiveKind(),
13301 C.getExpr(I).first, ER.get());
13302 if (!ER.isUsable())
13303 continue;
13304 TransformedGangKinds.push_back(C.getExpr(I).first);
13305 TransformedIntExprs.push_back(ER.get());
13306 }
13307
13308 NewClause = Self.getSema().OpenACC().CheckGangClause(
13309 ParsedClause.getDirectiveKind(), ExistingClauses,
13310 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13311 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
13312}
13313} // namespace
13314template <typename Derived>
13315OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
13316 ArrayRef<const OpenACCClause *> ExistingClauses,
13317 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
13318
13320 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
13321 ParsedClause.setEndLoc(OldClause->getEndLoc());
13322
13323 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
13324 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
13325
13326 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
13327 ParsedClause};
13328 Transform.Visit(OldClause);
13329
13330 return Transform.CreatedClause();
13331}
13332
13333template <typename Derived>
13335TreeTransform<Derived>::TransformOpenACCClauseList(
13337 llvm::SmallVector<OpenACCClause *> TransformedClauses;
13338 for (const auto *Clause : OldClauses) {
13339 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
13340 TransformedClauses, DirKind, Clause))
13341 TransformedClauses.push_back(TransformedClause);
13342 }
13343 return TransformedClauses;
13344}
13345
13346template <typename Derived>
13349 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13350
13351 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13352 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13353 C->clauses());
13354
13355 if (getSema().OpenACC().ActOnStartStmtDirective(
13356 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13357 return StmtError();
13358
13359 // Transform Structured Block.
13360 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13361 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13362 C->clauses(), TransformedClauses);
13363 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13364 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13365 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13366
13367 return getDerived().RebuildOpenACCComputeConstruct(
13368 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13369 C->getEndLoc(), TransformedClauses, StrBlock);
13370}
13371
13372template <typename Derived>
13375
13376 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13377
13378 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13379 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13380 C->clauses());
13381
13382 if (getSema().OpenACC().ActOnStartStmtDirective(
13383 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13384 return StmtError();
13385
13386 // Transform Loop.
13387 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13388 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13389 C->clauses(), TransformedClauses);
13390 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13391 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13392 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13393
13394 return getDerived().RebuildOpenACCLoopConstruct(
13395 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13396 TransformedClauses, Loop);
13397}
13398
13399template <typename Derived>
13401 OpenACCCombinedConstruct *C) {
13402 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13403
13404 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13405 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13406 C->clauses());
13407
13408 if (getSema().OpenACC().ActOnStartStmtDirective(
13409 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13410 return StmtError();
13411
13412 // Transform Loop.
13413 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13414 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13415 C->clauses(), TransformedClauses);
13416 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13417 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13418 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13419
13420 return getDerived().RebuildOpenACCCombinedConstruct(
13421 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13422 C->getEndLoc(), TransformedClauses, Loop);
13423}
13424
13425template <typename Derived>
13428 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13429
13430 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13431 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13432 C->clauses());
13433 if (getSema().OpenACC().ActOnStartStmtDirective(
13434 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13435 return StmtError();
13436
13437 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13438 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13439 C->clauses(), TransformedClauses);
13440 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13441 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13442 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13443
13444 return getDerived().RebuildOpenACCDataConstruct(
13445 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13446 TransformedClauses, StrBlock);
13447}
13448
13449template <typename Derived>
13451 OpenACCEnterDataConstruct *C) {
13452 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13453
13454 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13455 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13456 C->clauses());
13457 if (getSema().OpenACC().ActOnStartStmtDirective(
13458 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13459 return StmtError();
13460
13461 return getDerived().RebuildOpenACCEnterDataConstruct(
13462 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13463 TransformedClauses);
13464}
13465
13466template <typename Derived>
13468 OpenACCExitDataConstruct *C) {
13469 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13470
13471 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13472 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13473 C->clauses());
13474 if (getSema().OpenACC().ActOnStartStmtDirective(
13475 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13476 return StmtError();
13477
13478 return getDerived().RebuildOpenACCExitDataConstruct(
13479 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13480 TransformedClauses);
13481}
13482
13483template <typename Derived>
13485 OpenACCHostDataConstruct *C) {
13486 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13487
13488 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13489 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13490 C->clauses());
13491 if (getSema().OpenACC().ActOnStartStmtDirective(
13492 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13493 return StmtError();
13494
13495 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13496 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13497 C->clauses(), TransformedClauses);
13498 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13499 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13500 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13501
13502 return getDerived().RebuildOpenACCHostDataConstruct(
13503 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13504 TransformedClauses, StrBlock);
13505}
13506
13507template <typename Derived>
13510 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13511
13512 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13513 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13514 C->clauses());
13515 if (getSema().OpenACC().ActOnStartStmtDirective(
13516 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13517 return StmtError();
13518
13519 return getDerived().RebuildOpenACCInitConstruct(
13520 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13521 TransformedClauses);
13522}
13523
13524template <typename Derived>
13526 OpenACCShutdownConstruct *C) {
13527 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13528
13529 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13530 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13531 C->clauses());
13532 if (getSema().OpenACC().ActOnStartStmtDirective(
13533 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13534 return StmtError();
13535
13536 return getDerived().RebuildOpenACCShutdownConstruct(
13537 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13538 TransformedClauses);
13539}
13540template <typename Derived>
13543 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13544
13545 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13546 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13547 C->clauses());
13548 if (getSema().OpenACC().ActOnStartStmtDirective(
13549 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13550 return StmtError();
13551
13552 return getDerived().RebuildOpenACCSetConstruct(
13553 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13554 TransformedClauses);
13555}
13556
13557template <typename Derived>
13559 OpenACCUpdateConstruct *C) {
13560 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13561
13562 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13563 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13564 C->clauses());
13565 if (getSema().OpenACC().ActOnStartStmtDirective(
13566 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13567 return StmtError();
13568
13569 return getDerived().RebuildOpenACCUpdateConstruct(
13570 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13571 TransformedClauses);
13572}
13573
13574template <typename Derived>
13577 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13578
13579 ExprResult DevNumExpr;
13580 if (C->hasDevNumExpr()) {
13581 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
13582
13583 if (DevNumExpr.isUsable())
13584 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
13586 C->getBeginLoc(), DevNumExpr.get());
13587 }
13588
13589 llvm::SmallVector<Expr *> QueueIdExprs;
13590
13591 for (Expr *QE : C->getQueueIdExprs()) {
13592 assert(QE && "Null queue id expr?");
13593 ExprResult NewEQ = getDerived().TransformExpr(QE);
13594
13595 if (!NewEQ.isUsable())
13596 break;
13597 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
13599 C->getBeginLoc(), NewEQ.get());
13600 if (NewEQ.isUsable())
13601 QueueIdExprs.push_back(NewEQ.get());
13602 }
13603
13604 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13605 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13606 C->clauses());
13607
13608 if (getSema().OpenACC().ActOnStartStmtDirective(
13609 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13610 return StmtError();
13611
13612 return getDerived().RebuildOpenACCWaitConstruct(
13613 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13614 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
13615 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
13616}
13617template <typename Derived>
13619 OpenACCCacheConstruct *C) {
13620 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13621
13622 llvm::SmallVector<Expr *> TransformedVarList;
13623 for (Expr *Var : C->getVarList()) {
13624 assert(Var && "Null var listexpr?");
13625
13626 ExprResult NewVar = getDerived().TransformExpr(Var);
13627
13628 if (!NewVar.isUsable())
13629 break;
13630
13631 NewVar = getSema().OpenACC().ActOnVar(
13632 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
13633 if (!NewVar.isUsable())
13634 break;
13635
13636 TransformedVarList.push_back(NewVar.get());
13637 }
13638
13639 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13640 C->getBeginLoc(), {}))
13641 return StmtError();
13642
13643 return getDerived().RebuildOpenACCCacheConstruct(
13644 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13645 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
13646 C->getEndLoc());
13647}
13648
13649template <typename Derived>
13651 OpenACCAtomicConstruct *C) {
13652 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13653
13654 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13655 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13656 C->clauses());
13657
13658 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13659 C->getBeginLoc(), {}))
13660 return StmtError();
13661
13662 // Transform Associated Stmt.
13663 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13664 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
13665
13666 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
13667
13668 // DeclStmt is never valid here. Our pass through this while dependent already
13669 // diagnosed it, so there is no reason to check it again.
13670 if (!isa<DeclStmt>(C->getAssociatedStmt()))
13671 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
13672 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
13673 AssocStmt);
13674
13675 return getDerived().RebuildOpenACCAtomicConstruct(
13676 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
13677 C->getEndLoc(), TransformedClauses, AssocStmt);
13678}
13679
13680template <typename Derived>
13683 if (getDerived().AlwaysRebuild())
13684 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
13685 // Nothing can ever change, so there is never anything to transform.
13686 return E;
13687}
13688
13689//===----------------------------------------------------------------------===//
13690// Expression transformation
13691//===----------------------------------------------------------------------===//
13692template<typename Derived>
13695 return TransformExpr(E->getSubExpr());
13696}
13697
13698template <typename Derived>
13701 if (!E->isTypeDependent())
13702 return E;
13703
13704 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
13705
13706 if (!NewT)
13707 return ExprError();
13708
13709 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
13710 return E;
13711
13712 return getDerived().RebuildSYCLUniqueStableNameExpr(
13713 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
13714}
13715
13716template <typename Derived>
13719 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
13720
13721 const auto *SKEPAttr = FD->template getAttr<SYCLKernelEntryPointAttr>();
13722 if (!SKEPAttr || SKEPAttr->isInvalidAttr())
13723 return StmtError();
13724
13725 // The kernel name type held by the transformed SKEPAttr should no longer be
13726 // dependent. Ensure that is so and retrieve a non-dependent kernel info
13727 // specialization type. The call to GetSYCLKernelInfoClassSpecializationType()
13728 // doesn't just retrieve the type; it also builds an explicit specialization
13729 // declaration. A declaration of the explicit specialization must be built
13730 // before the following expression translations are transformed. Otherwise,
13731 // those transformations would trigger an implicit instantiation of the kernel
13732 // info type when explicit template arguments are transformed which would
13733 // build the wrong kind of specialization; one that can't be defined after
13734 // the body is translated.
13735 assert(!SKEPAttr->getKernelName()->isDependentType() &&
13736 "SYCL kernel name type should not be dependent here");
13738 SKEPAttr->getKernelName());
13739 (void)InfoType;
13740 assert(!InfoType.isNull());
13741
13742 ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
13743 if (IdExpr.isInvalid())
13744 return StmtError();
13745
13746 StmtResult Body = getDerived().TransformStmt(S->getOriginalStmt());
13747 if (Body.isInvalid())
13748 return StmtError();
13749
13750 SemaSYCL::SYCLKernelCallStmtASTFragments ASTFragments{IdExpr.get()};
13752 FD, cast<CompoundStmt>(Body.get()), ASTFragments);
13753 if (SR.isInvalid())
13754 return StmtError();
13755
13756 return SR;
13757}
13758
13759template <typename Derived>
13761 // TODO(reflection): Implement its transform
13762
13763 switch (E->getKind()) {
13764 case ReflectionKind::Type: {
13765 TypeSourceInfo *NewT = getDerived().TransformType(
13766 const_cast<TypeSourceInfo *>(E->getTypeSourceInfo()));
13767 if (!NewT)
13768 return ExprError();
13769 return SemaRef.BuildCXXReflectExpr(E->getOperatorLoc(), NewT);
13770 }
13772 llvm_unreachable("A null reflection should not reach here");
13773 }
13774
13775 assert(false && "unknown or unimplemented reflection entities");
13776 return ExprError();
13777}
13778
13779template<typename Derived>
13782 if (!E->isTypeDependent())
13783 return E;
13784
13785 return getDerived().RebuildPredefinedExpr(E->getLocation(),
13786 E->getIdentKind());
13787}
13788
13789template<typename Derived>
13792 NestedNameSpecifierLoc QualifierLoc;
13793 if (E->getQualifierLoc()) {
13794 QualifierLoc
13795 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13796 if (!QualifierLoc)
13797 return ExprError();
13798 }
13799
13800 ValueDecl *ND
13801 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
13802 E->getDecl()));
13803 if (!ND || ND->isInvalidDecl())
13804 return ExprError();
13805
13806 NamedDecl *Found = ND;
13807 if (E->getFoundDecl() != E->getDecl()) {
13808 Found = cast_or_null<NamedDecl>(
13809 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
13810 if (!Found)
13811 return ExprError();
13812 }
13813
13814 DeclarationNameInfo NameInfo = E->getNameInfo();
13815 if (NameInfo.getName()) {
13816 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
13817 if (!NameInfo.getName())
13818 return ExprError();
13819 }
13820
13821 if (!getDerived().AlwaysRebuild() &&
13822 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
13823 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
13824 Found == E->getFoundDecl() &&
13825 NameInfo.getName() == E->getDecl()->getDeclName() &&
13826 !E->hasExplicitTemplateArgs()) {
13827
13828 // Mark it referenced in the new context regardless.
13829 // FIXME: this is a bit instantiation-specific.
13830 SemaRef.MarkDeclRefReferenced(E);
13831
13832 return E;
13833 }
13834
13835 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
13836 if (E->hasExplicitTemplateArgs()) {
13837 TemplateArgs = &TransArgs;
13838 TransArgs.setLAngleLoc(E->getLAngleLoc());
13839 TransArgs.setRAngleLoc(E->getRAngleLoc());
13840 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13841 E->getNumTemplateArgs(),
13842 TransArgs))
13843 return ExprError();
13844 }
13845
13846 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13847 Found, TemplateArgs);
13848}
13849
13850template<typename Derived>
13853 return E;
13854}
13855
13856template <typename Derived>
13858 FixedPointLiteral *E) {
13859 return E;
13860}
13861
13862template<typename Derived>
13865 return E;
13866}
13867
13868template<typename Derived>
13871 return E;
13872}
13873
13874template<typename Derived>
13877 return E;
13878}
13879
13880template<typename Derived>
13883 return E;
13884}
13885
13886template<typename Derived>
13889 return getDerived().TransformCallExpr(E);
13890}
13891
13892template<typename Derived>
13895 ExprResult ControllingExpr;
13896 TypeSourceInfo *ControllingType = nullptr;
13897 if (E->isExprPredicate())
13898 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13899 else
13900 ControllingType = getDerived().TransformType(E->getControllingType());
13901
13902 if (!ControllingExpr.isUsable() && !ControllingType)
13903 return ExprError();
13904
13905 SmallVector<Expr *, 4> AssocExprs;
13907 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13908 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13909 if (TSI) {
13910 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13911 if (!AssocType)
13912 return ExprError();
13913 AssocTypes.push_back(AssocType);
13914 } else {
13915 AssocTypes.push_back(nullptr);
13916 }
13917
13918 ExprResult AssocExpr =
13919 getDerived().TransformExpr(Assoc.getAssociationExpr());
13920 if (AssocExpr.isInvalid())
13921 return ExprError();
13922 AssocExprs.push_back(AssocExpr.get());
13923 }
13924
13925 if (!ControllingType)
13926 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13927 E->getDefaultLoc(),
13928 E->getRParenLoc(),
13929 ControllingExpr.get(),
13930 AssocTypes,
13931 AssocExprs);
13932 return getDerived().RebuildGenericSelectionExpr(
13933 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13934 ControllingType, AssocTypes, AssocExprs);
13935}
13936
13937template<typename Derived>
13940 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13941 if (SubExpr.isInvalid())
13942 return ExprError();
13943
13944 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13945 return E;
13946
13947 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13948 E->getRParen());
13949}
13950
13951/// The operand of a unary address-of operator has special rules: it's
13952/// allowed to refer to a non-static member of a class even if there's no 'this'
13953/// object available.
13954template<typename Derived>
13957 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13958 return getDerived().TransformDependentScopeDeclRefExpr(
13959 DRE, /*IsAddressOfOperand=*/true, nullptr);
13960 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13961 return getDerived().TransformUnresolvedLookupExpr(
13962 ULE, /*IsAddressOfOperand=*/true);
13963 else
13964 return getDerived().TransformExpr(E);
13965}
13966
13967template<typename Derived>
13970 ExprResult SubExpr;
13971 if (E->getOpcode() == UO_AddrOf)
13972 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13973 else
13974 SubExpr = TransformExpr(E->getSubExpr());
13975 if (SubExpr.isInvalid())
13976 return ExprError();
13977
13978 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13979 return E;
13980
13981 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13982 E->getOpcode(),
13983 SubExpr.get());
13984}
13985
13986template<typename Derived>
13988TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13989 // Transform the type.
13990 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13991 if (!Type)
13992 return ExprError();
13993
13994 // Transform all of the components into a Designation similar to what the
13995 // parser builds.
13996 // FIXME: It would be slightly more efficient in the non-dependent case to
13997 // just map FieldDecls, rather than requiring the rebuilder to look for
13998 // the fields again. However, __builtin_offsetof is rare enough in
13999 // template code that we don't care.
14000 bool ExprChanged = false;
14001 Designation Desig;
14002 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
14003 const OffsetOfNode &ON = E->getComponent(I);
14004 switch (ON.getKind()) {
14005 case OffsetOfNode::Array: {
14006 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
14007 ExprResult Index = getDerived().TransformExpr(FromIndex);
14008 if (Index.isInvalid())
14009 return ExprError();
14010
14011 ExprChanged = ExprChanged || Index.get() != FromIndex;
14012 Designator AD =
14013 Designator::CreateArrayDesignator(Index.get(), ON.getBeginLoc());
14014 AD.setRBracketLoc(ON.getEndLoc());
14015 Desig.AddDesignator(AD);
14016 break;
14017 }
14018
14021 const IdentifierInfo *Name = ON.getFieldName();
14022 if (!Name)
14023 continue;
14024 // The leading designator has no '.'; subsequent ones do.
14025 SourceLocation DotLoc =
14026 Desig.empty() ? SourceLocation() : ON.getBeginLoc();
14027 Desig.AddDesignator(
14028 Designator::CreateFieldDesignator(Name, DotLoc, ON.getEndLoc()));
14029 break;
14030 }
14031
14032 case OffsetOfNode::Base:
14033 // Will be recomputed during the rebuild.
14034 continue;
14035 }
14036 }
14037
14038 // If nothing changed, retain the existing expression.
14039 if (!getDerived().AlwaysRebuild() &&
14040 Type == E->getTypeSourceInfo() &&
14041 !ExprChanged)
14042 return E;
14043
14044 // Build a new offsetof expression.
14045 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, Desig,
14046 E->getRParenLoc());
14047}
14048
14049template<typename Derived>
14052 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
14053 "opaque value expression requires transformation");
14054 return E;
14055}
14056
14057template <typename Derived>
14060 bool Changed = false;
14061 for (Expr *C : E->subExpressions()) {
14062 ExprResult NewC = getDerived().TransformExpr(C);
14063 if (NewC.isInvalid())
14064 return ExprError();
14065 Children.push_back(NewC.get());
14066
14067 Changed |= NewC.get() != C;
14068 }
14069 if (!getDerived().AlwaysRebuild() && !Changed)
14070 return E;
14071 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
14072 Children, E->getType());
14073}
14074
14075template<typename Derived>
14078 // Rebuild the syntactic form. The original syntactic form has
14079 // opaque-value expressions in it, so strip those away and rebuild
14080 // the result. This is a really awful way of doing this, but the
14081 // better solution (rebuilding the semantic expressions and
14082 // rebinding OVEs as necessary) doesn't work; we'd need
14083 // TreeTransform to not strip away implicit conversions.
14084 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
14085 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
14086 if (result.isInvalid()) return ExprError();
14087
14088 // If that gives us a pseudo-object result back, the pseudo-object
14089 // expression must have been an lvalue-to-rvalue conversion which we
14090 // should reapply.
14091 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
14092 result = SemaRef.PseudoObject().checkRValue(result.get());
14093
14094 return result;
14095}
14096
14097template<typename Derived>
14101 // C++0x [expr.sizeof]p1:
14102 // The operand is either an expression, which is an unevaluated operand
14103 // [...]
14107
14108 if (E->isArgumentType()) {
14109 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
14110
14111 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14112 if (!NewT)
14113 return ExprError();
14114
14115 if (!getDerived().AlwaysRebuild() && OldT == NewT)
14116 return E;
14117
14118 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
14119 E->getKind(),
14120 E->getSourceRange());
14121 }
14122
14123 // Try to recover if we have something like sizeof(T::X) where X is a type.
14124 // Notably, there must be *exactly* one set of parens if X is a type.
14125 TypeSourceInfo *RecoveryTSI = nullptr;
14126 ExprResult SubExpr;
14127 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
14128 if (auto *DRE =
14129 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
14130 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
14131 PE, DRE, false, &RecoveryTSI);
14132 else
14133 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
14134
14135 if (RecoveryTSI) {
14136 return getDerived().RebuildUnaryExprOrTypeTrait(
14137 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
14138 } else if (SubExpr.isInvalid())
14139 return ExprError();
14140
14141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
14142 return E;
14143
14144 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
14145 E->getOperatorLoc(),
14146 E->getKind(),
14147 E->getSourceRange());
14148}
14149
14150template<typename Derived>
14153 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14154 if (LHS.isInvalid())
14155 return ExprError();
14156
14157 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14158 if (RHS.isInvalid())
14159 return ExprError();
14160
14161
14162 if (!getDerived().AlwaysRebuild() &&
14163 LHS.get() == E->getLHS() &&
14164 RHS.get() == E->getRHS())
14165 return E;
14166
14167 return getDerived().RebuildArraySubscriptExpr(
14168 LHS.get(),
14169 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
14170}
14171
14172template <typename Derived>
14175 ExprResult Base = getDerived().TransformExpr(E->getBase());
14176 if (Base.isInvalid())
14177 return ExprError();
14178
14179 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
14180 if (RowIdx.isInvalid())
14181 return ExprError();
14182
14183 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14184 RowIdx.get() == E->getRowIdx())
14185 return E;
14186
14187 return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(),
14188 E->getRBracketLoc());
14189}
14190
14191template <typename Derived>
14194 ExprResult Base = getDerived().TransformExpr(E->getBase());
14195 if (Base.isInvalid())
14196 return ExprError();
14197
14198 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
14199 if (RowIdx.isInvalid())
14200 return ExprError();
14201
14202 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
14203 if (ColumnIdx.isInvalid())
14204 return ExprError();
14205
14206 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14207 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
14208 return E;
14209
14210 return getDerived().RebuildMatrixSubscriptExpr(
14211 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
14212}
14213
14214template <typename Derived>
14217 ExprResult Base = getDerived().TransformExpr(E->getBase());
14218 if (Base.isInvalid())
14219 return ExprError();
14220
14221 ExprResult LowerBound;
14222 if (E->getLowerBound()) {
14223 LowerBound = getDerived().TransformExpr(E->getLowerBound());
14224 if (LowerBound.isInvalid())
14225 return ExprError();
14226 }
14227
14228 ExprResult Length;
14229 if (E->getLength()) {
14230 Length = getDerived().TransformExpr(E->getLength());
14231 if (Length.isInvalid())
14232 return ExprError();
14233 }
14234
14235 ExprResult Stride;
14236 if (E->isOMPArraySection()) {
14237 if (Expr *Str = E->getStride()) {
14238 Stride = getDerived().TransformExpr(Str);
14239 if (Stride.isInvalid())
14240 return ExprError();
14241 }
14242 }
14243
14244 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14245 LowerBound.get() == E->getLowerBound() &&
14246 Length.get() == E->getLength() &&
14247 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
14248 return E;
14249
14250 return getDerived().RebuildArraySectionExpr(
14251 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
14252 LowerBound.get(), E->getColonLocFirst(),
14253 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
14254 Length.get(), Stride.get(), E->getRBracketLoc());
14255}
14256
14257template <typename Derived>
14260 ExprResult Base = getDerived().TransformExpr(E->getBase());
14261 if (Base.isInvalid())
14262 return ExprError();
14263
14265 bool ErrorFound = false;
14266 for (Expr *Dim : E->getDimensions()) {
14267 ExprResult DimRes = getDerived().TransformExpr(Dim);
14268 if (DimRes.isInvalid()) {
14269 ErrorFound = true;
14270 continue;
14271 }
14272 Dims.push_back(DimRes.get());
14273 }
14274
14275 if (ErrorFound)
14276 return ExprError();
14277 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
14278 E->getRParenLoc(), Dims,
14279 E->getBracketsRanges());
14280}
14281
14282template <typename Derived>
14285 unsigned NumIterators = E->numOfIterators();
14287
14288 bool ErrorFound = false;
14289 bool NeedToRebuild = getDerived().AlwaysRebuild();
14290 for (unsigned I = 0; I < NumIterators; ++I) {
14291 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
14292 Data[I].DeclIdent = D->getIdentifier();
14293 Data[I].DeclIdentLoc = D->getLocation();
14294 if (D->getLocation() == D->getBeginLoc()) {
14295 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
14296 "Implicit type must be int.");
14297 } else {
14298 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
14299 QualType DeclTy = getDerived().TransformType(D->getType());
14300 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
14301 }
14302 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
14303 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
14304 ExprResult End = getDerived().TransformExpr(Range.End);
14305 ExprResult Step = getDerived().TransformExpr(Range.Step);
14306 ErrorFound = ErrorFound ||
14307 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
14308 !Data[I].Type.get().isNull())) ||
14309 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
14310 if (ErrorFound)
14311 continue;
14312 Data[I].Range.Begin = Begin.get();
14313 Data[I].Range.End = End.get();
14314 Data[I].Range.Step = Step.get();
14315 Data[I].AssignLoc = E->getAssignLoc(I);
14316 Data[I].ColonLoc = E->getColonLoc(I);
14317 Data[I].SecColonLoc = E->getSecondColonLoc(I);
14318 NeedToRebuild =
14319 NeedToRebuild ||
14320 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
14321 D->getType().getTypePtrOrNull()) ||
14322 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
14323 Range.Step != Data[I].Range.Step;
14324 }
14325 if (ErrorFound)
14326 return ExprError();
14327 if (!NeedToRebuild)
14328 return E;
14329
14330 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
14331 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
14332 if (!Res.isUsable())
14333 return Res;
14334 auto *IE = cast<OMPIteratorExpr>(Res.get());
14335 for (unsigned I = 0; I < NumIterators; ++I)
14336 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
14337 IE->getIteratorDecl(I));
14338 return Res;
14339}
14340
14341template<typename Derived>
14344 // Transform the callee.
14345 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14346 if (Callee.isInvalid())
14347 return ExprError();
14348
14349 // Transform arguments.
14350 bool ArgChanged = false;
14352 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14353 &ArgChanged))
14354 return ExprError();
14355
14356 if (!getDerived().AlwaysRebuild() &&
14357 Callee.get() == E->getCallee() &&
14358 !ArgChanged)
14359 return SemaRef.MaybeBindToTemporary(E);
14360
14361 // FIXME: Wrong source location information for the '('.
14362 SourceLocation FakeLParenLoc
14363 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14364
14365 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14366 if (E->hasStoredFPFeatures()) {
14367 FPOptionsOverride NewOverrides = E->getFPFeatures();
14368 getSema().CurFPFeatures =
14369 NewOverrides.applyOverrides(getSema().getLangOpts());
14370 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14371 }
14372
14373 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14374 Args,
14375 E->getRParenLoc());
14376}
14377
14378template<typename Derived>
14381 ExprResult Base = getDerived().TransformExpr(E->getBase());
14382 if (Base.isInvalid())
14383 return ExprError();
14384
14385 NestedNameSpecifierLoc QualifierLoc;
14386 if (E->hasQualifier()) {
14387 QualifierLoc
14388 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14389
14390 if (!QualifierLoc)
14391 return ExprError();
14392 }
14393 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14394
14396 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
14397 E->getMemberDecl()));
14398 if (!Member)
14399 return ExprError();
14400
14401 NamedDecl *FoundDecl = E->getFoundDecl();
14402 if (FoundDecl == E->getMemberDecl()) {
14403 FoundDecl = Member;
14404 } else {
14405 FoundDecl = cast_or_null<NamedDecl>(
14406 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
14407 if (!FoundDecl)
14408 return ExprError();
14409 }
14410
14411 if (!getDerived().AlwaysRebuild() &&
14412 Base.get() == E->getBase() &&
14413 QualifierLoc == E->getQualifierLoc() &&
14414 Member == E->getMemberDecl() &&
14415 FoundDecl == E->getFoundDecl() &&
14416 !E->hasExplicitTemplateArgs()) {
14417
14418 // Skip for member expression of (this->f), rebuilt thisi->f is needed
14419 // for Openmp where the field need to be privatizized in the case.
14420 if (!(isa<CXXThisExpr>(E->getBase()) &&
14421 getSema().OpenMP().isOpenMPRebuildMemberExpr(
14423 // Mark it referenced in the new context regardless.
14424 // FIXME: this is a bit instantiation-specific.
14425 SemaRef.MarkMemberReferenced(E);
14426 return E;
14427 }
14428 }
14429
14430 TemplateArgumentListInfo TransArgs;
14431 if (E->hasExplicitTemplateArgs()) {
14432 TransArgs.setLAngleLoc(E->getLAngleLoc());
14433 TransArgs.setRAngleLoc(E->getRAngleLoc());
14434 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14435 E->getNumTemplateArgs(),
14436 TransArgs))
14437 return ExprError();
14438 }
14439
14440 // FIXME: Bogus source location for the operator
14441 SourceLocation FakeOperatorLoc =
14442 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
14443
14444 // FIXME: to do this check properly, we will need to preserve the
14445 // first-qualifier-in-scope here, just in case we had a dependent
14446 // base (and therefore couldn't do the check) and a
14447 // nested-name-qualifier (and therefore could do the lookup).
14448 NamedDecl *FirstQualifierInScope = nullptr;
14449 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
14450 if (MemberNameInfo.getName()) {
14451 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
14452 if (!MemberNameInfo.getName())
14453 return ExprError();
14454 }
14455
14456 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
14457 E->isArrow(),
14458 QualifierLoc,
14459 TemplateKWLoc,
14460 MemberNameInfo,
14461 Member,
14462 FoundDecl,
14463 (E->hasExplicitTemplateArgs()
14464 ? &TransArgs : nullptr),
14465 FirstQualifierInScope);
14466}
14467
14468template<typename Derived>
14471 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14472 if (LHS.isInvalid())
14473 return ExprError();
14474
14475 ExprResult RHS =
14476 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
14477 if (RHS.isInvalid())
14478 return ExprError();
14479
14480 if (!getDerived().AlwaysRebuild() &&
14481 LHS.get() == E->getLHS() &&
14482 RHS.get() == E->getRHS())
14483 return E;
14484
14485 if (E->isCompoundAssignmentOp())
14486 // FPFeatures has already been established from trailing storage
14487 return getDerived().RebuildBinaryOperator(
14488 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
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().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
14495 LHS.get(), RHS.get());
14496}
14497
14498template <typename Derived>
14501 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
14502
14503 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
14504 if (LHS.isInvalid())
14505 return ExprError();
14506
14507 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
14508 if (RHS.isInvalid())
14509 return ExprError();
14510
14511 // Extract the already-resolved callee declarations so that we can restrict
14512 // ourselves to using them as the unqualified lookup results when rebuilding.
14513 UnresolvedSet<2> UnqualLookups;
14514 bool ChangedAnyLookups = false;
14515 Expr *PossibleBinOps[] = {E->getSemanticForm(),
14516 const_cast<Expr *>(Decomp.InnerBinOp)};
14517 for (Expr *PossibleBinOp : PossibleBinOps) {
14518 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
14519 if (!Op)
14520 continue;
14521 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
14522 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
14523 continue;
14524
14525 // Transform the callee in case we built a call to a local extern
14526 // declaration.
14527 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
14528 E->getOperatorLoc(), Callee->getFoundDecl()));
14529 if (!Found)
14530 return ExprError();
14531 if (Found != Callee->getFoundDecl())
14532 ChangedAnyLookups = true;
14533 UnqualLookups.addDecl(Found);
14534 }
14535
14536 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
14537 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
14538 // Mark all functions used in the rewrite as referenced. Note that when
14539 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
14540 // function calls, and/or there might be a user-defined conversion sequence
14541 // applied to the operands of the <.
14542 // FIXME: this is a bit instantiation-specific.
14543 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
14544 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
14545 return E;
14546 }
14547
14548 return getDerived().RebuildCXXRewrittenBinaryOperator(
14549 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
14550}
14551
14552template<typename Derived>
14556 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14557 FPOptionsOverride NewOverrides(E->getFPFeatures());
14558 getSema().CurFPFeatures =
14559 NewOverrides.applyOverrides(getSema().getLangOpts());
14560 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14561 return getDerived().TransformBinaryOperator(E);
14562}
14563
14564template<typename Derived>
14567 // Just rebuild the common and RHS expressions and see whether we
14568 // get any changes.
14569
14570 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
14571 if (commonExpr.isInvalid())
14572 return ExprError();
14573
14574 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
14575 if (rhs.isInvalid())
14576 return ExprError();
14577
14578 if (!getDerived().AlwaysRebuild() &&
14579 commonExpr.get() == e->getCommon() &&
14580 rhs.get() == e->getFalseExpr())
14581 return e;
14582
14583 return getDerived().RebuildConditionalOperator(commonExpr.get(),
14584 e->getQuestionLoc(),
14585 nullptr,
14586 e->getColonLoc(),
14587 rhs.get());
14588}
14589
14590template<typename Derived>
14593 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14594 if (Cond.isInvalid())
14595 return ExprError();
14596
14597 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14598 if (LHS.isInvalid())
14599 return ExprError();
14600
14601 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14602 if (RHS.isInvalid())
14603 return ExprError();
14604
14605 if (!getDerived().AlwaysRebuild() &&
14606 Cond.get() == E->getCond() &&
14607 LHS.get() == E->getLHS() &&
14608 RHS.get() == E->getRHS())
14609 return E;
14610
14611 return getDerived().RebuildConditionalOperator(Cond.get(),
14612 E->getQuestionLoc(),
14613 LHS.get(),
14614 E->getColonLoc(),
14615 RHS.get());
14616}
14617
14618template<typename Derived>
14621 // Implicit casts are eliminated during transformation, since they
14622 // will be recomputed by semantic analysis after transformation.
14623 return getDerived().TransformExpr(E->getSubExprAsWritten());
14624}
14625
14626template<typename Derived>
14629 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14630 if (!Type)
14631 return ExprError();
14632
14633 ExprResult SubExpr
14634 = getDerived().TransformExpr(E->getSubExprAsWritten());
14635 if (SubExpr.isInvalid())
14636 return ExprError();
14637
14638 if (!getDerived().AlwaysRebuild() &&
14639 Type == E->getTypeInfoAsWritten() &&
14640 SubExpr.get() == E->getSubExpr())
14641 return E;
14642
14643 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
14644 Type,
14645 E->getRParenLoc(),
14646 SubExpr.get());
14647}
14648
14649template<typename Derived>
14652 TypeSourceInfo *OldT = E->getTypeSourceInfo();
14653 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14654 if (!NewT)
14655 return ExprError();
14656
14657 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
14658 if (Init.isInvalid())
14659 return ExprError();
14660
14661 if (!getDerived().AlwaysRebuild() &&
14662 OldT == NewT &&
14663 Init.get() == E->getInitializer())
14664 return SemaRef.MaybeBindToTemporary(E);
14665
14666 // Note: the expression type doesn't necessarily match the
14667 // type-as-written, but that's okay, because it should always be
14668 // derivable from the initializer.
14669
14670 return getDerived().RebuildCompoundLiteralExpr(
14671 E->getLParenLoc(), NewT,
14672 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
14673}
14674
14675template<typename Derived>
14678 ExprResult Base = getDerived().TransformExpr(E->getBase());
14679 if (Base.isInvalid())
14680 return ExprError();
14681
14682 if (!getDerived().AlwaysRebuild() &&
14683 Base.get() == E->getBase())
14684 return E;
14685
14686 // FIXME: Bad source location
14687 SourceLocation FakeOperatorLoc =
14688 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14689 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14690 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
14691 E->getAccessor());
14692}
14693
14694template <typename Derived>
14697 ExprResult Base = getDerived().TransformExpr(E->getBase());
14698 if (Base.isInvalid())
14699 return ExprError();
14700
14701 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase())
14702 return E;
14703
14704 // FIXME: Bad source location
14705 SourceLocation FakeOperatorLoc =
14706 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14707 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14708 Base.get(), FakeOperatorLoc, /*isArrow*/ false, E->getAccessorLoc(),
14709 E->getAccessor());
14710}
14711
14712template<typename Derived>
14715 if (InitListExpr *Syntactic = E->getSyntacticForm())
14716 E = Syntactic;
14717
14718 bool InitChanged = false;
14719
14722
14724 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
14725 Inits, &InitChanged))
14726 return ExprError();
14727
14728 if (!getDerived().AlwaysRebuild() && !InitChanged) {
14729 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
14730 // in some cases. We can't reuse it in general, because the syntactic and
14731 // semantic forms are linked, and we can't know that semantic form will
14732 // match even if the syntactic form does.
14733 }
14734
14735 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
14736 E->getRBraceLoc(), E->isExplicit());
14737}
14738
14739template<typename Derived>
14742 Designation Desig;
14743
14744 // transform the initializer value
14745 ExprResult Init = getDerived().TransformExpr(E->getInit());
14746 if (Init.isInvalid())
14747 return ExprError();
14748
14749 // transform the designators.
14750 SmallVector<Expr*, 4> ArrayExprs;
14751 bool ExprChanged = false;
14752 for (const DesignatedInitExpr::Designator &D : E->designators()) {
14753 if (D.isFieldDesignator()) {
14754 if (D.getFieldDecl()) {
14755 FieldDecl *Field = cast_or_null<FieldDecl>(
14756 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
14757 if (Field != D.getFieldDecl())
14758 // Rebuild the expression when the transformed FieldDecl is
14759 // different to the already assigned FieldDecl.
14760 ExprChanged = true;
14761 if (Field->isAnonymousStructOrUnion())
14762 continue;
14763 } else {
14764 // Ensure that the designator expression is rebuilt when there isn't
14765 // a resolved FieldDecl in the designator as we don't want to assign
14766 // a FieldDecl to a pattern designator that will be instantiated again.
14767 ExprChanged = true;
14768 }
14769 Desig.AddDesignator(Designator::CreateFieldDesignator(
14770 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
14771 continue;
14772 }
14773
14774 if (D.isArrayDesignator()) {
14775 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
14776 if (Index.isInvalid())
14777 return ExprError();
14778
14779 Desig.AddDesignator(
14780 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
14781
14782 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
14783 ArrayExprs.push_back(Index.get());
14784 continue;
14785 }
14786
14787 assert(D.isArrayRangeDesignator() && "New kind of designator?");
14788 ExprResult Start
14789 = getDerived().TransformExpr(E->getArrayRangeStart(D));
14790 if (Start.isInvalid())
14791 return ExprError();
14792
14793 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
14794 if (End.isInvalid())
14795 return ExprError();
14796
14797 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
14798 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
14799
14800 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
14801 End.get() != E->getArrayRangeEnd(D);
14802
14803 ArrayExprs.push_back(Start.get());
14804 ArrayExprs.push_back(End.get());
14805 }
14806
14807 if (!getDerived().AlwaysRebuild() &&
14808 Init.get() == E->getInit() &&
14809 !ExprChanged)
14810 return E;
14811
14812 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
14813 E->getEqualOrColonLoc(),
14814 E->usesGNUSyntax(), Init.get());
14815}
14816
14817// Seems that if TransformInitListExpr() only works on the syntactic form of an
14818// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
14819template<typename Derived>
14823 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
14824 "initializer");
14825 return ExprError();
14826}
14827
14828template<typename Derived>
14831 NoInitExpr *E) {
14832 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
14833 return ExprError();
14834}
14835
14836template<typename Derived>
14839 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
14840 return ExprError();
14841}
14842
14843template<typename Derived>
14846 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
14847 return ExprError();
14848}
14849
14850template<typename Derived>
14854 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
14855
14856 // FIXME: Will we ever have proper type location here? Will we actually
14857 // need to transform the type?
14858 QualType T = getDerived().TransformType(E->getType());
14859 if (T.isNull())
14860 return ExprError();
14861
14862 if (!getDerived().AlwaysRebuild() &&
14863 T == E->getType())
14864 return E;
14865
14866 return getDerived().RebuildImplicitValueInitExpr(T);
14867}
14868
14869template<typename Derived>
14872 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14873 if (!TInfo)
14874 return ExprError();
14875
14876 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14877 if (SubExpr.isInvalid())
14878 return ExprError();
14879
14880 if (!getDerived().AlwaysRebuild() &&
14881 TInfo == E->getWrittenTypeInfo() &&
14882 SubExpr.get() == E->getSubExpr())
14883 return E;
14884
14885 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14886 TInfo, E->getRParenLoc());
14887}
14888
14889template<typename Derived>
14892 bool ArgumentChanged = false;
14894 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14895 &ArgumentChanged))
14896 return ExprError();
14897
14898 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14899 Inits,
14900 E->getRParenLoc());
14901}
14902
14903/// Transform an address-of-label expression.
14904///
14905/// By default, the transformation of an address-of-label expression always
14906/// rebuilds the expression, so that the label identifier can be resolved to
14907/// the corresponding label statement by semantic analysis.
14908template<typename Derived>
14911 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14912 E->getLabel());
14913 if (!LD)
14914 return ExprError();
14915
14916 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14917 cast<LabelDecl>(LD));
14918}
14919
14920template<typename Derived>
14923 SemaRef.ActOnStartStmtExpr();
14924 StmtResult SubStmt
14925 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14926 if (SubStmt.isInvalid()) {
14927 SemaRef.ActOnStmtExprError();
14928 return ExprError();
14929 }
14930
14931 unsigned OldDepth = E->getTemplateDepth();
14932 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14933
14934 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14935 SubStmt.get() == E->getSubStmt()) {
14936 // Calling this an 'error' is unintuitive, but it does the right thing.
14937 SemaRef.ActOnStmtExprError();
14938 return SemaRef.MaybeBindToTemporary(E);
14939 }
14940
14941 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14942 E->getRParenLoc(), NewDepth,
14943 !E->getType()->isVoidType());
14944}
14945
14946template<typename Derived>
14949 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14950 if (Cond.isInvalid())
14951 return ExprError();
14952
14953 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14954 if (LHS.isInvalid())
14955 return ExprError();
14956
14957 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14958 if (RHS.isInvalid())
14959 return ExprError();
14960
14961 if (!getDerived().AlwaysRebuild() &&
14962 Cond.get() == E->getCond() &&
14963 LHS.get() == E->getLHS() &&
14964 RHS.get() == E->getRHS())
14965 return E;
14966
14967 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14968 Cond.get(), LHS.get(), RHS.get(),
14969 E->getRParenLoc());
14970}
14971
14972template<typename Derived>
14975 return E;
14976}
14977
14978template<typename Derived>
14981 switch (E->getOperator()) {
14982 case OO_New:
14983 case OO_Delete:
14984 case OO_Array_New:
14985 case OO_Array_Delete:
14986 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14987
14988 case OO_Subscript:
14989 case OO_Call: {
14990 // This is a call to an object's operator().
14991 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14992
14993 // Transform the object itself.
14994 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14995 if (Object.isInvalid())
14996 return ExprError();
14997
14998 // FIXME: Poor location information. Also, if the location for the end of
14999 // the token is within a macro expansion, getLocForEndOfToken() will return
15000 // an invalid source location. If that happens and we have an otherwise
15001 // valid end location, use the valid one instead of the invalid one.
15002 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
15003 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
15004 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
15005 FakeLParenLoc = EndLoc;
15006
15007 // Transform the call arguments.
15009 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
15010 Args))
15011 return ExprError();
15012
15013 if (E->getOperator() == OO_Subscript)
15014 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
15015 Args, E->getEndLoc());
15016
15017 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
15018 E->getEndLoc());
15019 }
15020
15021#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
15022 case OO_##Name: \
15023 break;
15024
15025#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
15026#include "clang/Basic/OperatorKinds.def"
15027
15028 case OO_Conditional:
15029 llvm_unreachable("conditional operator is not actually overloadable");
15030
15031 case OO_None:
15033 llvm_unreachable("not an overloaded operator?");
15034 }
15035
15037 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
15038 First = getDerived().TransformAddressOfOperand(E->getArg(0));
15039 else
15040 First = getDerived().TransformExpr(E->getArg(0));
15041 if (First.isInvalid())
15042 return ExprError();
15043
15044 ExprResult Second;
15045 if (E->getNumArgs() == 2) {
15046 Second =
15047 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
15048 if (Second.isInvalid())
15049 return ExprError();
15050 }
15051
15052 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
15053 FPOptionsOverride NewOverrides(E->getFPFeatures());
15054 getSema().CurFPFeatures =
15055 NewOverrides.applyOverrides(getSema().getLangOpts());
15056 getSema().FpPragmaStack.CurrentValue = NewOverrides;
15057
15058 Expr *Callee = E->getCallee();
15059 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
15060 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
15062 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
15063 return ExprError();
15064
15065 return getDerived().RebuildCXXOperatorCallExpr(
15066 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
15067 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
15068 }
15069
15070 UnresolvedSet<1> Functions;
15071 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
15072 Callee = ICE->getSubExprAsWritten();
15073 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
15074 ValueDecl *VD = cast_or_null<ValueDecl>(
15075 getDerived().TransformDecl(DR->getLocation(), DR));
15076 if (!VD)
15077 return ExprError();
15078
15079 if (!isa<CXXMethodDecl>(VD))
15080 Functions.addDecl(VD);
15081
15082 return getDerived().RebuildCXXOperatorCallExpr(
15083 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
15084 /*RequiresADL=*/false, Functions, First.get(), Second.get());
15085}
15086
15087template<typename Derived>
15090 return getDerived().TransformCallExpr(E);
15091}
15092
15093template <typename Derived>
15095 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
15096 getSema().CurContext != E->getParentContext();
15097
15098 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
15099 return E;
15100
15101 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
15102 E->getBeginLoc(), E->getEndLoc(),
15103 getSema().CurContext);
15104}
15105
15106template <typename Derived>
15108 return E;
15109}
15110
15111template<typename Derived>
15114 // Transform the callee.
15115 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
15116 if (Callee.isInvalid())
15117 return ExprError();
15118
15119 // Transform exec config.
15120 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
15121 if (EC.isInvalid())
15122 return ExprError();
15123
15124 // Transform arguments.
15125 bool ArgChanged = false;
15127 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15128 &ArgChanged))
15129 return ExprError();
15130
15131 if (!getDerived().AlwaysRebuild() &&
15132 Callee.get() == E->getCallee() &&
15133 !ArgChanged)
15134 return SemaRef.MaybeBindToTemporary(E);
15135
15136 // FIXME: Wrong source location information for the '('.
15137 SourceLocation FakeLParenLoc
15138 = ((Expr *)Callee.get())->getSourceRange().getBegin();
15139 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
15140 Args,
15141 E->getRParenLoc(), EC.get());
15142}
15143
15144template<typename Derived>
15147 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
15148 if (!Type)
15149 return ExprError();
15150
15151 ExprResult SubExpr
15152 = getDerived().TransformExpr(E->getSubExprAsWritten());
15153 if (SubExpr.isInvalid())
15154 return ExprError();
15155
15156 if (!getDerived().AlwaysRebuild() &&
15157 Type == E->getTypeInfoAsWritten() &&
15158 SubExpr.get() == E->getSubExpr())
15159 return E;
15160 return getDerived().RebuildCXXNamedCastExpr(
15163 // FIXME. this should be '(' location
15164 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
15165}
15166
15167template<typename Derived>
15170 TypeSourceInfo *TSI =
15171 getDerived().TransformType(BCE->getTypeInfoAsWritten());
15172 if (!TSI)
15173 return ExprError();
15174
15175 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
15176 if (Sub.isInvalid())
15177 return ExprError();
15178
15179 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
15180 Sub.get(), BCE->getEndLoc());
15181}
15182
15183template<typename Derived>
15185TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
15186 return getDerived().TransformCXXNamedCastExpr(E);
15187}
15188
15189template<typename Derived>
15192 return getDerived().TransformCXXNamedCastExpr(E);
15193}
15194
15195template<typename Derived>
15199 return getDerived().TransformCXXNamedCastExpr(E);
15200}
15201
15202template<typename Derived>
15205 return getDerived().TransformCXXNamedCastExpr(E);
15206}
15207
15208template<typename Derived>
15211 return getDerived().TransformCXXNamedCastExpr(E);
15212}
15213
15214template<typename Derived>
15219 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
15220 if (!Type)
15221 return ExprError();
15222
15223 ExprResult SubExpr
15224 = getDerived().TransformExpr(E->getSubExprAsWritten());
15225 if (SubExpr.isInvalid())
15226 return ExprError();
15227
15228 if (!getDerived().AlwaysRebuild() &&
15229 Type == E->getTypeInfoAsWritten() &&
15230 SubExpr.get() == E->getSubExpr())
15231 return E;
15232
15233 return getDerived().RebuildCXXFunctionalCastExpr(Type,
15234 E->getLParenLoc(),
15235 SubExpr.get(),
15236 E->getRParenLoc(),
15237 E->isListInitialization());
15238}
15239
15240template<typename Derived>
15243 if (E->isTypeOperand()) {
15244 TypeSourceInfo *TInfo
15245 = getDerived().TransformType(E->getTypeOperandSourceInfo());
15246 if (!TInfo)
15247 return ExprError();
15248
15249 if (!getDerived().AlwaysRebuild() &&
15250 TInfo == E->getTypeOperandSourceInfo())
15251 return E;
15252
15253 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
15254 TInfo, E->getEndLoc());
15255 }
15256
15257 // Typeid's operand is an unevaluated context, unless it's a polymorphic
15258 // type. We must not unilaterally enter unevaluated context here, as then
15259 // semantic processing can re-transform an already transformed operand.
15260 Expr *Op = E->getExprOperand();
15262 if (E->isGLValue()) {
15263 QualType OpType = Op->getType();
15264 if (auto *RD = OpType->getAsCXXRecordDecl()) {
15265 if (SemaRef.RequireCompleteType(E->getBeginLoc(), OpType,
15266 diag::err_incomplete_typeid))
15267 return ExprError();
15268
15269 if (RD->isPolymorphic())
15270 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
15271 }
15272 }
15273
15276
15277 ExprResult SubExpr = getDerived().TransformExpr(Op);
15278 if (SubExpr.isInvalid())
15279 return ExprError();
15280
15281 if (!getDerived().AlwaysRebuild() &&
15282 SubExpr.get() == E->getExprOperand())
15283 return E;
15284
15285 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
15286 SubExpr.get(), E->getEndLoc());
15287}
15288
15289template<typename Derived>
15292 if (E->isTypeOperand()) {
15293 TypeSourceInfo *TInfo
15294 = getDerived().TransformType(E->getTypeOperandSourceInfo());
15295 if (!TInfo)
15296 return ExprError();
15297
15298 if (!getDerived().AlwaysRebuild() &&
15299 TInfo == E->getTypeOperandSourceInfo())
15300 return E;
15301
15302 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
15303 TInfo, E->getEndLoc());
15304 }
15305
15308
15309 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
15310 if (SubExpr.isInvalid())
15311 return ExprError();
15312
15313 if (!getDerived().AlwaysRebuild() &&
15314 SubExpr.get() == E->getExprOperand())
15315 return E;
15316
15317 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
15318 SubExpr.get(), E->getEndLoc());
15319}
15320
15321template<typename Derived>
15324 return E;
15325}
15326
15327template<typename Derived>
15331 return E;
15332}
15333
15334template<typename Derived>
15337
15338 // In lambdas, the qualifiers of the type depends of where in
15339 // the call operator `this` appear, and we do not have a good way to
15340 // rebuild this information, so we transform the type.
15341 //
15342 // In other contexts, the type of `this` may be overrided
15343 // for type deduction, so we need to recompute it.
15344 //
15345 // Always recompute the type if we're in the body of a lambda, and
15346 // 'this' is dependent on a lambda's explicit object parameter; we
15347 // also need to always rebuild the expression in this case to clear
15348 // the flag.
15349 QualType T = [&]() {
15350 auto &S = getSema();
15351 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
15352 return S.getCurrentThisType();
15353 if (S.getCurLambda())
15354 return getDerived().TransformType(E->getType());
15355 return S.getCurrentThisType();
15356 }();
15357
15358 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
15359 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
15360 // Mark it referenced in the new context regardless.
15361 // FIXME: this is a bit instantiation-specific.
15362 getSema().MarkThisReferenced(E);
15363 return E;
15364 }
15365
15366 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
15367}
15368
15369template<typename Derived>
15372 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
15373 if (SubExpr.isInvalid())
15374 return ExprError();
15375
15376 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
15377
15378 if (!getDerived().AlwaysRebuild() &&
15379 SubExpr.get() == E->getSubExpr())
15380 return E;
15381
15382 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
15383 E->isThrownVariableInScope());
15384}
15385
15386template<typename Derived>
15389 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
15390 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
15391 if (!Param)
15392 return ExprError();
15393
15394 ExprResult InitRes;
15395 if (E->hasRewrittenInit()) {
15396 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15397 if (InitRes.isInvalid())
15398 return ExprError();
15399 }
15400
15401 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
15402 E->getUsedContext() == SemaRef.CurContext &&
15403 InitRes.get() == E->getRewrittenExpr())
15404 return E;
15405
15406 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
15407 InitRes.get());
15408}
15409
15410template<typename Derived>
15413 FieldDecl *Field = cast_or_null<FieldDecl>(
15414 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
15415 if (!Field)
15416 return ExprError();
15417
15418 ExprResult InitRes;
15419 if (E->hasRewrittenInit()) {
15420 // The initializer can refer to `this` and to other members, so it has to
15421 // be transformed in the scope of the field's class.
15422 Sema::CXXThisScopeRAII ThisScope(SemaRef, Field->getParent(), Qualifiers());
15423 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15424 if (InitRes.isInvalid())
15425 return ExprError();
15426 }
15427
15428 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
15429 E->getUsedContext() == SemaRef.CurContext &&
15430 InitRes.get() == E->getExpr())
15431 return E;
15432
15433 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field,
15434 InitRes.get());
15435}
15436
15437template<typename Derived>
15441 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
15442 if (!T)
15443 return ExprError();
15444
15445 if (!getDerived().AlwaysRebuild() &&
15446 T == E->getTypeSourceInfo())
15447 return E;
15448
15449 return getDerived().RebuildCXXScalarValueInitExpr(T,
15450 /*FIXME:*/T->getTypeLoc().getEndLoc(),
15451 E->getRParenLoc());
15452}
15453
15454template<typename Derived>
15457 // Transform the type that we're allocating
15458 TypeSourceInfo *AllocTypeInfo =
15459 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
15460 if (!AllocTypeInfo)
15461 return ExprError();
15462
15463 // Transform the size of the array we're allocating (if any).
15464 std::optional<Expr *> ArraySize;
15465 if (E->isArray()) {
15466 ExprResult NewArraySize;
15467 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
15468 NewArraySize = getDerived().TransformExpr(*OldArraySize);
15469 if (NewArraySize.isInvalid())
15470 return ExprError();
15471 }
15472 ArraySize = NewArraySize.get();
15473 }
15474
15475 // Transform the placement arguments (if any).
15476 bool ArgumentChanged = false;
15477 SmallVector<Expr*, 8> PlacementArgs;
15478 if (getDerived().TransformExprs(E->getPlacementArgs(),
15479 E->getNumPlacementArgs(), true,
15480 PlacementArgs, &ArgumentChanged))
15481 return ExprError();
15482
15483 // Transform the initializer (if any).
15484 Expr *OldInit = E->getInitializer();
15485 ExprResult NewInit;
15486 if (OldInit)
15487 NewInit = getDerived().TransformInitializer(OldInit, true);
15488 if (NewInit.isInvalid())
15489 return ExprError();
15490
15491 // Transform new operator and delete operator.
15492 FunctionDecl *OperatorNew = nullptr;
15493 if (E->getOperatorNew()) {
15494 OperatorNew = cast_or_null<FunctionDecl>(
15495 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
15496 if (!OperatorNew)
15497 return ExprError();
15498 }
15499
15500 FunctionDecl *OperatorDelete = nullptr;
15501 if (E->getOperatorDelete()) {
15502 OperatorDelete = cast_or_null<FunctionDecl>(
15503 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15504 if (!OperatorDelete)
15505 return ExprError();
15506 }
15507
15508 if (!getDerived().AlwaysRebuild() &&
15509 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
15510 ArraySize == E->getArraySize() &&
15511 NewInit.get() == OldInit &&
15512 OperatorNew == E->getOperatorNew() &&
15513 OperatorDelete == E->getOperatorDelete() &&
15514 !ArgumentChanged) {
15515 // Mark any declarations we need as referenced.
15516 // FIXME: instantiation-specific.
15517 if (OperatorNew)
15518 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
15519 if (OperatorDelete)
15520 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15521
15522 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
15523 QualType ElementType
15524 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
15525 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
15527 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
15528 }
15529 }
15530
15531 return E;
15532 }
15533
15534 QualType AllocType = AllocTypeInfo->getType();
15535 if (!ArraySize) {
15536 // If no array size was specified, but the new expression was
15537 // instantiated with an array type (e.g., "new T" where T is
15538 // instantiated with "int[4]"), extract the outer bound from the
15539 // array type as our array size. We do this with constant and
15540 // dependently-sized array types.
15541 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
15542 if (!ArrayT) {
15543 // Do nothing
15544 } else if (const ConstantArrayType *ConsArrayT
15545 = dyn_cast<ConstantArrayType>(ArrayT)) {
15546 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
15547 SemaRef.Context.getSizeType(),
15548 /*FIXME:*/ E->getBeginLoc());
15549 AllocType = ConsArrayT->getElementType();
15550 } else if (const DependentSizedArrayType *DepArrayT
15551 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
15552 if (DepArrayT->getSizeExpr()) {
15553 ArraySize = DepArrayT->getSizeExpr();
15554 AllocType = DepArrayT->getElementType();
15555 }
15556 }
15557 }
15558
15559 return getDerived().RebuildCXXNewExpr(
15560 E->getBeginLoc(), E->isGlobalNew(),
15561 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
15562 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
15563 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
15564}
15565
15566template<typename Derived>
15569 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
15570 if (Operand.isInvalid())
15571 return ExprError();
15572
15573 // Transform the delete operator, if known.
15574 FunctionDecl *OperatorDelete = nullptr;
15575 if (E->getOperatorDelete()) {
15576 OperatorDelete = cast_or_null<FunctionDecl>(
15577 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15578 if (!OperatorDelete)
15579 return ExprError();
15580 }
15581
15582 if (!getDerived().AlwaysRebuild() &&
15583 Operand.get() == E->getArgument() &&
15584 OperatorDelete == E->getOperatorDelete()) {
15585 // Mark any declarations we need as referenced.
15586 // FIXME: instantiation-specific.
15587 if (OperatorDelete)
15588 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15589
15590 if (!E->getArgument()->isTypeDependent()) {
15592 E->getDestroyedType());
15593 if (auto *Record = Destroyed->getAsCXXRecordDecl())
15594 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15595 SemaRef.LookupDestructor(Record));
15596 }
15597
15598 return E;
15599 }
15600
15601 return getDerived().RebuildCXXDeleteExpr(
15602 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
15603}
15604
15605template<typename Derived>
15609 ExprResult Base = getDerived().TransformExpr(E->getBase());
15610 if (Base.isInvalid())
15611 return ExprError();
15612
15613 ParsedType ObjectTypePtr;
15614 bool MayBePseudoDestructor = false;
15615 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15616 E->getOperatorLoc(),
15617 E->isArrow()? tok::arrow : tok::period,
15618 ObjectTypePtr,
15619 MayBePseudoDestructor);
15620 if (Base.isInvalid())
15621 return ExprError();
15622
15623 QualType ObjectType = ObjectTypePtr.get();
15624 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
15625 if (QualifierLoc) {
15626 QualifierLoc
15627 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
15628 if (!QualifierLoc)
15629 return ExprError();
15630 }
15631 CXXScopeSpec SS;
15632 SS.Adopt(QualifierLoc);
15633
15635 if (E->getDestroyedTypeInfo()) {
15636 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
15637 E->getDestroyedTypeInfo(), ObjectType,
15638 /*FirstQualifierInScope=*/nullptr);
15639 if (!DestroyedTypeInfo)
15640 return ExprError();
15641 Destroyed = DestroyedTypeInfo;
15642 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
15643 // We aren't likely to be able to resolve the identifier down to a type
15644 // now anyway, so just retain the identifier.
15645 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
15646 E->getDestroyedTypeLoc());
15647 } else {
15648 // Look for a destructor known with the given name.
15649 ParsedType T = SemaRef.getDestructorName(
15650 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
15651 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
15652 if (!T)
15653 return ExprError();
15654
15655 Destroyed
15657 E->getDestroyedTypeLoc());
15658 }
15659
15660 TypeSourceInfo *ScopeTypeInfo = nullptr;
15661 if (E->getScopeTypeInfo()) {
15662 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
15663 E->getScopeTypeInfo(), ObjectType, nullptr);
15664 if (!ScopeTypeInfo)
15665 return ExprError();
15666 }
15667
15668 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
15669 E->getOperatorLoc(),
15670 E->isArrow(),
15671 SS,
15672 ScopeTypeInfo,
15673 E->getColonColonLoc(),
15674 E->getTildeLoc(),
15675 Destroyed);
15676}
15677
15678template <typename Derived>
15680 bool RequiresADL,
15681 LookupResult &R) {
15682 // Transform all the decls.
15683 bool AllEmptyPacks = true;
15684 for (auto *OldD : Old->decls()) {
15685 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
15686 if (!InstD) {
15687 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
15688 // This can happen because of dependent hiding.
15689 if (isa<UsingShadowDecl>(OldD))
15690 continue;
15691 else {
15692 R.clear();
15693 return true;
15694 }
15695 }
15696
15697 // Expand using pack declarations.
15698 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
15699 ArrayRef<NamedDecl*> Decls = SingleDecl;
15700 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
15701 Decls = UPD->expansions();
15702
15703 // Expand using declarations.
15704 for (auto *D : Decls) {
15705 if (auto *UD = dyn_cast<UsingDecl>(D)) {
15706 for (auto *SD : UD->shadows())
15707 R.addDecl(SD);
15708 } else {
15709 R.addDecl(D);
15710 }
15711 }
15712
15713 AllEmptyPacks &= Decls.empty();
15714 }
15715
15716 // C++ [temp.res]/8.4.2:
15717 // The program is ill-formed, no diagnostic required, if [...] lookup for
15718 // a name in the template definition found a using-declaration, but the
15719 // lookup in the corresponding scope in the instantiation odoes not find
15720 // any declarations because the using-declaration was a pack expansion and
15721 // the corresponding pack is empty
15722 if (AllEmptyPacks && !RequiresADL) {
15723 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
15724 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
15725 return true;
15726 }
15727
15728 // Resolve a kind, but don't do any further analysis. If it's
15729 // ambiguous, the callee needs to deal with it.
15730 R.resolveKind();
15731
15732 if (Old->hasTemplateKeyword() && !R.empty()) {
15733 NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
15734 getSema().FilterAcceptableTemplateNames(R,
15735 /*AllowFunctionTemplates=*/true,
15736 /*AllowDependent=*/true);
15737 if (R.empty()) {
15738 // If a 'template' keyword was used, a lookup that finds only non-template
15739 // names is an error.
15740 getSema().Diag(R.getNameLoc(),
15741 diag::err_template_kw_refers_to_non_template)
15742 << R.getLookupName() << Old->getQualifierLoc().getSourceRange()
15743 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
15744 getSema().Diag(FoundDecl->getLocation(),
15745 diag::note_template_kw_refers_to_non_template)
15746 << R.getLookupName();
15747 return true;
15748 }
15749 }
15750
15751 return false;
15752}
15753
15754template <typename Derived>
15759
15760template <typename Derived>
15763 bool IsAddressOfOperand) {
15764 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
15766
15767 // Transform the declaration set.
15768 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
15769 return ExprError();
15770
15771 // Rebuild the nested-name qualifier, if present.
15772 CXXScopeSpec SS;
15773 if (Old->getQualifierLoc()) {
15774 NestedNameSpecifierLoc QualifierLoc
15775 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15776 if (!QualifierLoc)
15777 return ExprError();
15778
15779 SS.Adopt(QualifierLoc);
15780 }
15781
15782 if (Old->getNamingClass()) {
15783 CXXRecordDecl *NamingClass
15784 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
15785 Old->getNameLoc(),
15786 Old->getNamingClass()));
15787 if (!NamingClass) {
15788 R.clear();
15789 return ExprError();
15790 }
15791
15792 R.setNamingClass(NamingClass);
15793 }
15794
15795 // Rebuild the template arguments, if any.
15796 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15797 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
15798 if (Old->hasExplicitTemplateArgs() &&
15799 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15800 Old->getNumTemplateArgs(),
15801 TransArgs)) {
15802 R.clear();
15803 return ExprError();
15804 }
15805
15806 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
15807 // a non-static data member is named in an unevaluated operand, or when
15808 // a member is named in a dependent class scope function template explicit
15809 // specialization that is neither declared static nor with an explicit object
15810 // parameter.
15811 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
15812 return SemaRef.BuildPossibleImplicitMemberExpr(
15813 SS, TemplateKWLoc, R,
15814 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
15815 /*S=*/nullptr);
15816
15817 // If we have neither explicit template arguments, nor the template keyword,
15818 // it's a normal declaration name or member reference.
15819 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
15820 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
15821
15822 // If we have template arguments, then rebuild the template-id expression.
15823 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
15824 Old->requiresADL(), &TransArgs);
15825}
15826
15827template<typename Derived>
15830 bool ArgChanged = false;
15832 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
15833 TypeSourceInfo *From = E->getArg(I);
15834 TypeLoc FromTL = From->getTypeLoc();
15835 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
15836 TypeLocBuilder TLB;
15837 TLB.reserve(FromTL.getFullDataSize());
15838 QualType To = getDerived().TransformType(TLB, FromTL);
15839 if (To.isNull())
15840 return ExprError();
15841
15842 if (To == From->getType())
15843 Args.push_back(From);
15844 else {
15845 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15846 ArgChanged = true;
15847 }
15848 continue;
15849 }
15850
15851 ArgChanged = true;
15852
15853 // We have a pack expansion. Instantiate it.
15854 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
15855 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
15857 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
15858
15859 // Determine whether the set of unexpanded parameter packs can and should
15860 // be expanded.
15861 bool Expand = true;
15862 bool RetainExpansion = false;
15863 UnsignedOrNone OrigNumExpansions =
15864 ExpansionTL.getTypePtr()->getNumExpansions();
15865 UnsignedOrNone NumExpansions = OrigNumExpansions;
15866 if (getDerived().TryExpandParameterPacks(
15867 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
15868 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15869 RetainExpansion, NumExpansions))
15870 return ExprError();
15871
15872 if (!Expand) {
15873 // The transform has determined that we should perform a simple
15874 // transformation on the pack expansion, producing another pack
15875 // expansion.
15876 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
15877
15878 TypeLocBuilder TLB;
15879 TLB.reserve(From->getTypeLoc().getFullDataSize());
15880
15881 QualType To = getDerived().TransformType(TLB, PatternTL);
15882 if (To.isNull())
15883 return ExprError();
15884
15885 To = getDerived().RebuildPackExpansionType(To,
15886 PatternTL.getSourceRange(),
15887 ExpansionTL.getEllipsisLoc(),
15888 NumExpansions);
15889 if (To.isNull())
15890 return ExprError();
15891
15892 PackExpansionTypeLoc ToExpansionTL
15893 = TLB.push<PackExpansionTypeLoc>(To);
15894 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15895 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15896 continue;
15897 }
15898
15899 // Expand the pack expansion by substituting for each argument in the
15900 // pack(s).
15901 for (unsigned I = 0; I != *NumExpansions; ++I) {
15902 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15903 TypeLocBuilder TLB;
15904 TLB.reserve(PatternTL.getFullDataSize());
15905 QualType To = getDerived().TransformType(TLB, PatternTL);
15906 if (To.isNull())
15907 return ExprError();
15908
15909 if (To->containsUnexpandedParameterPack()) {
15910 To = getDerived().RebuildPackExpansionType(To,
15911 PatternTL.getSourceRange(),
15912 ExpansionTL.getEllipsisLoc(),
15913 NumExpansions);
15914 if (To.isNull())
15915 return ExprError();
15916
15917 PackExpansionTypeLoc ToExpansionTL
15918 = TLB.push<PackExpansionTypeLoc>(To);
15919 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15920 }
15921
15922 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15923 }
15924
15925 if (!RetainExpansion)
15926 continue;
15927
15928 // If we're supposed to retain a pack expansion, do so by temporarily
15929 // forgetting the partially-substituted parameter pack.
15930 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15931
15932 TypeLocBuilder TLB;
15933 TLB.reserve(From->getTypeLoc().getFullDataSize());
15934
15935 QualType To = getDerived().TransformType(TLB, PatternTL);
15936 if (To.isNull())
15937 return ExprError();
15938
15939 To = getDerived().RebuildPackExpansionType(To,
15940 PatternTL.getSourceRange(),
15941 ExpansionTL.getEllipsisLoc(),
15942 NumExpansions);
15943 if (To.isNull())
15944 return ExprError();
15945
15946 PackExpansionTypeLoc ToExpansionTL
15947 = TLB.push<PackExpansionTypeLoc>(To);
15948 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15949 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15950 }
15951
15952 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15953 return E;
15954
15955 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15956 E->getEndLoc());
15957}
15958
15959template<typename Derived>
15963 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15964 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15965 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15966 Old->NumTemplateArgs, TransArgs))
15967 return ExprError();
15968
15969 return getDerived().RebuildConceptSpecializationExpr(
15970 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15971 E->getConceptNameInfo(), E->getFoundDecl(), E->getConceptDecl(),
15972 &TransArgs);
15973}
15974
15975template<typename Derived>
15978 SmallVector<ParmVarDecl*, 4> TransParams;
15979 SmallVector<QualType, 4> TransParamTypes;
15980 Sema::ExtParameterInfoBuilder ExtParamInfos;
15981
15982 // C++2a [expr.prim.req]p2
15983 // Expressions appearing within a requirement-body are unevaluated operands.
15987
15989 getSema().Context, getSema().CurContext,
15990 E->getBody()->getBeginLoc());
15991
15992 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15993
15994 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15995 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15996 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15997
15998 for (ParmVarDecl *Param : TransParams)
15999 if (Param)
16000 Param->setDeclContext(Body);
16001
16002 // On failure to transform, TransformRequiresTypeParams returns an expression
16003 // in the event that the transformation of the type params failed in some way.
16004 // It is expected that this will result in a 'not satisfied' Requires clause
16005 // when instantiating.
16006 if (!TypeParamResult.isUnset())
16007 return TypeParamResult;
16008
16010 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
16011 TransReqs))
16012 return ExprError();
16013
16014 for (concepts::Requirement *Req : TransReqs) {
16015 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
16016 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
16017 ER->getReturnTypeRequirement()
16018 .getTypeConstraintTemplateParameterList()->getParam(0)
16019 ->setDeclContext(Body);
16020 }
16021 }
16022 }
16023
16024 return getDerived().RebuildRequiresExpr(
16025 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
16026 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
16027}
16028
16029template<typename Derived>
16033 for (concepts::Requirement *Req : Reqs) {
16034 concepts::Requirement *TransReq = nullptr;
16035 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
16036 TransReq = getDerived().TransformTypeRequirement(TypeReq);
16037 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
16038 TransReq = getDerived().TransformExprRequirement(ExprReq);
16039 else
16040 TransReq = getDerived().TransformNestedRequirement(
16042 if (!TransReq)
16043 return true;
16044 Transformed.push_back(TransReq);
16045 }
16046 return false;
16047}
16048
16049template<typename Derived>
16053 if (Req->isSubstitutionFailure()) {
16054 if (getDerived().AlwaysRebuild())
16055 return getDerived().RebuildTypeRequirement(
16057 return Req;
16058 }
16059 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
16060 if (!TransType)
16061 return nullptr;
16062 return getDerived().RebuildTypeRequirement(TransType);
16063}
16064
16065template<typename Derived>
16068 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
16069 if (Req->isExprSubstitutionFailure())
16070 TransExpr = Req->getExprSubstitutionDiagnostic();
16071 else {
16072 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
16073 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
16074 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
16075 if (TransExprRes.isInvalid())
16076 return nullptr;
16077 TransExpr = TransExprRes.get();
16078 }
16079
16080 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
16081 const auto &RetReq = Req->getReturnTypeRequirement();
16082 if (RetReq.isEmpty())
16083 TransRetReq.emplace();
16084 else if (RetReq.isSubstitutionFailure())
16085 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
16086 else if (RetReq.isTypeConstraint()) {
16087 TemplateParameterList *OrigTPL =
16088 RetReq.getTypeConstraintTemplateParameterList();
16090 getDerived().TransformTemplateParameterList(OrigTPL);
16091 if (!TPL)
16092 return nullptr;
16093 TransRetReq.emplace(TPL);
16094 }
16095 assert(TransRetReq && "All code paths leading here must set TransRetReq");
16096 if (Expr *E = dyn_cast<Expr *>(TransExpr))
16097 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
16098 Req->getNoexceptLoc(),
16099 std::move(*TransRetReq));
16100 return getDerived().RebuildExprRequirement(
16102 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
16103}
16104
16105template<typename Derived>
16109 if (Req->hasInvalidConstraint()) {
16110 if (getDerived().AlwaysRebuild())
16111 return getDerived().RebuildNestedRequirement(
16113 return Req;
16114 }
16115 ExprResult TransConstraint =
16116 getDerived().TransformExpr(Req->getConstraintExpr());
16117 if (TransConstraint.isInvalid())
16118 return nullptr;
16119 return getDerived().RebuildNestedRequirement(TransConstraint.get());
16120}
16121
16122template<typename Derived>
16125 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
16126 if (!T)
16127 return ExprError();
16128
16129 if (!getDerived().AlwaysRebuild() &&
16130 T == E->getQueriedTypeSourceInfo())
16131 return E;
16132
16133 ExprResult SubExpr;
16134 {
16137 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
16138 if (SubExpr.isInvalid())
16139 return ExprError();
16140 }
16141
16142 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
16143 SubExpr.get(), E->getEndLoc());
16144}
16145
16146template<typename Derived>
16149 ExprResult SubExpr;
16150 {
16153 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
16154 if (SubExpr.isInvalid())
16155 return ExprError();
16156
16157 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
16158 return E;
16159 }
16160
16161 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
16162 SubExpr.get(), E->getEndLoc());
16163}
16164
16165template <typename Derived>
16167 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
16168 TypeSourceInfo **RecoveryTSI) {
16169 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
16170 DRE, AddrTaken, RecoveryTSI);
16171
16172 // Propagate both errors and recovered types, which return ExprEmpty.
16173 if (!NewDRE.isUsable())
16174 return NewDRE;
16175
16176 // We got an expr, wrap it up in parens.
16177 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
16178 return PE;
16179 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
16180 PE->getRParen());
16181}
16182
16183template <typename Derived>
16189
16190template <typename Derived>
16192 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
16193 TypeSourceInfo **RecoveryTSI) {
16194 assert(E->getQualifierLoc());
16195 NestedNameSpecifierLoc QualifierLoc =
16196 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
16197 if (!QualifierLoc)
16198 return ExprError();
16199 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16200
16201 // TODO: If this is a conversion-function-id, verify that the
16202 // destination type name (if present) resolves the same way after
16203 // instantiation as it did in the local scope.
16204
16205 DeclarationNameInfo NameInfo =
16206 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
16207 if (!NameInfo.getName())
16208 return ExprError();
16209
16210 if (!E->hasExplicitTemplateArgs()) {
16211 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
16212 // Note: it is sufficient to compare the Name component of NameInfo:
16213 // if name has not changed, DNLoc has not changed either.
16214 NameInfo.getName() == E->getDeclName())
16215 return E;
16216
16217 return getDerived().RebuildDependentScopeDeclRefExpr(
16218 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
16219 IsAddressOfOperand, RecoveryTSI);
16220 }
16221
16222 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16223 if (getDerived().TransformTemplateArguments(
16224 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
16225 return ExprError();
16226
16227 return getDerived().RebuildDependentScopeDeclRefExpr(
16228 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
16229 RecoveryTSI);
16230}
16231
16232template<typename Derived>
16235 // CXXConstructExprs other than for list-initialization and
16236 // CXXTemporaryObjectExpr are always implicit, so when we have
16237 // a 1-argument construction we just transform that argument.
16238 if (getDerived().AllowSkippingCXXConstructExpr() &&
16239 ((E->getNumArgs() == 1 ||
16240 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
16241 (!getDerived().DropCallArgument(E->getArg(0))) &&
16242 !E->isListInitialization()))
16243 return getDerived().TransformInitializer(E->getArg(0),
16244 /*DirectInit*/ false);
16245
16246 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
16247
16248 QualType T = getDerived().TransformType(E->getType());
16249 if (T.isNull())
16250 return ExprError();
16251
16252 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16253 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16254 if (!Constructor)
16255 return ExprError();
16256
16257 bool ArgumentChanged = false;
16259 {
16262 E->isListInitialization());
16263 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16264 &ArgumentChanged))
16265 return ExprError();
16266 }
16267
16268 if (!getDerived().AlwaysRebuild() &&
16269 T == E->getType() &&
16270 Constructor == E->getConstructor() &&
16271 !ArgumentChanged) {
16272 // Mark the constructor as referenced.
16273 // FIXME: Instantiation-specific
16274 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16275 return E;
16276 }
16277
16278 return getDerived().RebuildCXXConstructExpr(
16279 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
16280 E->hadMultipleCandidates(), E->isListInitialization(),
16281 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
16282 E->getConstructionKind(), E->getParenOrBraceRange());
16283}
16284
16285template<typename Derived>
16288 QualType T = getDerived().TransformType(E->getType());
16289 if (T.isNull())
16290 return ExprError();
16291
16292 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16293 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16294 if (!Constructor)
16295 return ExprError();
16296
16297 if (!getDerived().AlwaysRebuild() &&
16298 T == E->getType() &&
16299 Constructor == E->getConstructor()) {
16300 // Mark the constructor as referenced.
16301 // FIXME: Instantiation-specific
16302 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16303 return E;
16304 }
16305
16306 return getDerived().RebuildCXXInheritedCtorInitExpr(
16307 T, E->getLocation(), Constructor,
16308 E->constructsVBase(), E->inheritedFromVBase());
16309}
16310
16311/// Transform a C++ temporary-binding expression.
16312///
16313/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
16314/// transform the subexpression and return that.
16315template<typename Derived>
16318 if (auto *Dtor = E->getTemporary()->getDestructor())
16319 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
16320 const_cast<CXXDestructorDecl *>(Dtor));
16321 return getDerived().TransformExpr(E->getSubExpr());
16322}
16323
16324/// Transform a C++ expression that contains cleanups that should
16325/// be run after the expression is evaluated.
16326///
16327/// Since ExprWithCleanups nodes are implicitly generated, we
16328/// just transform the subexpression and return that.
16329template<typename Derived>
16332 return getDerived().TransformExpr(E->getSubExpr());
16333}
16334
16335template<typename Derived>
16339 TypeSourceInfo *T =
16340 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16341 if (!T)
16342 return ExprError();
16343
16344 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16345 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16346 if (!Constructor)
16347 return ExprError();
16348
16349 bool ArgumentChanged = false;
16351 Args.reserve(E->getNumArgs());
16352 {
16355 E->isListInitialization());
16356 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16357 &ArgumentChanged))
16358 return ExprError();
16359
16360 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
16361 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc(),
16362 /*IsExplicit=*/true);
16363 if (Res.isInvalid())
16364 return ExprError();
16365 Args = {Res.get()};
16366 }
16367 }
16368
16369 if (!getDerived().AlwaysRebuild() &&
16370 T == E->getTypeSourceInfo() &&
16371 Constructor == E->getConstructor() &&
16372 !ArgumentChanged) {
16373 // FIXME: Instantiation-specific
16374 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16375 return SemaRef.MaybeBindToTemporary(E);
16376 }
16377
16378 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
16379 return getDerived().RebuildCXXTemporaryObjectExpr(
16380 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
16381}
16382
16383template<typename Derived>
16386 // Transform any init-capture expressions before entering the scope of the
16387 // lambda body, because they are not semantically within that scope.
16388 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
16389 struct TransformedInitCapture {
16390 // The location of the ... if the result is retaining a pack expansion.
16391 SourceLocation EllipsisLoc;
16392 // Zero or more expansions of the init-capture.
16393 SmallVector<InitCaptureInfoTy, 4> Expansions;
16394 };
16396 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
16397 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16398 CEnd = E->capture_end();
16399 C != CEnd; ++C) {
16400 if (!E->isInitCapture(C))
16401 continue;
16402
16403 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
16404 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16405
16406 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
16407 UnsignedOrNone NumExpansions) {
16408 ExprResult NewExprInitResult = getDerived().TransformInitializer(
16409 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
16410
16411 if (NewExprInitResult.isInvalid()) {
16412 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
16413 return;
16414 }
16415 Expr *NewExprInit = NewExprInitResult.get();
16416
16417 QualType NewInitCaptureType =
16418 getSema().buildLambdaInitCaptureInitialization(
16419 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
16420 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
16421 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
16423 NewExprInit);
16424 Result.Expansions.push_back(
16425 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
16426 };
16427
16428 // If this is an init-capture pack, consider expanding the pack now.
16429 if (OldVD->isParameterPack()) {
16430 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
16431 ->getTypeLoc()
16434 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
16435
16436 // Determine whether the set of unexpanded parameter packs can and should
16437 // be expanded.
16438 bool Expand = true;
16439 bool RetainExpansion = false;
16440 UnsignedOrNone OrigNumExpansions =
16441 ExpansionTL.getTypePtr()->getNumExpansions();
16442 UnsignedOrNone NumExpansions = OrigNumExpansions;
16443 if (getDerived().TryExpandParameterPacks(
16444 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
16445 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
16446 RetainExpansion, NumExpansions))
16447 return ExprError();
16448 assert(!RetainExpansion && "Should not need to retain expansion after a "
16449 "capture since it cannot be extended");
16450 if (Expand) {
16451 for (unsigned I = 0; I != *NumExpansions; ++I) {
16452 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16453 SubstInitCapture(SourceLocation(), std::nullopt);
16454 }
16455 } else {
16456 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
16457 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
16458 }
16459 } else {
16460 SubstInitCapture(SourceLocation(), std::nullopt);
16461 }
16462 }
16463
16464 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
16465 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
16466
16467 // Create the local class that will describe the lambda.
16468
16469 // FIXME: DependencyKind below is wrong when substituting inside a templated
16470 // context that isn't a DeclContext (such as a variable template), or when
16471 // substituting an unevaluated lambda inside of a function's parameter's type
16472 // - as parameter types are not instantiated from within a function's DC. We
16473 // use evaluation contexts to distinguish the function parameter case.
16476 DeclContext *DC = getSema().CurContext;
16477 // A RequiresExprBodyDecl is not interesting for dependencies.
16478 // For the following case,
16479 //
16480 // template <typename>
16481 // concept C = requires { [] {}; };
16482 //
16483 // template <class F>
16484 // struct Widget;
16485 //
16486 // template <C F>
16487 // struct Widget<F> {};
16488 //
16489 // While we are substituting Widget<F>, the parent of DC would be
16490 // the template specialization itself. Thus, the lambda expression
16491 // will be deemed as dependent even if there are no dependent template
16492 // arguments.
16493 // (A ClassTemplateSpecializationDecl is always a dependent context.)
16494 while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
16495 DC = DC->getParent();
16496 if ((getSema().isUnevaluatedContext() ||
16497 getSema().isConstantEvaluatedContext()) &&
16498 !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
16499 cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
16500 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
16501 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
16502
16503 CXXRecordDecl *OldClass = E->getLambdaClass();
16504 CXXRecordDecl *Class = getSema().createLambdaClosureType(
16505 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
16506 E->getCaptureDefault());
16507 getDerived().transformedLocalDecl(OldClass, {Class});
16508
16509 CXXMethodDecl *NewCallOperator =
16510 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
16511
16512 // Enter the scope of the lambda.
16513 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
16514 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
16515 E->hasExplicitParameters(), E->isMutable());
16516
16517 // Introduce the context of the call operator.
16518 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
16519 /*NewThisContext*/false);
16520
16521 bool Invalid = false;
16522
16523 // Transform captures.
16524 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16525 CEnd = E->capture_end();
16526 C != CEnd; ++C) {
16527 // When we hit the first implicit capture, tell Sema that we've finished
16528 // the list of explicit captures.
16529 if (C->isImplicit())
16530 break;
16531
16532 // Capturing 'this' is trivial.
16533 if (C->capturesThis()) {
16534 // If this is a lambda that is part of a default member initialiser
16535 // and which we're instantiating outside the class that 'this' is
16536 // supposed to refer to, adjust the type of 'this' accordingly.
16537 //
16538 // Otherwise, leave the type of 'this' as-is.
16539 Sema::CXXThisScopeRAII ThisScope(
16540 getSema(),
16541 dyn_cast_if_present<CXXRecordDecl>(
16542 getSema().getFunctionLevelDeclContext()),
16543 Qualifiers());
16544 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16545 /*BuildAndDiagnose*/ true, nullptr,
16546 C->getCaptureKind() == LCK_StarThis);
16547 continue;
16548 }
16549 // Captured expression will be recaptured during captured variables
16550 // rebuilding.
16551 if (C->capturesVLAType())
16552 continue;
16553
16554 // Rebuild init-captures, including the implied field declaration.
16555 if (E->isInitCapture(C)) {
16556 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
16557
16558 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16560
16561 for (InitCaptureInfoTy &Info : NewC.Expansions) {
16562 ExprResult Init = Info.first;
16563 QualType InitQualType = Info.second;
16564 if (Init.isInvalid() || InitQualType.isNull()) {
16565 Invalid = true;
16566 break;
16567 }
16568 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
16569 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
16570 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
16571 getSema().CurContext);
16572 if (!NewVD) {
16573 Invalid = true;
16574 break;
16575 }
16576 NewVDs.push_back(NewVD);
16577 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
16578 // Cases we want to tackle:
16579 // ([C(Pack)] {}, ...)
16580 // But rule out cases e.g.
16581 // [...C = Pack()] {}
16582 if (NewC.EllipsisLoc.isInvalid())
16583 LSI->ContainsUnexpandedParameterPack |=
16584 Init.get()->containsUnexpandedParameterPack();
16585 }
16586
16587 if (Invalid)
16588 break;
16589
16590 getDerived().transformedLocalDecl(OldVD, NewVDs);
16591 continue;
16592 }
16593
16594 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16595
16596 // Determine the capture kind for Sema.
16598 : C->getCaptureKind() == LCK_ByCopy
16601 SourceLocation EllipsisLoc;
16602 if (C->isPackExpansion()) {
16603 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
16604 bool ShouldExpand = false;
16605 bool RetainExpansion = false;
16606 UnsignedOrNone NumExpansions = std::nullopt;
16607 if (getDerived().TryExpandParameterPacks(
16608 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
16609 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16610 RetainExpansion, NumExpansions)) {
16611 Invalid = true;
16612 continue;
16613 }
16614
16615 if (ShouldExpand) {
16616 // The transform has determined that we should perform an expansion;
16617 // transform and capture each of the arguments.
16618 // expansion of the pattern. Do so.
16619 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
16620 for (unsigned I = 0; I != *NumExpansions; ++I) {
16621 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16622 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
16623 getDerived().TransformDecl(C->getLocation(), Pack));
16624 if (!CapturedVar) {
16625 Invalid = true;
16626 continue;
16627 }
16628
16629 // Capture the transformed variable.
16630 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
16631 }
16632
16633 // FIXME: Retain a pack expansion if RetainExpansion is true.
16634
16635 continue;
16636 }
16637
16638 EllipsisLoc = C->getEllipsisLoc();
16639 }
16640
16641 // Transform the captured variable.
16642 auto *CapturedVar = cast_or_null<ValueDecl>(
16643 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16644 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
16645 Invalid = true;
16646 continue;
16647 }
16648
16649 // This is not an init-capture; however it contains an unexpanded pack e.g.
16650 // ([Pack] {}(), ...)
16651 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
16652 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
16653
16654 // Capture the transformed variable.
16655 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
16656 EllipsisLoc);
16657 }
16658 getSema().finishLambdaExplicitCaptures(LSI);
16659
16660 // Transform the template parameters, and add them to the current
16661 // instantiation scope. The null case is handled correctly.
16662 auto TPL = getDerived().TransformTemplateParameterList(
16663 E->getTemplateParameterList());
16664 LSI->GLTemplateParameterList = TPL;
16665 if (TPL) {
16666 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
16667 TPL);
16668 LSI->ContainsUnexpandedParameterPack |=
16669 TPL->containsUnexpandedParameterPack();
16670 }
16671
16672 TypeLocBuilder NewCallOpTLBuilder;
16673 TypeLoc OldCallOpTypeLoc =
16674 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
16675 QualType NewCallOpType =
16676 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
16677 if (NewCallOpType.isNull())
16678 return ExprError();
16679 LSI->ContainsUnexpandedParameterPack |=
16680 NewCallOpType->containsUnexpandedParameterPack();
16681 TypeSourceInfo *NewCallOpTSI =
16682 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
16683
16684 // The type may be an AttributedType or some other kind of sugar;
16685 // get the actual underlying FunctionProtoType.
16686 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
16687 assert(FPTL && "Not a FunctionProtoType?");
16688
16689 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
16690 if (TRC) {
16691 ExprResult E = getDerived().TransformLambdaConstraint(
16692 const_cast<Expr *>(TRC.ConstraintExpr));
16693 if (E.isInvalid())
16694 return E;
16695 TRC.ConstraintExpr = E.get();
16696 }
16697
16698 LSI->BeforeCompoundStatement = false;
16699 getSema().CompleteLambdaCallOperator(
16700 NewCallOperator, E->getCallOperator()->getLocation(),
16701 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
16702 E->getCallOperator()->getConstexprKind(),
16703 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
16704 E->hasExplicitResultType());
16705
16706 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
16707 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
16708
16709 {
16710 // Number the lambda for linkage purposes if necessary.
16711 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
16712
16713 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
16714 if (getDerived().ReplacingOriginal()) {
16715 Numbering = OldClass->getLambdaNumbering();
16716 }
16717
16718 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
16719 }
16720
16721 // FIXME: Sema's lambda-building mechanism expects us to push an expression
16722 // evaluation context even if we're not transforming the function body.
16723 getSema().PushExpressionEvaluationContextForFunction(
16725 E->getCallOperator());
16726
16727 StmtResult Body;
16728 {
16729 Sema::NonSFINAEContext _(getSema());
16732 C.PointOfInstantiation = E->getBody()->getBeginLoc();
16733 getSema().pushCodeSynthesisContext(C);
16734
16735 // Instantiate the body of the lambda expression.
16736 Body = Invalid ? StmtError()
16737 : getDerived().TransformLambdaBody(E, E->getBody());
16738
16739 getSema().popCodeSynthesisContext();
16740 }
16741
16742 // ActOnLambda* will pop the function scope for us.
16743 FuncScopeCleanup.disable();
16744
16745 if (Body.isInvalid()) {
16746 SavedContext.pop();
16747 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
16748 /*IsInstantiation=*/true);
16749 return ExprError();
16750 }
16751
16752 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
16753 /*IsInstantiation=*/true,
16754 /*RetainFunctionScopeInfo=*/true);
16755 SavedContext.pop();
16756
16757 // Recompute the dependency of the lambda so that we can defer the lambda call
16758 // construction until after we have all the necessary template arguments. For
16759 // example, given
16760 //
16761 // template <class> struct S {
16762 // template <class U>
16763 // using Type = decltype([](U){}(42.0));
16764 // };
16765 // void foo() {
16766 // using T = S<int>::Type<float>;
16767 // ^~~~~~
16768 // }
16769 //
16770 // We would end up here from instantiating S<int> when ensuring its
16771 // completeness. That would transform the lambda call expression regardless of
16772 // the absence of the corresponding argument for U.
16773 //
16774 // Going ahead with unsubstituted type U makes things worse: we would soon
16775 // compare the argument type (which is float) against the parameter U
16776 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
16777 // error suggesting unmatched types 'U' and 'float'!
16778 //
16779 // That said, everything will be fine if we defer that semantic checking.
16780 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
16781 // dependent. Since the CallExpr's dependency boils down to the lambda's
16782 // dependency in this case, we can harness that by recomputing the dependency
16783 // from the instantiation arguments.
16784 //
16785 // FIXME: Creating the type of a lambda requires us to have a dependency
16786 // value, which happens before its substitution. We update its dependency
16787 // *after* the substitution in case we can't decide the dependency
16788 // so early, e.g. because we want to see if any of the *substituted*
16789 // parameters are dependent.
16790 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
16791 Class->setLambdaDependencyKind(DependencyKind);
16792
16793 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
16794 Body.get()->getEndLoc(), LSI);
16795}
16796
16797template<typename Derived>
16802
16803template<typename Derived>
16806 // Transform captures.
16808 CEnd = E->capture_end();
16809 C != CEnd; ++C) {
16810 // When we hit the first implicit capture, tell Sema that we've finished
16811 // the list of explicit captures.
16812 if (!C->isImplicit())
16813 continue;
16814
16815 // Capturing 'this' is trivial.
16816 if (C->capturesThis()) {
16817 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16818 /*BuildAndDiagnose*/ true, nullptr,
16819 C->getCaptureKind() == LCK_StarThis);
16820 continue;
16821 }
16822 // Captured expression will be recaptured during captured variables
16823 // rebuilding.
16824 if (C->capturesVLAType())
16825 continue;
16826
16827 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16828 assert(!E->isInitCapture(C) && "implicit init-capture?");
16829
16830 // Transform the captured variable.
16831 VarDecl *CapturedVar = cast_or_null<VarDecl>(
16832 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16833 if (!CapturedVar || CapturedVar->isInvalidDecl())
16834 return StmtError();
16835
16836 // Capture the transformed variable.
16837 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
16838 }
16839
16840 return S;
16841}
16842
16843template<typename Derived>
16847 TypeSourceInfo *T =
16848 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16849 if (!T)
16850 return ExprError();
16851
16852 bool ArgumentChanged = false;
16854 Args.reserve(E->getNumArgs());
16855 {
16859 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
16860 &ArgumentChanged))
16861 return ExprError();
16862 }
16863
16864 if (!getDerived().AlwaysRebuild() &&
16865 T == E->getTypeSourceInfo() &&
16866 !ArgumentChanged)
16867 return E;
16868
16869 // FIXME: we're faking the locations of the commas
16870 return getDerived().RebuildCXXUnresolvedConstructExpr(
16871 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
16872}
16873
16874template <typename Derived>
16877
16878 TemplateName Name = getDerived().TransformConceptTemplateName(
16879 E->getTemplateName(), E->getNameLoc());
16880 if (Name.isNull())
16881 return ExprError();
16882
16883 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16884 if (getDerived().TransformTemplateArguments(
16885 E->template_arguments().data(), E->getNumTemplateArgs(), TransArgs))
16886 return ExprError();
16887
16888 TemplateDecl *TD = Name.getAsTemplateDecl();
16889 if (!TD)
16890 return SemaRef.CheckVarOrConceptTemplateTemplateId(E->getNameInfo(), Name,
16891 &TransArgs);
16892
16893 CXXScopeSpec SS;
16894
16895 LookupResult R(SemaRef, E->getNameInfo(), Sema::LookupOrdinaryName);
16896 R.addDecl(TD);
16897 R.resolveKind();
16898 return getDerived().RebuildTemplateIdExpr(
16899 SS, /*Template Keyword=*/SourceLocation(), R,
16900 /*RequiresADL=*/false, &TransArgs);
16901}
16902
16903template<typename Derived>
16907 // Transform the base of the expression.
16908 ExprResult Base((Expr*) nullptr);
16909 Expr *OldBase;
16910 QualType BaseType;
16911 QualType ObjectType;
16912 if (!E->isImplicitAccess()) {
16913 OldBase = E->getBase();
16914 Base = getDerived().TransformExpr(OldBase);
16915 if (Base.isInvalid())
16916 return ExprError();
16917
16918 // Start the member reference and compute the object's type.
16919 ParsedType ObjectTy;
16920 bool MayBePseudoDestructor = false;
16921 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
16922 E->getOperatorLoc(),
16923 E->isArrow()? tok::arrow : tok::period,
16924 ObjectTy,
16925 MayBePseudoDestructor);
16926 if (Base.isInvalid())
16927 return ExprError();
16928
16929 ObjectType = ObjectTy.get();
16930 BaseType = ((Expr*) Base.get())->getType();
16931 } else {
16932 OldBase = nullptr;
16933 BaseType = getDerived().TransformType(E->getBaseType());
16934 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16935 }
16936
16937 // Transform the first part of the nested-name-specifier that qualifies
16938 // the member name.
16939 NamedDecl *FirstQualifierInScope
16940 = getDerived().TransformFirstQualifierInScope(
16941 E->getFirstQualifierFoundInScope(),
16942 E->getQualifierLoc().getBeginLoc());
16943
16944 NestedNameSpecifierLoc QualifierLoc;
16945 if (E->getQualifier()) {
16946 QualifierLoc
16947 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16948 ObjectType,
16949 FirstQualifierInScope);
16950 if (!QualifierLoc)
16951 return ExprError();
16952 }
16953
16954 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16955
16956 // TODO: If this is a conversion-function-id, verify that the
16957 // destination type name (if present) resolves the same way after
16958 // instantiation as it did in the local scope.
16959
16960 DeclarationNameInfo NameInfo
16961 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16962 if (!NameInfo.getName())
16963 return ExprError();
16964
16965 if (!E->hasExplicitTemplateArgs()) {
16966 // This is a reference to a member without an explicitly-specified
16967 // template argument list. Optimize for this common case.
16968 if (!getDerived().AlwaysRebuild() &&
16969 Base.get() == OldBase &&
16970 BaseType == E->getBaseType() &&
16971 QualifierLoc == E->getQualifierLoc() &&
16972 NameInfo.getName() == E->getMember() &&
16973 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16974 return E;
16975
16976 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16977 BaseType,
16978 E->isArrow(),
16979 E->getOperatorLoc(),
16980 QualifierLoc,
16981 TemplateKWLoc,
16982 FirstQualifierInScope,
16983 NameInfo,
16984 /*TemplateArgs*/nullptr);
16985 }
16986
16987 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16988 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16989 E->getNumTemplateArgs(),
16990 TransArgs))
16991 return ExprError();
16992
16993 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16994 BaseType,
16995 E->isArrow(),
16996 E->getOperatorLoc(),
16997 QualifierLoc,
16998 TemplateKWLoc,
16999 FirstQualifierInScope,
17000 NameInfo,
17001 &TransArgs);
17002}
17003
17004template <typename Derived>
17006 UnresolvedMemberExpr *Old) {
17007 // Transform the base of the expression.
17008 ExprResult Base((Expr *)nullptr);
17009 QualType BaseType;
17010 if (!Old->isImplicitAccess()) {
17011 Base = getDerived().TransformExpr(Old->getBase());
17012 if (Base.isInvalid())
17013 return ExprError();
17014 Base =
17015 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
17016 if (Base.isInvalid())
17017 return ExprError();
17018 BaseType = Base.get()->getType();
17019 } else {
17020 BaseType = getDerived().TransformType(Old->getBaseType());
17021 }
17022
17023 NestedNameSpecifierLoc QualifierLoc;
17024 if (Old->getQualifierLoc()) {
17025 QualifierLoc =
17026 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
17027 if (!QualifierLoc)
17028 return ExprError();
17029 }
17030
17031 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
17032
17033 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
17034
17035 // Transform the declaration set.
17036 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
17037 return ExprError();
17038
17039 // Determine the naming class.
17040 if (Old->getNamingClass()) {
17041 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
17042 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
17043 if (!NamingClass)
17044 return ExprError();
17045
17046 R.setNamingClass(NamingClass);
17047 }
17048
17049 TemplateArgumentListInfo TransArgs;
17050 if (Old->hasExplicitTemplateArgs()) {
17051 TransArgs.setLAngleLoc(Old->getLAngleLoc());
17052 TransArgs.setRAngleLoc(Old->getRAngleLoc());
17053 if (getDerived().TransformTemplateArguments(
17054 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
17055 return ExprError();
17056 }
17057
17058 // FIXME: to do this check properly, we will need to preserve the
17059 // first-qualifier-in-scope here, just in case we had a dependent
17060 // base (and therefore couldn't do the check) and a
17061 // nested-name-qualifier (and therefore could do the lookup).
17062 NamedDecl *FirstQualifierInScope = nullptr;
17063
17064 return getDerived().RebuildUnresolvedMemberExpr(
17065 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
17066 TemplateKWLoc, FirstQualifierInScope, R,
17067 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
17068}
17069
17070template<typename Derived>
17075 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
17076 if (SubExpr.isInvalid())
17077 return ExprError();
17078
17079 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
17080 return E;
17081
17082 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
17083}
17084
17085template<typename Derived>
17088 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
17089 if (Pattern.isInvalid())
17090 return ExprError();
17091
17092 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
17093 return E;
17094
17095 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
17096 E->getNumExpansions());
17097}
17098
17099template <typename Derived>
17101 ArrayRef<TemplateArgument> PackArgs) {
17103 for (const TemplateArgument &Arg : PackArgs) {
17104 if (!Arg.isPackExpansion()) {
17105 Result = *Result + 1;
17106 continue;
17107 }
17108
17109 TemplateArgumentLoc ArgLoc;
17110 InventTemplateArgumentLoc(Arg, ArgLoc);
17111
17112 // Find the pattern of the pack expansion.
17113 SourceLocation Ellipsis;
17114 UnsignedOrNone OrigNumExpansions = std::nullopt;
17115 TemplateArgumentLoc Pattern =
17116 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
17117 OrigNumExpansions);
17118
17119 // Substitute under the pack expansion. Do not expand the pack (yet).
17120 TemplateArgumentLoc OutPattern;
17121 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17122 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
17123 /*Uneval*/ true))
17124 return 1u;
17125
17126 // See if we can determine the number of arguments from the result.
17127 UnsignedOrNone NumExpansions =
17128 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
17129 if (!NumExpansions) {
17130 // No: we must be in an alias template expansion, and we're going to
17131 // need to actually expand the packs.
17132 Result = std::nullopt;
17133 break;
17134 }
17135
17136 Result = *Result + *NumExpansions;
17137 }
17138 return Result;
17139}
17140
17141template<typename Derived>
17144 // If E is not value-dependent, then nothing will change when we transform it.
17145 // Note: This is an instantiation-centric view.
17146 if (!E->isValueDependent())
17147 return E;
17148
17151
17153 TemplateArgument ArgStorage;
17154
17155 // Find the argument list to transform.
17156 if (E->isPartiallySubstituted()) {
17157 PackArgs = E->getPartialArguments();
17158 } else if (E->isValueDependent()) {
17159 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
17160 bool ShouldExpand = false;
17161 bool RetainExpansion = false;
17162 UnsignedOrNone NumExpansions = std::nullopt;
17163 if (getDerived().TryExpandParameterPacks(
17164 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
17165 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
17166 RetainExpansion, NumExpansions))
17167 return ExprError();
17168
17169 // If we need to expand the pack, build a template argument from it and
17170 // expand that.
17171 if (ShouldExpand) {
17172 auto *Pack = E->getPack();
17173 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
17174 ArgStorage = getSema().Context.getPackExpansionType(
17175 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
17176 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
17177 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
17178 } else {
17179 auto *VD = cast<ValueDecl>(Pack);
17180 ExprResult DRE = getSema().BuildDeclRefExpr(
17181 VD, VD->getType().getNonLValueExprType(getSema().Context),
17182 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
17183 E->getPackLoc());
17184 if (DRE.isInvalid())
17185 return ExprError();
17186 ArgStorage = TemplateArgument(
17187 new (getSema().Context)
17188 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
17189 /*IsCanonical=*/false);
17190 }
17191 PackArgs = ArgStorage;
17192 }
17193 }
17194
17195 // If we're not expanding the pack, just transform the decl.
17196 if (!PackArgs.size()) {
17197 auto *Pack = cast_or_null<NamedDecl>(
17198 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
17199 if (!Pack)
17200 return ExprError();
17201 return getDerived().RebuildSizeOfPackExpr(
17202 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
17203 std::nullopt, {});
17204 }
17205
17206 // Try to compute the result without performing a partial substitution.
17208 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
17209
17210 // Common case: we could determine the number of expansions without
17211 // substituting.
17212 if (Result)
17213 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
17214 E->getPackLoc(),
17215 E->getRParenLoc(), *Result, {});
17216
17217 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
17218 E->getPackLoc());
17219 {
17220 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
17222 Derived, const TemplateArgument*> PackLocIterator;
17223 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
17224 PackLocIterator(*this, PackArgs.end()),
17225 TransformedPackArgs, /*Uneval*/true))
17226 return ExprError();
17227 }
17228
17229 // Check whether we managed to fully-expand the pack.
17230 // FIXME: Is it possible for us to do so and not hit the early exit path?
17232 bool PartialSubstitution = false;
17233 for (auto &Loc : TransformedPackArgs.arguments()) {
17234 Args.push_back(Loc.getArgument());
17235 if (Loc.getArgument().isPackExpansion())
17236 PartialSubstitution = true;
17237 }
17238
17239 if (PartialSubstitution)
17240 return getDerived().RebuildSizeOfPackExpr(
17241 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
17242 std::nullopt, Args);
17243
17244 return getDerived().RebuildSizeOfPackExpr(
17245 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
17246 /*Length=*/static_cast<unsigned>(Args.size()),
17247 /*PartialArgs=*/{});
17248}
17249
17250template <typename Derived>
17253 if (!E->isValueDependent())
17254 return E;
17255
17256 // Transform the index
17257 ExprResult IndexExpr;
17258 {
17259 EnterExpressionEvaluationContext ConstantContext(
17261 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
17262 if (IndexExpr.isInvalid())
17263 return ExprError();
17264 }
17265
17266 SmallVector<Expr *, 5> ExpandedExprs;
17267 bool FullySubstituted = true;
17268 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
17269 Expr *Pattern = E->getPackIdExpression();
17271 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
17272 Unexpanded);
17273 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17274
17275 // Determine whether the set of unexpanded parameter packs can and should
17276 // be expanded.
17277 bool ShouldExpand = true;
17278 bool RetainExpansion = false;
17279 UnsignedOrNone OrigNumExpansions = std::nullopt,
17280 NumExpansions = std::nullopt;
17281 if (getDerived().TryExpandParameterPacks(
17282 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17283 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
17284 RetainExpansion, NumExpansions))
17285 return true;
17286 if (!ShouldExpand) {
17287 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17288 ExprResult Pack = getDerived().TransformExpr(Pattern);
17289 if (Pack.isInvalid())
17290 return ExprError();
17291 return getDerived().RebuildPackIndexingExpr(
17292 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
17293 {}, /*FullySubstituted=*/false);
17294 }
17295 for (unsigned I = 0; I != *NumExpansions; ++I) {
17296 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17297 ExprResult Out = getDerived().TransformExpr(Pattern);
17298 if (Out.isInvalid())
17299 return true;
17300 if (Out.get()->containsUnexpandedParameterPack()) {
17301 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
17302 OrigNumExpansions);
17303 if (Out.isInvalid())
17304 return true;
17305 FullySubstituted = false;
17306 }
17307 ExpandedExprs.push_back(Out.get());
17308 }
17309 // If we're supposed to retain a pack expansion, do so by temporarily
17310 // forgetting the partially-substituted parameter pack.
17311 if (RetainExpansion) {
17312 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17313
17314 ExprResult Out = getDerived().TransformExpr(Pattern);
17315 if (Out.isInvalid())
17316 return true;
17317
17318 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
17319 OrigNumExpansions);
17320 if (Out.isInvalid())
17321 return true;
17322 FullySubstituted = false;
17323 ExpandedExprs.push_back(Out.get());
17324 }
17325 } else if (!E->expandsToEmptyPack()) {
17326 if (getDerived().TransformExprs(E->getExpressions().data(),
17327 E->getExpressions().size(), false,
17328 ExpandedExprs))
17329 return ExprError();
17330 }
17331
17332 return getDerived().RebuildPackIndexingExpr(
17333 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
17334 IndexExpr.get(), ExpandedExprs, FullySubstituted);
17335}
17336
17337template <typename Derived>
17340 if (!getSema().ArgPackSubstIndex)
17341 // We aren't expanding the parameter pack, so just return ourselves.
17342 return E;
17343
17344 TemplateArgument Pack = E->getArgumentPack();
17346 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17347 E->getAssociatedDecl(), E->getParameterPack()->getPosition(),
17348 E->getParameterPack()->getType(), E->getParameterPackLocation(), Arg,
17349 SemaRef.getPackIndex(Pack), E->getFinal());
17350}
17351
17352template <typename Derived>
17355 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
17356
17357 // Insert a constant-evaluated context for the transform.
17358 // Otherwise, when a normalized constraint places the replacement inside
17359 // an unevaluated operand (e.g. decltype), entities it refers to are not
17360 // odr-used, and the constant evaluation performed by CheckTemplateArgument
17361 // below can spuriously fail for otherwise valid replacements,
17362 // e.g. when a call materializes a function parameter of class type whose
17363 // special members were never instantiated.
17364 EnterExpressionEvaluationContext ConstantEvaluated(
17368
17369 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
17370 if (Replacement.isInvalid())
17371 return true;
17372
17373 Decl *AssociatedDecl =
17374 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
17375 if (!AssociatedDecl)
17376 return true;
17377
17378 QualType ParamType = TransformType(E->getParameterType());
17379 if (ParamType.isNull())
17380 return true;
17381
17382 if (Replacement.get() == OrigReplacement &&
17383 AssociatedDecl == E->getAssociatedDecl() &&
17384 ParamType == E->getParameterType())
17385 return E;
17386
17387 if (Replacement.get() != OrigReplacement ||
17388 ParamType != E->getParameterType()) {
17389 auto *Param = cast<NonTypeTemplateParmDecl>(std::get<0>(
17390 getReplacedTemplateParameter(AssociatedDecl, E->getIndex())));
17391 // When transforming the replacement expression previously, all Sema
17392 // specific annotations, such as implicit casts, are discarded. Calling the
17393 // corresponding sema action is necessary to recover those. Otherwise,
17394 // equivalency of the result would be lost.
17395 TemplateArgument SugaredConverted, CanonicalConverted;
17396 Replacement = SemaRef.CheckTemplateArgument(
17397 Param, ParamType, Replacement.get(), SugaredConverted,
17398 CanonicalConverted,
17399 /*StrictCheck=*/false, Sema::CTAK_Specified);
17400 if (Replacement.isInvalid())
17401 return true;
17402 } else {
17403 // Otherwise, the same expression would have been produced.
17404 Replacement = E->getReplacement();
17405 }
17406
17407 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17408 AssociatedDecl, E->getIndex(), ParamType, E->getNameLoc(),
17409 TemplateArgument(Replacement.get(), /*IsCanonical=*/false),
17410 E->getPackIndex(), E->getFinal());
17411}
17412
17413template<typename Derived>
17416 // Default behavior is to do nothing with this transformation.
17417 return E;
17418}
17419
17420template<typename Derived>
17424 return getDerived().TransformExpr(E->getSubExpr());
17425}
17426
17427template<typename Derived>
17430 UnresolvedLookupExpr *Callee = nullptr;
17431 if (Expr *OldCallee = E->getCallee()) {
17432 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
17433 if (CalleeResult.isInvalid())
17434 return ExprError();
17435 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
17436 }
17437
17438 Expr *Pattern = E->getPattern();
17439
17441 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
17442 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17443
17444 // Determine whether the set of unexpanded parameter packs can and should
17445 // be expanded.
17446 bool Expand = true;
17447 bool RetainExpansion = false;
17448 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
17449 NumExpansions = OrigNumExpansions;
17450 if (getDerived().TryExpandParameterPacks(
17451 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17452 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17453 NumExpansions))
17454 return true;
17455
17456 if (!Expand) {
17457 // Do not expand any packs here, just transform and rebuild a fold
17458 // expression.
17459 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17460
17461 ExprResult LHS =
17462 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
17463 if (LHS.isInvalid())
17464 return true;
17465
17466 ExprResult RHS =
17467 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
17468 if (RHS.isInvalid())
17469 return true;
17470
17471 if (!getDerived().AlwaysRebuild() &&
17472 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
17473 return E;
17474
17475 return getDerived().RebuildCXXFoldExpr(
17476 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
17477 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
17478 }
17479
17480 // Formally a fold expression expands to nested parenthesized expressions.
17481 // Enforce this limit to avoid creating trees so deep we can't safely traverse
17482 // them.
17483 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
17484 SemaRef.Diag(E->getEllipsisLoc(),
17485 clang::diag::err_fold_expression_limit_exceeded)
17486 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
17487 << E->getSourceRange();
17488 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
17489 return ExprError();
17490 }
17491
17492 // The transform has determined that we should perform an elementwise
17493 // expansion of the pattern. Do so.
17494 ExprResult Result = getDerived().TransformExpr(E->getInit());
17495 if (Result.isInvalid())
17496 return true;
17497 bool LeftFold = E->isLeftFold();
17498
17499 // If we're retaining an expansion for a right fold, it is the innermost
17500 // component and takes the init (if any).
17501 if (!LeftFold && RetainExpansion) {
17502 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17503
17504 ExprResult Out = getDerived().TransformExpr(Pattern);
17505 if (Out.isInvalid())
17506 return true;
17507
17508 Result = getDerived().RebuildCXXFoldExpr(
17509 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
17510 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
17511 if (Result.isInvalid())
17512 return true;
17513 }
17514
17515 bool WarnedOnComparison = false;
17516 for (unsigned I = 0; I != *NumExpansions; ++I) {
17517 Sema::ArgPackSubstIndexRAII SubstIndex(
17518 getSema(), LeftFold ? I : *NumExpansions - I - 1);
17519 ExprResult Out = getDerived().TransformExpr(Pattern);
17520 if (Out.isInvalid())
17521 return true;
17522
17523 if (Out.get()->containsUnexpandedParameterPack()) {
17524 // We still have a pack; retain a pack expansion for this slice.
17525 Result = getDerived().RebuildCXXFoldExpr(
17526 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
17527 E->getOperator(), E->getEllipsisLoc(),
17528 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
17529 OrigNumExpansions);
17530 } else if (Result.isUsable()) {
17531 // We've got down to a single element; build a binary operator.
17532 Expr *LHS = LeftFold ? Result.get() : Out.get();
17533 Expr *RHS = LeftFold ? Out.get() : Result.get();
17534 if (Callee) {
17535 UnresolvedSet<16> Functions;
17536 Functions.append(Callee->decls_begin(), Callee->decls_end());
17537 Result = getDerived().RebuildCXXOperatorCallExpr(
17538 BinaryOperator::getOverloadedOperator(E->getOperator()),
17539 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
17540 Functions, LHS, RHS);
17541 } else {
17542 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
17543 E->getOperator(), LHS, RHS,
17544 /*ForFoldExpresion=*/true);
17545 if (!WarnedOnComparison && Result.isUsable()) {
17546 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
17547 BO && BO->isComparisonOp()) {
17548 WarnedOnComparison = true;
17549 SemaRef.Diag(BO->getBeginLoc(),
17550 diag::warn_comparison_in_fold_expression)
17551 << BO->getOpcodeStr();
17552 }
17553 }
17554 }
17555 } else
17556 Result = Out;
17557
17558 if (Result.isInvalid())
17559 return true;
17560 }
17561
17562 // If we're retaining an expansion for a left fold, it is the outermost
17563 // component and takes the complete expansion so far as its init (if any).
17564 if (LeftFold && RetainExpansion) {
17565 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17566
17567 ExprResult Out = getDerived().TransformExpr(Pattern);
17568 if (Out.isInvalid())
17569 return true;
17570
17571 Result = getDerived().RebuildCXXFoldExpr(
17572 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
17573 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
17574 if (Result.isInvalid())
17575 return true;
17576 }
17577
17578 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
17579 PE->setIsProducedByFoldExpansion();
17580
17581 // If we had no init and an empty pack, and we're not retaining an expansion,
17582 // then produce a fallback value or error.
17583 if (Result.isUnset())
17584 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
17585 E->getOperator());
17586 return Result;
17587}
17588
17589template <typename Derived>
17592 SmallVector<Expr *, 4> TransformedInits;
17593 ArrayRef<Expr *> InitExprs = E->getInitExprs();
17594
17595 QualType T = getDerived().TransformType(E->getType());
17596
17597 bool ArgChanged = false;
17598
17599 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
17600 TransformedInits, &ArgChanged))
17601 return ExprError();
17602
17603 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
17604 return E;
17605
17606 return getDerived().RebuildCXXParenListInitExpr(
17607 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
17608 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
17609}
17610
17611template<typename Derived>
17615 return getDerived().TransformExpr(E->getSubExpr());
17616}
17617
17618template<typename Derived>
17621 return SemaRef.MaybeBindToTemporary(E);
17622}
17623
17624template<typename Derived>
17627 return E;
17628}
17629
17630template<typename Derived>
17633 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
17634 if (SubExpr.isInvalid())
17635 return ExprError();
17636
17637 if (!getDerived().AlwaysRebuild() &&
17638 SubExpr.get() == E->getSubExpr())
17639 return E;
17640
17641 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
17642}
17643
17644template<typename Derived>
17647 // Transform each of the elements.
17648 SmallVector<Expr *, 8> Elements;
17649 bool ArgChanged = false;
17650 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
17651 /*IsCall=*/false, Elements, &ArgChanged))
17652 return ExprError();
17653
17654 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17655 return SemaRef.MaybeBindToTemporary(E);
17656
17657 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
17658 Elements.data(),
17659 Elements.size());
17660}
17661
17662template<typename Derived>
17666 // Transform each of the elements.
17668 bool ArgChanged = false;
17669 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
17670 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
17671
17672 if (OrigElement.isPackExpansion()) {
17673 // This key/value element is a pack expansion.
17675 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
17676 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
17677 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17678
17679 // Determine whether the set of unexpanded parameter packs can
17680 // and should be expanded.
17681 bool Expand = true;
17682 bool RetainExpansion = false;
17683 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
17684 UnsignedOrNone NumExpansions = OrigNumExpansions;
17685 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
17686 OrigElement.Value->getEndLoc());
17687 if (getDerived().TryExpandParameterPacks(
17688 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
17689 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17690 NumExpansions))
17691 return ExprError();
17692
17693 if (!Expand) {
17694 // The transform has determined that we should perform a simple
17695 // transformation on the pack expansion, producing another pack
17696 // expansion.
17697 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17698 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17699 if (Key.isInvalid())
17700 return ExprError();
17701
17702 if (Key.get() != OrigElement.Key)
17703 ArgChanged = true;
17704
17705 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17706 if (Value.isInvalid())
17707 return ExprError();
17708
17709 if (Value.get() != OrigElement.Value)
17710 ArgChanged = true;
17711
17712 ObjCDictionaryElement Expansion = {
17713 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
17714 };
17715 Elements.push_back(Expansion);
17716 continue;
17717 }
17718
17719 // Record right away that the argument was changed. This needs
17720 // to happen even if the array expands to nothing.
17721 ArgChanged = true;
17722
17723 // The transform has determined that we should perform an elementwise
17724 // expansion of the pattern. Do so.
17725 for (unsigned I = 0; I != *NumExpansions; ++I) {
17726 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17727 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17728 if (Key.isInvalid())
17729 return ExprError();
17730
17731 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17732 if (Value.isInvalid())
17733 return ExprError();
17734
17735 ObjCDictionaryElement Element = {
17736 Key.get(), Value.get(), SourceLocation(), NumExpansions
17737 };
17738
17739 // If any unexpanded parameter packs remain, we still have a
17740 // pack expansion.
17741 // FIXME: Can this really happen?
17742 if (Key.get()->containsUnexpandedParameterPack() ||
17743 Value.get()->containsUnexpandedParameterPack())
17744 Element.EllipsisLoc = OrigElement.EllipsisLoc;
17745
17746 Elements.push_back(Element);
17747 }
17748
17749 // FIXME: Retain a pack expansion if RetainExpansion is true.
17750
17751 // We've finished with this pack expansion.
17752 continue;
17753 }
17754
17755 // Transform and check key.
17756 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17757 if (Key.isInvalid())
17758 return ExprError();
17759
17760 if (Key.get() != OrigElement.Key)
17761 ArgChanged = true;
17762
17763 // Transform and check value.
17765 = getDerived().TransformExpr(OrigElement.Value);
17766 if (Value.isInvalid())
17767 return ExprError();
17768
17769 if (Value.get() != OrigElement.Value)
17770 ArgChanged = true;
17771
17772 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
17773 std::nullopt};
17774 Elements.push_back(Element);
17775 }
17776
17777 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17778 return SemaRef.MaybeBindToTemporary(E);
17779
17780 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
17781 Elements);
17782}
17783
17784template<typename Derived>
17787 TypeSourceInfo *EncodedTypeInfo
17788 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
17789 if (!EncodedTypeInfo)
17790 return ExprError();
17791
17792 if (!getDerived().AlwaysRebuild() &&
17793 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
17794 return E;
17795
17796 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
17797 EncodedTypeInfo,
17798 E->getRParenLoc());
17799}
17800
17801template<typename Derived>
17804 // This is a kind of implicit conversion, and it needs to get dropped
17805 // and recomputed for the same general reasons that ImplicitCastExprs
17806 // do, as well a more specific one: this expression is only valid when
17807 // it appears *immediately* as an argument expression.
17808 return getDerived().TransformExpr(E->getSubExpr());
17809}
17810
17811template<typename Derived>
17814 TypeSourceInfo *TSInfo
17815 = getDerived().TransformType(E->getTypeInfoAsWritten());
17816 if (!TSInfo)
17817 return ExprError();
17818
17819 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
17820 if (Result.isInvalid())
17821 return ExprError();
17822
17823 if (!getDerived().AlwaysRebuild() &&
17824 TSInfo == E->getTypeInfoAsWritten() &&
17825 Result.get() == E->getSubExpr())
17826 return E;
17827
17828 return SemaRef.ObjC().BuildObjCBridgedCast(
17829 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
17830 Result.get());
17831}
17832
17833template <typename Derived>
17836 return E;
17837}
17838
17839template<typename Derived>
17842 // Transform arguments.
17843 bool ArgChanged = false;
17845 Args.reserve(E->getNumArgs());
17846 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
17847 &ArgChanged))
17848 return ExprError();
17849
17850 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
17851 // Class message: transform the receiver type.
17852 TypeSourceInfo *ReceiverTypeInfo
17853 = getDerived().TransformType(E->getClassReceiverTypeInfo());
17854 if (!ReceiverTypeInfo)
17855 return ExprError();
17856
17857 // If nothing changed, just retain the existing message send.
17858 if (!getDerived().AlwaysRebuild() &&
17859 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
17860 return SemaRef.MaybeBindToTemporary(E);
17861
17862 // Build a new class message send.
17864 E->getSelectorLocs(SelLocs);
17865 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
17866 E->getSelector(),
17867 SelLocs,
17868 E->getMethodDecl(),
17869 E->getLeftLoc(),
17870 Args,
17871 E->getRightLoc());
17872 }
17873 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
17874 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
17875 if (!E->getMethodDecl())
17876 return ExprError();
17877
17878 // Build a new class message send to 'super'.
17880 E->getSelectorLocs(SelLocs);
17881 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
17882 E->getSelector(),
17883 SelLocs,
17884 E->getReceiverType(),
17885 E->getMethodDecl(),
17886 E->getLeftLoc(),
17887 Args,
17888 E->getRightLoc());
17889 }
17890
17891 // Instance message: transform the receiver
17892 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
17893 "Only class and instance messages may be instantiated");
17894 ExprResult Receiver
17895 = getDerived().TransformExpr(E->getInstanceReceiver());
17896 if (Receiver.isInvalid())
17897 return ExprError();
17898
17899 // If nothing changed, just retain the existing message send.
17900 if (!getDerived().AlwaysRebuild() &&
17901 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
17902 return SemaRef.MaybeBindToTemporary(E);
17903
17904 // Build a new instance message send.
17906 E->getSelectorLocs(SelLocs);
17907 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
17908 E->getSelector(),
17909 SelLocs,
17910 E->getMethodDecl(),
17911 E->getLeftLoc(),
17912 Args,
17913 E->getRightLoc());
17914}
17915
17916template<typename Derived>
17919 return E;
17920}
17921
17922template<typename Derived>
17925 return E;
17926}
17927
17928template<typename Derived>
17931 // Transform the base expression.
17932 ExprResult Base = getDerived().TransformExpr(E->getBase());
17933 if (Base.isInvalid())
17934 return ExprError();
17935
17936 // We don't need to transform the ivar; it will never change.
17937
17938 // If nothing changed, just retain the existing expression.
17939 if (!getDerived().AlwaysRebuild() &&
17940 Base.get() == E->getBase())
17941 return E;
17942
17943 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17944 E->getLocation(),
17945 E->isArrow(), E->isFreeIvar());
17946}
17947
17948template<typename Derived>
17951 // 'super' and types never change. Property never changes. Just
17952 // retain the existing expression.
17953 if (!E->isObjectReceiver())
17954 return E;
17955
17956 // Transform the base expression.
17957 ExprResult Base = getDerived().TransformExpr(E->getBase());
17958 if (Base.isInvalid())
17959 return ExprError();
17960
17961 // We don't need to transform the property; it will never change.
17962
17963 // If nothing changed, just retain the existing expression.
17964 if (!getDerived().AlwaysRebuild() &&
17965 Base.get() == E->getBase())
17966 return E;
17967
17968 if (E->isExplicitProperty())
17969 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17970 E->getExplicitProperty(),
17971 E->getLocation());
17972
17973 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17974 SemaRef.Context.PseudoObjectTy,
17975 E->getImplicitPropertyGetter(),
17976 E->getImplicitPropertySetter(),
17977 E->getLocation());
17978}
17979
17980template<typename Derived>
17983 // Transform the base expression.
17984 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17985 if (Base.isInvalid())
17986 return ExprError();
17987
17988 // Transform the key expression.
17989 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17990 if (Key.isInvalid())
17991 return ExprError();
17992
17993 // If nothing changed, just retain the existing expression.
17994 if (!getDerived().AlwaysRebuild() &&
17995 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17996 return E;
17997
17998 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17999 Base.get(), Key.get(),
18000 E->getAtIndexMethodDecl(),
18001 E->setAtIndexMethodDecl());
18002}
18003
18004template<typename Derived>
18007 // Transform the base expression.
18008 ExprResult Base = getDerived().TransformExpr(E->getBase());
18009 if (Base.isInvalid())
18010 return ExprError();
18011
18012 // If nothing changed, just retain the existing expression.
18013 if (!getDerived().AlwaysRebuild() &&
18014 Base.get() == E->getBase())
18015 return E;
18016
18017 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
18018 E->getOpLoc(),
18019 E->isArrow());
18020}
18021
18022template<typename Derived>
18025 bool ArgumentChanged = false;
18026 SmallVector<Expr*, 8> SubExprs;
18027 SubExprs.reserve(E->getNumSubExprs());
18028 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
18029 SubExprs, &ArgumentChanged))
18030 return ExprError();
18031
18032 if (!getDerived().AlwaysRebuild() &&
18033 !ArgumentChanged)
18034 return E;
18035
18036 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
18037 SubExprs,
18038 E->getRParenLoc());
18039}
18040
18041template<typename Derived>
18044 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
18045 if (SrcExpr.isInvalid())
18046 return ExprError();
18047
18048 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
18049 if (!Type)
18050 return ExprError();
18051
18052 if (!getDerived().AlwaysRebuild() &&
18053 Type == E->getTypeSourceInfo() &&
18054 SrcExpr.get() == E->getSrcExpr())
18055 return E;
18056
18057 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
18058 SrcExpr.get(), Type,
18059 E->getRParenLoc());
18060}
18061
18062template<typename Derived>
18065 BlockDecl *oldBlock = E->getBlockDecl();
18066
18067 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
18068 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
18069
18070 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
18071 blockScope->TheDecl->setBlockMissingReturnType(
18072 oldBlock->blockMissingReturnType());
18073
18075 SmallVector<QualType, 4> paramTypes;
18076
18077 const FunctionProtoType *exprFunctionType = E->getFunctionType();
18078
18079 // Parameter substitution.
18080 Sema::ExtParameterInfoBuilder extParamInfos;
18081 if (getDerived().TransformFunctionTypeParams(
18082 E->getCaretLocation(), oldBlock->parameters(), nullptr,
18083 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
18084 extParamInfos)) {
18085 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
18086 return ExprError();
18087 }
18088
18089 QualType exprResultType =
18090 getDerived().TransformType(exprFunctionType->getReturnType());
18091
18092 auto epi = exprFunctionType->getExtProtoInfo();
18093 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
18094
18096 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
18097 blockScope->FunctionType = functionType;
18098
18099 // Set the parameters on the block decl.
18100 if (!params.empty())
18101 blockScope->TheDecl->setParams(params);
18102
18103 if (!oldBlock->blockMissingReturnType()) {
18104 blockScope->HasImplicitReturnType = false;
18105 blockScope->ReturnType = exprResultType;
18106 }
18107
18108 // Transform the body
18109 StmtResult body = getDerived().TransformStmt(E->getBody());
18110 if (body.isInvalid()) {
18111 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
18112 return ExprError();
18113 }
18114
18115#ifndef NDEBUG
18116 // In builds with assertions, make sure that we captured everything we
18117 // captured before.
18118 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
18119 for (const auto &I : oldBlock->captures()) {
18120 VarDecl *oldCapture = I.getVariable();
18121
18122 // Ignore parameter packs.
18123 if (oldCapture->isParameterPack())
18124 continue;
18125
18126 VarDecl *newCapture =
18127 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
18128 oldCapture));
18129 assert(blockScope->CaptureMap.count(newCapture));
18130 }
18131 }
18132#endif
18133
18134 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
18135 /*Scope=*/nullptr);
18136}
18137
18138template<typename Derived>
18141 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
18142 if (SrcExpr.isInvalid())
18143 return ExprError();
18144
18145 QualType Type = getDerived().TransformType(E->getType());
18146
18147 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
18148 E->getRParenLoc());
18149}
18150
18151template<typename Derived>
18154 bool ArgumentChanged = false;
18155 SmallVector<Expr*, 8> SubExprs;
18156 SubExprs.reserve(E->getNumSubExprs());
18157 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
18158 SubExprs, &ArgumentChanged))
18159 return ExprError();
18160
18161 if (!getDerived().AlwaysRebuild() &&
18162 !ArgumentChanged)
18163 return E;
18164
18165 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
18166 E->getOp(), E->getRParenLoc());
18167}
18168
18169//===----------------------------------------------------------------------===//
18170// Type reconstruction
18171//===----------------------------------------------------------------------===//
18172
18173template<typename Derived>
18176 return SemaRef.BuildPointerType(PointeeType, Star,
18178}
18179
18180template<typename Derived>
18183 return SemaRef.BuildBlockPointerType(PointeeType, Star,
18185}
18186
18187template<typename Derived>
18190 bool WrittenAsLValue,
18191 SourceLocation Sigil) {
18192 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
18193 Sigil, getDerived().getBaseEntity());
18194}
18195
18196template <typename Derived>
18198 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
18199 SourceLocation Sigil) {
18200 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
18202}
18203
18204template<typename Derived>
18206 const ObjCTypeParamDecl *Decl,
18207 SourceLocation ProtocolLAngleLoc,
18209 ArrayRef<SourceLocation> ProtocolLocs,
18210 SourceLocation ProtocolRAngleLoc) {
18211 return SemaRef.ObjC().BuildObjCTypeParamType(
18212 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
18213 /*FailOnError=*/true);
18214}
18215
18216template<typename Derived>
18218 QualType BaseType,
18219 SourceLocation Loc,
18220 SourceLocation TypeArgsLAngleLoc,
18222 SourceLocation TypeArgsRAngleLoc,
18223 SourceLocation ProtocolLAngleLoc,
18225 ArrayRef<SourceLocation> ProtocolLocs,
18226 SourceLocation ProtocolRAngleLoc) {
18227 return SemaRef.ObjC().BuildObjCObjectType(
18228 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
18229 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
18230 /*FailOnError=*/true,
18231 /*Rebuilding=*/true);
18232}
18233
18234template<typename Derived>
18236 QualType PointeeType,
18238 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
18239}
18240
18241template <typename Derived>
18243 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
18244 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
18245 if (SizeExpr || !Size)
18246 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
18247 IndexTypeQuals, BracketsRange,
18249
18250 QualType Types[] = {
18251 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
18252 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
18253 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
18254 };
18255 QualType SizeType;
18256 for (const auto &T : Types)
18257 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
18258 SizeType = T;
18259 break;
18260 }
18261
18262 // Note that we can return a VariableArrayType here in the case where
18263 // the element type was a dependent VariableArrayType.
18264 IntegerLiteral *ArraySize
18265 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
18266 /*FIXME*/BracketsRange.getBegin());
18267 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
18268 IndexTypeQuals, BracketsRange,
18270}
18271
18272template <typename Derived>
18274 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
18275 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
18276 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
18277 IndexTypeQuals, BracketsRange);
18278}
18279
18280template <typename Derived>
18282 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
18283 SourceRange BracketsRange) {
18284 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
18285 IndexTypeQuals, BracketsRange);
18286}
18287
18288template <typename Derived>
18290 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
18291 unsigned IndexTypeQuals, SourceRange BracketsRange) {
18292 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
18293 SizeExpr,
18294 IndexTypeQuals, BracketsRange);
18295}
18296
18297template <typename Derived>
18299 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
18300 unsigned IndexTypeQuals, SourceRange BracketsRange) {
18301 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
18302 SizeExpr,
18303 IndexTypeQuals, BracketsRange);
18304}
18305
18306template <typename Derived>
18308 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
18309 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
18310 AttributeLoc);
18311}
18312
18313template <typename Derived>
18315 unsigned NumElements,
18316 VectorKind VecKind) {
18317 // FIXME: semantic checking!
18318 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
18319}
18320
18321template <typename Derived>
18323 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
18324 VectorKind VecKind) {
18325 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
18326}
18327
18328template<typename Derived>
18330 unsigned NumElements,
18331 SourceLocation AttributeLoc) {
18332 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18333 NumElements, true);
18334 IntegerLiteral *VectorSize
18335 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
18336 AttributeLoc);
18337 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
18338}
18339
18340template<typename Derived>
18343 Expr *SizeExpr,
18344 SourceLocation AttributeLoc) {
18345 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
18346}
18347
18348template <typename Derived>
18350 QualType ElementType, unsigned NumRows, unsigned NumColumns,
18351 SourceLocation AttributeLoc) {
18352 ASTContext &Ctx = SemaRef.Context;
18353 QualType SizeTy = Ctx.getSizeType();
18354 unsigned SizeWidth = Ctx.getIntWidth(SizeTy);
18356 Ctx, llvm::APInt(SizeWidth, NumRows), SizeTy, AttributeLoc);
18358 Ctx, llvm::APInt(SizeWidth, NumColumns), SizeTy, AttributeLoc);
18359 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
18360 AttributeLoc);
18361}
18362
18363template <typename Derived>
18365 QualType ElementType, unsigned Scope, unsigned NumRows, unsigned NumColumns,
18366 unsigned Use) {
18367 return SemaRef.Context.getCooperativeMatrixType(ElementType, Scope, NumRows,
18368 NumColumns, Use);
18369}
18370
18371template <typename Derived>
18373 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
18374 SourceLocation AttributeLoc) {
18375 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
18376 AttributeLoc);
18377}
18378
18379template <typename Derived>
18381 QualType T, MutableArrayRef<QualType> ParamTypes,
18383 return SemaRef.BuildFunctionType(T, ParamTypes,
18386 EPI);
18387}
18388
18389template<typename Derived>
18391 return SemaRef.Context.getFunctionNoProtoType(T);
18392}
18393
18394template <typename Derived>
18397 SourceLocation NameLoc, Decl *D) {
18398 assert(D && "no decl found");
18399 if (D->isInvalidDecl()) return QualType();
18400
18401 // FIXME: Doesn't account for ObjCInterfaceDecl!
18402 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
18403 // A valid resolved using typename pack expansion decl can have multiple
18404 // UsingDecls, but they must each have exactly one type, and it must be
18405 // the same type in every case. But we must have at least one expansion!
18406 if (UPD->expansions().empty()) {
18407 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
18408 << UPD->isCXXClassMember() << UPD;
18409 return QualType();
18410 }
18411
18412 // We might still have some unresolved types. Try to pick a resolved type
18413 // if we can. The final instantiation will check that the remaining
18414 // unresolved types instantiate to the type we pick.
18415 QualType FallbackT;
18416 QualType T;
18417 for (auto *E : UPD->expansions()) {
18418 QualType ThisT =
18419 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
18420 if (ThisT.isNull())
18421 continue;
18422 if (ThisT->getAs<UnresolvedUsingType>())
18423 FallbackT = ThisT;
18424 else if (T.isNull())
18425 T = ThisT;
18426 else
18427 assert(getSema().Context.hasSameType(ThisT, T) &&
18428 "mismatched resolved types in using pack expansion");
18429 }
18430 return T.isNull() ? FallbackT : T;
18431 }
18432 if (auto *Using = dyn_cast<UsingDecl>(D)) {
18433 assert(Using->hasTypename() &&
18434 "UnresolvedUsingTypenameDecl transformed to non-typename using");
18435
18436 // A valid resolved using typename decl points to exactly one type decl.
18437 assert(++Using->shadow_begin() == Using->shadow_end());
18438
18439 UsingShadowDecl *Shadow = *Using->shadow_begin();
18440 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
18441 return QualType();
18442 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
18443 }
18445 "UnresolvedUsingTypenameDecl transformed to non-using decl");
18446 return SemaRef.Context.getUnresolvedUsingType(
18448}
18449
18450template <typename Derived>
18452 TypeOfKind Kind) {
18453 return SemaRef.BuildTypeofExprType(E, Kind);
18454}
18455
18456template<typename Derived>
18458 TypeOfKind Kind) {
18459 return SemaRef.Context.getTypeOfType(Underlying, Kind);
18460}
18461
18462template <typename Derived>
18464 return SemaRef.BuildDecltypeType(E);
18465}
18466
18467template <typename Derived>
18469 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
18470 bool FullySubstituted, ArrayRef<QualType> Expansions) {
18471 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc,
18472 FullySubstituted, Expansions);
18473}
18474
18475template<typename Derived>
18477 UnaryTransformType::UTTKind UKind,
18478 SourceLocation Loc) {
18479 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
18480}
18481
18482template <typename Derived>
18485 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
18486 return SemaRef.CheckTemplateIdType(
18487 Keyword, Template, TemplateNameLoc, TemplateArgs,
18488 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
18489}
18490
18491template<typename Derived>
18493 SourceLocation KWLoc) {
18494 return SemaRef.BuildAtomicType(ValueType, KWLoc);
18495}
18496
18497template<typename Derived>
18499 SourceLocation KWLoc,
18500 bool isReadPipe) {
18501 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
18502 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
18503}
18504
18505template <typename Derived>
18507 unsigned NumBits,
18508 SourceLocation Loc) {
18509 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18510 NumBits, true);
18511 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
18512 SemaRef.Context.IntTy, Loc);
18513 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
18514}
18515
18516template <typename Derived>
18518 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
18519 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
18520}
18521
18522template <typename Derived>
18524 bool TemplateKW,
18525 TemplateName Name) {
18526 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
18527 Name);
18528}
18529
18530template <typename Derived>
18532 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
18533 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
18535 TemplateName.setIdentifier(&Name, NameLoc);
18537 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
18538 TemplateName, ParsedType::make(ObjectType),
18539 /*EnteringContext=*/false, Template,
18540 AllowInjectedClassName);
18541 return Template.get();
18542}
18543
18544template<typename Derived>
18547 SourceLocation TemplateKWLoc,
18548 OverloadedOperatorKind Operator,
18549 SourceLocation NameLoc,
18550 QualType ObjectType,
18551 bool AllowInjectedClassName) {
18552 UnqualifiedId Name;
18553 // FIXME: Bogus location information.
18554 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
18555 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
18557 getSema().ActOnTemplateName(
18558 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
18559 /*EnteringContext=*/false, Template, AllowInjectedClassName);
18560 return Template.get();
18561}
18562
18563template <typename Derived>
18566 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
18567 Expr *Second) {
18568 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
18569
18570 if (First->getObjectKind() == OK_ObjCProperty) {
18573 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
18574 Opc, First, Second);
18575 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
18576 if (Result.isInvalid())
18577 return ExprError();
18578 First = Result.get();
18579 }
18580
18581 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
18582 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
18583 if (Result.isInvalid())
18584 return ExprError();
18585 Second = Result.get();
18586 }
18587
18588 // Determine whether this should be a builtin operation.
18589 if (Op == OO_Subscript) {
18590 if (!First->getType()->isOverloadableType() &&
18591 !Second->getType()->isOverloadableType())
18592 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
18593 OpLoc);
18594 } else if (Op == OO_Arrow) {
18595 // It is possible that the type refers to a RecoveryExpr created earlier
18596 // in the tree transformation.
18597 if (First->getType()->isDependentType())
18598 return ExprError();
18599 // -> is never a builtin operation.
18600 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
18601 } else if (Second == nullptr || isPostIncDec) {
18602 if (!First->getType()->isOverloadableType() ||
18603 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
18604 // The argument is not of overloadable type, or this is an expression
18605 // of the form &Class::member, so try to create a built-in unary
18606 // operation.
18608 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18609
18610 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
18611 }
18612 } else {
18613 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
18614 !First->getType()->isOverloadableType() &&
18615 !Second->getType()->isOverloadableType()) {
18616 // Neither of the arguments is type-dependent or has an overloadable
18617 // type, so try to create a built-in binary operation.
18620 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
18621 if (Result.isInvalid())
18622 return ExprError();
18623
18624 return Result;
18625 }
18626 }
18627
18628 // Create the overloaded operator invocation for unary operators.
18629 if (!Second || isPostIncDec) {
18631 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18632 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
18633 RequiresADL);
18634 }
18635
18636 // Create the overloaded operator invocation for binary operators.
18638 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
18639 First, Second, RequiresADL);
18640 if (Result.isInvalid())
18641 return ExprError();
18642
18643 return Result;
18644}
18645
18646template<typename Derived>
18649 SourceLocation OperatorLoc,
18650 bool isArrow,
18651 CXXScopeSpec &SS,
18652 TypeSourceInfo *ScopeType,
18653 SourceLocation CCLoc,
18654 SourceLocation TildeLoc,
18655 PseudoDestructorTypeStorage Destroyed) {
18656 QualType CanonicalBaseType = Base->getType().getCanonicalType();
18657 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
18658 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
18659 (isArrow && isa<PointerType>(CanonicalBaseType) &&
18660 !cast<PointerType>(CanonicalBaseType)
18661 ->getPointeeType()
18662 ->getAsCanonical<RecordType>())) {
18663 // This pseudo-destructor expression is still a pseudo-destructor.
18664 return SemaRef.BuildPseudoDestructorExpr(
18665 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
18666 CCLoc, TildeLoc, Destroyed);
18667 }
18668
18669 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
18670 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
18671 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
18672 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
18673 NameInfo.setNamedTypeInfo(DestroyedType);
18674
18675 // The scope type is now known to be a valid nested name specifier
18676 // component. Tack it on to the nested name specifier.
18677 if (ScopeType) {
18678 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
18679 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
18680 diag::err_expected_class_or_namespace)
18681 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
18682 return ExprError();
18683 }
18684 SS.clear();
18685 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
18686 }
18687
18688 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
18689 return getSema().BuildMemberReferenceExpr(
18690 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
18691 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
18692 /*TemplateArgs*/ nullptr,
18693 /*S*/ nullptr);
18694}
18695
18696template<typename Derived>
18699 SourceLocation Loc = S->getBeginLoc();
18700 CapturedDecl *CD = S->getCapturedDecl();
18701 unsigned NumParams = CD->getNumParams();
18702 unsigned ContextParamPos = CD->getContextParamPosition();
18704 for (unsigned I = 0; I < NumParams; ++I) {
18705 if (I != ContextParamPos) {
18706 Params.push_back(
18707 std::make_pair(
18708 CD->getParam(I)->getName(),
18709 getDerived().TransformType(CD->getParam(I)->getType())));
18710 } else {
18711 Params.push_back(std::make_pair(StringRef(), QualType()));
18712 }
18713 }
18714 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
18715 S->getCapturedRegionKind(), Params);
18716 StmtResult Body;
18717 {
18718 Sema::CompoundScopeRAII CompoundScope(getSema());
18719 Body = getDerived().TransformStmt(S->getCapturedStmt());
18720 }
18721
18722 if (Body.isInvalid()) {
18723 getSema().ActOnCapturedRegionError();
18724 return StmtError();
18725 }
18726
18727 return getSema().ActOnCapturedRegionEnd(Body.get());
18728}
18729
18730template <typename Derived>
18733 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
18734 // function definition or instantiation of a function template specialization
18735 // and will therefore never appear in a dependent context.
18736 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
18737 "context");
18738}
18739
18740template <typename Derived>
18742 // We can transform the base expression and allow argument resolution to fill
18743 // in the rest.
18744 return getDerived().TransformExpr(E->getArgLValue());
18745}
18746
18747} // end namespace clang
18748
18749#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:246
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:3821
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:2796
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:2218
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:2180
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8538
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4862
void setIsVariadic(bool value)
Definition Decl.h:4941
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:5137
unsigned getNumParams() const
Definition Decl.h:5175
unsigned getContextParamPosition() const
Definition Decl.h:5204
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5177
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:2017
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:3859
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:4623
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
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2243
Represents an opaque OpenCL cooperative matrix type.
Definition TypeBase.h:4718
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:3510
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:1468
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2113
DeclContextLookupResult lookup_result
Definition DeclBase.h:2614
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:2222
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:598
SourceLocation getLocation() const
Definition DeclBase.h:449
DeclContext * getDeclContext()
Definition DeclBase.h:458
AccessSpecifier getAccess() const
Definition DeclBase.h:517
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:2000
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2411
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2636
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:4160
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5455
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2704
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:4110
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2140
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4200
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4816
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:2106
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4458
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:923
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:5370
Expr * getCondition() const
Definition TypeBase.h:5377
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:3122
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3254
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:3346
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:2952
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5618
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:5263
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5972
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5958
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5484
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:5228
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:5650
param_type_iterator param_type_begin() const
Definition TypeBase.h:6094
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:4872
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:4008
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:3578
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:2177
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:3752
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:162
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:2756
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2752
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2768
A structure for storing a pack-index-template-name ([temp.names]).
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2439
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:2965
unsigned getFunctionScopeDepth() const
Definition Decl.h:1882
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2848
PipeType - OpenCL20.
Definition TypeBase.h:8509
bool isReadOnly() const
Definition TypeBase.h:8534
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:3404
[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
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8680
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8712
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:3679
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3695
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
Scope - A scope is a transient data structure that is used while parsing the program.
Definition Scope.h:42
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)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition SemaSYCL.cpp:153
QualType GetSYCLKernelInfoClassSpecializationType(QualType KNT)
GetSYCLKernelInfoClassSpecializationType returns a type for the class template returned by GetSYCLKer...
Definition SemaSYCL.cpp:481
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body, const SYCLKernelCallStmtASTFragments &ASTFragments)
BuildSYCLKernelCallStmt constructs a SYCLKernelCallStmt or an UnresolvedSYCLKernelCallStmt depending ...
RAII object used to change the argument pack substitution index within a Sema object.
Definition Sema.h:14011
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8718
A RAII object to enter scope of a compound statement.
Definition Sema.h:1348
std::optional< bool > getKnownValue() const
Definition Sema.h:8069
A RAII object to temporarily push a declaration context.
Definition Sema.h:3683
A helper class for building up ExtParameterInfos.
Definition Sema.h:13380
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:13399
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:13387
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:14439
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
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:9615
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9623
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9618
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:1578
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:8085
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:8087
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:8086
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:7156
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:445
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:527
StmtResult BuildNonEnumeratingCXXExpansionStmtPattern(CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVarStmt, Expr *ExpansionInitializer, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
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:1603
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:12309
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:1339
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:932
SemaObjC & ObjC()
Definition Sema.h:1563
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:935
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:83
const LangOptions & getLangOpts() const
Definition Sema.h:928
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1568
@ ReuseLambdaContextDecl
Definition Sema.h:7247
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:1528
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:12111
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:1374
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:12106
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2700
void ApplyForRangeOrExpansionStatementLifetimeExtension(VarDecl *RangeVar, ArrayRef< MaterializeTemporaryExpr * > Temporaries)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1491
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,...
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth, bool HasResult=true)
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:6957
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6967
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6936
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6962
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel, bool IsConstexpr=false)
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:77
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:8583
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:11359
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:629
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:340
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.
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:1331
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:8071
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:458
SemaPseudoObject & PseudoObject()
Definition Sema.h:1588
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:1330
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:634
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:595
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:8931
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:3904
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.
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.
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.
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 RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth, bool HasResult)
Build a new GNU statement expression.
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.
QualType RebuildCooperativeMatrixType(QualType ElementType, unsigned Scope, unsigned NumRows, unsigned NumColumns, unsigned Use)
Build a new cooperative matrix type given the element type and scope and use and dimensions.
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:2858
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:6560
A container of type source information.
Definition TypeBase.h:8651
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:8662
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:9460
bool isObjCObjectPointerType() const
Definition TypeBase.h:9100
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9537
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3749
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2323
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:2467
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1114
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:6365
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:5714
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:4065
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2078
Represents a GCC generic vector type.
Definition TypeBase.h:4399
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:798
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition ScopeInfo.h:736
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition ScopeInfo.h:879
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition ScopeInfo.h:882
@ 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:647
@ 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:62
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:598
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:243
@ 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:143
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:3818
OptionalUnsigned< unsigned > UnsignedOrNone
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
@ Template
We are parsing a template declaration.
Definition Parser.h:82
ActionResult< CXXBaseSpecifier * > BaseResult
Definition Ownership.h:252
OpenMPGrainsizeClauseModifier
OpenMPNumTasksClauseModifier
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6273
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:556
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:806
@ Exists
The symbol exists.
Definition Sema.h:799
@ Error
An error occurred.
Definition Sema.h:809
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:802
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:845
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:6248
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6269
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6259
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6266
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:5387
Holds information about the various types of exception specification.
Definition TypeBase.h:5707
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5723
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5709
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5712
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5715
Extra information about a function prototype.
Definition TypeBase.h:5735
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5740
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3558
const NamespaceBaseDecl * Namespace
Iterator range representation begin:end[:step].
Definition ExprOpenMP.h:165
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.
SYCLKernelCallStmtASTFragments holds portions of the AST used to resolve SYCL runtime library functio...
Definition SemaSYCL.h:114
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition Sema.h:13460
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13491
bool InLifetimeExtendingContext
Whether we are currently in a context in which all temporaries must be lifetime-extended,...
Definition Sema.h:7078
SmallVector< MaterializeTemporaryExpr *, 8 > ForRangeLifetimeExtendTemps
P2718R0 - Lifetime extension in range-based for loops.
Definition Sema.h:7046
bool RebuildDefaultArgOrDefaultInit
Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
Definition Sema.h:7084
ExpressionEvaluationContext Context
The expression evaluation context.
Definition Sema.h:6994
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1363
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3484
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions