clang 24.0.0git
TreeTransform.h
Go to the documentation of this file.
1//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
32#include "clang/AST/StmtSYCL.h"
37#include "clang/Sema/Lookup.h"
42#include "clang/Sema/SemaHLSL.h"
44#include "clang/Sema/SemaObjC.h"
48#include "clang/Sema/SemaSYCL.h"
49#include "clang/Sema/Template.h"
50#include "llvm/ADT/ArrayRef.h"
51#include "llvm/Support/ErrorHandling.h"
52#include <algorithm>
53#include <optional>
54
55using namespace llvm::omp;
56
57namespace clang {
58using namespace sema;
59
60// This helper class is used to facilitate pack expansion during tree transform.
70
71/// A semantic tree transformation that allows one to transform one
72/// abstract syntax tree into another.
73///
74/// A new tree transformation is defined by creating a new subclass \c X of
75/// \c TreeTransform<X> and then overriding certain operations to provide
76/// behavior specific to that transformation. For example, template
77/// instantiation is implemented as a tree transformation where the
78/// transformation of TemplateTypeParmType nodes involves substituting the
79/// template arguments for their corresponding template parameters; a similar
80/// transformation is performed for non-type template parameters and
81/// template template parameters.
82///
83/// This tree-transformation template uses static polymorphism to allow
84/// subclasses to customize any of its operations. Thus, a subclass can
85/// override any of the transformation or rebuild operators by providing an
86/// operation with the same signature as the default implementation. The
87/// overriding function should not be virtual.
88///
89/// Semantic tree transformations are split into two stages, either of which
90/// can be replaced by a subclass. The "transform" step transforms an AST node
91/// or the parts of an AST node using the various transformation functions,
92/// then passes the pieces on to the "rebuild" step, which constructs a new AST
93/// node of the appropriate kind from the pieces. The default transformation
94/// routines recursively transform the operands to composite AST nodes (e.g.,
95/// the pointee type of a PointerType node) and, if any of those operand nodes
96/// were changed by the transformation, invokes the rebuild operation to create
97/// a new AST node.
98///
99/// Subclasses can customize the transformation at various levels. The
100/// most coarse-grained transformations involve replacing TransformType(),
101/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
102/// TransformTemplateName(), or TransformTemplateArgument() with entirely
103/// new implementations.
104///
105/// For more fine-grained transformations, subclasses can replace any of the
106/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
107/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
108/// replacing TransformTemplateTypeParmType() allows template instantiation
109/// to substitute template arguments for their corresponding template
110/// parameters. Additionally, subclasses can override the \c RebuildXXX
111/// functions to control how AST nodes are rebuilt when their operands change.
112/// By default, \c TreeTransform will invoke semantic analysis to rebuild
113/// AST nodes. However, certain other tree transformations (e.g, cloning) may
114/// be able to use more efficient rebuild steps.
115///
116/// There are a handful of other functions that can be overridden, allowing one
117/// to avoid traversing nodes that don't need any transformation
118/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
119/// operands have not changed (\c AlwaysRebuild()), and customize the
120/// default locations and entity names used for type-checking
121/// (\c getBaseLocation(), \c getBaseEntity()).
122template<typename Derived>
124 /// Private RAII object that helps us forget and then re-remember
125 /// the template argument corresponding to a partially-substituted parameter
126 /// pack.
127 class ForgetPartiallySubstitutedPackRAII {
128 Derived &Self;
130 // Set the pack expansion index to -1 to avoid pack substitution and
131 // indicate that parameter packs should be instantiated as themselves.
132 Sema::ArgPackSubstIndexRAII ResetPackSubstIndex;
133
134 public:
135 ForgetPartiallySubstitutedPackRAII(Derived &Self)
136 : Self(Self), ResetPackSubstIndex(Self.getSema(), std::nullopt) {
137 Old = Self.ForgetPartiallySubstitutedPack();
138 }
139
140 ~ForgetPartiallySubstitutedPackRAII() {
141 Self.RememberPartiallySubstitutedPack(Old);
142 }
143 ForgetPartiallySubstitutedPackRAII(
144 const ForgetPartiallySubstitutedPackRAII &) = delete;
145 ForgetPartiallySubstitutedPackRAII &
146 operator=(const ForgetPartiallySubstitutedPackRAII &) = delete;
147 };
148
149protected:
151
152 /// The set of local declarations that have been transformed, for
153 /// cases where we are forced to build new declarations within the transformer
154 /// rather than in the subclass (e.g., lambda closure types).
155 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
156
157public:
158 /// Initializes a new tree transformer.
160
161 /// Retrieves a reference to the derived class.
162 Derived &getDerived() { return static_cast<Derived&>(*this); }
163
164 /// Retrieves a reference to the derived class.
165 const Derived &getDerived() const {
166 return static_cast<const Derived&>(*this);
167 }
168
169 static inline ExprResult Owned(Expr *E) { return E; }
170 static inline StmtResult Owned(Stmt *S) { return S; }
171
172 /// Retrieves a reference to the semantic analysis object used for
173 /// this tree transform.
174 Sema &getSema() const { return SemaRef; }
175
176 /// Whether the transformation should always rebuild AST nodes, even
177 /// if none of the children have changed.
178 ///
179 /// Subclasses may override this function to specify when the transformation
180 /// should rebuild all AST nodes.
181 ///
182 /// We must always rebuild all AST nodes when performing variadic template
183 /// pack expansion, in order to avoid violating the AST invariant that each
184 /// statement node appears at most once in its containing declaration.
185 bool AlwaysRebuild() { return static_cast<bool>(SemaRef.ArgPackSubstIndex); }
186
187 /// Whether the transformation is forming an expression or statement that
188 /// replaces the original. In this case, we'll reuse mangling numbers from
189 /// existing lambdas.
190 bool ReplacingOriginal() { return false; }
191
192 /// Wether CXXConstructExpr can be skipped when they are implicit.
193 /// They will be reconstructed when used if needed.
194 /// This is useful when the user that cause rebuilding of the
195 /// CXXConstructExpr is outside of the expression at which the TreeTransform
196 /// started.
197 bool AllowSkippingCXXConstructExpr() { return true; }
198
199 /// Returns the location of the entity being transformed, if that
200 /// information was not available elsewhere in the AST.
201 ///
202 /// By default, returns no source-location information. Subclasses can
203 /// provide an alternative implementation that provides better location
204 /// information.
206
207 /// Returns the name of the entity being transformed, if that
208 /// information was not available elsewhere in the AST.
209 ///
210 /// By default, returns an empty name. Subclasses can provide an alternative
211 /// implementation with a more precise name.
213
214 /// Sets the "base" location and entity when that
215 /// information is known based on another transformation.
216 ///
217 /// By default, the source location and entity are ignored. Subclasses can
218 /// override this function to provide a customized implementation.
220
221 /// RAII object that temporarily sets the base location and entity
222 /// used for reporting diagnostics in types.
224 TreeTransform &Self;
225 SourceLocation OldLocation;
226 DeclarationName OldEntity;
227
228 public:
230 DeclarationName Entity) : Self(Self) {
231 OldLocation = Self.getDerived().getBaseLocation();
232 OldEntity = Self.getDerived().getBaseEntity();
233
234 if (Location.isValid())
235 Self.getDerived().setBase(Location, Entity);
236 }
237
239 Self.getDerived().setBase(OldLocation, OldEntity);
240 }
241 TemporaryBase(const TemporaryBase &) = delete;
243 };
244
245 /// Determine whether the given type \p T has already been
246 /// transformed.
247 ///
248 /// Subclasses can provide an alternative implementation of this routine
249 /// to short-circuit evaluation when it is known that a given type will
250 /// not change. For example, template instantiation need not traverse
251 /// non-dependent types.
253 return T.isNull();
254 }
255
256 /// Transform a template parameter depth level.
257 ///
258 /// During a transformation that transforms template parameters, this maps
259 /// an old template parameter depth to a new depth.
260 unsigned TransformTemplateDepth(unsigned Depth) {
261 return Depth;
262 }
263
264 /// Determine whether the given call argument should be dropped, e.g.,
265 /// because it is a default argument.
266 ///
267 /// Subclasses can provide an alternative implementation of this routine to
268 /// determine which kinds of call arguments get dropped. By default,
269 /// CXXDefaultArgument nodes are dropped (prior to transformation).
271 return E->isDefaultArgument();
272 }
273
274 /// Determine whether we should expand a pack expansion with the
275 /// given set of parameter packs into separate arguments by repeatedly
276 /// transforming the pattern.
277 ///
278 /// By default, the transformer never tries to expand pack expansions.
279 /// Subclasses can override this routine to provide different behavior.
280 ///
281 /// \param EllipsisLoc The location of the ellipsis that identifies the
282 /// pack expansion.
283 ///
284 /// \param PatternRange The source range that covers the entire pattern of
285 /// the pack expansion.
286 ///
287 /// \param Unexpanded The set of unexpanded parameter packs within the
288 /// pattern.
289 ///
290 /// \param ShouldExpand Will be set to \c true if the transformer should
291 /// expand the corresponding pack expansions into separate arguments. When
292 /// set, \c NumExpansions must also be set.
293 ///
294 /// \param RetainExpansion Whether the caller should add an unexpanded
295 /// pack expansion after all of the expanded arguments. This is used
296 /// when extending explicitly-specified template argument packs per
297 /// C++0x [temp.arg.explicit]p9.
298 ///
299 /// \param NumExpansions The number of separate arguments that will be in
300 /// the expanded form of the corresponding pack expansion. This is both an
301 /// input and an output parameter, which can be set by the caller if the
302 /// number of expansions is known a priori (e.g., due to a prior substitution)
303 /// and will be set by the callee when the number of expansions is known.
304 /// The callee must set this value when \c ShouldExpand is \c true; it may
305 /// set this value in other cases.
306 ///
307 /// \returns true if an error occurred (e.g., because the parameter packs
308 /// are to be instantiated with arguments of different lengths), false
309 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
310 /// must be set.
312 SourceRange PatternRange,
314 bool FailOnPackProducingTemplates,
315 bool &ShouldExpand, bool &RetainExpansion,
316 UnsignedOrNone &NumExpansions) {
317 ShouldExpand = false;
318 return false;
319 }
320
321 /// "Forget" about the partially-substituted pack template argument,
322 /// when performing an instantiation that must preserve the parameter pack
323 /// use.
324 ///
325 /// This routine is meant to be overridden by the template instantiator.
329
330 /// "Remember" the partially-substituted pack template argument
331 /// after performing an instantiation that must preserve the parameter pack
332 /// use.
333 ///
334 /// This routine is meant to be overridden by the template instantiator.
336
337 /// "Forget" the template substitution to allow transforming the AST without
338 /// any template instantiations. This is used to expand template packs when
339 /// their size is not known in advance (e.g. for builtins that produce type
340 /// packs).
343
344private:
345 struct ForgetSubstitutionRAII {
346 Derived &Self;
348
349 public:
350 ForgetSubstitutionRAII(Derived &Self) : Self(Self) {
351 Old = Self.ForgetSubstitution();
352 }
353
354 ~ForgetSubstitutionRAII() { Self.RememberSubstitution(std::move(Old)); }
355 };
356
357public:
358 /// Note to the derived class when a function parameter pack is
359 /// being expanded.
361
362 /// Transforms the given type into another type.
363 ///
364 /// By default, this routine transforms a type by creating a
365 /// TypeSourceInfo for it and delegating to the appropriate
366 /// function. This is expensive, but we don't mind, because
367 /// this method is deprecated anyway; all users should be
368 /// switched to storing TypeSourceInfos.
369 ///
370 /// \returns the transformed type.
372
373 /// Transforms the given type-with-location into a new
374 /// type-with-location.
375 ///
376 /// By default, this routine transforms a type by delegating to the
377 /// appropriate TransformXXXType to build a new type. Subclasses
378 /// may override this function (to take over all type
379 /// transformations) or some set of the TransformXXXType functions
380 /// to alter the transformation.
382
383 /// Transform the given type-with-location into a new
384 /// type, collecting location information in the given builder
385 /// as necessary.
386 ///
388
389 /// Transform a type that is permitted to produce a
390 /// DeducedTemplateSpecializationType.
391 ///
392 /// This is used in the (relatively rare) contexts where it is acceptable
393 /// for transformation to produce a class template type with deduced
394 /// template arguments.
395 /// @{
398 /// @}
399
400 /// The reason why the value of a statement is not discarded, if any.
406
407 /// Transform the given statement.
408 ///
409 /// By default, this routine transforms a statement by delegating to the
410 /// appropriate TransformXXXStmt function to transform a specific kind of
411 /// statement or the TransformExpr() function to transform an expression.
412 /// Subclasses may override this function to transform statements using some
413 /// other mechanism.
414 ///
415 /// \returns the transformed statement.
418
419 /// Transform the given statement.
420 ///
421 /// By default, this routine transforms a statement by delegating to the
422 /// appropriate TransformOMPXXXClause function to transform a specific kind
423 /// of clause. Subclasses may override this function to transform statements
424 /// using some other mechanism.
425 ///
426 /// \returns the transformed OpenMP clause.
428
429 /// Transform the given attribute.
430 ///
431 /// By default, this routine transforms a statement by delegating to the
432 /// appropriate TransformXXXAttr function to transform a specific kind
433 /// of attribute. Subclasses may override this function to transform
434 /// attributed statements/types using some other mechanism.
435 ///
436 /// \returns the transformed attribute
437 const Attr *TransformAttr(const Attr *S);
438
439 // Transform the given statement attribute.
440 //
441 // Delegates to the appropriate TransformXXXAttr function to transform a
442 // specific kind of statement attribute. Unlike the non-statement taking
443 // version of this, this implements all attributes, not just pragmas.
444 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
445 const Attr *A);
446
447 // Transform the specified attribute.
448 //
449 // Subclasses should override the transformation of attributes with a pragma
450 // spelling to transform expressions stored within the attribute.
451 //
452 // \returns the transformed attribute.
453#define ATTR(X) \
454 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
455#include "clang/Basic/AttrList.inc"
456
457 // Transform the specified attribute.
458 //
459 // Subclasses should override the transformation of attributes to do
460 // transformation and checking of statement attributes. By default, this
461 // delegates to the non-statement taking version.
462 //
463 // \returns the transformed attribute.
464#define ATTR(X) \
465 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
466 const X##Attr *A) { \
467 return getDerived().Transform##X##Attr(A); \
468 }
469#include "clang/Basic/AttrList.inc"
470
471 /// Transform the given expression.
472 ///
473 /// By default, this routine transforms an expression by delegating to the
474 /// appropriate TransformXXXExpr function to build a new expression.
475 /// Subclasses may override this function to transform expressions using some
476 /// other mechanism.
477 ///
478 /// \returns the transformed expression.
480
481 /// Transform the given initializer.
482 ///
483 /// By default, this routine transforms an initializer by stripping off the
484 /// semantic nodes added by initialization, then passing the result to
485 /// TransformExpr or TransformExprs.
486 ///
487 /// \returns the transformed initializer.
489
490 /// Transform the given list of expressions.
491 ///
492 /// This routine transforms a list of expressions by invoking
493 /// \c TransformExpr() for each subexpression. However, it also provides
494 /// support for variadic templates by expanding any pack expansions (if the
495 /// derived class permits such expansion) along the way. When pack expansions
496 /// are present, the number of outputs may not equal the number of inputs.
497 ///
498 /// \param Inputs The set of expressions to be transformed.
499 ///
500 /// \param NumInputs The number of expressions in \c Inputs.
501 ///
502 /// \param IsCall If \c true, then this transform is being performed on
503 /// function-call arguments, and any arguments that should be dropped, will
504 /// be.
505 ///
506 /// \param Outputs The transformed input expressions will be added to this
507 /// vector.
508 ///
509 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
510 /// due to transformation.
511 ///
512 /// \returns true if an error occurred, false otherwise.
513 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
515 bool *ArgChanged = nullptr);
516
517 /// Transform the given declaration, which is referenced from a type
518 /// or expression.
519 ///
520 /// By default, acts as the identity function on declarations, unless the
521 /// transformer has had to transform the declaration itself. Subclasses
522 /// may override this function to provide alternate behavior.
524 llvm::DenseMap<Decl *, Decl *>::iterator Known
525 = TransformedLocalDecls.find(D);
526 if (Known != TransformedLocalDecls.end())
527 return Known->second;
528
529 return D;
530 }
531
532 /// Transform the specified condition.
533 ///
534 /// By default, this transforms the variable and expression and rebuilds
535 /// the condition.
537 Expr *Expr,
539
540 /// Transform the attributes associated with the given declaration and
541 /// place them on the new declaration.
542 ///
543 /// By default, this operation does nothing. Subclasses may override this
544 /// behavior to transform attributes.
545 void transformAttrs(Decl *Old, Decl *New) { }
546
547 /// Note that a local declaration has been transformed by this
548 /// transformer.
549 ///
550 /// Local declarations are typically transformed via a call to
551 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
552 /// the transformer itself has to transform the declarations. This routine
553 /// can be overridden by a subclass that keeps track of such mappings.
555 assert(New.size() == 1 &&
556 "must override transformedLocalDecl if performing pack expansion");
557 TransformedLocalDecls[Old] = New.front();
558 }
559
560 /// Transform the definition of the given declaration.
561 ///
562 /// By default, invokes TransformDecl() to transform the declaration.
563 /// Subclasses may override this function to provide alternate behavior.
565 return getDerived().TransformDecl(Loc, D);
566 }
567
568 /// Transform the given declaration, which was the first part of a
569 /// nested-name-specifier in a member access expression.
570 ///
571 /// This specific declaration transformation only applies to the first
572 /// identifier in a nested-name-specifier of a member access expression, e.g.,
573 /// the \c T in \c x->T::member
574 ///
575 /// By default, invokes TransformDecl() to transform the declaration.
576 /// Subclasses may override this function to provide alternate behavior.
578 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
579 }
580
581 /// Transform the set of declarations in an OverloadExpr.
582 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
583 LookupResult &R);
584
585 /// Transform the given nested-name-specifier with source-location
586 /// information.
587 ///
588 /// By default, transforms all of the types and declarations within the
589 /// nested-name-specifier. Subclasses may override this function to provide
590 /// alternate behavior.
593 QualType ObjectType = QualType(),
594 NamedDecl *FirstQualifierInScope = nullptr);
595
596 /// Transform the given declaration name.
597 ///
598 /// By default, transforms the types of conversion function, constructor,
599 /// and destructor names and then (if needed) rebuilds the declaration name.
600 /// Identifiers and selectors are returned unmodified. Subclasses may
601 /// override this function to provide alternate behavior.
604
614
615 /// Transform the given template name.
616 ///
617 /// \param SS The nested-name-specifier that qualifies the template
618 /// name. This nested-name-specifier must already have been transformed.
619 ///
620 /// \param Name The template name to transform.
621 ///
622 /// \param NameLoc The source location of the template name.
623 ///
624 /// \param ObjectType If we're translating a template name within a member
625 /// access expression, this is the type of the object whose member template
626 /// is being referenced.
627 ///
628 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
629 /// also refers to a name within the current (lexical) scope, this is the
630 /// declaration it refers to.
631 ///
632 /// By default, transforms the template name by transforming the declarations
633 /// and nested-name-specifiers that occur within the template name.
634 /// Subclasses may override this function to provide alternate behavior.
636 SourceLocation TemplateKWLoc,
637 TemplateName Name, SourceLocation NameLoc,
638 QualType ObjectType = QualType(),
639 NamedDecl *FirstQualifierInScope = nullptr,
640 bool AllowInjectedClassName = false);
641
642 /// Transform the given template argument.
643 ///
644 /// By default, this operation transforms the type, expression, or
645 /// declaration stored within the template argument and constructs a
646 /// new template argument from the transformed result. Subclasses may
647 /// override this function to provide alternate behavior.
648 ///
649 /// Returns true if there was an error.
651 TemplateArgumentLoc &Output,
652 bool Uneval = false);
653
655 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
656 TemplateName Name, SourceLocation NameLoc);
657
658 /// Transform the given set of template arguments.
659 ///
660 /// By default, this operation transforms all of the template arguments
661 /// in the input set using \c TransformTemplateArgument(), and appends
662 /// the transformed arguments to the output list.
663 ///
664 /// Note that this overload of \c TransformTemplateArguments() is merely
665 /// a convenience function. Subclasses that wish to override this behavior
666 /// should override the iterator-based member template version.
667 ///
668 /// \param Inputs The set of template arguments to be transformed.
669 ///
670 /// \param NumInputs The number of template arguments in \p Inputs.
671 ///
672 /// \param Outputs The set of transformed template arguments output by this
673 /// routine.
674 ///
675 /// Returns true if an error occurred.
677 unsigned NumInputs,
679 bool Uneval = false) {
680 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
681 Uneval);
682 }
683
684 /// Transform the given set of template arguments.
685 ///
686 /// By default, this operation transforms all of the template arguments
687 /// in the input set using \c TransformTemplateArgument(), and appends
688 /// the transformed arguments to the output list.
689 ///
690 /// \param First An iterator to the first template argument.
691 ///
692 /// \param Last An iterator one step past the last template argument.
693 ///
694 /// \param Outputs The set of transformed template arguments output by this
695 /// routine.
696 ///
697 /// Returns true if an error occurred.
698 template<typename InputIterator>
700 InputIterator Last,
702 bool Uneval = false);
703
704 template <typename InputIterator>
706 InputIterator Last,
708 bool Uneval = false);
709
710 /// Checks if the argument pack from \p In will need to be expanded and does
711 /// the necessary prework.
712 /// Whether the expansion is needed is captured in Info.Expand.
713 ///
714 /// - When the expansion is required, \p Out will be a template pattern that
715 /// would need to be expanded.
716 /// - When the expansion must not happen, \p Out will be a pack that must be
717 /// returned to the outputs directly.
718 ///
719 /// \return true iff the error occurred
722
723 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
725 TemplateArgumentLoc &ArgLoc);
726
727 /// Fakes up a TypeSourceInfo for a type.
729 return SemaRef.Context.getTrivialTypeSourceInfo(T,
731 }
732
733#define ABSTRACT_TYPELOC(CLASS, PARENT)
734#define TYPELOC(CLASS, PARENT) \
735 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
736#include "clang/AST/TypeLocNodes.def"
737
740 bool SuppressObjCLifetime);
744 bool SuppressObjCLifetime);
745
746 template<typename Fn>
749 CXXRecordDecl *ThisContext,
750 Qualifiers ThisTypeQuals,
752
755 SmallVectorImpl<QualType> &Exceptions,
756 bool &Changed);
757
759
762 QualType ObjectType,
763 NamedDecl *FirstQualifierInScope,
764 bool AllowInjectedClassName);
765
767
768 /// Transforms the parameters of a function type into the
769 /// given vectors.
770 ///
771 /// The result vectors should be kept in sync; null entries in the
772 /// variables vector are acceptable.
773 ///
774 /// LastParamTransformed, if non-null, will be set to the index of the last
775 /// parameter on which transformation was started. In the event of an error,
776 /// this will contain the parameter which failed to instantiate.
777 ///
778 /// Return true on error.
781 const QualType *ParamTypes,
782 const FunctionProtoType::ExtParameterInfo *ParamInfos,
784 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
785
788 const QualType *ParamTypes,
789 const FunctionProtoType::ExtParameterInfo *ParamInfos,
792 return getDerived().TransformFunctionTypeParams(
793 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
794 }
795
796 /// Transforms the parameters of a requires expresison into the given vectors.
797 ///
798 /// The result vectors should be kept in sync; null entries in the
799 /// variables vector are acceptable.
800 ///
801 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
802 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
803 /// which are cases where transformation shouldn't continue.
805 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
811 KWLoc, Params, /*ParamTypes=*/nullptr,
812 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
813 return ExprError();
814
815 return ExprResult{};
816 }
817
818 /// Transforms a single function-type parameter. Return null
819 /// on error.
820 ///
821 /// \param indexAdjustment - A number to add to the parameter's
822 /// scope index; can be negative
824 int indexAdjustment,
825 UnsignedOrNone NumExpansions,
826 bool ExpectParameterPack);
827
828 /// Transform the body of a lambda-expression.
830 /// Alternative implementation of TransformLambdaBody that skips transforming
831 /// the body.
833
839
841
843
846
851
853
855 bool IsAddressOfOperand,
856 TypeSourceInfo **RecoveryTSI);
857
859 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
860 TypeSourceInfo **RecoveryTSI);
861
863 bool IsAddressOfOperand);
864
866
868
869// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
870// amount of stack usage with clang.
871#define STMT(Node, Parent) \
872 LLVM_ATTRIBUTE_NOINLINE \
873 StmtResult Transform##Node(Node *S);
874#define VALUESTMT(Node, Parent) \
875 LLVM_ATTRIBUTE_NOINLINE \
876 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
877#define EXPR(Node, Parent) \
878 LLVM_ATTRIBUTE_NOINLINE \
879 ExprResult Transform##Node(Node *E);
880#define ABSTRACT_STMT(Stmt)
881#include "clang/AST/StmtNodes.inc"
882
883#define GEN_CLANG_CLAUSE_CLASS
884#define CLAUSE_CLASS(Enum, Str, Class) \
885 LLVM_ATTRIBUTE_NOINLINE \
886 OMPClause *Transform##Class(Class *S);
887#include "llvm/Frontend/OpenMP/OMP.inc"
888
889 /// Build a new qualified type given its unqualified type and type location.
890 ///
891 /// By default, this routine adds type qualifiers only to types that can
892 /// have qualifiers, and silently suppresses those qualifiers that are not
893 /// permitted. Subclasses may override this routine to provide different
894 /// behavior.
896
897 /// Build a new pointer type given its pointee type.
898 ///
899 /// By default, performs semantic analysis when building the pointer type.
900 /// Subclasses may override this routine to provide different behavior.
902
903 /// Build a new block pointer type given its pointee type.
904 ///
905 /// By default, performs semantic analysis when building the block pointer
906 /// type. Subclasses may override this routine to provide different behavior.
908
909 /// Build a new reference type given the type it references.
910 ///
911 /// By default, performs semantic analysis when building the
912 /// reference type. Subclasses may override this routine to provide
913 /// different behavior.
914 ///
915 /// \param LValue whether the type was written with an lvalue sigil
916 /// or an rvalue sigil.
918 bool LValue,
919 SourceLocation Sigil);
920
921 /// Build a new member pointer type given the pointee type and the
922 /// qualifier it refers into.
923 ///
924 /// By default, performs semantic analysis when building the member pointer
925 /// type. Subclasses may override this routine to provide different behavior.
927 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
928 SourceLocation Sigil);
929
931 SourceLocation ProtocolLAngleLoc,
933 ArrayRef<SourceLocation> ProtocolLocs,
934 SourceLocation ProtocolRAngleLoc);
935
936 /// Build an Objective-C object type.
937 ///
938 /// By default, performs semantic analysis when building the object type.
939 /// Subclasses may override this routine to provide different behavior.
941 SourceLocation Loc,
942 SourceLocation TypeArgsLAngleLoc,
944 SourceLocation TypeArgsRAngleLoc,
945 SourceLocation ProtocolLAngleLoc,
947 ArrayRef<SourceLocation> ProtocolLocs,
948 SourceLocation ProtocolRAngleLoc);
949
950 /// Build a new Objective-C object pointer type given the pointee type.
951 ///
952 /// By default, directly builds the pointer type, with no additional semantic
953 /// analysis.
956
957 /// Build a new array type given the element type, size
958 /// modifier, size of the array (if known), size expression, and index type
959 /// qualifiers.
960 ///
961 /// By default, performs semantic analysis when building the array type.
962 /// Subclasses may override this routine to provide different behavior.
963 /// Also by default, all of the other Rebuild*Array
965 const llvm::APInt *Size, Expr *SizeExpr,
966 unsigned IndexTypeQuals, SourceRange BracketsRange);
967
968 /// Build a new constant array type given the element type, size
969 /// modifier, (known) size of the array, and index type qualifiers.
970 ///
971 /// By default, performs semantic analysis when building the array type.
972 /// Subclasses may override this routine to provide different behavior.
974 ArraySizeModifier SizeMod,
975 const llvm::APInt &Size, Expr *SizeExpr,
976 unsigned IndexTypeQuals,
977 SourceRange BracketsRange);
978
979 /// Build a new incomplete array type given the element type, size
980 /// modifier, and index type qualifiers.
981 ///
982 /// By default, performs semantic analysis when building the array type.
983 /// Subclasses may override this routine to provide different behavior.
985 ArraySizeModifier SizeMod,
986 unsigned IndexTypeQuals,
987 SourceRange BracketsRange);
988
989 /// Build a new variable-length array type given the element type,
990 /// size modifier, size expression, and index type qualifiers.
991 ///
992 /// By default, performs semantic analysis when building the array type.
993 /// Subclasses may override this routine to provide different behavior.
995 ArraySizeModifier SizeMod, Expr *SizeExpr,
996 unsigned IndexTypeQuals,
997 SourceRange BracketsRange);
998
999 /// Build a new dependent-sized array type given the element type,
1000 /// size modifier, size expression, and index type qualifiers.
1001 ///
1002 /// By default, performs semantic analysis when building the array type.
1003 /// Subclasses may override this routine to provide different behavior.
1005 ArraySizeModifier SizeMod,
1006 Expr *SizeExpr,
1007 unsigned IndexTypeQuals,
1008 SourceRange BracketsRange);
1009
1010 /// Build a new vector type given the element type and
1011 /// number of elements.
1012 ///
1013 /// By default, performs semantic analysis when building the vector type.
1014 /// Subclasses may override this routine to provide different behavior.
1015 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1016 VectorKind VecKind);
1017
1018 /// Build a new potentially dependently-sized extended vector type
1019 /// given the element type and number of elements.
1020 ///
1021 /// By default, performs semantic analysis when building the vector type.
1022 /// Subclasses may override this routine to provide different behavior.
1024 SourceLocation AttributeLoc, VectorKind);
1025
1026 /// Build a new extended vector type given the element type and
1027 /// number of elements.
1028 ///
1029 /// By default, performs semantic analysis when building the vector type.
1030 /// Subclasses may override this routine to provide different behavior.
1031 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1032 SourceLocation AttributeLoc);
1033
1034 /// Build a new potentially dependently-sized extended vector type
1035 /// given the element type and number of elements.
1036 ///
1037 /// By default, performs semantic analysis when building the vector type.
1038 /// Subclasses may override this routine to provide different behavior.
1040 Expr *SizeExpr,
1041 SourceLocation AttributeLoc);
1042
1043 /// Build a new matrix type given the element type and dimensions.
1044 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1045 unsigned NumColumns);
1046
1047 /// Build a new matrix type given the type and dependently-defined
1048 /// dimensions.
1050 Expr *ColumnExpr,
1051 SourceLocation AttributeLoc);
1052
1053 /// Build a new DependentAddressSpaceType or return the pointee
1054 /// type variable with the correct address space (retrieved from
1055 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1056 /// where the address space remains dependent.
1057 ///
1058 /// By default, performs semantic analysis when building the type with address
1059 /// space applied. Subclasses may override this routine to provide different
1060 /// behavior.
1062 Expr *AddrSpaceExpr,
1063 SourceLocation AttributeLoc);
1064
1065 /// Build a new function type.
1066 ///
1067 /// By default, performs semantic analysis when building the function type.
1068 /// Subclasses may override this routine to provide different behavior.
1070 MutableArrayRef<QualType> ParamTypes,
1072
1073 /// Build a new unprototyped function type.
1075
1076 /// Rebuild an unresolved typename type, given the decl that
1077 /// the UnresolvedUsingTypenameDecl was transformed to.
1079 NestedNameSpecifier Qualifier,
1080 SourceLocation NameLoc, Decl *D);
1081
1082 /// Build a new type found via an alias.
1085 QualType UnderlyingType) {
1086 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1087 }
1088
1089 /// Build a new typedef type.
1091 NestedNameSpecifier Qualifier,
1093 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1094 }
1095
1096 /// Build a new MacroDefined type.
1098 const IdentifierInfo *MacroII) {
1099 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1100 }
1101
1102 /// Build a new class/struct/union/enum type.
1104 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1105 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1106 /*OwnsTag=*/false);
1107 }
1109 return SemaRef.Context.getCanonicalTagType(Tag);
1110 }
1111
1112 /// Build a new typeof(expr) type.
1113 ///
1114 /// By default, performs semantic analysis when building the typeof type.
1115 /// Subclasses may override this routine to provide different behavior.
1117 TypeOfKind Kind);
1118
1119 /// Build a new typeof(type) type.
1120 ///
1121 /// By default, builds a new TypeOfType with the given underlying type.
1123
1124 /// Build a new unary transform type.
1126 UnaryTransformType::UTTKind UKind,
1127 SourceLocation Loc);
1128
1129 /// Build a new C++11 decltype type.
1130 ///
1131 /// By default, performs semantic analysis when building the decltype type.
1132 /// Subclasses may override this routine to provide different behavior.
1134
1136 SourceLocation Loc,
1137 SourceLocation EllipsisLoc,
1138 bool FullySubstituted,
1139 ArrayRef<QualType> Expansions = {});
1140
1141 /// Build a new C++11 auto type.
1142 ///
1143 /// By default, builds a new AutoType with the given deduced type.
1146 ConceptDecl *TypeConstraintConcept,
1147 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1148 return SemaRef.Context.getAutoType(
1149 DK, DeducedAsType, Keyword, TypeConstraintConcept, TypeConstraintArgs);
1150 }
1151
1152 /// By default, builds a new DeducedTemplateSpecializationType with the given
1153 /// deduced type.
1157 return SemaRef.Context.getDeducedTemplateSpecializationType(
1158 DK, DeducedAsType, Keyword, Template);
1159 }
1160
1161 /// Build a new template specialization type.
1162 ///
1163 /// By default, performs semantic analysis when building the template
1164 /// specialization type. Subclasses may override this routine to provide
1165 /// different behavior.
1168 SourceLocation TemplateLoc,
1170
1171 /// Build a new parenthesized type.
1172 ///
1173 /// By default, builds a new ParenType type from the inner type.
1174 /// Subclasses may override this routine to provide different behavior.
1176 return SemaRef.BuildParenType(InnerType);
1177 }
1178
1179 /// Build a new typename type that refers to an identifier.
1180 ///
1181 /// By default, performs semantic analysis when building the typename type
1182 /// (or elaborated type). Subclasses may override this routine to provide
1183 /// different behavior.
1185 SourceLocation KeywordLoc,
1186 NestedNameSpecifierLoc QualifierLoc,
1187 const IdentifierInfo *Id,
1188 SourceLocation IdLoc,
1189 bool DeducedTSTContext) {
1190 CXXScopeSpec SS;
1191 SS.Adopt(QualifierLoc);
1192
1193 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1194 // If the name is still dependent, just build a new dependent name type.
1195 if (!SemaRef.computeDeclContext(SS))
1196 return SemaRef.Context.getDependentNameType(Keyword,
1197 QualifierLoc.getNestedNameSpecifier(),
1198 Id);
1199 }
1200
1203 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1204 *Id, IdLoc, DeducedTSTContext);
1205 }
1206
1208
1209 // We had a dependent elaborated-type-specifier that has been transformed
1210 // into a non-dependent elaborated-type-specifier. Find the tag we're
1211 // referring to.
1213 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1214 if (!DC)
1215 return QualType();
1216
1217 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1218 return QualType();
1219
1220 TagDecl *Tag = nullptr;
1221 SemaRef.LookupQualifiedName(Result, DC);
1222 switch (Result.getResultKind()) {
1225 break;
1226
1228 Tag = Result.getAsSingle<TagDecl>();
1229 break;
1230
1233 llvm_unreachable("Tag lookup cannot find non-tags");
1234
1236 // Let the LookupResult structure handle ambiguities.
1237 return QualType();
1238 }
1239
1240 if (!Tag) {
1241 // Check where the name exists but isn't a tag type and use that to emit
1242 // better diagnostics.
1244 SemaRef.LookupQualifiedName(Result, DC);
1245 switch (Result.getResultKind()) {
1249 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1250 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1251 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1252 << SomeDecl << NTK << Kind;
1253 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1254 break;
1255 }
1256 default:
1257 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1258 << Kind << Id << DC << QualifierLoc.getSourceRange();
1259 break;
1260 }
1261 return QualType();
1262 }
1263 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1264 IdLoc, Id)) {
1265 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1266 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1267 return QualType();
1268 }
1269 return getDerived().RebuildTagType(
1270 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1271 }
1272
1273 /// Build a new pack expansion type.
1274 ///
1275 /// By default, builds a new PackExpansionType type from the given pattern.
1276 /// Subclasses may override this routine to provide different behavior.
1278 SourceLocation EllipsisLoc,
1279 UnsignedOrNone NumExpansions) {
1280 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1281 NumExpansions);
1282 }
1283
1284 /// Build a new atomic type given its value type.
1285 ///
1286 /// By default, performs semantic analysis when building the atomic type.
1287 /// Subclasses may override this routine to provide different behavior.
1289
1290 /// Build a new pipe type given its value type.
1292 bool isReadPipe);
1293
1294 /// Build a bit-precise int given its value type.
1295 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1296 SourceLocation Loc);
1297
1298 /// Build a dependent bit-precise int given its value type.
1299 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1300 SourceLocation Loc);
1301
1302 /// Build a new template name given a nested name specifier, a flag
1303 /// indicating whether the "template" keyword was provided, and the template
1304 /// that the template name refers to.
1305 ///
1306 /// By default, builds the new template name directly. Subclasses may override
1307 /// this routine to provide different behavior.
1309 TemplateName Name);
1310
1311 /// Build a new template name given a nested name specifier and the
1312 /// name that is referred to as a template.
1313 ///
1314 /// By default, performs semantic analysis to determine whether the name can
1315 /// be resolved to a specific template, then builds the appropriate kind of
1316 /// template name. Subclasses may override this routine to provide different
1317 /// behavior.
1319 SourceLocation TemplateKWLoc,
1320 const IdentifierInfo &Name,
1321 SourceLocation NameLoc, QualType ObjectType,
1322 bool AllowInjectedClassName);
1323
1324 /// Build a new template name given a nested name specifier and the
1325 /// overloaded operator name that is referred to as a template.
1326 ///
1327 /// By default, performs semantic analysis to determine whether the name can
1328 /// be resolved to a specific template, then builds the appropriate kind of
1329 /// template name. Subclasses may override this routine to provide different
1330 /// behavior.
1332 SourceLocation TemplateKWLoc,
1333 OverloadedOperatorKind Operator,
1334 SourceLocation NameLoc, QualType ObjectType,
1335 bool AllowInjectedClassName);
1336
1338 SourceLocation TemplateKWLoc,
1340 SourceLocation NameLoc, QualType ObjectType,
1341 bool AllowInjectedClassName);
1342
1343 /// Build a new template name given a template template parameter pack
1344 /// and the
1345 ///
1346 /// By default, performs semantic analysis to determine whether the name can
1347 /// be resolved to a specific template, then builds the appropriate kind of
1348 /// template name. Subclasses may override this routine to provide different
1349 /// behavior.
1351 Decl *AssociatedDecl, unsigned Index,
1352 bool Final) {
1354 ArgPack, AssociatedDecl, Index, Final);
1355 }
1356
1357 /// Build a new compound statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1362 MultiStmtArg Statements,
1363 SourceLocation RBraceLoc,
1364 bool IsStmtExpr) {
1365 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1366 IsStmtExpr);
1367 }
1368
1369 /// Build a new case statement.
1370 ///
1371 /// By default, performs semantic analysis to build the new statement.
1372 /// Subclasses may override this routine to provide different behavior.
1374 Expr *LHS,
1375 SourceLocation EllipsisLoc,
1376 Expr *RHS,
1377 SourceLocation ColonLoc) {
1378 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1379 ColonLoc);
1380 }
1381
1382 /// Attach the body to a new case statement.
1383 ///
1384 /// By default, performs semantic analysis to build the new statement.
1385 /// Subclasses may override this routine to provide different behavior.
1387 getSema().ActOnCaseStmtBody(S, Body);
1388 return S;
1389 }
1390
1391 /// Build a new default statement.
1392 ///
1393 /// By default, performs semantic analysis to build the new statement.
1394 /// Subclasses may override this routine to provide different behavior.
1396 SourceLocation ColonLoc,
1397 Stmt *SubStmt) {
1398 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1399 /*CurScope=*/nullptr);
1400 }
1401
1402 /// Build a new label statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
1407 SourceLocation ColonLoc, Stmt *SubStmt) {
1408 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1409 }
1410
1411 /// Build a new attributed statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1417 Stmt *SubStmt) {
1418 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1419 return StmtError();
1420 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1421 }
1422
1423 /// Build a new "if" statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1429 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1430 SourceLocation ElseLoc, Stmt *Else) {
1431 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1432 Then, ElseLoc, Else);
1433 }
1434
1435 /// Start building a new switch statement.
1436 ///
1437 /// By default, performs semantic analysis to build the new statement.
1438 /// Subclasses may override this routine to provide different behavior.
1440 SourceLocation LParenLoc, Stmt *Init,
1442 SourceLocation RParenLoc) {
1443 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1444 RParenLoc);
1445 }
1446
1447 /// Attach the body to the switch statement.
1448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
1452 Stmt *Switch, Stmt *Body) {
1453 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1454 }
1455
1456 /// Build a new while statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1462 SourceLocation RParenLoc, Stmt *Body) {
1463 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1464 }
1465
1466 /// Build a new do-while statement.
1467 ///
1468 /// By default, performs semantic analysis to build the new statement.
1469 /// Subclasses may override this routine to provide different behavior.
1471 SourceLocation WhileLoc, SourceLocation LParenLoc,
1472 Expr *Cond, SourceLocation RParenLoc) {
1473 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1474 Cond, RParenLoc);
1475 }
1476
1477 /// Build a new for statement.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1483 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1484 Stmt *Body) {
1485 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1486 Inc, RParenLoc, Body);
1487 }
1488
1489 /// Build a new goto statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
1494 LabelDecl *Label) {
1495 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1496 }
1497
1498 /// Build a new indirect goto statement.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1503 SourceLocation StarLoc,
1504 Expr *Target) {
1505 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1506 }
1507
1508 /// Build a new return statement.
1509 ///
1510 /// By default, performs semantic analysis to build the new statement.
1511 /// Subclasses may override this routine to provide different behavior.
1513 return getSema().BuildReturnStmt(ReturnLoc, Result);
1514 }
1515
1516 /// Build a new declaration statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 SourceLocation StartLoc, SourceLocation EndLoc) {
1523 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1524 }
1525
1526 /// Build a new inline asm statement.
1527 ///
1528 /// By default, performs semantic analysis to build the new statement.
1529 /// Subclasses may override this routine to provide different behavior.
1531 bool IsVolatile, unsigned NumOutputs,
1532 unsigned NumInputs, IdentifierInfo **Names,
1533 MultiExprArg Constraints, MultiExprArg Exprs,
1534 Expr *AsmString, MultiExprArg Clobbers,
1535 unsigned NumLabels,
1536 SourceLocation RParenLoc) {
1537 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1538 NumInputs, Names, Constraints, Exprs,
1539 AsmString, Clobbers, NumLabels, RParenLoc);
1540 }
1541
1542 /// Build a new MS style inline asm statement.
1543 ///
1544 /// By default, performs semantic analysis to build the new statement.
1545 /// Subclasses may override this routine to provide different behavior.
1547 ArrayRef<Token> AsmToks,
1548 StringRef AsmString,
1549 unsigned NumOutputs, unsigned NumInputs,
1550 ArrayRef<StringRef> Constraints,
1551 ArrayRef<StringRef> Clobbers,
1552 ArrayRef<Expr*> Exprs,
1553 SourceLocation EndLoc) {
1554 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1555 NumOutputs, NumInputs,
1556 Constraints, Clobbers, Exprs, EndLoc);
1557 }
1558
1559 /// Build a new co_return statement.
1560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
1564 bool IsImplicit) {
1565 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1566 }
1567
1568 /// Build a new co_await expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
1573 UnresolvedLookupExpr *OpCoawaitLookup,
1574 bool IsImplicit) {
1575 // This function rebuilds a coawait-expr given its operator.
1576 // For an explicit coawait-expr, the rebuild involves the full set
1577 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1578 // including calling await_transform().
1579 // For an implicit coawait-expr, we need to rebuild the "operator
1580 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1581 // This mirrors how the implicit CoawaitExpr is originally created
1582 // in Sema::ActOnCoroutineBodyStart().
1583 if (IsImplicit) {
1585 CoawaitLoc, Operand, OpCoawaitLookup);
1586 if (Suspend.isInvalid())
1587 return ExprError();
1588 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1589 Suspend.get(), true);
1590 }
1591
1592 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1593 OpCoawaitLookup);
1594 }
1595
1596 /// Build a new co_await expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1601 Expr *Result,
1602 UnresolvedLookupExpr *Lookup) {
1603 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1604 }
1605
1606 /// Build a new co_yield expression.
1607 ///
1608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
1611 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1612 }
1613
1617
1618 /// Build a new Objective-C \@try statement.
1619 ///
1620 /// By default, performs semantic analysis to build the new statement.
1621 /// Subclasses may override this routine to provide different behavior.
1623 Stmt *TryBody,
1624 MultiStmtArg CatchStmts,
1625 Stmt *Finally) {
1626 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1627 Finally);
1628 }
1629
1630 /// Rebuild an Objective-C exception declaration.
1631 ///
1632 /// By default, performs semantic analysis to build the new declaration.
1633 /// Subclasses may override this routine to provide different behavior.
1635 TypeSourceInfo *TInfo, QualType T) {
1637 TInfo, T, ExceptionDecl->getInnerLocStart(),
1638 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1639 }
1640
1641 /// Build a new Objective-C \@catch statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
1646 SourceLocation RParenLoc,
1647 VarDecl *Var,
1648 Stmt *Body) {
1649 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1650 }
1651
1652 /// Build a new Objective-C \@finally statement.
1653 ///
1654 /// By default, performs semantic analysis to build the new statement.
1655 /// Subclasses may override this routine to provide different behavior.
1657 Stmt *Body) {
1658 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1659 }
1660
1661 /// Build a new Objective-C \@throw statement.
1662 ///
1663 /// By default, performs semantic analysis to build the new statement.
1664 /// Subclasses may override this routine to provide different behavior.
1666 Expr *Operand) {
1667 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1668 }
1669
1670 /// Build a new OpenMP Canonical loop.
1671 ///
1672 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1673 /// OMPCanonicalLoop.
1675 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1676 }
1677
1678 /// Build a new OpenMP executable directive.
1679 ///
1680 /// By default, performs semantic analysis to build the new statement.
1681 /// Subclasses may override this routine to provide different behavior.
1683 DeclarationNameInfo DirName,
1684 OpenMPDirectiveKind CancelRegion,
1685 ArrayRef<OMPClause *> Clauses,
1686 Stmt *AStmt, SourceLocation StartLoc,
1687 SourceLocation EndLoc) {
1688
1690 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1691 }
1692
1693 /// Build a new OpenMP informational directive.
1695 DeclarationNameInfo DirName,
1696 ArrayRef<OMPClause *> Clauses,
1697 Stmt *AStmt,
1698 SourceLocation StartLoc,
1699 SourceLocation EndLoc) {
1700
1702 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1703 }
1704
1705 /// Build a new OpenMP 'if' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new OpenMP clause.
1708 /// Subclasses may override this routine to provide different behavior.
1710 Expr *Condition, SourceLocation StartLoc,
1711 SourceLocation LParenLoc,
1712 SourceLocation NameModifierLoc,
1713 SourceLocation ColonLoc,
1714 SourceLocation EndLoc) {
1716 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1717 EndLoc);
1718 }
1719
1720 /// Build a new OpenMP 'final' clause.
1721 ///
1722 /// By default, performs semantic analysis to build the new OpenMP clause.
1723 /// Subclasses may override this routine to provide different behavior.
1725 SourceLocation LParenLoc,
1726 SourceLocation EndLoc) {
1727 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1728 LParenLoc, EndLoc);
1729 }
1730
1731 /// Build a new OpenMP 'num_threads' clause.
1732 ///
1733 /// By default, performs semantic analysis to build the new OpenMP clause.
1734 /// Subclasses may override this routine to provide different behavior.
1736 Expr *NumThreads,
1737 SourceLocation StartLoc,
1738 SourceLocation LParenLoc,
1739 SourceLocation ModifierLoc,
1740 SourceLocation EndLoc) {
1742 Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc);
1743 }
1744
1745 /// Build a new OpenMP 'safelen' clause.
1746 ///
1747 /// By default, performs semantic analysis to build the new OpenMP clause.
1748 /// Subclasses may override this routine to provide different behavior.
1750 SourceLocation LParenLoc,
1751 SourceLocation EndLoc) {
1752 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1753 EndLoc);
1754 }
1755
1756 /// Build a new OpenMP 'simdlen' clause.
1757 ///
1758 /// By default, performs semantic analysis to build the new OpenMP clause.
1759 /// Subclasses may override this routine to provide different behavior.
1761 SourceLocation LParenLoc,
1762 SourceLocation EndLoc) {
1763 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1764 EndLoc);
1765 }
1766
1768 SourceLocation StartLoc,
1769 SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1772 EndLoc);
1773 }
1774
1776 SourceLocation StartLoc,
1777 SourceLocation LParenLoc,
1778 SourceLocation EndLoc,
1779 std::optional<unsigned> FillIdx,
1780 SourceLocation FillLoc) {
1781 unsigned FillCount = FillIdx ? 1 : 0;
1783 Counts, StartLoc, LParenLoc, EndLoc, FillIdx, FillLoc, FillCount);
1784 }
1785
1786 /// Build a new OpenMP 'permutation' clause.
1788 SourceLocation StartLoc,
1789 SourceLocation LParenLoc,
1790 SourceLocation EndLoc) {
1791 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1792 LParenLoc, EndLoc);
1793 }
1794
1795 /// Build a new OpenMP 'full' clause.
1797 SourceLocation EndLoc) {
1798 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1799 }
1800
1801 /// Build a new OpenMP 'partial' clause.
1803 SourceLocation LParenLoc,
1804 SourceLocation EndLoc) {
1805 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1806 LParenLoc, EndLoc);
1807 }
1808
1809 OMPClause *
1811 SourceLocation LParenLoc, SourceLocation FirstLoc,
1812 SourceLocation CountLoc, SourceLocation EndLoc) {
1814 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1815 }
1816
1817 /// Build a new OpenMP 'allocator' clause.
1818 ///
1819 /// By default, performs semantic analysis to build the new OpenMP clause.
1820 /// Subclasses may override this routine to provide different behavior.
1822 SourceLocation LParenLoc,
1823 SourceLocation EndLoc) {
1824 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1825 EndLoc);
1826 }
1827
1828 /// Build a new OpenMP 'collapse' clause.
1829 ///
1830 /// By default, performs semantic analysis to build the new OpenMP clause.
1831 /// Subclasses may override this routine to provide different behavior.
1833 SourceLocation LParenLoc,
1834 SourceLocation EndLoc) {
1835 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1836 LParenLoc, EndLoc);
1837 }
1838
1839 /// Build a new OpenMP 'default' clause.
1840 ///
1841 /// By default, performs semantic analysis to build the new OpenMP clause.
1842 /// Subclasses may override this routine to provide different behavior.
1845 SourceLocation VCLoc,
1846 SourceLocation StartLoc,
1847 SourceLocation LParenLoc,
1848 SourceLocation EndLoc) {
1850 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1851 }
1852
1853 /// Build a new OpenMP 'proc_bind' clause.
1854 ///
1855 /// By default, performs semantic analysis to build the new OpenMP clause.
1856 /// Subclasses may override this routine to provide different behavior.
1858 SourceLocation KindKwLoc,
1859 SourceLocation StartLoc,
1860 SourceLocation LParenLoc,
1861 SourceLocation EndLoc) {
1863 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1864 }
1866 SourceLocation StartLoc,
1867 SourceLocation LParenLoc,
1868 SourceLocation EndLoc) {
1870 ImpexTypeArg, StartLoc, LParenLoc, EndLoc);
1871 }
1872
1873 /// Build a new OpenMP 'schedule' clause.
1874 ///
1875 /// By default, performs semantic analysis to build the new OpenMP clause.
1876 /// Subclasses may override this routine to provide different behavior.
1879 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1880 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1881 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1883 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1884 CommaLoc, EndLoc);
1885 }
1886
1887 /// Build a new OpenMP 'ordered' clause.
1888 ///
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1892 SourceLocation EndLoc,
1893 SourceLocation LParenLoc, Expr *Num) {
1894 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1895 LParenLoc, Num);
1896 }
1897
1898 /// Build a new OpenMP 'nowait' clause.
1899 ///
1900 /// By default, performs semantic analysis to build the new OpenMP clause.
1901 /// Subclasses may override this routine to provide different behavior.
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc,
1906 LParenLoc, Condition);
1907 }
1908
1909 /// Build a new OpenMP 'private' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new OpenMP clause.
1912 /// Subclasses may override this routine to provide different behavior.
1914 SourceLocation StartLoc,
1915 SourceLocation LParenLoc,
1916 SourceLocation EndLoc) {
1917 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1918 LParenLoc, EndLoc);
1919 }
1920
1921 /// Build a new OpenMP 'firstprivate' clause.
1922 ///
1923 /// By default, performs semantic analysis to build the new OpenMP clause.
1924 /// Subclasses may override this routine to provide different behavior.
1926 SourceLocation StartLoc,
1927 SourceLocation LParenLoc,
1928 SourceLocation EndLoc) {
1929 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1930 LParenLoc, EndLoc);
1931 }
1932
1933 /// Build a new OpenMP 'lastprivate' clause.
1934 ///
1935 /// By default, performs semantic analysis to build the new OpenMP clause.
1936 /// Subclasses may override this routine to provide different behavior.
1939 SourceLocation LPKindLoc,
1940 SourceLocation ColonLoc,
1941 SourceLocation StartLoc,
1942 SourceLocation LParenLoc,
1943 SourceLocation EndLoc) {
1945 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1946 }
1947
1948 /// Build a new OpenMP 'shared' clause.
1949 ///
1950 /// By default, performs semantic analysis to build the new OpenMP clause.
1951 /// Subclasses may override this routine to provide different behavior.
1953 SourceLocation StartLoc,
1954 SourceLocation LParenLoc,
1955 SourceLocation EndLoc) {
1956 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1957 LParenLoc, EndLoc);
1958 }
1959
1960 /// Build a new OpenMP 'reduction' clause.
1961 ///
1962 /// By default, performs semantic analysis to build the new statement.
1963 /// Subclasses may override this routine to provide different behavior.
1966 OpenMPOriginalSharingModifier OriginalSharingModifier,
1967 SourceLocation StartLoc, SourceLocation LParenLoc,
1968 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1969 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1970 const DeclarationNameInfo &ReductionId,
1971 ArrayRef<Expr *> UnresolvedReductions) {
1973 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1974 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1975 UnresolvedReductions);
1976 }
1977
1978 /// Build a new OpenMP 'task_reduction' clause.
1979 ///
1980 /// By default, performs semantic analysis to build the new statement.
1981 /// Subclasses may override this routine to provide different behavior.
1983 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1984 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1985 CXXScopeSpec &ReductionIdScopeSpec,
1986 const DeclarationNameInfo &ReductionId,
1987 ArrayRef<Expr *> UnresolvedReductions) {
1989 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1990 ReductionId, UnresolvedReductions);
1991 }
1992
1993 /// Build a new OpenMP 'in_reduction' clause.
1994 ///
1995 /// By default, performs semantic analysis to build the new statement.
1996 /// Subclasses may override this routine to provide different behavior.
1997 OMPClause *
1999 SourceLocation LParenLoc, SourceLocation ColonLoc,
2000 SourceLocation EndLoc,
2001 CXXScopeSpec &ReductionIdScopeSpec,
2002 const DeclarationNameInfo &ReductionId,
2003 ArrayRef<Expr *> UnresolvedReductions) {
2005 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2006 ReductionId, UnresolvedReductions);
2007 }
2008
2009 /// Build a new OpenMP 'linear' clause.
2010 ///
2011 /// By default, performs semantic analysis to build the new OpenMP clause.
2012 /// Subclasses may override this routine to provide different behavior.
2014 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
2015 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
2016 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2017 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
2019 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
2020 StepModifierLoc, EndLoc);
2021 }
2022
2023 /// Build a new OpenMP 'aligned' clause.
2024 ///
2025 /// By default, performs semantic analysis to build the new OpenMP clause.
2026 /// Subclasses may override this routine to provide different behavior.
2028 SourceLocation StartLoc,
2029 SourceLocation LParenLoc,
2030 SourceLocation ColonLoc,
2031 SourceLocation EndLoc) {
2033 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2034 }
2035
2036 /// Build a new OpenMP 'copyin' clause.
2037 ///
2038 /// By default, performs semantic analysis to build the new OpenMP clause.
2039 /// Subclasses may override this routine to provide different behavior.
2041 SourceLocation StartLoc,
2042 SourceLocation LParenLoc,
2043 SourceLocation EndLoc) {
2044 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2045 LParenLoc, EndLoc);
2046 }
2047
2048 /// Build a new OpenMP 'copyprivate' clause.
2049 ///
2050 /// By default, performs semantic analysis to build the new OpenMP clause.
2051 /// Subclasses may override this routine to provide different behavior.
2053 SourceLocation StartLoc,
2054 SourceLocation LParenLoc,
2055 SourceLocation EndLoc) {
2056 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2057 LParenLoc, EndLoc);
2058 }
2059
2060 /// Build a new OpenMP 'flush' pseudo clause.
2061 ///
2062 /// By default, performs semantic analysis to build the new OpenMP clause.
2063 /// Subclasses may override this routine to provide different behavior.
2065 SourceLocation StartLoc,
2066 SourceLocation LParenLoc,
2067 SourceLocation EndLoc) {
2068 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2069 LParenLoc, EndLoc);
2070 }
2071
2072 /// Build a new OpenMP 'depobj' pseudo clause.
2073 ///
2074 /// By default, performs semantic analysis to build the new OpenMP clause.
2075 /// Subclasses may override this routine to provide different behavior.
2077 SourceLocation LParenLoc,
2078 SourceLocation EndLoc) {
2079 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2080 LParenLoc, EndLoc);
2081 }
2082
2083 /// Build a new OpenMP 'depend' pseudo clause.
2084 ///
2085 /// By default, performs semantic analysis to build the new OpenMP clause.
2086 /// Subclasses may override this routine to provide different behavior.
2088 Expr *DepModifier, ArrayRef<Expr *> VarList,
2089 SourceLocation StartLoc,
2090 SourceLocation LParenLoc,
2091 SourceLocation EndLoc) {
2093 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2094 }
2095
2096 /// Build a new OpenMP 'device' clause.
2097 ///
2098 /// By default, performs semantic analysis to build the new statement.
2099 /// Subclasses may override this routine to provide different behavior.
2101 Expr *Device, SourceLocation StartLoc,
2102 SourceLocation LParenLoc,
2103 SourceLocation ModifierLoc,
2104 SourceLocation EndLoc) {
2106 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2107 }
2108
2109 /// Build a new OpenMP 'map' clause.
2110 ///
2111 /// By default, performs semantic analysis to build the new OpenMP clause.
2112 /// Subclasses may override this routine to provide different behavior.
2114 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2115 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2116 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2117 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2118 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2119 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2121 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2122 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2123 ColonLoc, VarList, Locs,
2124 /*NoDiagnose=*/false, UnresolvedMappers);
2125 }
2126
2127 /// Build a new OpenMP 'allocate' clause.
2128 ///
2129 /// By default, performs semantic analysis to build the new OpenMP clause.
2130 /// Subclasses may override this routine to provide different behavior.
2131 OMPClause *
2132 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2133 OpenMPAllocateClauseModifier FirstModifier,
2134 SourceLocation FirstModifierLoc,
2135 OpenMPAllocateClauseModifier SecondModifier,
2136 SourceLocation SecondModifierLoc,
2137 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2138 SourceLocation LParenLoc, SourceLocation ColonLoc,
2139 SourceLocation EndLoc) {
2141 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2142 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2143 }
2144
2145 /// Build a new OpenMP 'num_teams' clause.
2146 ///
2147 /// By default, performs semantic analysis to build the new statement.
2148 /// Subclasses may override this routine to provide different behavior.
2151 Expr *ModifierExpr, SourceLocation ModifierLoc,
2152 OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr,
2153 SourceLocation ModifierExtraLoc, SourceLocation StartLoc,
2154 SourceLocation LParenLoc, SourceLocation EndLoc) {
2156 VarList, Modifier, ModifierExpr, ModifierLoc, ModifierExtra,
2157 ModifierExtraExpr, ModifierExtraLoc, StartLoc, LParenLoc, EndLoc);
2158 }
2159
2160 /// Build a new OpenMP 'thread_limit' clause.
2161 ///
2162 /// By default, performs semantic analysis to build the new statement.
2163 /// Subclasses may override this routine to provide different behavior.
2166 Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
2167 SourceLocation LParenLoc, SourceLocation EndLoc) {
2169 VarList, Modifier, ModifierExpr, ModifierLoc, StartLoc, LParenLoc,
2170 EndLoc);
2171 }
2172
2173 /// Build a new OpenMP 'priority' clause.
2174 ///
2175 /// By default, performs semantic analysis to build the new statement.
2176 /// Subclasses may override this routine to provide different behavior.
2178 SourceLocation LParenLoc,
2179 SourceLocation EndLoc) {
2180 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2181 LParenLoc, EndLoc);
2182 }
2183
2184 /// Build a new OpenMP 'grainsize' clause.
2185 ///
2186 /// By default, performs semantic analysis to build the new statement.
2187 /// Subclasses may override this routine to provide different behavior.
2189 Expr *Device, SourceLocation StartLoc,
2190 SourceLocation LParenLoc,
2191 SourceLocation ModifierLoc,
2192 SourceLocation EndLoc) {
2194 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2195 }
2196
2197 /// Build a new OpenMP 'num_tasks' clause.
2198 ///
2199 /// By default, performs semantic analysis to build the new statement.
2200 /// Subclasses may override this routine to provide different behavior.
2202 Expr *NumTasks, SourceLocation StartLoc,
2203 SourceLocation LParenLoc,
2204 SourceLocation ModifierLoc,
2205 SourceLocation EndLoc) {
2207 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2208 }
2209
2210 /// Build a new OpenMP 'hint' clause.
2211 ///
2212 /// By default, performs semantic analysis to build the new statement.
2213 /// Subclasses may override this routine to provide different behavior.
2215 SourceLocation LParenLoc,
2216 SourceLocation EndLoc) {
2217 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2218 EndLoc);
2219 }
2220
2221 /// Build a new OpenMP 'detach' clause.
2222 ///
2223 /// By default, performs semantic analysis to build the new statement.
2224 /// Subclasses may override this routine to provide different behavior.
2226 SourceLocation LParenLoc,
2227 SourceLocation EndLoc) {
2228 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2229 EndLoc);
2230 }
2231
2232 /// Build a new OpenMP 'dist_schedule' clause.
2233 ///
2234 /// By default, performs semantic analysis to build the new OpenMP clause.
2235 /// Subclasses may override this routine to provide different behavior.
2236 OMPClause *
2238 Expr *ChunkSize, SourceLocation StartLoc,
2239 SourceLocation LParenLoc, SourceLocation KindLoc,
2240 SourceLocation CommaLoc, SourceLocation EndLoc) {
2242 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2243 }
2244
2245 /// Build a new OpenMP 'to' clause.
2246 ///
2247 /// By default, performs semantic analysis to build the new statement.
2248 /// Subclasses may override this routine to provide different behavior.
2249 OMPClause *
2251 ArrayRef<SourceLocation> MotionModifiersLoc,
2252 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2253 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2254 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2255 ArrayRef<Expr *> UnresolvedMappers) {
2257 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2258 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2259 UnresolvedMappers);
2260 }
2261
2262 /// Build a new OpenMP 'from' clause.
2263 ///
2264 /// By default, performs semantic analysis to build the new statement.
2265 /// Subclasses may override this routine to provide different behavior.
2266 OMPClause *
2268 ArrayRef<SourceLocation> MotionModifiersLoc,
2269 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2270 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2271 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2272 ArrayRef<Expr *> UnresolvedMappers) {
2274 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2275 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2276 UnresolvedMappers);
2277 }
2278
2279 /// Build a new OpenMP 'use_device_ptr' clause.
2280 ///
2281 /// By default, performs semantic analysis to build the new OpenMP clause.
2282 /// Subclasses may override this routine to provide different behavior.
2284 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2285 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
2286 SourceLocation FallbackModifierLoc) {
2288 VarList, Locs, FallbackModifier, FallbackModifierLoc);
2289 }
2290
2291 /// Build a new OpenMP 'use_device_addr' clause.
2292 ///
2293 /// By default, performs semantic analysis to build the new OpenMP clause.
2294 /// Subclasses may override this routine to provide different behavior.
2299
2300 /// Build a new OpenMP 'is_device_ptr' clause.
2301 ///
2302 /// By default, performs semantic analysis to build the new OpenMP clause.
2303 /// Subclasses may override this routine to provide different behavior.
2305 const OMPVarListLocTy &Locs) {
2306 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2307 }
2308
2309 /// Build a new OpenMP 'has_device_addr' clause.
2310 ///
2311 /// By default, performs semantic analysis to build the new OpenMP clause.
2312 /// Subclasses may override this routine to provide different behavior.
2317
2318 /// Build a new OpenMP 'defaultmap' clause.
2319 ///
2320 /// By default, performs semantic analysis to build the new OpenMP clause.
2321 /// Subclasses may override this routine to provide different behavior.
2324 SourceLocation StartLoc,
2325 SourceLocation LParenLoc,
2326 SourceLocation MLoc,
2327 SourceLocation KindLoc,
2328 SourceLocation EndLoc) {
2330 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2331 }
2332
2333 /// Build a new OpenMP 'nontemporal' clause.
2334 ///
2335 /// By default, performs semantic analysis to build the new OpenMP clause.
2336 /// Subclasses may override this routine to provide different behavior.
2338 SourceLocation StartLoc,
2339 SourceLocation LParenLoc,
2340 SourceLocation EndLoc) {
2341 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2342 LParenLoc, EndLoc);
2343 }
2344
2345 /// Build a new OpenMP 'inclusive' clause.
2346 ///
2347 /// By default, performs semantic analysis to build the new OpenMP clause.
2348 /// Subclasses may override this routine to provide different behavior.
2350 SourceLocation StartLoc,
2351 SourceLocation LParenLoc,
2352 SourceLocation EndLoc) {
2353 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2354 LParenLoc, EndLoc);
2355 }
2356
2357 /// Build a new OpenMP 'exclusive' clause.
2358 ///
2359 /// By default, performs semantic analysis to build the new OpenMP clause.
2360 /// Subclasses may override this routine to provide different behavior.
2362 SourceLocation StartLoc,
2363 SourceLocation LParenLoc,
2364 SourceLocation EndLoc) {
2365 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2366 LParenLoc, EndLoc);
2367 }
2368
2369 /// Build a new OpenMP 'uses_allocators' clause.
2370 ///
2371 /// By default, performs semantic analysis to build the new OpenMP clause.
2372 /// Subclasses may override this routine to provide different behavior.
2379
2380 /// Build a new OpenMP 'affinity' clause.
2381 ///
2382 /// By default, performs semantic analysis to build the new OpenMP clause.
2383 /// Subclasses may override this routine to provide different behavior.
2385 SourceLocation LParenLoc,
2386 SourceLocation ColonLoc,
2387 SourceLocation EndLoc, Expr *Modifier,
2388 ArrayRef<Expr *> Locators) {
2390 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2391 }
2392
2393 /// Build a new OpenMP 'order' clause.
2394 ///
2395 /// By default, performs semantic analysis to build the new OpenMP clause.
2396 /// Subclasses may override this routine to provide different behavior.
2398 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2399 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2400 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2402 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2403 }
2404
2405 /// Build a new OpenMP 'init' clause.
2406 ///
2407 /// By default, performs semantic analysis to build the new OpenMP clause.
2408 /// Subclasses may override this routine to provide different behavior.
2410 SourceLocation StartLoc,
2411 SourceLocation LParenLoc,
2412 SourceLocation VarLoc,
2413 SourceLocation EndLoc) {
2415 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2416 }
2417
2418 /// Build a new OpenMP 'use' clause.
2419 ///
2420 /// By default, performs semantic analysis to build the new OpenMP clause.
2421 /// Subclasses may override this routine to provide different behavior.
2423 SourceLocation LParenLoc,
2424 SourceLocation VarLoc, SourceLocation EndLoc) {
2425 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2426 LParenLoc, VarLoc, EndLoc);
2427 }
2428
2429 /// Build a new OpenMP 'destroy' clause.
2430 ///
2431 /// By default, performs semantic analysis to build the new OpenMP clause.
2432 /// Subclasses may override this routine to provide different behavior.
2434 SourceLocation LParenLoc,
2435 SourceLocation VarLoc,
2436 SourceLocation EndLoc) {
2438 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2439 }
2440
2441 /// Build a new OpenMP 'novariants' clause.
2442 ///
2443 /// By default, performs semantic analysis to build the new OpenMP clause.
2444 /// Subclasses may override this routine to provide different behavior.
2446 SourceLocation StartLoc,
2447 SourceLocation LParenLoc,
2448 SourceLocation EndLoc) {
2450 LParenLoc, EndLoc);
2451 }
2452
2453 /// Build a new OpenMP 'nocontext' clause.
2454 ///
2455 /// By default, performs semantic analysis to build the new OpenMP clause.
2456 /// Subclasses may override this routine to provide different behavior.
2458 SourceLocation LParenLoc,
2459 SourceLocation EndLoc) {
2461 LParenLoc, EndLoc);
2462 }
2463
2464 /// Build a new OpenMP 'filter' clause.
2465 ///
2466 /// By default, performs semantic analysis to build the new OpenMP clause.
2467 /// Subclasses may override this routine to provide different behavior.
2469 SourceLocation LParenLoc,
2470 SourceLocation EndLoc) {
2471 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2472 LParenLoc, EndLoc);
2473 }
2474
2475 /// Build a new OpenMP 'bind' clause.
2476 ///
2477 /// By default, performs semantic analysis to build the new OpenMP clause.
2478 /// Subclasses may override this routine to provide different behavior.
2480 SourceLocation KindLoc,
2481 SourceLocation StartLoc,
2482 SourceLocation LParenLoc,
2483 SourceLocation EndLoc) {
2484 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2485 LParenLoc, EndLoc);
2486 }
2487
2488 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2489 ///
2490 /// By default, performs semantic analysis to build the new OpenMP clause.
2491 /// Subclasses may override this routine to provide different behavior.
2493 SourceLocation LParenLoc,
2494 SourceLocation EndLoc) {
2495 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2496 LParenLoc, EndLoc);
2497 }
2498
2499 /// Build a new OpenMP 'dyn_groupprivate' clause.
2500 ///
2501 /// By default, performs semantic analysis to build the new OpenMP clause.
2502 /// Subclasses may override this routine to provide different behavior.
2506 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
2507 SourceLocation M2Loc, SourceLocation EndLoc) {
2509 M1, M2, Size, StartLoc, LParenLoc, M1Loc, M2Loc, EndLoc);
2510 }
2511
2512 /// Build a new OpenMP 'ompx_attribute' clause.
2513 ///
2514 /// By default, performs semantic analysis to build the new OpenMP clause.
2515 /// Subclasses may override this routine to provide different behavior.
2517 SourceLocation StartLoc,
2518 SourceLocation LParenLoc,
2519 SourceLocation EndLoc) {
2520 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2521 LParenLoc, EndLoc);
2522 }
2523
2524 /// Build a new OpenMP 'ompx_bare' clause.
2525 ///
2526 /// By default, performs semantic analysis to build the new OpenMP clause.
2527 /// Subclasses may override this routine to provide different behavior.
2529 SourceLocation EndLoc) {
2530 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2531 }
2532
2533 /// Build a new OpenMP 'align' clause.
2534 ///
2535 /// By default, performs semantic analysis to build the new OpenMP clause.
2536 /// Subclasses may override this routine to provide different behavior.
2538 SourceLocation LParenLoc,
2539 SourceLocation EndLoc) {
2540 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2541 EndLoc);
2542 }
2543
2544 /// Build a new OpenMP 'at' clause.
2545 ///
2546 /// By default, performs semantic analysis to build the new OpenMP clause.
2547 /// Subclasses may override this routine to provide different behavior.
2549 SourceLocation StartLoc,
2550 SourceLocation LParenLoc,
2551 SourceLocation EndLoc) {
2552 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2553 LParenLoc, EndLoc);
2554 }
2555
2556 /// Build a new OpenMP 'severity' clause.
2557 ///
2558 /// By default, performs semantic analysis to build the new OpenMP clause.
2559 /// Subclasses may override this routine to provide different behavior.
2561 SourceLocation KwLoc,
2562 SourceLocation StartLoc,
2563 SourceLocation LParenLoc,
2564 SourceLocation EndLoc) {
2565 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2566 LParenLoc, EndLoc);
2567 }
2568
2569 /// Build a new OpenMP 'message' clause.
2570 ///
2571 /// By default, performs semantic analysis to build the new OpenMP clause.
2572 /// Subclasses may override this routine to provide different behavior.
2574 SourceLocation LParenLoc,
2575 SourceLocation EndLoc) {
2576 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2577 EndLoc);
2578 }
2579
2580 /// Build a new OpenMP 'doacross' clause.
2581 ///
2582 /// By default, performs semantic analysis to build the new OpenMP clause.
2583 /// Subclasses may override this routine to provide different behavior.
2584 OMPClause *
2586 SourceLocation DepLoc, SourceLocation ColonLoc,
2587 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2588 SourceLocation LParenLoc, SourceLocation EndLoc) {
2590 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2591 }
2592
2593 /// Build a new OpenMP 'holds' clause.
2595 SourceLocation LParenLoc,
2596 SourceLocation EndLoc) {
2597 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2598 EndLoc);
2599 }
2600
2601 /// Rebuild the operand to an Objective-C \@synchronized statement.
2602 ///
2603 /// By default, performs semantic analysis to build the new statement.
2604 /// Subclasses may override this routine to provide different behavior.
2609
2610 /// Build a new Objective-C \@synchronized statement.
2611 ///
2612 /// By default, performs semantic analysis to build the new statement.
2613 /// Subclasses may override this routine to provide different behavior.
2618
2619 /// Build a new Objective-C \@autoreleasepool statement.
2620 ///
2621 /// By default, performs semantic analysis to build the new statement.
2622 /// Subclasses may override this routine to provide different behavior.
2627
2628 /// Build a new Objective-C fast enumeration statement.
2629 ///
2630 /// By default, performs semantic analysis to build the new statement.
2631 /// Subclasses may override this routine to provide different behavior.
2633 Stmt *Element,
2634 Expr *Collection,
2635 SourceLocation RParenLoc,
2636 Stmt *Body) {
2638 ForLoc, Element, Collection, RParenLoc);
2639 if (ForEachStmt.isInvalid())
2640 return StmtError();
2641
2642 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2643 Body);
2644 }
2645
2646 /// Build a new C++ exception declaration.
2647 ///
2648 /// By default, performs semantic analysis to build the new decaration.
2649 /// Subclasses may override this routine to provide different behavior.
2652 SourceLocation StartLoc,
2653 SourceLocation IdLoc,
2654 IdentifierInfo *Id) {
2656 StartLoc, IdLoc, Id);
2657 if (Var)
2658 getSema().CurContext->addDecl(Var);
2659 return Var;
2660 }
2661
2662 /// Build a new C++ catch statement.
2663 ///
2664 /// By default, performs semantic analysis to build the new statement.
2665 /// Subclasses may override this routine to provide different behavior.
2667 VarDecl *ExceptionDecl,
2668 Stmt *Handler) {
2669 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2670 Handler));
2671 }
2672
2673 /// Build a new C++ try statement.
2674 ///
2675 /// By default, performs semantic analysis to build the new statement.
2676 /// Subclasses may override this routine to provide different behavior.
2678 ArrayRef<Stmt *> Handlers) {
2679 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2680 }
2681
2682 /// Build a new C++0x range-based for statement.
2683 ///
2684 /// By default, performs semantic analysis to build the new statement.
2685 /// Subclasses may override this routine to provide different behavior.
2687 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2688 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2689 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2690 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2691 // If we've just learned that the range is actually an Objective-C
2692 // collection, treat this as an Objective-C fast enumeration loop.
2693 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2694 if (RangeStmt->isSingleDecl()) {
2695 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2696 if (RangeVar->isInvalidDecl())
2697 return StmtError();
2698
2699 Expr *RangeExpr = RangeVar->getInit();
2700 if (!RangeExpr->isTypeDependent() &&
2701 RangeExpr->getType()->isObjCObjectPointerType()) {
2702 // FIXME: Support init-statements in Objective-C++20 ranged for
2703 // statement.
2704 if (Init) {
2705 return SemaRef.Diag(Init->getBeginLoc(),
2706 diag::err_objc_for_range_init_stmt)
2707 << Init->getSourceRange();
2708 }
2710 ForLoc, LoopVar, RangeExpr, RParenLoc);
2711 }
2712 }
2713 }
2714 }
2715
2717 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2718 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2719 }
2720
2721 /// Build a new C++0x range-based for statement.
2722 ///
2723 /// By default, performs semantic analysis to build the new statement.
2724 /// Subclasses may override this routine to provide different behavior.
2726 bool IsIfExists,
2727 NestedNameSpecifierLoc QualifierLoc,
2728 DeclarationNameInfo NameInfo,
2729 Stmt *Nested) {
2730 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2731 QualifierLoc, NameInfo, Nested);
2732 }
2733
2734 /// Attach body to a C++0x range-based for statement.
2735 ///
2736 /// By default, performs semantic analysis to finish the new statement.
2737 /// Subclasses may override this routine to provide different behavior.
2739 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2740 }
2741
2743 Stmt *TryBlock, Stmt *Handler) {
2744 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2745 }
2746
2748 Stmt *Block) {
2749 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2750 }
2751
2753 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2754 }
2755
2757 SourceLocation LParen,
2758 SourceLocation RParen,
2759 TypeSourceInfo *TSI) {
2760 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2761 TSI);
2762 }
2763
2764 /// Build a new predefined expression.
2765 ///
2766 /// By default, performs semantic analysis to build the new expression.
2767 /// Subclasses may override this routine to provide different behavior.
2771
2772 /// Build a new expression that references a declaration.
2773 ///
2774 /// By default, performs semantic analysis to build the new expression.
2775 /// Subclasses may override this routine to provide different behavior.
2777 LookupResult &R,
2778 bool RequiresADL) {
2779 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2780 }
2781
2782
2783 /// Build a new expression that references a declaration.
2784 ///
2785 /// By default, performs semantic analysis to build the new expression.
2786 /// Subclasses may override this routine to provide different behavior.
2788 ValueDecl *VD,
2789 const DeclarationNameInfo &NameInfo,
2791 TemplateArgumentListInfo *TemplateArgs) {
2792 CXXScopeSpec SS;
2793 SS.Adopt(QualifierLoc);
2794 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2795 TemplateArgs);
2796 }
2797
2798 /// Build a new expression in parentheses.
2799 ///
2800 /// By default, performs semantic analysis to build the new expression.
2801 /// Subclasses may override this routine to provide different behavior.
2803 SourceLocation RParen) {
2804 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2805 }
2806
2807 /// Build a new pseudo-destructor expression.
2808 ///
2809 /// By default, performs semantic analysis to build the new expression.
2810 /// Subclasses may override this routine to provide different behavior.
2812 SourceLocation OperatorLoc,
2813 bool isArrow,
2814 CXXScopeSpec &SS,
2815 TypeSourceInfo *ScopeType,
2816 SourceLocation CCLoc,
2817 SourceLocation TildeLoc,
2818 PseudoDestructorTypeStorage Destroyed);
2819
2820 /// Build a new unary operator expression.
2821 ///
2822 /// By default, performs semantic analysis to build the new expression.
2823 /// Subclasses may override this routine to provide different behavior.
2826 Expr *SubExpr) {
2827 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2828 }
2829
2830 /// Build a new builtin offsetof expression.
2831 ///
2832 /// By default, performs semantic analysis to build the new expression.
2833 /// Subclasses may override this routine to provide different behavior.
2835 TypeSourceInfo *Type, const Designation &Desig,
2836 SourceLocation RParenLoc) {
2837 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Desig, RParenLoc);
2838 }
2839
2840 /// Build a new sizeof, alignof or vec_step expression with a
2841 /// type argument.
2842 ///
2843 /// By default, performs semantic analysis to build the new expression.
2844 /// Subclasses may override this routine to provide different behavior.
2846 SourceLocation OpLoc,
2847 UnaryExprOrTypeTrait ExprKind,
2848 SourceRange R) {
2849 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2850 }
2851
2852 /// Build a new sizeof, alignof or vec step expression with an
2853 /// expression argument.
2854 ///
2855 /// By default, performs semantic analysis to build the new expression.
2856 /// Subclasses may override this routine to provide different behavior.
2858 UnaryExprOrTypeTrait ExprKind,
2859 SourceRange R) {
2861 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2862 if (Result.isInvalid())
2863 return ExprError();
2864
2865 return Result;
2866 }
2867
2868 /// Build a new array subscript expression.
2869 ///
2870 /// By default, performs semantic analysis to build the new expression.
2871 /// Subclasses may override this routine to provide different behavior.
2873 SourceLocation LBracketLoc,
2874 Expr *RHS,
2875 SourceLocation RBracketLoc) {
2876 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2877 LBracketLoc, RHS,
2878 RBracketLoc);
2879 }
2880
2881 /// Build a new matrix single subscript expression.
2882 ///
2883 /// By default, performs semantic analysis to build the new expression.
2884 /// Subclasses may override this routine to provide different behavior.
2886 SourceLocation RBracketLoc) {
2888 RBracketLoc);
2889 }
2890
2891 /// Build a new matrix subscript expression.
2892 ///
2893 /// By default, performs semantic analysis to build the new expression.
2894 /// Subclasses may override this routine to provide different behavior.
2896 Expr *ColumnIdx,
2897 SourceLocation RBracketLoc) {
2898 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2899 RBracketLoc);
2900 }
2901
2902 /// Build a new array section expression.
2903 ///
2904 /// By default, performs semantic analysis to build the new expression.
2905 /// Subclasses may override this routine to provide different behavior.
2907 SourceLocation LBracketLoc,
2908 Expr *LowerBound,
2909 SourceLocation ColonLocFirst,
2910 SourceLocation ColonLocSecond,
2911 Expr *Length, Expr *Stride,
2912 SourceLocation RBracketLoc) {
2913 if (IsOMPArraySection)
2915 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2916 Stride, RBracketLoc);
2917
2918 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2919 "Stride/second colon not allowed for OpenACC");
2920
2922 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2923 }
2924
2925 /// Build a new array shaping expression.
2926 ///
2927 /// By default, performs semantic analysis to build the new expression.
2928 /// Subclasses may override this routine to provide different behavior.
2930 SourceLocation RParenLoc,
2931 ArrayRef<Expr *> Dims,
2932 ArrayRef<SourceRange> BracketsRanges) {
2934 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2935 }
2936
2937 /// Build a new iterator expression.
2938 ///
2939 /// By default, performs semantic analysis to build the new expression.
2940 /// Subclasses may override this routine to provide different behavior.
2943 SourceLocation RLoc,
2946 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2947 }
2948
2949 /// Build a new call expression.
2950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
2954 MultiExprArg Args,
2955 SourceLocation RParenLoc,
2956 Expr *ExecConfig = nullptr) {
2957 return getSema().ActOnCallExpr(
2958 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2959 }
2960
2962 MultiExprArg Args,
2963 SourceLocation RParenLoc) {
2965 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2966 }
2967
2968 /// Build a new member access expression.
2969 ///
2970 /// By default, performs semantic analysis to build the new expression.
2971 /// Subclasses may override this routine to provide different behavior.
2973 bool isArrow,
2974 NestedNameSpecifierLoc QualifierLoc,
2975 SourceLocation TemplateKWLoc,
2976 const DeclarationNameInfo &MemberNameInfo,
2978 NamedDecl *FoundDecl,
2979 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2980 NamedDecl *FirstQualifierInScope) {
2982 isArrow);
2983 if (!Member->getDeclName()) {
2984 // We have a reference to an unnamed field. This is always the
2985 // base of an anonymous struct/union member access, i.e. the
2986 // field is always of record type.
2987 assert(Member->getType()->isRecordType() &&
2988 "unnamed member not of record type?");
2989
2990 BaseResult =
2992 QualifierLoc.getNestedNameSpecifier(),
2993 FoundDecl, Member);
2994 if (BaseResult.isInvalid())
2995 return ExprError();
2996 Base = BaseResult.get();
2997
2998 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2999 // from the AST, so we need to re-insert them if needed (since
3000 // `BuildFieldRefereneExpr()` doesn't do this).
3001 if (!isArrow && Base->isPRValue()) {
3003 if (BaseResult.isInvalid())
3004 return ExprError();
3005 Base = BaseResult.get();
3006 }
3007
3008 CXXScopeSpec EmptySS;
3010 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
3011 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
3012 MemberNameInfo);
3013 }
3014
3015 CXXScopeSpec SS;
3016 SS.Adopt(QualifierLoc);
3017
3018 Base = BaseResult.get();
3019 if (Base->containsErrors())
3020 return ExprError();
3021
3022 QualType BaseType = Base->getType();
3023
3024 if (isArrow && !BaseType->isPointerType())
3025 return ExprError();
3026
3027 // FIXME: this involves duplicating earlier analysis in a lot of
3028 // cases; we should avoid this when possible.
3029 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
3030 R.addDecl(FoundDecl);
3031 R.resolveKind();
3032
3033 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
3035 if (auto *ThisClass = cast<CXXThisExpr>(Base)
3036 ->getType()
3037 ->getPointeeType()
3038 ->getAsCXXRecordDecl()) {
3039 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
3040 // In unevaluated contexts, an expression supposed to be a member access
3041 // might reference a member in an unrelated class.
3042 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
3043 return getSema().BuildDeclRefExpr(Member, Member->getType(),
3044 VK_LValue, Member->getLocation());
3045 }
3046 }
3047
3048 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
3049 SS, TemplateKWLoc,
3050 FirstQualifierInScope,
3051 R, ExplicitTemplateArgs,
3052 /*S*/nullptr);
3053 }
3054
3055 /// Build a new binary operator expression.
3056 ///
3057 /// By default, performs semantic analysis to build the new expression.
3058 /// Subclasses may override this routine to provide different behavior.
3060 Expr *LHS, Expr *RHS,
3061 bool ForFoldExpression = false) {
3062 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
3063 ForFoldExpression);
3064 }
3065
3066 /// Build a new rewritten operator expression.
3067 ///
3068 /// By default, performs semantic analysis to build the new expression.
3069 /// Subclasses may override this routine to provide different behavior.
3071 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3072 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3073 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3074 RHS, /*RequiresADL*/false);
3075 }
3076
3077 /// Build a new conditional operator expression.
3078 ///
3079 /// By default, performs semantic analysis to build the new expression.
3080 /// Subclasses may override this routine to provide different behavior.
3082 SourceLocation QuestionLoc,
3083 Expr *LHS,
3084 SourceLocation ColonLoc,
3085 Expr *RHS) {
3086 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3087 LHS, RHS);
3088 }
3089
3090 /// Build a new C-style cast expression.
3091 ///
3092 /// By default, performs semantic analysis to build the new expression.
3093 /// Subclasses may override this routine to provide different behavior.
3095 TypeSourceInfo *TInfo,
3096 SourceLocation RParenLoc,
3097 Expr *SubExpr) {
3098 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3099 SubExpr);
3100 }
3101
3102 /// Build a new compound literal expression.
3103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
3107 TypeSourceInfo *TInfo,
3108 SourceLocation RParenLoc,
3109 Expr *Init) {
3110 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3111 Init);
3112 }
3113
3114 /// Build a new extended vector or matrix element access expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3119 SourceLocation OpLoc,
3120 bool IsArrow,
3121 SourceLocation AccessorLoc,
3122 IdentifierInfo &Accessor) {
3123
3124 CXXScopeSpec SS;
3125 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3127 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3128 /*FirstQualifierInScope*/ nullptr, NameInfo,
3129 /* TemplateArgs */ nullptr,
3130 /*S*/ nullptr);
3131 }
3132
3133 /// Build a new initializer list expression.
3134 ///
3135 /// By default, performs semantic analysis to build the new expression.
3136 /// Subclasses may override this routine to provide different behavior.
3138 SourceLocation RBraceLoc, bool IsExplicit) {
3139 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc, IsExplicit);
3140 }
3141
3142 /// Build a new designated initializer expression.
3143 ///
3144 /// By default, performs semantic analysis to build the new expression.
3145 /// Subclasses may override this routine to provide different behavior.
3147 MultiExprArg ArrayExprs,
3148 SourceLocation EqualOrColonLoc,
3149 bool GNUSyntax,
3150 Expr *Init) {
3152 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3153 Init);
3154 if (Result.isInvalid())
3155 return ExprError();
3156
3157 return Result;
3158 }
3159
3160 /// Build a new value-initialized expression.
3161 ///
3162 /// By default, builds the implicit value initialization without performing
3163 /// any semantic analysis. Subclasses may override this routine to provide
3164 /// different behavior.
3168
3169 /// Build a new \c va_arg expression.
3170 ///
3171 /// By default, performs semantic analysis to build the new expression.
3172 /// Subclasses may override this routine to provide different behavior.
3174 Expr *SubExpr, TypeSourceInfo *TInfo,
3175 SourceLocation RParenLoc) {
3176 return getSema().BuildVAArgExpr(BuiltinLoc,
3177 SubExpr, TInfo,
3178 RParenLoc);
3179 }
3180
3181 /// Build a new expression list in parentheses.
3182 ///
3183 /// By default, performs semantic analysis to build the new expression.
3184 /// Subclasses may override this routine to provide different behavior.
3186 MultiExprArg SubExprs,
3187 SourceLocation RParenLoc) {
3188 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3189 }
3190
3192 unsigned NumUserSpecifiedExprs,
3193 SourceLocation InitLoc,
3194 SourceLocation LParenLoc,
3195 SourceLocation RParenLoc) {
3196 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3197 InitLoc, LParenLoc, RParenLoc);
3198 }
3199
3200 /// Build a new address-of-label expression.
3201 ///
3202 /// By default, performs semantic analysis, using the name of the label
3203 /// rather than attempting to map the label statement itself.
3204 /// Subclasses may override this routine to provide different behavior.
3206 SourceLocation LabelLoc, LabelDecl *Label) {
3207 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3208 }
3209
3210 /// Build a new GNU statement expression.
3211 ///
3212 /// By default, performs semantic analysis to build the new expression.
3213 /// Subclasses may override this routine to provide different behavior.
3215 SourceLocation RParenLoc, unsigned TemplateDepth) {
3216 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3217 TemplateDepth);
3218 }
3219
3220 /// Build a new __builtin_choose_expr expression.
3221 ///
3222 /// By default, performs semantic analysis to build the new expression.
3223 /// Subclasses may override this routine to provide different behavior.
3225 Expr *Cond, Expr *LHS, Expr *RHS,
3226 SourceLocation RParenLoc) {
3227 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3228 Cond, LHS, RHS,
3229 RParenLoc);
3230 }
3231
3232 /// Build a new generic selection expression with an expression predicate.
3233 ///
3234 /// By default, performs semantic analysis to build the new expression.
3235 /// Subclasses may override this routine to provide different behavior.
3237 SourceLocation DefaultLoc,
3238 SourceLocation RParenLoc,
3239 Expr *ControllingExpr,
3241 ArrayRef<Expr *> Exprs) {
3242 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3243 /*PredicateIsExpr=*/true,
3244 ControllingExpr, Types, Exprs);
3245 }
3246
3247 /// Build a new generic selection expression with a type predicate.
3248 ///
3249 /// By default, performs semantic analysis to build the new expression.
3250 /// Subclasses may override this routine to provide different behavior.
3252 SourceLocation DefaultLoc,
3253 SourceLocation RParenLoc,
3254 TypeSourceInfo *ControllingType,
3256 ArrayRef<Expr *> Exprs) {
3257 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3258 /*PredicateIsExpr=*/false,
3259 ControllingType, Types, Exprs);
3260 }
3261
3262 /// Build a new overloaded operator call expression.
3263 ///
3264 /// By default, performs semantic analysis to build the new expression.
3265 /// The semantic analysis provides the behavior of template instantiation,
3266 /// copying with transformations that turn what looks like an overloaded
3267 /// operator call into a use of a builtin operator, performing
3268 /// argument-dependent lookup, etc. Subclasses may override this routine to
3269 /// provide different behavior.
3271 SourceLocation OpLoc,
3272 SourceLocation CalleeLoc,
3273 bool RequiresADL,
3274 const UnresolvedSetImpl &Functions,
3275 Expr *First, Expr *Second);
3276
3277 /// Build a new C++ "named" cast expression, such as static_cast or
3278 /// reinterpret_cast.
3279 ///
3280 /// By default, this routine dispatches to one of the more-specific routines
3281 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3282 /// Subclasses may override this routine to provide different behavior.
3285 SourceLocation LAngleLoc,
3286 TypeSourceInfo *TInfo,
3287 SourceLocation RAngleLoc,
3288 SourceLocation LParenLoc,
3289 Expr *SubExpr,
3290 SourceLocation RParenLoc) {
3291 switch (Class) {
3292 case Stmt::CXXStaticCastExprClass:
3293 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3294 RAngleLoc, LParenLoc,
3295 SubExpr, RParenLoc);
3296
3297 case Stmt::CXXDynamicCastExprClass:
3298 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3299 RAngleLoc, LParenLoc,
3300 SubExpr, RParenLoc);
3301
3302 case Stmt::CXXReinterpretCastExprClass:
3303 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3304 RAngleLoc, LParenLoc,
3305 SubExpr,
3306 RParenLoc);
3307
3308 case Stmt::CXXConstCastExprClass:
3309 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3310 RAngleLoc, LParenLoc,
3311 SubExpr, RParenLoc);
3312
3313 case Stmt::CXXAddrspaceCastExprClass:
3314 return getDerived().RebuildCXXAddrspaceCastExpr(
3315 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3316
3317 default:
3318 llvm_unreachable("Invalid C++ named cast");
3319 }
3320 }
3321
3322 /// Build a new C++ static_cast expression.
3323 ///
3324 /// By default, performs semantic analysis to build the new expression.
3325 /// Subclasses may override this routine to provide different behavior.
3327 SourceLocation LAngleLoc,
3328 TypeSourceInfo *TInfo,
3329 SourceLocation RAngleLoc,
3330 SourceLocation LParenLoc,
3331 Expr *SubExpr,
3332 SourceLocation RParenLoc) {
3333 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3334 TInfo, SubExpr,
3335 SourceRange(LAngleLoc, RAngleLoc),
3336 SourceRange(LParenLoc, RParenLoc));
3337 }
3338
3339 /// Build a new C++ dynamic_cast expression.
3340 ///
3341 /// By default, performs semantic analysis to build the new expression.
3342 /// Subclasses may override this routine to provide different behavior.
3344 SourceLocation LAngleLoc,
3345 TypeSourceInfo *TInfo,
3346 SourceLocation RAngleLoc,
3347 SourceLocation LParenLoc,
3348 Expr *SubExpr,
3349 SourceLocation RParenLoc) {
3350 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3351 TInfo, SubExpr,
3352 SourceRange(LAngleLoc, RAngleLoc),
3353 SourceRange(LParenLoc, RParenLoc));
3354 }
3355
3356 /// Build a new C++ reinterpret_cast expression.
3357 ///
3358 /// By default, performs semantic analysis to build the new expression.
3359 /// Subclasses may override this routine to provide different behavior.
3361 SourceLocation LAngleLoc,
3362 TypeSourceInfo *TInfo,
3363 SourceLocation RAngleLoc,
3364 SourceLocation LParenLoc,
3365 Expr *SubExpr,
3366 SourceLocation RParenLoc) {
3367 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3368 TInfo, SubExpr,
3369 SourceRange(LAngleLoc, RAngleLoc),
3370 SourceRange(LParenLoc, RParenLoc));
3371 }
3372
3373 /// Build a new C++ const_cast expression.
3374 ///
3375 /// By default, performs semantic analysis to build the new expression.
3376 /// Subclasses may override this routine to provide different behavior.
3378 SourceLocation LAngleLoc,
3379 TypeSourceInfo *TInfo,
3380 SourceLocation RAngleLoc,
3381 SourceLocation LParenLoc,
3382 Expr *SubExpr,
3383 SourceLocation RParenLoc) {
3384 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3385 TInfo, SubExpr,
3386 SourceRange(LAngleLoc, RAngleLoc),
3387 SourceRange(LParenLoc, RParenLoc));
3388 }
3389
3392 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3393 SourceLocation LParenLoc, Expr *SubExpr,
3394 SourceLocation RParenLoc) {
3395 return getSema().BuildCXXNamedCast(
3396 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3397 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3398 }
3399
3400 /// Build a new C++ functional-style 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 LParenLoc,
3406 Expr *Sub,
3407 SourceLocation RParenLoc,
3408 bool ListInitialization) {
3409 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3410 // CXXParenListInitExpr. Pass its expanded arguments so that the
3411 // CXXParenListInitExpr can be rebuilt.
3412 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3414 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3415 RParenLoc, ListInitialization);
3416
3417 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3419 TInfo, LParenLoc, PLE->getUserSpecifiedInitExprs(), RParenLoc,
3420 ListInitialization);
3421
3422 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3423 MultiExprArg(&Sub, 1), RParenLoc,
3424 ListInitialization);
3425 }
3426
3427 /// Build a new C++ __builtin_bit_cast expression.
3428 ///
3429 /// By default, performs semantic analysis to build the new expression.
3430 /// Subclasses may override this routine to provide different behavior.
3432 TypeSourceInfo *TSI, Expr *Sub,
3433 SourceLocation RParenLoc) {
3434 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3435 }
3436
3437 /// Build a new C++ typeid(type) expression.
3438 ///
3439 /// By default, performs semantic analysis to build the new expression.
3440 /// Subclasses may override this routine to provide different behavior.
3442 SourceLocation TypeidLoc,
3443 TypeSourceInfo *Operand,
3444 SourceLocation RParenLoc) {
3445 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3446 RParenLoc);
3447 }
3448
3449
3450 /// Build a new C++ typeid(expr) expression.
3451 ///
3452 /// By default, performs semantic analysis to build the new expression.
3453 /// Subclasses may override this routine to provide different behavior.
3455 SourceLocation TypeidLoc,
3456 Expr *Operand,
3457 SourceLocation RParenLoc) {
3458 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3459 RParenLoc);
3460 }
3461
3462 /// Build a new C++ __uuidof(type) expression.
3463 ///
3464 /// By default, performs semantic analysis to build the new expression.
3465 /// Subclasses may override this routine to provide different behavior.
3467 TypeSourceInfo *Operand,
3468 SourceLocation RParenLoc) {
3469 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3470 }
3471
3472 /// Build a new C++ __uuidof(expr) expression.
3473 ///
3474 /// By default, performs semantic analysis to build the new expression.
3475 /// Subclasses may override this routine to provide different behavior.
3477 Expr *Operand, SourceLocation RParenLoc) {
3478 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3479 }
3480
3481 /// Build a new C++ "this" expression.
3482 ///
3483 /// By default, performs semantic analysis to build a new "this" expression.
3484 /// Subclasses may override this routine to provide different behavior.
3486 QualType ThisType,
3487 bool isImplicit) {
3488 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3489 return ExprError();
3490 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3491 }
3492
3493 /// Build a new C++ throw expression.
3494 ///
3495 /// By default, performs semantic analysis to build the new expression.
3496 /// Subclasses may override this routine to provide different behavior.
3498 bool IsThrownVariableInScope) {
3499 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3500 }
3501
3502 /// Build a new C++ default-argument expression.
3503 ///
3504 /// By default, builds a new default-argument expression, which does not
3505 /// require any semantic analysis. Subclasses may override this routine to
3506 /// provide different behavior.
3508 Expr *RewrittenExpr) {
3509 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3510 RewrittenExpr, getSema().CurContext);
3511 }
3512
3513 /// Build a new C++11 default-initialization expression.
3514 ///
3515 /// By default, builds a new default field initialization expression, which
3516 /// does not require any semantic analysis. Subclasses may override this
3517 /// routine to provide different behavior.
3522
3523 /// Build a new C++ zero-initialization expression.
3524 ///
3525 /// By default, performs semantic analysis to build the new expression.
3526 /// Subclasses may override this routine to provide different behavior.
3528 SourceLocation LParenLoc,
3529 SourceLocation RParenLoc) {
3530 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3531 /*ListInitialization=*/false);
3532 }
3533
3534 /// Build a new C++ "new" expression.
3535 ///
3536 /// By default, performs semantic analysis to build the new expression.
3537 /// Subclasses may override this routine to provide different behavior.
3539 SourceLocation PlacementLParen,
3540 MultiExprArg PlacementArgs,
3541 SourceLocation PlacementRParen,
3542 SourceRange TypeIdParens, QualType AllocatedType,
3543 TypeSourceInfo *AllocatedTypeInfo,
3544 std::optional<Expr *> ArraySize,
3545 SourceRange DirectInitRange, Expr *Initializer) {
3546 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3547 PlacementLParen,
3548 PlacementArgs,
3549 PlacementRParen,
3550 TypeIdParens,
3551 AllocatedType,
3552 AllocatedTypeInfo,
3553 ArraySize,
3554 DirectInitRange,
3555 Initializer);
3556 }
3557
3558 /// Build a new C++ "delete" expression.
3559 ///
3560 /// By default, performs semantic analysis to build the new expression.
3561 /// Subclasses may override this routine to provide different behavior.
3563 bool IsGlobalDelete,
3564 bool IsArrayForm,
3565 Expr *Operand) {
3566 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3567 Operand);
3568 }
3569
3570 /// Build a new type trait expression.
3571 ///
3572 /// By default, performs semantic analysis to build the new expression.
3573 /// Subclasses may override this routine to provide different behavior.
3575 SourceLocation StartLoc,
3577 SourceLocation RParenLoc) {
3578 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3579 }
3580
3581 /// Build a new array type trait expression.
3582 ///
3583 /// By default, performs semantic analysis to build the new expression.
3584 /// Subclasses may override this routine to provide different behavior.
3585 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
3586 SourceLocation StartLoc,
3587 TypeSourceInfo *TSInfo,
3588 Expr *DimExpr,
3589 SourceLocation RParenLoc) {
3590 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3591 }
3592
3593 /// Build a new expression trait expression.
3594 ///
3595 /// By default, performs semantic analysis to build the new expression.
3596 /// Subclasses may override this routine to provide different behavior.
3597 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
3598 SourceLocation StartLoc,
3599 Expr *Queried,
3600 SourceLocation RParenLoc) {
3601 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3602 }
3603
3604 /// Build a new (previously unresolved) declaration reference
3605 /// expression.
3606 ///
3607 /// By default, performs semantic analysis to build the new expression.
3608 /// Subclasses may override this routine to provide different behavior.
3610 NestedNameSpecifierLoc QualifierLoc,
3611 SourceLocation TemplateKWLoc,
3612 const DeclarationNameInfo &NameInfo,
3613 const TemplateArgumentListInfo *TemplateArgs,
3614 bool IsAddressOfOperand,
3615 TypeSourceInfo **RecoveryTSI) {
3616 CXXScopeSpec SS;
3617 SS.Adopt(QualifierLoc);
3618
3619 if (TemplateArgs || TemplateKWLoc.isValid())
3621 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3622
3624 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3625 }
3626
3627 /// Build a new template-id expression.
3628 ///
3629 /// By default, performs semantic analysis to build the new expression.
3630 /// Subclasses may override this routine to provide different behavior.
3632 SourceLocation TemplateKWLoc,
3633 LookupResult &R,
3634 bool RequiresADL,
3635 const TemplateArgumentListInfo *TemplateArgs) {
3636 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3637 TemplateArgs);
3638 }
3639
3640 /// Build a new object-construction expression.
3641 ///
3642 /// By default, performs semantic analysis to build the new expression.
3643 /// Subclasses may override this routine to provide different behavior.
3646 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3647 bool ListInitialization, bool StdInitListInitialization,
3648 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3649 SourceRange ParenRange) {
3650 // Reconstruct the constructor we originally found, which might be
3651 // different if this is a call to an inherited constructor.
3652 CXXConstructorDecl *FoundCtor = Constructor;
3653 if (Constructor->isInheritingConstructor())
3654 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3655
3656 SmallVector<Expr *, 8> ConvertedArgs;
3657 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3658 ConvertedArgs))
3659 return ExprError();
3660
3662 IsElidable,
3663 ConvertedArgs,
3664 HadMultipleCandidates,
3665 ListInitialization,
3666 StdInitListInitialization,
3667 RequiresZeroInit, ConstructKind,
3668 ParenRange);
3669 }
3670
3671 /// Build a new implicit construction via inherited constructor
3672 /// expression.
3675 bool ConstructsVBase,
3676 bool InheritedFromVBase) {
3678 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3679 }
3680
3681 /// Build a new object-construction expression.
3682 ///
3683 /// By default, performs semantic analysis to build the new expression.
3684 /// Subclasses may override this routine to provide different behavior.
3686 SourceLocation LParenOrBraceLoc,
3687 MultiExprArg Args,
3688 SourceLocation RParenOrBraceLoc,
3689 bool ListInitialization) {
3691 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3692 }
3693
3694 /// Build a new object-construction expression.
3695 ///
3696 /// By default, performs semantic analysis to build the new expression.
3697 /// Subclasses may override this routine to provide different behavior.
3699 SourceLocation LParenLoc,
3700 MultiExprArg Args,
3701 SourceLocation RParenLoc,
3702 bool ListInitialization) {
3703 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3704 RParenLoc, ListInitialization);
3705 }
3706
3707 /// Build a new member reference expression.
3708 ///
3709 /// By default, performs semantic analysis to build the new expression.
3710 /// Subclasses may override this routine to provide different behavior.
3712 QualType BaseType,
3713 bool IsArrow,
3714 SourceLocation OperatorLoc,
3715 NestedNameSpecifierLoc QualifierLoc,
3716 SourceLocation TemplateKWLoc,
3717 NamedDecl *FirstQualifierInScope,
3718 const DeclarationNameInfo &MemberNameInfo,
3719 const TemplateArgumentListInfo *TemplateArgs) {
3720 CXXScopeSpec SS;
3721 SS.Adopt(QualifierLoc);
3722
3723 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3724 OperatorLoc, IsArrow,
3725 SS, TemplateKWLoc,
3726 FirstQualifierInScope,
3727 MemberNameInfo,
3728 TemplateArgs, /*S*/nullptr);
3729 }
3730
3731 /// Build a new member reference expression.
3732 ///
3733 /// By default, performs semantic analysis to build the new expression.
3734 /// Subclasses may override this routine to provide different behavior.
3736 SourceLocation OperatorLoc,
3737 bool IsArrow,
3738 NestedNameSpecifierLoc QualifierLoc,
3739 SourceLocation TemplateKWLoc,
3740 NamedDecl *FirstQualifierInScope,
3741 LookupResult &R,
3742 const TemplateArgumentListInfo *TemplateArgs) {
3743 CXXScopeSpec SS;
3744 SS.Adopt(QualifierLoc);
3745
3746 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3747 OperatorLoc, IsArrow,
3748 SS, TemplateKWLoc,
3749 FirstQualifierInScope,
3750 R, TemplateArgs, /*S*/nullptr);
3751 }
3752
3753 /// Build a new noexcept expression.
3754 ///
3755 /// By default, performs semantic analysis to build the new expression.
3756 /// Subclasses may override this routine to provide different behavior.
3758 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3759 }
3760
3763
3764 /// Build a new expression to compute the length of a parameter pack.
3766 SourceLocation PackLoc,
3767 SourceLocation RParenLoc,
3768 UnsignedOrNone Length,
3769 ArrayRef<TemplateArgument> PartialArgs) {
3770 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3771 RParenLoc, Length, PartialArgs);
3772 }
3773
3775 SourceLocation RSquareLoc,
3776 Expr *PackIdExpression, Expr *IndexExpr,
3777 ArrayRef<Expr *> ExpandedExprs,
3778 bool FullySubstituted = false) {
3779 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3780 IndexExpr, RSquareLoc, ExpandedExprs,
3781 FullySubstituted);
3782 }
3783
3784 /// Build a new expression representing a call to a source location
3785 /// builtin.
3786 ///
3787 /// By default, performs semantic analysis to build the new expression.
3788 /// Subclasses may override this routine to provide different behavior.
3790 SourceLocation BuiltinLoc,
3791 SourceLocation RPLoc,
3792 DeclContext *ParentContext) {
3793 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3794 ParentContext);
3795 }
3796
3798 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3799 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3801 CXXScopeSpec SS;
3802 SS.Adopt(NNS);
3803 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3804 ConceptNameInfo,
3805 FoundDecl,
3806 NamedConcept, TALI);
3807 if (Result.isInvalid())
3808 return ExprError();
3809 return Result;
3810 }
3811
3812 /// \brief Build a new requires expression.
3813 ///
3814 /// By default, performs semantic analysis to build the new expression.
3815 /// Subclasses may override this routine to provide different behavior.
3818 SourceLocation LParenLoc,
3819 ArrayRef<ParmVarDecl *> LocalParameters,
3820 SourceLocation RParenLoc,
3822 SourceLocation ClosingBraceLoc) {
3823 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3824 LocalParameters, RParenLoc, Requirements,
3825 ClosingBraceLoc);
3826 }
3827
3831 return SemaRef.BuildTypeRequirement(SubstDiag);
3832 }
3833
3835 return SemaRef.BuildTypeRequirement(T);
3836 }
3837
3840 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3841 SourceLocation NoexceptLoc,
3843 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3844 std::move(Ret));
3845 }
3846
3848 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3850 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3851 std::move(Ret));
3852 }
3853
3855 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3856 const ASTConstraintSatisfaction &Satisfaction) {
3857 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3858 Satisfaction);
3859 }
3860
3862 return SemaRef.BuildNestedRequirement(Constraint);
3863 }
3864
3865 /// \brief Build a new Objective-C boxed expression.
3866 ///
3867 /// By default, performs semantic analysis to build the new expression.
3868 /// Subclasses may override this routine to provide different behavior.
3870 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3871 }
3872
3873 /// Build a new Objective-C array literal.
3874 ///
3875 /// By default, performs semantic analysis to build the new expression.
3876 /// Subclasses may override this routine to provide different behavior.
3878 Expr **Elements, unsigned NumElements) {
3880 Range, MultiExprArg(Elements, NumElements));
3881 }
3882
3884 Expr *Base, Expr *Key,
3885 ObjCMethodDecl *getterMethod,
3886 ObjCMethodDecl *setterMethod) {
3888 RB, Base, Key, getterMethod, setterMethod);
3889 }
3890
3891 /// Build a new Objective-C dictionary literal.
3892 ///
3893 /// By default, performs semantic analysis to build the new expression.
3894 /// Subclasses may override this routine to provide different behavior.
3899
3900 /// Build a new Objective-C \@encode expression.
3901 ///
3902 /// By default, performs semantic analysis to build the new expression.
3903 /// Subclasses may override this routine to provide different behavior.
3905 TypeSourceInfo *EncodeTypeInfo,
3906 SourceLocation RParenLoc) {
3907 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3908 RParenLoc);
3909 }
3910
3911 /// Build a new Objective-C class message.
3913 Selector Sel,
3914 ArrayRef<SourceLocation> SelectorLocs,
3916 SourceLocation LBracLoc,
3917 MultiExprArg Args,
3918 SourceLocation RBracLoc) {
3919 return SemaRef.ObjC().BuildClassMessage(
3920 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3921 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3922 RBracLoc, Args);
3923 }
3924
3925 /// Build a new Objective-C instance message.
3927 Selector Sel,
3928 ArrayRef<SourceLocation> SelectorLocs,
3930 SourceLocation LBracLoc,
3931 MultiExprArg Args,
3932 SourceLocation RBracLoc) {
3933 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3934 /*SuperLoc=*/SourceLocation(),
3935 Sel, Method, LBracLoc,
3936 SelectorLocs, RBracLoc, Args);
3937 }
3938
3939 /// Build a new Objective-C instance/class message to 'super'.
3941 Selector Sel,
3942 ArrayRef<SourceLocation> SelectorLocs,
3943 QualType SuperType,
3945 SourceLocation LBracLoc,
3946 MultiExprArg Args,
3947 SourceLocation RBracLoc) {
3948 return Method->isInstanceMethod()
3949 ? SemaRef.ObjC().BuildInstanceMessage(
3950 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3951 SelectorLocs, RBracLoc, Args)
3952 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3953 Sel, Method, LBracLoc,
3954 SelectorLocs, RBracLoc, Args);
3955 }
3956
3957 /// Build a new Objective-C ivar reference expression.
3958 ///
3959 /// By default, performs semantic analysis to build the new expression.
3960 /// Subclasses may override this routine to provide different behavior.
3962 SourceLocation IvarLoc,
3963 bool IsArrow, bool IsFreeIvar) {
3964 CXXScopeSpec SS;
3965 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3967 BaseArg, BaseArg->getType(),
3968 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3969 /*FirstQualifierInScope=*/nullptr, NameInfo,
3970 /*TemplateArgs=*/nullptr,
3971 /*S=*/nullptr);
3972 if (IsFreeIvar && Result.isUsable())
3973 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3974 return Result;
3975 }
3976
3977 /// Build a new Objective-C property reference expression.
3978 ///
3979 /// By default, performs semantic analysis to build the new expression.
3980 /// Subclasses may override this routine to provide different behavior.
3983 SourceLocation PropertyLoc) {
3984 CXXScopeSpec SS;
3985 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3986 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3987 /*FIXME:*/PropertyLoc,
3988 /*IsArrow=*/false,
3989 SS, SourceLocation(),
3990 /*FirstQualifierInScope=*/nullptr,
3991 NameInfo,
3992 /*TemplateArgs=*/nullptr,
3993 /*S=*/nullptr);
3994 }
3995
3996 /// Build a new Objective-C property reference expression.
3997 ///
3998 /// By default, performs semantic analysis to build the new expression.
3999 /// Subclasses may override this routine to provide different behavior.
4001 ObjCMethodDecl *Getter,
4002 ObjCMethodDecl *Setter,
4003 SourceLocation PropertyLoc) {
4004 // Since these expressions can only be value-dependent, we do not
4005 // need to perform semantic analysis again.
4006 return Owned(
4007 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
4009 PropertyLoc, Base));
4010 }
4011
4012 /// Build a new Objective-C "isa" expression.
4013 ///
4014 /// By default, performs semantic analysis to build the new expression.
4015 /// Subclasses may override this routine to provide different behavior.
4017 SourceLocation OpLoc, bool IsArrow) {
4018 CXXScopeSpec SS;
4019 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
4020 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4021 OpLoc, IsArrow,
4022 SS, SourceLocation(),
4023 /*FirstQualifierInScope=*/nullptr,
4024 NameInfo,
4025 /*TemplateArgs=*/nullptr,
4026 /*S=*/nullptr);
4027 }
4028
4029 /// Build a new shuffle vector expression.
4030 ///
4031 /// By default, performs semantic analysis to build the new expression.
4032 /// Subclasses may override this routine to provide different behavior.
4034 MultiExprArg SubExprs,
4035 SourceLocation RParenLoc) {
4036 // Find the declaration for __builtin_shufflevector
4037 const IdentifierInfo &Name
4038 = SemaRef.Context.Idents.get("__builtin_shufflevector");
4039 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
4040 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
4041 assert(!Lookup.empty() && "No __builtin_shufflevector?");
4042
4043 // Build a reference to the __builtin_shufflevector builtin
4045 Expr *Callee = new (SemaRef.Context)
4046 DeclRefExpr(SemaRef.Context, Builtin, false,
4047 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
4048 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
4049 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
4050 CK_BuiltinFnToFnPtr).get();
4051
4052 // Build the CallExpr
4053 ExprResult TheCall = CallExpr::Create(
4054 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
4055 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
4057
4058 // Type-check the __builtin_shufflevector expression.
4059 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
4060 }
4061
4062 /// Build a new convert vector expression.
4064 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4065 SourceLocation RParenLoc) {
4066 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4067 }
4068
4069 /// Build a new template argument pack expansion.
4070 ///
4071 /// By default, performs semantic analysis to build a new pack expansion
4072 /// for a template argument. Subclasses may override this routine to provide
4073 /// different behavior.
4075 SourceLocation EllipsisLoc,
4076 UnsignedOrNone NumExpansions) {
4077 switch (Pattern.getArgument().getKind()) {
4081 EllipsisLoc, NumExpansions);
4082 if (Result.isInvalid())
4083 return TemplateArgumentLoc();
4084
4086 /*IsCanonical=*/false),
4087 Result.get());
4088 }
4089
4091 return TemplateArgumentLoc(
4092 SemaRef.Context,
4094 NumExpansions),
4095 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4096 Pattern.getTemplateNameLoc(), EllipsisLoc);
4097
4105 llvm_unreachable("Pack expansion pattern has no parameter packs");
4106
4108 if (TypeSourceInfo *Expansion
4109 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4110 EllipsisLoc,
4111 NumExpansions))
4112 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4113 Expansion);
4114 break;
4115 }
4116
4117 return TemplateArgumentLoc();
4118 }
4119
4120 /// Build a new expression pack expansion.
4121 ///
4122 /// By default, performs semantic analysis to build a new pack expansion
4123 /// for an expression. Subclasses may override this routine to provide
4124 /// different behavior.
4126 UnsignedOrNone NumExpansions) {
4127 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4128 }
4129
4130 /// Build a new C++1z fold-expression.
4131 ///
4132 /// By default, performs semantic analysis in order to build a new fold
4133 /// expression.
4135 SourceLocation LParenLoc, Expr *LHS,
4136 BinaryOperatorKind Operator,
4137 SourceLocation EllipsisLoc, Expr *RHS,
4138 SourceLocation RParenLoc,
4139 UnsignedOrNone NumExpansions) {
4140 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4141 EllipsisLoc, RHS, RParenLoc,
4142 NumExpansions);
4143 }
4144
4146 LambdaScopeInfo *LSI) {
4147 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4148 if (Expr *Init = PVD->getInit())
4150 Init->containsUnexpandedParameterPack();
4151 else if (PVD->hasUninstantiatedDefaultArg())
4153 PVD->getUninstantiatedDefaultArg()
4154 ->containsUnexpandedParameterPack();
4155 }
4156 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4157 }
4158
4159 /// Build an empty C++1z fold-expression with the given operator.
4160 ///
4161 /// By default, produces the fallback value for the fold-expression, or
4162 /// produce an error if there is no fallback value.
4164 BinaryOperatorKind Operator) {
4165 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4166 }
4167
4168 /// Build a new atomic operation expression.
4169 ///
4170 /// By default, performs semantic analysis to build the new expression.
4171 /// Subclasses may override this routine to provide different behavior.
4174 SourceLocation RParenLoc) {
4175 // Use this for all of the locations, since we don't know the difference
4176 // between the call and the expr at this point.
4177 SourceRange Range{BuiltinLoc, RParenLoc};
4178 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4180 }
4181
4183 ArrayRef<Expr *> SubExprs, QualType Type) {
4184 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4185 }
4186
4188 SourceLocation BeginLoc,
4189 SourceLocation DirLoc,
4190 SourceLocation EndLoc,
4192 StmtResult StrBlock) {
4194 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4195 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4196 }
4197
4208
4210 SourceLocation BeginLoc,
4211 SourceLocation DirLoc,
4212 SourceLocation EndLoc,
4214 StmtResult Loop) {
4216 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4217 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4218 }
4219
4221 SourceLocation DirLoc,
4222 SourceLocation EndLoc,
4224 StmtResult StrBlock) {
4226 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4228 Clauses, StrBlock);
4229 }
4230
4240
4250
4252 SourceLocation DirLoc,
4253 SourceLocation EndLoc,
4255 StmtResult StrBlock) {
4259 Clauses, StrBlock);
4260 }
4261
4263 SourceLocation DirLoc,
4264 SourceLocation EndLoc,
4265 ArrayRef<OpenACCClause *> Clauses) {
4267 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4269 Clauses, {});
4270 }
4271
4281
4283 SourceLocation DirLoc,
4284 SourceLocation EndLoc,
4285 ArrayRef<OpenACCClause *> Clauses) {
4287 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4289 Clauses, {});
4290 }
4291
4293 SourceLocation DirLoc,
4294 SourceLocation EndLoc,
4295 ArrayRef<OpenACCClause *> Clauses) {
4297 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4299 Clauses, {});
4300 }
4301
4303 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4304 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4305 SourceLocation RParenLoc, SourceLocation EndLoc,
4306 ArrayRef<OpenACCClause *> Clauses) {
4308 Exprs.push_back(DevNumExpr);
4309 llvm::append_range(Exprs, QueueIdExprs);
4311 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4312 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4313 }
4314
4316 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4317 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4318 SourceLocation RParenLoc, SourceLocation EndLoc) {
4320 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4321 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4322 }
4323
4325 SourceLocation DirLoc,
4326 OpenACCAtomicKind AtKind,
4327 SourceLocation EndLoc,
4329 StmtResult AssociatedStmt) {
4331 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4332 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4333 AssociatedStmt);
4334 }
4335
4339
4341 RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index,
4342 QualType ParamType, SourceLocation Loc,
4343 TemplateArgument Arg,
4344 UnsignedOrNone PackIndex, bool Final) {
4346 AssociatedDecl, Index, ParamType, Loc, Arg, PackIndex, Final);
4347 }
4348
4350 SourceLocation StartLoc,
4351 SourceLocation LParenLoc,
4352 SourceLocation EndLoc) {
4353 return getSema().OpenMP().ActOnOpenMPTransparentClause(ImpexType, StartLoc,
4354 LParenLoc, EndLoc);
4355 }
4356
4357private:
4358 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4359 QualType ObjectType,
4360 NamedDecl *FirstQualifierInScope);
4361
4362 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4363 QualType ObjectType,
4364 NamedDecl *FirstQualifierInScope) {
4365 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4366 return TSInfo;
4367
4368 TypeLocBuilder TLB;
4369 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4370 ObjectType, FirstQualifierInScope);
4371 if (T.isNull())
4372 return nullptr;
4373 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4374 }
4375
4376 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4377 DependentNameTypeLoc TL,
4378 bool DeducibleTSTContext,
4379 QualType ObjectType = QualType(),
4380 NamedDecl *UnqualLookup = nullptr);
4381
4383 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4385
4386 OpenACCClause *
4387 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4388 OpenACCDirectiveKind DirKind,
4389 const OpenACCClause *OldClause);
4390};
4391
4392template <typename Derived>
4394 if (!S)
4395 return S;
4396
4397 switch (S->getStmtClass()) {
4398 case Stmt::NoStmtClass: break;
4399
4400 // Transform individual statement nodes
4401 // Pass SDK into statements that can produce a value
4402#define STMT(Node, Parent) \
4403 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4404#define VALUESTMT(Node, Parent) \
4405 case Stmt::Node##Class: \
4406 return getDerived().Transform##Node(cast<Node>(S), SDK);
4407#define ABSTRACT_STMT(Node)
4408#define EXPR(Node, Parent)
4409#include "clang/AST/StmtNodes.inc"
4410
4411 // Transform expressions by calling TransformExpr.
4412#define STMT(Node, Parent)
4413#define ABSTRACT_STMT(Stmt)
4414#define EXPR(Node, Parent) case Stmt::Node##Class:
4415#include "clang/AST/StmtNodes.inc"
4416 {
4417 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4418
4420 E = getSema().ActOnStmtExprResult(E);
4421 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4422 }
4423 }
4424
4425 return S;
4426}
4427
4428template<typename Derived>
4430 if (!S)
4431 return S;
4432
4433 switch (S->getClauseKind()) {
4434 default: break;
4435 // Transform individual clause nodes
4436#define GEN_CLANG_CLAUSE_CLASS
4437#define CLAUSE_CLASS(Enum, Str, Class) \
4438 case Enum: \
4439 return getDerived().Transform##Class(cast<Class>(S));
4440#include "llvm/Frontend/OpenMP/OMP.inc"
4441 }
4442
4443 return S;
4444}
4445
4446
4447template<typename Derived>
4449 if (!E)
4450 return E;
4451
4452 switch (E->getStmtClass()) {
4453 case Stmt::NoStmtClass: break;
4454#define STMT(Node, Parent) case Stmt::Node##Class: break;
4455#define ABSTRACT_STMT(Stmt)
4456#define EXPR(Node, Parent) \
4457 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4458#include "clang/AST/StmtNodes.inc"
4459 }
4460
4461 return E;
4462}
4463
4464template<typename Derived>
4466 bool NotCopyInit) {
4467 // Initializers are instantiated like expressions, except that various outer
4468 // layers are stripped.
4469 if (!Init)
4470 return Init;
4471
4472 if (auto *FE = dyn_cast<FullExpr>(Init))
4473 Init = FE->getSubExpr();
4474
4475 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4476 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4477 Init = OVE->getSourceExpr();
4478 }
4479
4480 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4481 Init = MTE->getSubExpr();
4482
4483 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4484 Init = Binder->getSubExpr();
4485
4486 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4487 Init = ICE->getSubExprAsWritten();
4488
4489 if (CXXStdInitializerListExpr *ILE =
4490 dyn_cast<CXXStdInitializerListExpr>(Init))
4491 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4492
4493 // If this is copy-initialization, we only need to reconstruct
4494 // InitListExprs. Other forms of copy-initialization will be a no-op if
4495 // the initializer is already the right type.
4496 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4497 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4498 return getDerived().TransformExpr(Init);
4499
4500 // Revert value-initialization back to empty parens.
4501 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4502 SourceRange Parens = VIE->getSourceRange();
4503 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4504 Parens.getEnd());
4505 }
4506
4507 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4509 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4510 SourceLocation());
4511
4512 // Revert initialization by constructor back to a parenthesized or braced list
4513 // of expressions. Any other form of initializer can just be reused directly.
4514 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4515 return getDerived().TransformExpr(Init);
4516
4517 // If the initialization implicitly converted an initializer list to a
4518 // std::initializer_list object, unwrap the std::initializer_list too.
4519 if (Construct && Construct->isStdInitListInitialization())
4520 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4521
4522 // Enter a list-init context if this was list initialization.
4525 Construct->isListInitialization());
4526
4527 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4528 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4529 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4530 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4531 SmallVector<Expr*, 8> NewArgs;
4532 bool ArgChanged = false;
4533 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4534 /*IsCall*/true, NewArgs, &ArgChanged))
4535 return ExprError();
4536
4537 // If this was list initialization, revert to syntactic list form.
4538 if (Construct->isListInitialization())
4539 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4540 Construct->getEndLoc(),
4541 /*IsExplicit=*/true);
4542
4543 // Build a ParenListExpr to represent anything else.
4545 if (Parens.isInvalid()) {
4546 // This was a variable declaration's initialization for which no initializer
4547 // was specified.
4548 assert(NewArgs.empty() &&
4549 "no parens or braces but have direct init with arguments?");
4550 return ExprEmpty();
4551 }
4552 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4553 Parens.getEnd());
4554}
4555
4556template<typename Derived>
4558 unsigned NumInputs,
4559 bool IsCall,
4560 SmallVectorImpl<Expr *> &Outputs,
4561 bool *ArgChanged) {
4562 for (unsigned I = 0; I != NumInputs; ++I) {
4563 // If requested, drop call arguments that need to be dropped.
4564 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4565 if (ArgChanged)
4566 *ArgChanged = true;
4567
4568 break;
4569 }
4570
4571 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4572 Expr *Pattern = Expansion->getPattern();
4573
4575 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4576 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4577
4578 // Determine whether the set of unexpanded parameter packs can and should
4579 // be expanded.
4580 bool Expand = true;
4581 bool RetainExpansion = false;
4582 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4583 UnsignedOrNone NumExpansions = OrigNumExpansions;
4585 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4586 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4587 RetainExpansion, NumExpansions))
4588 return true;
4589
4590 if (!Expand) {
4591 // The transform has determined that we should perform a simple
4592 // transformation on the pack expansion, producing another pack
4593 // expansion.
4594 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4595 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4596 if (OutPattern.isInvalid())
4597 return true;
4598
4599 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4600 Expansion->getEllipsisLoc(),
4601 NumExpansions);
4602 if (Out.isInvalid())
4603 return true;
4604
4605 if (ArgChanged)
4606 *ArgChanged = true;
4607 Outputs.push_back(Out.get());
4608 continue;
4609 }
4610
4611 // Record right away that the argument was changed. This needs
4612 // to happen even if the array expands to nothing.
4613 if (ArgChanged) *ArgChanged = true;
4614
4615 // The transform has determined that we should perform an elementwise
4616 // expansion of the pattern. Do so.
4617 for (unsigned I = 0; I != *NumExpansions; ++I) {
4618 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4619 ExprResult Out = getDerived().TransformExpr(Pattern);
4620 if (Out.isInvalid())
4621 return true;
4622
4623 if (Out.get()->containsUnexpandedParameterPack()) {
4624 Out = getDerived().RebuildPackExpansion(
4625 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4626 if (Out.isInvalid())
4627 return true;
4628 }
4629
4630 Outputs.push_back(Out.get());
4631 }
4632
4633 // If we're supposed to retain a pack expansion, do so by temporarily
4634 // forgetting the partially-substituted parameter pack.
4635 if (RetainExpansion) {
4636 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4637
4638 ExprResult Out = getDerived().TransformExpr(Pattern);
4639 if (Out.isInvalid())
4640 return true;
4641
4642 Out = getDerived().RebuildPackExpansion(
4643 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4644 if (Out.isInvalid())
4645 return true;
4646
4647 Outputs.push_back(Out.get());
4648 }
4649
4650 continue;
4651 }
4652
4654 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4655 : getDerived().TransformExpr(Inputs[I]);
4656 if (Result.isInvalid())
4657 return true;
4658
4659 if (Result.get() != Inputs[I] && ArgChanged)
4660 *ArgChanged = true;
4661
4662 Outputs.push_back(Result.get());
4663 }
4664
4665 return false;
4666}
4667
4668template <typename Derived>
4671
4674 /*LambdaContextDecl=*/nullptr,
4676 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4677
4678 if (Var) {
4679 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4681
4682 if (!ConditionVar)
4683 return Sema::ConditionError();
4684
4685 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4686 }
4687
4688 if (Expr) {
4689 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4690
4691 if (CondExpr.isInvalid())
4692 return Sema::ConditionError();
4693
4694 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4695 /*MissingOK=*/true);
4696 }
4697
4698 return Sema::ConditionResult();
4699}
4700
4701template <typename Derived>
4703 NestedNameSpecifierLoc NNS, QualType ObjectType,
4704 NamedDecl *FirstQualifierInScope) {
4706
4707 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4708 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4709 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4710 Qualifiers.push_back(Qualifier);
4711 };
4712 insertNNS(NNS);
4713
4714 CXXScopeSpec SS;
4715 while (!Qualifiers.empty()) {
4716 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4718
4719 switch (QNNS.getKind()) {
4721 llvm_unreachable("unexpected null nested name specifier");
4722
4725 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4727 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4728 break;
4729 }
4730
4732 // There is no meaningful transformation that one could perform on the
4733 // global scope.
4734 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4735 break;
4736
4738 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4740 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4741 Q.getEndLoc());
4742 break;
4743 }
4744
4746 assert(SS.isEmpty());
4747 TypeLoc TL = Q.castAsTypeLoc();
4748
4749 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4750 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4751 if (QualifierLoc) {
4752 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4753 QualifierLoc, ObjectType, FirstQualifierInScope);
4754 if (!QualifierLoc)
4755 return NestedNameSpecifierLoc();
4756 ObjectType = QualType();
4757 FirstQualifierInScope = nullptr;
4758 }
4759 SS.Adopt(QualifierLoc);
4761 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4762 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4763 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4764 false, SS,
4765 FirstQualifierInScope, false))
4766 return NestedNameSpecifierLoc();
4767 return SS.getWithLocInContext(SemaRef.Context);
4768 }
4769
4770 QualType T = TL.getType();
4771 TypeLocBuilder TLB;
4773 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4774 FirstQualifierInScope);
4775 if (T.isNull())
4776 return NestedNameSpecifierLoc();
4777 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4778 }
4779
4780 if (T->isDependentType() || T->isRecordType() ||
4781 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4782 if (T->isEnumeralType())
4783 SemaRef.Diag(TL.getBeginLoc(),
4784 diag::warn_cxx98_compat_enum_nested_name_spec);
4785 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4786 break;
4787 }
4788 // If the nested-name-specifier is an invalid type def, don't emit an
4789 // error because a previous error should have already been emitted.
4791 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4792 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4793 << T << SS.getRange();
4794 }
4795 return NestedNameSpecifierLoc();
4796 }
4797 }
4798 }
4799
4800 // Don't rebuild the nested-name-specifier if we don't have to.
4801 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4803 return NNS;
4804
4805 // If we can re-use the source-location data from the original
4806 // nested-name-specifier, do so.
4807 if (SS.location_size() == NNS.getDataLength() &&
4808 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4810
4811 // Allocate new nested-name-specifier location information.
4812 return SS.getWithLocInContext(SemaRef.Context);
4813}
4814
4815template<typename Derived>
4819 DeclarationName Name = NameInfo.getName();
4820 if (!Name)
4821 return DeclarationNameInfo();
4822
4823 switch (Name.getNameKind()) {
4831 return NameInfo;
4832
4834 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4835 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4836 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4837 if (!NewTemplate)
4838 return DeclarationNameInfo();
4839
4840 DeclarationNameInfo NewNameInfo(NameInfo);
4841 NewNameInfo.setName(
4842 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4843 return NewNameInfo;
4844 }
4845
4849 TypeSourceInfo *NewTInfo;
4850 CanQualType NewCanTy;
4851 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4852 NewTInfo = getDerived().TransformType(OldTInfo);
4853 if (!NewTInfo)
4854 return DeclarationNameInfo();
4855 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4856 }
4857 else {
4858 NewTInfo = nullptr;
4859 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4860 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4861 if (NewT.isNull())
4862 return DeclarationNameInfo();
4863 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4864 }
4865
4866 DeclarationName NewName
4867 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4868 NewCanTy);
4869 DeclarationNameInfo NewNameInfo(NameInfo);
4870 NewNameInfo.setName(NewName);
4871 NewNameInfo.setNamedTypeInfo(NewTInfo);
4872 return NewNameInfo;
4873 }
4874 }
4875
4876 llvm_unreachable("Unknown name kind.");
4877}
4878
4879template <typename Derived>
4881 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4883 QualType ObjectType, bool AllowInjectedClassName) {
4884 if (const IdentifierInfo *II = IO.getIdentifier())
4885 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4886 ObjectType, AllowInjectedClassName);
4887 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4888 NameLoc, ObjectType,
4889 AllowInjectedClassName);
4890}
4891
4892template <typename Derived>
4894 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4895 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4896 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4898 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4899
4900 if (QualifierLoc) {
4901 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4902 QualifierLoc, ObjectType, FirstQualifierInScope);
4903 if (!QualifierLoc)
4904 return TemplateName();
4905 }
4906
4907 NestedNameSpecifierLoc UnderlyingQualifier;
4908 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4909 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4910 FirstQualifierInScope, AllowInjectedClassName);
4911 if (NewUnderlyingName.isNull())
4912 return TemplateName();
4913 assert(!UnderlyingQualifier && "unexpected qualifier");
4914
4915 if (!getDerived().AlwaysRebuild() &&
4916 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4917 NewUnderlyingName == UnderlyingName)
4918 return Name;
4919 CXXScopeSpec SS;
4920 SS.Adopt(QualifierLoc);
4921 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4922 NewUnderlyingName);
4923 }
4924
4926 if (QualifierLoc) {
4927 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4928 QualifierLoc, ObjectType, FirstQualifierInScope);
4929 if (!QualifierLoc)
4930 return TemplateName();
4931 // The qualifier-in-scope and object type only apply to the leftmost
4932 // entity.
4933 ObjectType = QualType();
4934 }
4935
4936 if (!getDerived().AlwaysRebuild() &&
4937 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4938 ObjectType.isNull())
4939 return Name;
4940
4941 CXXScopeSpec SS;
4942 SS.Adopt(QualifierLoc);
4943 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4944 NameLoc, ObjectType,
4945 AllowInjectedClassName);
4946 }
4947
4950 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4951
4952 NestedNameSpecifierLoc ReplacementQualifierLoc;
4953 TemplateName ReplacementName = S->getReplacement();
4954 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4956 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4957 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4958 }
4959
4960 TemplateName NewName = getDerived().TransformTemplateName(
4961 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4962 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4963 if (NewName.isNull())
4964 return TemplateName();
4965 Decl *AssociatedDecl =
4966 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4967 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4968 AssociatedDecl == S->getAssociatedDecl())
4969 return Name;
4970 return SemaRef.Context.getSubstTemplateTemplateParm(
4971 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4972 S->getFinal());
4973 }
4974
4975 assert(!Name.getAsDeducedTemplateName() &&
4976 "DeducedTemplateName should not escape partial ordering");
4977
4978 // FIXME: Preserve UsingTemplateName.
4979 if (auto *Template = Name.getAsTemplateDecl()) {
4980 assert(!QualifierLoc && "Unexpected qualifier");
4981 return TemplateName(cast_or_null<TemplateDecl>(
4982 getDerived().TransformDecl(NameLoc, Template)));
4983 }
4984
4987 assert(!QualifierLoc &&
4988 "Unexpected qualified SubstTemplateTemplateParmPack");
4989 return getDerived().RebuildTemplateName(
4990 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4991 SubstPack->getIndex(), SubstPack->getFinal());
4992 }
4993
4994 // These should be getting filtered out before they reach the AST.
4995 llvm_unreachable("overloaded function decl survived to here");
4996}
4997
4998template <typename Derived>
5000 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
5001 TemplateName Name, SourceLocation NameLoc) {
5002 TemplateName TN = getDerived().TransformTemplateName(
5003 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
5004 if (TN.isNull())
5005 return TemplateArgument();
5006 return TemplateArgument(TN);
5007}
5008
5009template<typename Derived>
5011 const TemplateArgument &Arg,
5012 TemplateArgumentLoc &Output) {
5013 Output = getSema().getTrivialTemplateArgumentLoc(
5014 Arg, QualType(), getDerived().getBaseLocation());
5015}
5016
5017template <typename Derived>
5019 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
5020 bool Uneval) {
5021 const TemplateArgument &Arg = Input.getArgument();
5022 switch (Arg.getKind()) {
5025 llvm_unreachable("Unexpected TemplateArgument");
5026
5031 // Transform a resolved template argument straight to a resolved template
5032 // argument. We get here when substituting into an already-substituted
5033 // template type argument during concept satisfaction checking.
5035 QualType NewT = getDerived().TransformType(T);
5036 if (NewT.isNull())
5037 return true;
5038
5040 ? Arg.getAsDecl()
5041 : nullptr;
5042 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
5044 : nullptr;
5045 if (D && !NewD)
5046 return true;
5047
5048 if (NewT == T && D == NewD)
5049 Output = Input;
5050 else if (Arg.getKind() == TemplateArgument::Integral)
5051 Output = TemplateArgumentLoc(
5052 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
5054 else if (Arg.getKind() == TemplateArgument::NullPtr)
5055 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
5057 else if (Arg.getKind() == TemplateArgument::Declaration)
5058 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
5061 Output = TemplateArgumentLoc(
5062 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
5064 else
5065 llvm_unreachable("unexpected template argument kind");
5066
5067 return false;
5068 }
5069
5071 TypeSourceInfo *TSI = Input.getTypeSourceInfo();
5072 if (!TSI)
5074
5075 TSI = getDerived().TransformType(TSI);
5076 if (!TSI)
5077 return true;
5078
5079 Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI);
5080 return false;
5081 }
5082
5084 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5085
5086 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5087 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5088 Input.getTemplateNameLoc());
5089 if (Out.isNull())
5090 return true;
5091 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5092 QualifierLoc, Input.getTemplateNameLoc());
5093 return false;
5094 }
5095
5097 llvm_unreachable("Caller should expand pack expansions");
5098
5100 // Template argument expressions are constant expressions.
5102 getSema(),
5105 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5107
5108 Expr *InputExpr = Input.getSourceExpression();
5109 if (!InputExpr)
5110 InputExpr = Input.getArgument().getAsExpr();
5111
5112 ExprResult E = getDerived().TransformExpr(InputExpr);
5113 E = SemaRef.ActOnConstantExpression(E);
5114 if (E.isInvalid())
5115 return true;
5116 Output = TemplateArgumentLoc(
5117 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5118 return false;
5119 }
5120 }
5121
5122 // Work around bogus GCC warning
5123 return true;
5124}
5125
5126/// Iterator adaptor that invents template argument location information
5127/// for each of the template arguments in its underlying iterator.
5128template<typename Derived, typename InputIterator>
5131 InputIterator Iter;
5132
5133public:
5136 typedef typename std::iterator_traits<InputIterator>::difference_type
5138 typedef std::input_iterator_tag iterator_category;
5139
5140 class pointer {
5142
5143 public:
5144 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5145
5146 const TemplateArgumentLoc *operator->() const { return &Arg; }
5147 };
5148
5150 InputIterator Iter)
5151 : Self(Self), Iter(Iter) { }
5152
5154 ++Iter;
5155 return *this;
5156 }
5157
5160 ++(*this);
5161 return Old;
5162 }
5163
5166 Self.InventTemplateArgumentLoc(*Iter, Result);
5167 return Result;
5168 }
5169
5170 pointer operator->() const { return pointer(**this); }
5171
5174 return X.Iter == Y.Iter;
5175 }
5176
5179 return X.Iter != Y.Iter;
5180 }
5181};
5182
5183template<typename Derived>
5184template<typename InputIterator>
5186 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5187 bool Uneval) {
5188 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5190 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5191 // Unpack argument packs, which we translate them into separate
5192 // arguments.
5193 // FIXME: We could do much better if we could guarantee that the
5194 // TemplateArgumentLocInfo for the pack expansion would be usable for
5195 // all of the template arguments in the argument pack.
5196 typedef TemplateArgumentLocInventIterator<Derived,
5198 PackLocIterator;
5199
5200 TemplateArgumentListInfo *PackOutput = &Outputs;
5202
5204 PackLocIterator(*this, In.getArgument().pack_begin()),
5205 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5206 Uneval))
5207 return true;
5208
5209 continue;
5210 }
5211
5212 if (In.getArgument().isPackExpansion()) {
5213 UnexpandedInfo Info;
5214 TemplateArgumentLoc Prepared;
5215 if (getDerived().PreparePackForExpansion(In, Uneval, Prepared, Info))
5216 return true;
5217 if (!Info.Expand) {
5218 Outputs.addArgument(Prepared);
5219 continue;
5220 }
5221
5222 // The transform has determined that we should perform an elementwise
5223 // expansion of the pattern. Do so.
5224 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5226 ForgetSubst.emplace(getDerived());
5227 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5228 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5229
5231 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5232 return true;
5233
5234 if (Out.getArgument().containsUnexpandedParameterPack()) {
5235 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5236 Info.OrigNumExpansions);
5237 if (Out.getArgument().isNull())
5238 return true;
5239 }
5240
5241 Outputs.addArgument(Out);
5242 }
5243
5244 // If we're supposed to retain a pack expansion, do so by temporarily
5245 // forgetting the partially-substituted parameter pack.
5246 if (Info.RetainExpansion) {
5247 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5248
5250 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5251 return true;
5252
5253 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5254 Info.OrigNumExpansions);
5255 if (Out.getArgument().isNull())
5256 return true;
5257
5258 Outputs.addArgument(Out);
5259 }
5260
5261 continue;
5262 }
5263
5264 // The simple case:
5265 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5266 return true;
5267
5268 Outputs.addArgument(Out);
5269 }
5270
5271 return false;
5272}
5273
5274template <typename Derived>
5275template <typename InputIterator>
5277 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5278 bool Uneval) {
5279
5280 // [C++26][temp.constr.normal]
5281 // any non-dependent concept template argument
5282 // is substituted into the constraint-expression of C.
5283 auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) {
5284 return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter();
5285 };
5286
5287 for (; First != Last; ++First) {
5290
5291 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5292 typedef TemplateArgumentLocInventIterator<Derived,
5294 PackLocIterator;
5296 PackLocIterator(*this, In.getArgument().pack_begin()),
5297 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5298 Uneval))
5299 return true;
5300 continue;
5301 }
5302
5303 if (!isNonDependentConceptArgument(In.getArgument())) {
5304 Outputs.addArgument(In);
5305 continue;
5306 }
5307
5308 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5309 return true;
5310
5311 Outputs.addArgument(Out);
5312 }
5313
5314 return false;
5315}
5316
5317// FIXME: Find ways to reduce code duplication for pack expansions.
5318template <typename Derived>
5320 bool Uneval,
5322 UnexpandedInfo &Info) {
5323 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5324 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5325 TemplateArgumentLoc &Pattern) {
5326 assert(Arg.getArgument().isPackExpansion());
5327 // We have a pack expansion, for which we will be substituting into the
5328 // pattern.
5329 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5330 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5332 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5333 if (IsLateExpansionAttempt) {
5334 // Request expansion only when there is an opportunity to expand a pack
5335 // that required a substituion first.
5336 bool SawPackTypes =
5337 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5338 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5339 });
5340 if (!SawPackTypes) {
5341 Info.Expand = false;
5342 return false;
5343 }
5344 }
5345 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5346
5347 // Determine whether the set of unexpanded parameter packs can and
5348 // should be expanded.
5349 Info.Expand = true;
5350 Info.RetainExpansion = false;
5351 Info.NumExpansions = Info.OrigNumExpansions;
5352 return getDerived().TryExpandParameterPacks(
5353 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5354 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5355 Info.RetainExpansion, Info.NumExpansions);
5356 };
5357
5358 TemplateArgumentLoc Pattern;
5359 if (ComputeInfo(In, false, Info, Pattern))
5360 return true;
5361
5362 if (Info.Expand) {
5363 Out = Pattern;
5364 return false;
5365 }
5366
5367 // The transform has determined that we should perform a simple
5368 // transformation on the pack expansion, producing another pack
5369 // expansion.
5370 TemplateArgumentLoc OutPattern;
5371 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5372 std::in_place, getSema(), std::nullopt);
5373 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5374 return true;
5375
5376 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5377 Info.NumExpansions);
5378 if (Out.getArgument().isNull())
5379 return true;
5380 SubstIndex.reset();
5381
5382 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5383 return false;
5384
5385 // Some packs will learn their length after substitution, e.g.
5386 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5387 // value of `T`.
5388 //
5389 // We only expand after we know sizes of all packs, check if this is the case
5390 // or not. However, we avoid a full template substitution and only do
5391 // expanstions after this point.
5392
5393 // E.g. when substituting template arguments of tuple with {T -> int} in the
5394 // following example:
5395 // template <class T>
5396 // struct TupleWithInt {
5397 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5398 // };
5399 // TupleWithInt<int>::type y;
5400 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5401 // length and run `ComputeInfo()` to provide the necessary information to our
5402 // caller.
5403 //
5404 // Note that we may still have situations where builtin is not going to be
5405 // expanded. For example:
5406 // template <class T>
5407 // struct Foo {
5408 // template <class U> using tuple_with_t =
5409 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5410 // tuple_with_t<short>;
5411 // }
5412 // Because the substitution into `type` happens in dependent context, `type`
5413 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5414 // and the caller will not be able to expand it.
5415 ForgetSubstitutionRAII ForgetSubst(getDerived());
5416 if (ComputeInfo(Out, true, Info, OutPattern))
5417 return true;
5418 if (!Info.Expand)
5419 return false;
5420 Out = OutPattern;
5421 Info.ExpandUnderForgetSubstitions = true;
5422 return false;
5423}
5424
5425//===----------------------------------------------------------------------===//
5426// Type transformation
5427//===----------------------------------------------------------------------===//
5428
5429template<typename Derived>
5432 return T;
5433
5434 // Temporary workaround. All of these transformations should
5435 // eventually turn into transformations on TypeLocs.
5436 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5438
5439 TypeSourceInfo *NewTSI = getDerived().TransformType(TSI);
5440
5441 if (!NewTSI)
5442 return QualType();
5443
5444 return NewTSI->getType();
5445}
5446
5447template <typename Derived>
5449 // Refine the base location to the type's location.
5450 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5453 return TSI;
5454
5455 TypeLocBuilder TLB;
5456
5457 TypeLoc TL = TSI->getTypeLoc();
5458 TLB.reserve(TL.getFullDataSize());
5459
5460 QualType Result = getDerived().TransformType(TLB, TL);
5461 if (Result.isNull())
5462 return nullptr;
5463
5464 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5465}
5466
5467template<typename Derived>
5470 switch (T.getTypeLocClass()) {
5471#define ABSTRACT_TYPELOC(CLASS, PARENT)
5472#define TYPELOC(CLASS, PARENT) \
5473 case TypeLoc::CLASS: \
5474 return getDerived().Transform##CLASS##Type(TLB, \
5475 T.castAs<CLASS##TypeLoc>());
5476#include "clang/AST/TypeLocNodes.def"
5477 }
5478
5479 llvm_unreachable("unhandled type loc!");
5480}
5481
5482template<typename Derived>
5485 return TransformType(T);
5486
5488 return T;
5489 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5491 TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI);
5492 return NewTSI ? NewTSI->getType() : QualType();
5493}
5494
5495template <typename Derived>
5498 if (!isa<DependentNameType>(TSI->getType()))
5499 return TransformType(TSI);
5500
5501 // Refine the base location to the type's location.
5502 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5505 return TSI;
5506
5507 TypeLocBuilder TLB;
5508
5509 TypeLoc TL = TSI->getTypeLoc();
5510 TLB.reserve(TL.getFullDataSize());
5511
5512 auto QTL = TL.getAs<QualifiedTypeLoc>();
5513 if (QTL)
5514 TL = QTL.getUnqualifiedLoc();
5515
5516 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5517
5518 QualType Result = getDerived().TransformDependentNameType(
5519 TLB, DNTL, /*DeducedTSTContext*/true);
5520 if (Result.isNull())
5521 return nullptr;
5522
5523 if (QTL) {
5524 Result = getDerived().RebuildQualifiedType(Result, QTL);
5525 if (Result.isNull())
5526 return nullptr;
5528 }
5529
5530 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5531}
5532
5533template<typename Derived>
5538 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5539 auto SuppressObjCLifetime =
5540 T.getType().getLocalQualifiers().hasObjCLifetime();
5541 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5542 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5543 SuppressObjCLifetime);
5544 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5545 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5546 TLB, STTP, SuppressObjCLifetime);
5547 } else {
5548 Result = getDerived().TransformType(TLB, UnqualTL);
5549 }
5550
5551 if (Result.isNull())
5552 return QualType();
5553
5554 Result = getDerived().RebuildQualifiedType(Result, T);
5555
5556 if (Result.isNull())
5557 return QualType();
5558
5559 // RebuildQualifiedType might have updated the type, but not in a way
5560 // that invalidates the TypeLoc. (There's no location information for
5561 // qualifiers.)
5563
5564 return Result;
5565}
5566
5567template <typename Derived>
5569 QualifiedTypeLoc TL) {
5570
5571 SourceLocation Loc = TL.getBeginLoc();
5572 Qualifiers Quals = TL.getType().getLocalQualifiers();
5573
5574 if ((T.getAddressSpace() != LangAS::Default &&
5575 Quals.getAddressSpace() != LangAS::Default) &&
5576 T.getAddressSpace() != Quals.getAddressSpace()) {
5577 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5578 << TL.getType() << T;
5579 return QualType();
5580 }
5581
5582 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5583 if (LocalPointerAuth.isPresent()) {
5584 if (T.getPointerAuth().isPresent()) {
5585 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5586 return QualType();
5587 }
5588 if (!T->isDependentType()) {
5589 if (!T->isSignableType(SemaRef.getASTContext())) {
5590 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5591 return QualType();
5592 }
5593 }
5594 }
5595 // C++ [dcl.fct]p7:
5596 // [When] adding cv-qualifications on top of the function type [...] the
5597 // cv-qualifiers are ignored.
5598 if (T->isFunctionType()) {
5599 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5600 Quals.getAddressSpace());
5601 return T;
5602 }
5603
5604 // C++ [dcl.ref]p1:
5605 // when the cv-qualifiers are introduced through the use of a typedef-name
5606 // or decltype-specifier [...] the cv-qualifiers are ignored.
5607 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5608 // applied to a reference type.
5609 if (T->isReferenceType()) {
5610 // The only qualifier that applies to a reference type is restrict.
5611 if (!Quals.hasRestrict())
5612 return T;
5614 }
5615
5616 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5617 // resulting type.
5618 if (Quals.hasObjCLifetime()) {
5619 if (!T->isObjCLifetimeType() && !T->isDependentType())
5620 Quals.removeObjCLifetime();
5621 else if (T.getObjCLifetime()) {
5622 // Objective-C ARC:
5623 // A lifetime qualifier applied to a substituted template parameter
5624 // overrides the lifetime qualifier from the template argument.
5625 const AutoType *AutoTy;
5626 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5627 // 'auto' types behave the same way as template parameters.
5628 QualType Deduced = AutoTy->getDeducedType();
5629 Qualifiers Qs = Deduced.getQualifiers();
5630 Qs.removeObjCLifetime();
5631 Deduced =
5632 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5633 T = SemaRef.Context.getAutoType(AutoTy->getDeducedKind(), Deduced,
5634 AutoTy->getKeyword(),
5635 AutoTy->getTypeConstraintConcept(),
5636 AutoTy->getTypeConstraintArguments());
5637 } else {
5638 // Otherwise, complain about the addition of a qualifier to an
5639 // already-qualified type.
5640 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5641 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5642 Quals.removeObjCLifetime();
5643 }
5644 }
5645 }
5646
5647 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5648}
5649
5650template <typename Derived>
5651QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5652 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5653 NamedDecl *FirstQualifierInScope) {
5654 assert(!getDerived().AlreadyTransformed(TL.getType()));
5655
5656 switch (TL.getTypeLocClass()) {
5657 case TypeLoc::TemplateSpecialization:
5658 return getDerived().TransformTemplateSpecializationType(
5659 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5660 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5661 case TypeLoc::DependentName:
5662 return getDerived().TransformDependentNameType(
5663 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5664 ObjectType, FirstQualifierInScope);
5665 default:
5666 // Any dependent canonical type can appear here, through type alias
5667 // templates.
5668 return getDerived().TransformType(TLB, TL);
5669 }
5670}
5671
5672template <class TyLoc> static inline
5674 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5675 NewT.setNameLoc(T.getNameLoc());
5676 return T.getType();
5677}
5678
5679template<typename Derived>
5680QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5681 BuiltinTypeLoc T) {
5682 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5683 NewT.setBuiltinLoc(T.getBuiltinLoc());
5684 if (T.needsExtraLocalData())
5685 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5686 return T.getType();
5687}
5688
5689template<typename Derived>
5691 ComplexTypeLoc T) {
5692 // FIXME: recurse?
5693 return TransformTypeSpecType(TLB, T);
5694}
5695
5696template <typename Derived>
5698 AdjustedTypeLoc TL) {
5699 // Adjustments applied during transformation are handled elsewhere.
5700 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5701}
5702
5703template<typename Derived>
5705 DecayedTypeLoc TL) {
5706 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5707 if (OriginalType.isNull())
5708 return QualType();
5709
5710 QualType Result = TL.getType();
5711 if (getDerived().AlwaysRebuild() ||
5712 OriginalType != TL.getOriginalLoc().getType())
5713 Result = SemaRef.Context.getDecayedType(OriginalType);
5714 TLB.push<DecayedTypeLoc>(Result);
5715 // Nothing to set for DecayedTypeLoc.
5716 return Result;
5717}
5718
5719template <typename Derived>
5723 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5724 if (OriginalType.isNull())
5725 return QualType();
5726
5727 QualType Result = TL.getType();
5728 if (getDerived().AlwaysRebuild() ||
5729 OriginalType != TL.getElementLoc().getType())
5730 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5731 TLB.push<ArrayParameterTypeLoc>(Result);
5732 // Nothing to set for ArrayParameterTypeLoc.
5733 return Result;
5734}
5735
5736template<typename Derived>
5738 PointerTypeLoc TL) {
5739 QualType PointeeType
5740 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5741 if (PointeeType.isNull())
5742 return QualType();
5743
5744 QualType Result = TL.getType();
5745 if (PointeeType->getAs<ObjCObjectType>()) {
5746 // A dependent pointer type 'T *' has is being transformed such
5747 // that an Objective-C class type is being replaced for 'T'. The
5748 // resulting pointer type is an ObjCObjectPointerType, not a
5749 // PointerType.
5750 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5751
5753 NewT.setStarLoc(TL.getStarLoc());
5754 return Result;
5755 }
5756
5757 if (getDerived().AlwaysRebuild() ||
5758 PointeeType != TL.getPointeeLoc().getType()) {
5759 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5760 if (Result.isNull())
5761 return QualType();
5762 }
5763
5764 // Objective-C ARC can add lifetime qualifiers to the type that we're
5765 // pointing to.
5766 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5767
5768 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5769 NewT.setSigilLoc(TL.getSigilLoc());
5770 return Result;
5771}
5772
5773template<typename Derived>
5777 QualType PointeeType
5778 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5779 if (PointeeType.isNull())
5780 return QualType();
5781
5782 QualType Result = TL.getType();
5783 if (getDerived().AlwaysRebuild() ||
5784 PointeeType != TL.getPointeeLoc().getType()) {
5785 Result = getDerived().RebuildBlockPointerType(PointeeType,
5786 TL.getSigilLoc());
5787 if (Result.isNull())
5788 return QualType();
5789 }
5790
5792 NewT.setSigilLoc(TL.getSigilLoc());
5793 return Result;
5794}
5795
5796/// Transforms a reference type. Note that somewhat paradoxically we
5797/// don't care whether the type itself is an l-value type or an r-value
5798/// type; we only care if the type was *written* as an l-value type
5799/// or an r-value type.
5800template<typename Derived>
5803 ReferenceTypeLoc TL) {
5804 const ReferenceType *T = TL.getTypePtr();
5805
5806 // Note that this works with the pointee-as-written.
5807 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5808 if (PointeeType.isNull())
5809 return QualType();
5810
5811 QualType Result = TL.getType();
5812 if (getDerived().AlwaysRebuild() ||
5813 PointeeType != T->getPointeeTypeAsWritten()) {
5814 Result = getDerived().RebuildReferenceType(PointeeType,
5815 T->isSpelledAsLValue(),
5816 TL.getSigilLoc());
5817 if (Result.isNull())
5818 return QualType();
5819 }
5820
5821 // Objective-C ARC can add lifetime qualifiers to the type that we're
5822 // referring to.
5825
5826 // r-value references can be rebuilt as l-value references.
5827 ReferenceTypeLoc NewTL;
5829 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5830 else
5831 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5832 NewTL.setSigilLoc(TL.getSigilLoc());
5833
5834 return Result;
5835}
5836
5837template<typename Derived>
5841 return TransformReferenceType(TLB, TL);
5842}
5843
5844template<typename Derived>
5845QualType
5846TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5847 RValueReferenceTypeLoc TL) {
5848 return TransformReferenceType(TLB, TL);
5849}
5850
5851template<typename Derived>
5855 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5856 if (PointeeType.isNull())
5857 return QualType();
5858
5859 const MemberPointerType *T = TL.getTypePtr();
5860
5861 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5862 NestedNameSpecifierLoc NewQualifierLoc =
5863 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5864 if (!NewQualifierLoc)
5865 return QualType();
5866
5867 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5868 if (OldCls) {
5869 NewCls = cast_or_null<CXXRecordDecl>(
5870 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5871 if (!NewCls)
5872 return QualType();
5873 }
5874
5875 QualType Result = TL.getType();
5876 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5877 NewQualifierLoc.getNestedNameSpecifier() !=
5878 OldQualifierLoc.getNestedNameSpecifier() ||
5879 NewCls != OldCls) {
5880 CXXScopeSpec SS;
5881 SS.Adopt(NewQualifierLoc);
5882 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5883 TL.getStarLoc());
5884 if (Result.isNull())
5885 return QualType();
5886 }
5887
5888 // If we had to adjust the pointee type when building a member pointer, make
5889 // sure to push TypeLoc info for it.
5890 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5891 if (MPT && PointeeType != MPT->getPointeeType()) {
5892 assert(isa<AdjustedType>(MPT->getPointeeType()));
5893 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5894 }
5895
5897 NewTL.setSigilLoc(TL.getSigilLoc());
5898 NewTL.setQualifierLoc(NewQualifierLoc);
5899
5900 return Result;
5901}
5902
5903template<typename Derived>
5907 const ConstantArrayType *T = TL.getTypePtr();
5908 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5909 if (ElementType.isNull())
5910 return QualType();
5911
5912 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5913 Expr *OldSize = TL.getSizeExpr();
5914 if (!OldSize)
5915 OldSize = const_cast<Expr*>(T->getSizeExpr());
5916 Expr *NewSize = nullptr;
5917 if (OldSize) {
5920 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5921 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5922 }
5923
5924 QualType Result = TL.getType();
5925 if (getDerived().AlwaysRebuild() ||
5926 ElementType != T->getElementType() ||
5927 (T->getSizeExpr() && NewSize != OldSize)) {
5928 Result = getDerived().RebuildConstantArrayType(ElementType,
5929 T->getSizeModifier(),
5930 T->getSize(), NewSize,
5931 T->getIndexTypeCVRQualifiers(),
5932 TL.getBracketsRange());
5933 if (Result.isNull())
5934 return QualType();
5935 }
5936
5937 // We might have either a ConstantArrayType or a VariableArrayType now:
5938 // a ConstantArrayType is allowed to have an element type which is a
5939 // VariableArrayType if the type is dependent. Fortunately, all array
5940 // types have the same location layout.
5941 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5942 NewTL.setLBracketLoc(TL.getLBracketLoc());
5943 NewTL.setRBracketLoc(TL.getRBracketLoc());
5944 NewTL.setSizeExpr(NewSize);
5945
5946 return Result;
5947}
5948
5949template<typename Derived>
5951 TypeLocBuilder &TLB,
5953 const IncompleteArrayType *T = TL.getTypePtr();
5954 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5955 if (ElementType.isNull())
5956 return QualType();
5957
5958 QualType Result = TL.getType();
5959 if (getDerived().AlwaysRebuild() ||
5960 ElementType != T->getElementType()) {
5961 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5962 T->getSizeModifier(),
5963 T->getIndexTypeCVRQualifiers(),
5964 TL.getBracketsRange());
5965 if (Result.isNull())
5966 return QualType();
5967 }
5968
5970 NewTL.setLBracketLoc(TL.getLBracketLoc());
5971 NewTL.setRBracketLoc(TL.getRBracketLoc());
5972 NewTL.setSizeExpr(nullptr);
5973
5974 return Result;
5975}
5976
5977template<typename Derived>
5981 const VariableArrayType *T = TL.getTypePtr();
5982 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5983 if (ElementType.isNull())
5984 return QualType();
5985
5986 ExprResult SizeResult;
5987 {
5990 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5991 }
5992 if (SizeResult.isInvalid())
5993 return QualType();
5994 SizeResult =
5995 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5996 if (SizeResult.isInvalid())
5997 return QualType();
5998
5999 Expr *Size = SizeResult.get();
6000
6001 QualType Result = TL.getType();
6002 if (getDerived().AlwaysRebuild() ||
6003 ElementType != T->getElementType() ||
6004 Size != T->getSizeExpr()) {
6005 Result = getDerived().RebuildVariableArrayType(ElementType,
6006 T->getSizeModifier(),
6007 Size,
6008 T->getIndexTypeCVRQualifiers(),
6009 TL.getBracketsRange());
6010 if (Result.isNull())
6011 return QualType();
6012 }
6013
6014 // We might have constant size array now, but fortunately it has the same
6015 // location layout.
6016 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6017 NewTL.setLBracketLoc(TL.getLBracketLoc());
6018 NewTL.setRBracketLoc(TL.getRBracketLoc());
6019 NewTL.setSizeExpr(Size);
6020
6021 return Result;
6022}
6023
6024template<typename Derived>
6028 const DependentSizedArrayType *T = TL.getTypePtr();
6029 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6030 if (ElementType.isNull())
6031 return QualType();
6032
6033 // Array bounds are constant expressions.
6036
6037 // If we have a VLA then it won't be a constant.
6038 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
6039
6040 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6041 Expr *origSize = TL.getSizeExpr();
6042 if (!origSize) origSize = T->getSizeExpr();
6043
6044 ExprResult sizeResult
6045 = getDerived().TransformExpr(origSize);
6046 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
6047 if (sizeResult.isInvalid())
6048 return QualType();
6049
6050 Expr *size = sizeResult.get();
6051
6052 QualType Result = TL.getType();
6053 if (getDerived().AlwaysRebuild() ||
6054 ElementType != T->getElementType() ||
6055 size != origSize) {
6056 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
6057 T->getSizeModifier(),
6058 size,
6059 T->getIndexTypeCVRQualifiers(),
6060 TL.getBracketsRange());
6061 if (Result.isNull())
6062 return QualType();
6063 }
6064
6065 // We might have any sort of array type now, but fortunately they
6066 // all have the same location layout.
6067 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6068 NewTL.setLBracketLoc(TL.getLBracketLoc());
6069 NewTL.setRBracketLoc(TL.getRBracketLoc());
6070 NewTL.setSizeExpr(size);
6071
6072 return Result;
6073}
6074
6075template <typename Derived>
6078 const DependentVectorType *T = TL.getTypePtr();
6079 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6080 if (ElementType.isNull())
6081 return QualType();
6082
6085
6086 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6087 Size = SemaRef.ActOnConstantExpression(Size);
6088 if (Size.isInvalid())
6089 return QualType();
6090
6091 QualType Result = TL.getType();
6092 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6093 Size.get() != T->getSizeExpr()) {
6094 Result = getDerived().RebuildDependentVectorType(
6095 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
6096 if (Result.isNull())
6097 return QualType();
6098 }
6099
6100 // Result might be dependent or not.
6103 TLB.push<DependentVectorTypeLoc>(Result);
6104 NewTL.setNameLoc(TL.getNameLoc());
6105 } else {
6106 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6107 NewTL.setNameLoc(TL.getNameLoc());
6108 }
6109
6110 return Result;
6111}
6112
6113template<typename Derived>
6115 TypeLocBuilder &TLB,
6117 const DependentSizedExtVectorType *T = TL.getTypePtr();
6118
6119 // FIXME: ext vector locs should be nested
6120 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6121 if (ElementType.isNull())
6122 return QualType();
6123
6124 // Vector sizes are constant expressions.
6127
6128 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6129 Size = SemaRef.ActOnConstantExpression(Size);
6130 if (Size.isInvalid())
6131 return QualType();
6132
6133 QualType Result = TL.getType();
6134 if (getDerived().AlwaysRebuild() ||
6135 ElementType != T->getElementType() ||
6136 Size.get() != T->getSizeExpr()) {
6137 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6138 Size.get(),
6139 T->getAttributeLoc());
6140 if (Result.isNull())
6141 return QualType();
6142 }
6143
6144 // Result might be dependent or not.
6148 NewTL.setNameLoc(TL.getNameLoc());
6149 } else {
6150 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6151 NewTL.setNameLoc(TL.getNameLoc());
6152 }
6153
6154 return Result;
6155}
6156
6157template <typename Derived>
6161 const ConstantMatrixType *T = TL.getTypePtr();
6162 QualType ElementType = getDerived().TransformType(T->getElementType());
6163 if (ElementType.isNull())
6164 return QualType();
6165
6166 QualType Result = TL.getType();
6167 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6168 Result = getDerived().RebuildConstantMatrixType(
6169 ElementType, T->getNumRows(), T->getNumColumns());
6170 if (Result.isNull())
6171 return QualType();
6172 }
6173
6175 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6176 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6177 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6178 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6179
6180 return Result;
6181}
6182
6183template <typename Derived>
6186 const DependentSizedMatrixType *T = TL.getTypePtr();
6187
6188 QualType ElementType = getDerived().TransformType(T->getElementType());
6189 if (ElementType.isNull()) {
6190 return QualType();
6191 }
6192
6193 // Matrix dimensions are constant expressions.
6196
6197 Expr *origRows = TL.getAttrRowOperand();
6198 if (!origRows)
6199 origRows = T->getRowExpr();
6200 Expr *origColumns = TL.getAttrColumnOperand();
6201 if (!origColumns)
6202 origColumns = T->getColumnExpr();
6203
6204 ExprResult rowResult = getDerived().TransformExpr(origRows);
6205 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6206 if (rowResult.isInvalid())
6207 return QualType();
6208
6209 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6210 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6211 if (columnResult.isInvalid())
6212 return QualType();
6213
6214 Expr *rows = rowResult.get();
6215 Expr *columns = columnResult.get();
6216
6217 QualType Result = TL.getType();
6218 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6219 rows != origRows || columns != origColumns) {
6220 Result = getDerived().RebuildDependentSizedMatrixType(
6221 ElementType, rows, columns, T->getAttributeLoc());
6222
6223 if (Result.isNull())
6224 return QualType();
6225 }
6226
6227 // We might have any sort of matrix type now, but fortunately they
6228 // all have the same location layout.
6229 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6230 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6231 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6232 NewTL.setAttrRowOperand(rows);
6233 NewTL.setAttrColumnOperand(columns);
6234 return Result;
6235}
6236
6237template <typename Derived>
6240 const DependentAddressSpaceType *T = TL.getTypePtr();
6241
6242 QualType pointeeType =
6243 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6244
6245 if (pointeeType.isNull())
6246 return QualType();
6247
6248 // Address spaces are constant expressions.
6251
6252 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6253 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6254 if (AddrSpace.isInvalid())
6255 return QualType();
6256
6257 QualType Result = TL.getType();
6258 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6259 AddrSpace.get() != T->getAddrSpaceExpr()) {
6260 Result = getDerived().RebuildDependentAddressSpaceType(
6261 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6262 if (Result.isNull())
6263 return QualType();
6264 }
6265
6266 // Result might be dependent or not.
6270
6271 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6272 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6273 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6274
6275 } else {
6276 TLB.TypeWasModifiedSafely(Result);
6277 }
6278
6279 return Result;
6280}
6281
6282template <typename Derived>
6284 VectorTypeLoc TL) {
6285 const VectorType *T = TL.getTypePtr();
6286 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6287 if (ElementType.isNull())
6288 return QualType();
6289
6290 QualType Result = TL.getType();
6291 if (getDerived().AlwaysRebuild() ||
6292 ElementType != T->getElementType()) {
6293 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6294 T->getVectorKind());
6295 if (Result.isNull())
6296 return QualType();
6297 }
6298
6299 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6300 NewTL.setNameLoc(TL.getNameLoc());
6301
6302 return Result;
6303}
6304
6305template<typename Derived>
6307 ExtVectorTypeLoc TL) {
6308 const VectorType *T = TL.getTypePtr();
6309 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6310 if (ElementType.isNull())
6311 return QualType();
6312
6313 QualType Result = TL.getType();
6314 if (getDerived().AlwaysRebuild() ||
6315 ElementType != T->getElementType()) {
6316 Result = getDerived().RebuildExtVectorType(ElementType,
6317 T->getNumElements(),
6318 /*FIXME*/ SourceLocation());
6319 if (Result.isNull())
6320 return QualType();
6321 }
6322
6323 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6324 NewTL.setNameLoc(TL.getNameLoc());
6325
6326 return Result;
6327}
6328
6329template <typename Derived>
6331 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6332 bool ExpectParameterPack) {
6333 TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo();
6334 TypeSourceInfo *NewTSI = nullptr;
6335
6336 if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) {
6337 // If we're substituting into a pack expansion type and we know the
6338 // length we want to expand to, just substitute for the pattern.
6339 TypeLoc OldTL = OldTSI->getTypeLoc();
6340 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6341
6342 TypeLocBuilder TLB;
6343 TypeLoc NewTL = OldTSI->getTypeLoc();
6344 TLB.reserve(NewTL.getFullDataSize());
6345
6346 QualType Result = getDerived().TransformType(TLB,
6347 OldExpansionTL.getPatternLoc());
6348 if (Result.isNull())
6349 return nullptr;
6350
6352 OldExpansionTL.getPatternLoc().getSourceRange(),
6353 OldExpansionTL.getEllipsisLoc(),
6354 NumExpansions);
6355 if (Result.isNull())
6356 return nullptr;
6357
6358 PackExpansionTypeLoc NewExpansionTL
6359 = TLB.push<PackExpansionTypeLoc>(Result);
6360 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6361 NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6362 } else
6363 NewTSI = getDerived().TransformType(OldTSI);
6364 if (!NewTSI)
6365 return nullptr;
6366
6367 if (NewTSI == OldTSI && indexAdjustment == 0)
6368 return OldParm;
6369
6371 SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(),
6372 OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(),
6373 NewTSI, OldParm->getStorageClass(),
6374 /* DefArg */ nullptr);
6375 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6376 OldParm->getFunctionScopeIndex() + indexAdjustment);
6377 getDerived().transformedLocalDecl(OldParm, {newParm});
6378 return newParm;
6379}
6380
6381template <typename Derived>
6384 const QualType *ParamTypes,
6385 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6386 SmallVectorImpl<QualType> &OutParamTypes,
6389 unsigned *LastParamTransformed) {
6390 int indexAdjustment = 0;
6391
6392 unsigned NumParams = Params.size();
6393 for (unsigned i = 0; i != NumParams; ++i) {
6394 if (LastParamTransformed)
6395 *LastParamTransformed = i;
6396 if (ParmVarDecl *OldParm = Params[i]) {
6397 assert(OldParm->getFunctionScopeIndex() == i);
6398
6399 UnsignedOrNone NumExpansions = std::nullopt;
6400 ParmVarDecl *NewParm = nullptr;
6401 if (OldParm->isParameterPack()) {
6402 // We have a function parameter pack that may need to be expanded.
6404
6405 // Find the parameter packs that could be expanded.
6406 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6408 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6409 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6410
6411 // Determine whether we should expand the parameter packs.
6412 bool ShouldExpand = false;
6413 bool RetainExpansion = false;
6414 UnsignedOrNone OrigNumExpansions = std::nullopt;
6415 if (Unexpanded.size() > 0) {
6416 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6417 NumExpansions = OrigNumExpansions;
6419 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6420 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6421 ShouldExpand, RetainExpansion, NumExpansions)) {
6422 return true;
6423 }
6424 } else {
6425#ifndef NDEBUG
6426 const AutoType *AT =
6427 Pattern.getType().getTypePtr()->getContainedAutoType();
6428 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6429 "Could not find parameter packs or undeduced auto type!");
6430#endif
6431 }
6432
6433 if (ShouldExpand) {
6434 // Expand the function parameter pack into multiple, separate
6435 // parameters.
6436 getDerived().ExpandingFunctionParameterPack(OldParm);
6437 for (unsigned I = 0; I != *NumExpansions; ++I) {
6438 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6439 ParmVarDecl *NewParm
6440 = getDerived().TransformFunctionTypeParam(OldParm,
6441 indexAdjustment++,
6442 OrigNumExpansions,
6443 /*ExpectParameterPack=*/false);
6444 if (!NewParm)
6445 return true;
6446
6447 if (ParamInfos)
6448 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6449 OutParamTypes.push_back(NewParm->getType());
6450 if (PVars)
6451 PVars->push_back(NewParm);
6452 }
6453
6454 // If we're supposed to retain a pack expansion, do so by temporarily
6455 // forgetting the partially-substituted parameter pack.
6456 if (RetainExpansion) {
6457 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6458 ParmVarDecl *NewParm
6459 = getDerived().TransformFunctionTypeParam(OldParm,
6460 indexAdjustment++,
6461 OrigNumExpansions,
6462 /*ExpectParameterPack=*/false);
6463 if (!NewParm)
6464 return true;
6465
6466 if (ParamInfos)
6467 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6468 OutParamTypes.push_back(NewParm->getType());
6469 if (PVars)
6470 PVars->push_back(NewParm);
6471 }
6472
6473 // The next parameter should have the same adjustment as the
6474 // last thing we pushed, but we post-incremented indexAdjustment
6475 // on every push. Also, if we push nothing, the adjustment should
6476 // go down by one.
6477 indexAdjustment--;
6478
6479 // We're done with the pack expansion.
6480 continue;
6481 }
6482
6483 // We'll substitute the parameter now without expanding the pack
6484 // expansion.
6485 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6486 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6487 indexAdjustment,
6488 NumExpansions,
6489 /*ExpectParameterPack=*/true);
6490 assert(NewParm->isParameterPack() &&
6491 "Parameter pack no longer a parameter pack after "
6492 "transformation.");
6493 } else {
6494 NewParm = getDerived().TransformFunctionTypeParam(
6495 OldParm, indexAdjustment, std::nullopt,
6496 /*ExpectParameterPack=*/false);
6497 }
6498
6499 if (!NewParm)
6500 return true;
6501
6502 if (ParamInfos)
6503 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6504 OutParamTypes.push_back(NewParm->getType());
6505 if (PVars)
6506 PVars->push_back(NewParm);
6507 continue;
6508 }
6509
6510 // Deal with the possibility that we don't have a parameter
6511 // declaration for this parameter.
6512 assert(ParamTypes);
6513 QualType OldType = ParamTypes[i];
6514 bool IsPackExpansion = false;
6515 UnsignedOrNone NumExpansions = std::nullopt;
6516 QualType NewType;
6517 if (const PackExpansionType *Expansion
6518 = dyn_cast<PackExpansionType>(OldType)) {
6519 // We have a function parameter pack that may need to be expanded.
6520 QualType Pattern = Expansion->getPattern();
6522 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6523
6524 // Determine whether we should expand the parameter packs.
6525 bool ShouldExpand = false;
6526 bool RetainExpansion = false;
6528 Loc, SourceRange(), Unexpanded,
6529 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6530 RetainExpansion, NumExpansions)) {
6531 return true;
6532 }
6533
6534 if (ShouldExpand) {
6535 // Expand the function parameter pack into multiple, separate
6536 // parameters.
6537 for (unsigned I = 0; I != *NumExpansions; ++I) {
6538 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6539 QualType NewType = getDerived().TransformType(Pattern);
6540 if (NewType.isNull())
6541 return true;
6542
6543 if (NewType->containsUnexpandedParameterPack()) {
6544 NewType = getSema().getASTContext().getPackExpansionType(
6545 NewType, std::nullopt);
6546
6547 if (NewType.isNull())
6548 return true;
6549 }
6550
6551 if (ParamInfos)
6552 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6553 OutParamTypes.push_back(NewType);
6554 if (PVars)
6555 PVars->push_back(nullptr);
6556 }
6557
6558 // We're done with the pack expansion.
6559 continue;
6560 }
6561
6562 // If we're supposed to retain a pack expansion, do so by temporarily
6563 // forgetting the partially-substituted parameter pack.
6564 if (RetainExpansion) {
6565 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6566 QualType NewType = getDerived().TransformType(Pattern);
6567 if (NewType.isNull())
6568 return true;
6569
6570 if (ParamInfos)
6571 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6572 OutParamTypes.push_back(NewType);
6573 if (PVars)
6574 PVars->push_back(nullptr);
6575 }
6576
6577 // We'll substitute the parameter now without expanding the pack
6578 // expansion.
6579 OldType = Expansion->getPattern();
6580 IsPackExpansion = true;
6581 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6582 NewType = getDerived().TransformType(OldType);
6583 } else {
6584 NewType = getDerived().TransformType(OldType);
6585 }
6586
6587 if (NewType.isNull())
6588 return true;
6589
6590 if (IsPackExpansion)
6591 NewType = getSema().Context.getPackExpansionType(NewType,
6592 NumExpansions);
6593
6594 if (ParamInfos)
6595 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6596 OutParamTypes.push_back(NewType);
6597 if (PVars)
6598 PVars->push_back(nullptr);
6599 }
6600
6601#ifndef NDEBUG
6602 if (PVars) {
6603 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6604 if (ParmVarDecl *parm = (*PVars)[i])
6605 assert(parm->getFunctionScopeIndex() == i);
6606 }
6607#endif
6608
6609 return false;
6610}
6611
6612template<typename Derived>
6616 SmallVector<QualType, 4> ExceptionStorage;
6617 return getDerived().TransformFunctionProtoType(
6618 TLB, TL, nullptr, Qualifiers(),
6619 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6620 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6621 ExceptionStorage, Changed);
6622 });
6623}
6624
6625template<typename Derived> template<typename Fn>
6627 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6628 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6629
6630 // Transform the parameters and return type.
6631 //
6632 // We are required to instantiate the params and return type in source order.
6633 // When the function has a trailing return type, we instantiate the
6634 // parameters before the return type, since the return type can then refer
6635 // to the parameters themselves (via decltype, sizeof, etc.).
6636 //
6637 SmallVector<QualType, 4> ParamTypes;
6639 Sema::ExtParameterInfoBuilder ExtParamInfos;
6640 const FunctionProtoType *T = TL.getTypePtr();
6641
6642 QualType ResultType;
6643
6644 if (T->hasTrailingReturn()) {
6646 TL.getBeginLoc(), TL.getParams(),
6648 T->getExtParameterInfosOrNull(),
6649 ParamTypes, &ParamDecls, ExtParamInfos))
6650 return QualType();
6651
6652 {
6653 // C++11 [expr.prim.general]p3:
6654 // If a declaration declares a member function or member function
6655 // template of a class X, the expression this is a prvalue of type
6656 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6657 // and the end of the function-definition, member-declarator, or
6658 // declarator.
6659 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6660 Sema::CXXThisScopeRAII ThisScope(
6661 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6662
6663 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6664 if (ResultType.isNull())
6665 return QualType();
6666 }
6667 }
6668 else {
6669 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6670 if (ResultType.isNull())
6671 return QualType();
6672
6674 TL.getBeginLoc(), TL.getParams(),
6676 T->getExtParameterInfosOrNull(),
6677 ParamTypes, &ParamDecls, ExtParamInfos))
6678 return QualType();
6679 }
6680
6681 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6682
6683 bool EPIChanged = false;
6684 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6685 return QualType();
6686
6687 // Handle extended parameter information.
6688 if (auto NewExtParamInfos =
6689 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6690 if (!EPI.ExtParameterInfos ||
6692 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6693 EPIChanged = true;
6694 }
6695 EPI.ExtParameterInfos = NewExtParamInfos;
6696 } else if (EPI.ExtParameterInfos) {
6697 EPIChanged = true;
6698 EPI.ExtParameterInfos = nullptr;
6699 }
6700
6701 // Transform any function effects with unevaluated conditions.
6702 // Hold this set in a local for the rest of this function, since EPI
6703 // may need to hold a FunctionEffectsRef pointing into it.
6704 std::optional<FunctionEffectSet> NewFX;
6705 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6706 NewFX.emplace();
6709
6710 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6711 FunctionEffectWithCondition NewEC = PrevEC;
6712 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6713 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6714 if (NewExpr.isInvalid())
6715 return QualType();
6716 std::optional<FunctionEffectMode> Mode =
6717 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6718 if (!Mode)
6719 return QualType();
6720
6721 // The condition expression has been transformed, and re-evaluated.
6722 // It may or may not have become constant.
6723 switch (*Mode) {
6725 NewEC.Cond = {};
6726 break;
6728 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6729 NewEC.Cond = {};
6730 break;
6732 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6733 break;
6735 llvm_unreachable(
6736 "FunctionEffectMode::None shouldn't be possible here");
6737 }
6738 }
6739 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6740 TL.getBeginLoc())) {
6742 NewFX->insert(NewEC, Errs);
6743 assert(Errs.empty());
6744 }
6745 }
6746 EPI.FunctionEffects = *NewFX;
6747 EPIChanged = true;
6748 }
6749
6750 QualType Result = TL.getType();
6751 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6752 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6753 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6754 if (Result.isNull())
6755 return QualType();
6756 }
6757
6760 NewTL.setLParenLoc(TL.getLParenLoc());
6761 NewTL.setRParenLoc(TL.getRParenLoc());
6764 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6765 NewTL.setParam(i, ParamDecls[i]);
6766
6767 return Result;
6768}
6769
6770template<typename Derived>
6773 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6774 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6775
6776 // Instantiate a dynamic noexcept expression, if any.
6777 if (isComputedNoexcept(ESI.Type)) {
6778 // Update this scrope because ContextDecl in Sema will be used in
6779 // TransformExpr.
6780 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6781 Sema::CXXThisScopeRAII ThisScope(
6782 SemaRef, Method ? Method->getParent() : nullptr,
6783 Method ? Method->getMethodQualifiers() : Qualifiers{},
6784 Method != nullptr);
6787 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6788 if (NoexceptExpr.isInvalid())
6789 return true;
6790
6792 NoexceptExpr =
6793 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6794 if (NoexceptExpr.isInvalid())
6795 return true;
6796
6797 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6798 Changed = true;
6799 ESI.NoexceptExpr = NoexceptExpr.get();
6800 ESI.Type = EST;
6801 }
6802
6803 if (ESI.Type != EST_Dynamic)
6804 return false;
6805
6806 // Instantiate a dynamic exception specification's type.
6807 for (QualType T : ESI.Exceptions) {
6808 if (const PackExpansionType *PackExpansion =
6809 T->getAs<PackExpansionType>()) {
6810 Changed = true;
6811
6812 // We have a pack expansion. Instantiate it.
6814 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6815 Unexpanded);
6816 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6817
6818 // Determine whether the set of unexpanded parameter packs can and
6819 // should
6820 // be expanded.
6821 bool Expand = false;
6822 bool RetainExpansion = false;
6823 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6824 // FIXME: Track the location of the ellipsis (and track source location
6825 // information for the types in the exception specification in general).
6827 Loc, SourceRange(), Unexpanded,
6828 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6829 NumExpansions))
6830 return true;
6831
6832 if (!Expand) {
6833 // We can't expand this pack expansion into separate arguments yet;
6834 // just substitute into the pattern and create a new pack expansion
6835 // type.
6836 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6837 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6838 if (U.isNull())
6839 return true;
6840
6841 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6842 Exceptions.push_back(U);
6843 continue;
6844 }
6845
6846 // Substitute into the pack expansion pattern for each slice of the
6847 // pack.
6848 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6849 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6850
6851 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6852 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6853 return true;
6854
6855 Exceptions.push_back(U);
6856 }
6857 } else {
6858 QualType U = getDerived().TransformType(T);
6859 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6860 return true;
6861 if (T != U)
6862 Changed = true;
6863
6864 Exceptions.push_back(U);
6865 }
6866 }
6867
6868 ESI.Exceptions = Exceptions;
6869 if (ESI.Exceptions.empty())
6870 ESI.Type = EST_DynamicNone;
6871 return false;
6872}
6873
6874template<typename Derived>
6876 TypeLocBuilder &TLB,
6878 const FunctionNoProtoType *T = TL.getTypePtr();
6879 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6880 if (ResultType.isNull())
6881 return QualType();
6882
6883 QualType Result = TL.getType();
6884 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6885 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6886
6889 NewTL.setLParenLoc(TL.getLParenLoc());
6890 NewTL.setRParenLoc(TL.getRParenLoc());
6892
6893 return Result;
6894}
6895
6896template <typename Derived>
6897QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6898 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6899
6900 const UnresolvedUsingType *T = TL.getTypePtr();
6901 bool Changed = false;
6902
6903 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6904 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6905 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6906 if (!QualifierLoc)
6907 return QualType();
6908 Changed |= QualifierLoc != OldQualifierLoc;
6909 }
6910
6911 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6912 if (!D)
6913 return QualType();
6914 Changed |= D != T->getDecl();
6915
6916 QualType Result = TL.getType();
6917 if (getDerived().AlwaysRebuild() || Changed) {
6918 Result = getDerived().RebuildUnresolvedUsingType(
6919 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6920 D);
6921 if (Result.isNull())
6922 return QualType();
6923 }
6924
6926 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6927 QualifierLoc, TL.getNameLoc());
6928 else
6929 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6930 QualifierLoc, TL.getNameLoc());
6931 return Result;
6932}
6933
6934template <typename Derived>
6936 UsingTypeLoc TL) {
6937 const UsingType *T = TL.getTypePtr();
6938 bool Changed = false;
6939
6940 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6941 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6942 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6943 if (!QualifierLoc)
6944 return QualType();
6945 Changed |= QualifierLoc != OldQualifierLoc;
6946 }
6947
6948 auto *D = cast_or_null<UsingShadowDecl>(
6949 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6950 if (!D)
6951 return QualType();
6952 Changed |= D != T->getDecl();
6953
6954 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6955 if (UnderlyingType.isNull())
6956 return QualType();
6957 Changed |= UnderlyingType != T->desugar();
6958
6959 QualType Result = TL.getType();
6960 if (getDerived().AlwaysRebuild() || Changed) {
6961 Result = getDerived().RebuildUsingType(
6962 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6963 UnderlyingType);
6964 if (Result.isNull())
6965 return QualType();
6966 }
6967 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6968 TL.getNameLoc());
6969 return Result;
6970}
6971
6972template<typename Derived>
6974 TypedefTypeLoc TL) {
6975 const TypedefType *T = TL.getTypePtr();
6976 bool Changed = false;
6977
6978 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6979 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6980 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6981 if (!QualifierLoc)
6982 return QualType();
6983 Changed |= QualifierLoc != OldQualifierLoc;
6984 }
6985
6986 auto *Typedef = cast_or_null<TypedefNameDecl>(
6987 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6988 if (!Typedef)
6989 return QualType();
6990 Changed |= Typedef != T->getDecl();
6991
6992 // FIXME: Transform the UnderlyingType if different from decl.
6993
6994 QualType Result = TL.getType();
6995 if (getDerived().AlwaysRebuild() || Changed) {
6996 Result = getDerived().RebuildTypedefType(
6997 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6998 if (Result.isNull())
6999 return QualType();
7000 }
7001
7002 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7003 QualifierLoc, TL.getNameLoc());
7004 return Result;
7005}
7006
7007template<typename Derived>
7009 TypeOfExprTypeLoc TL) {
7010 // typeof expressions are not potentially evaluated contexts
7014
7015 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
7016 if (E.isInvalid())
7017 return QualType();
7018
7019 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
7020 if (E.isInvalid())
7021 return QualType();
7022
7023 QualType Result = TL.getType();
7025 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
7026 Result =
7027 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
7028 if (Result.isNull())
7029 return QualType();
7030 }
7031
7032 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
7033 NewTL.setTypeofLoc(TL.getTypeofLoc());
7034 NewTL.setLParenLoc(TL.getLParenLoc());
7035 NewTL.setRParenLoc(TL.getRParenLoc());
7036
7037 return Result;
7038}
7039
7040template<typename Derived>
7042 TypeOfTypeLoc TL) {
7043 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
7044 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
7045 if (!New_Under_TI)
7046 return QualType();
7047
7048 QualType Result = TL.getType();
7049 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
7050 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
7051 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
7052 if (Result.isNull())
7053 return QualType();
7054 }
7055
7056 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
7057 NewTL.setTypeofLoc(TL.getTypeofLoc());
7058 NewTL.setLParenLoc(TL.getLParenLoc());
7059 NewTL.setRParenLoc(TL.getRParenLoc());
7060 NewTL.setUnmodifiedTInfo(New_Under_TI);
7061
7062 return Result;
7063}
7064
7065template<typename Derived>
7067 DecltypeTypeLoc TL) {
7068 const DecltypeType *T = TL.getTypePtr();
7069
7070 // decltype expressions are not potentially evaluated contexts
7074
7075 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
7076 if (E.isInvalid())
7077 return QualType();
7078
7079 E = getSema().ActOnDecltypeExpression(E.get());
7080 if (E.isInvalid())
7081 return QualType();
7082
7083 QualType Result = TL.getType();
7084 if (getDerived().AlwaysRebuild() ||
7085 E.get() != T->getUnderlyingExpr()) {
7086 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
7087 if (Result.isNull())
7088 return QualType();
7089 }
7090 else E.get();
7091
7092 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
7093 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
7094 NewTL.setRParenLoc(TL.getRParenLoc());
7095 return Result;
7096}
7097
7098template <typename Derived>
7102 // Transform the index
7103 ExprResult IndexExpr;
7104 {
7105 EnterExpressionEvaluationContext ConstantContext(
7107
7108 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
7109 if (IndexExpr.isInvalid())
7110 return QualType();
7111 }
7112 QualType Pattern = TL.getPattern();
7113
7114 const PackIndexingType *PIT = TL.getTypePtr();
7115 SmallVector<QualType, 5> SubtitutedTypes;
7116 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
7117
7118 bool NotYetExpanded = Types.empty();
7119 bool FullySubstituted = true;
7120
7121 if (Types.empty() && !PIT->expandsToEmptyPack())
7122 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7123
7124 for (QualType T : Types) {
7125 if (!T->containsUnexpandedParameterPack()) {
7126 QualType Transformed = getDerived().TransformType(T);
7127 if (Transformed.isNull())
7128 return QualType();
7129 SubtitutedTypes.push_back(Transformed);
7130 continue;
7131 }
7132
7134 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7135 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7136 // Determine whether the set of unexpanded parameter packs can and should
7137 // be expanded.
7138 bool ShouldExpand = true;
7139 bool RetainExpansion = false;
7140 UnsignedOrNone NumExpansions = std::nullopt;
7141 if (getDerived().TryExpandParameterPacks(
7142 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7143 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7144 RetainExpansion, NumExpansions))
7145 return QualType();
7146 if (!ShouldExpand) {
7147 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7148 // FIXME: should we keep TypeLoc for individual expansions in
7149 // PackIndexingTypeLoc?
7150 TypeSourceInfo *TI =
7151 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7152 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7153 if (Pack.isNull())
7154 return QualType();
7155 if (NotYetExpanded) {
7156 FullySubstituted = false;
7157 QualType Out = getDerived().RebuildPackIndexingType(
7158 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7159 FullySubstituted);
7160 if (Out.isNull())
7161 return QualType();
7162
7164 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7165 return Out;
7166 }
7167 SubtitutedTypes.push_back(Pack);
7168 continue;
7169 }
7170 for (unsigned I = 0; I != *NumExpansions; ++I) {
7171 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7172 QualType Out = getDerived().TransformType(T);
7173 if (Out.isNull())
7174 return QualType();
7175 SubtitutedTypes.push_back(Out);
7176 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7177 }
7178 // If we're supposed to retain a pack expansion, do so by temporarily
7179 // forgetting the partially-substituted parameter pack.
7180 if (RetainExpansion) {
7181 FullySubstituted = false;
7182 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7183 QualType Out = getDerived().TransformType(T);
7184 if (Out.isNull())
7185 return QualType();
7186 SubtitutedTypes.push_back(Out);
7187 }
7188 }
7189
7190 // A pack indexing type can appear in a larger pack expansion,
7191 // e.g. `Pack...[pack_of_indexes]...`
7192 // so we need to temporarily disable substitution of pack elements
7193 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7194 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7195
7196 QualType Out = getDerived().RebuildPackIndexingType(
7197 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7198 FullySubstituted, SubtitutedTypes);
7199 if (Out.isNull())
7200 return Out;
7201
7203 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7204 return Out;
7205}
7206
7207template<typename Derived>
7209 TypeLocBuilder &TLB,
7211 QualType Result = TL.getType();
7212 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7213 if (Result->isDependentType()) {
7214 const UnaryTransformType *T = TL.getTypePtr();
7215
7216 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7217 if (!NewBaseTSI)
7218 return QualType();
7219 QualType NewBase = NewBaseTSI->getType();
7220
7221 Result = getDerived().RebuildUnaryTransformType(NewBase,
7222 T->getUTTKind(),
7223 TL.getKWLoc());
7224 if (Result.isNull())
7225 return QualType();
7226 }
7227
7229 NewTL.setKWLoc(TL.getKWLoc());
7230 NewTL.setParensRange(TL.getParensRange());
7231 NewTL.setUnderlyingTInfo(NewBaseTSI);
7232 return Result;
7233}
7234
7235template<typename Derived>
7238 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7239
7240 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7241 TemplateName TemplateName = getDerived().TransformTemplateName(
7242 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7243 TL.getTemplateNameLoc());
7244 if (TemplateName.isNull())
7245 return QualType();
7246
7247 QualType OldDeduced = T->getDeducedType();
7248 QualType NewDeduced;
7249 if (!OldDeduced.isNull()) {
7250 NewDeduced = getDerived().TransformType(OldDeduced);
7251 if (NewDeduced.isNull())
7252 return QualType();
7253 }
7254
7255 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7256 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7257 NewDeduced, T->getKeyword(), TemplateName);
7258 if (Result.isNull())
7259 return QualType();
7260
7261 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7262 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7263 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7264 NewTL.setQualifierLoc(QualifierLoc);
7265 return Result;
7266}
7267
7268template <typename Derived>
7270 TagTypeLoc TL) {
7271 const TagType *T = TL.getTypePtr();
7272
7273 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7274 if (QualifierLoc) {
7275 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7276 if (!QualifierLoc)
7277 return QualType();
7278 }
7279
7280 auto *TD = cast_or_null<TagDecl>(
7281 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7282 if (!TD)
7283 return QualType();
7284
7285 QualType Result = TL.getType();
7286 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7287 TD != T->getDecl()) {
7288 if (T->isCanonicalUnqualified())
7289 Result = getDerived().RebuildCanonicalTagType(TD);
7290 else
7291 Result = getDerived().RebuildTagType(
7292 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7293 if (Result.isNull())
7294 return QualType();
7295 }
7296
7297 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7299 NewTL.setQualifierLoc(QualifierLoc);
7300 NewTL.setNameLoc(TL.getNameLoc());
7301
7302 return Result;
7303}
7304
7305template <typename Derived>
7307 EnumTypeLoc TL) {
7308 return getDerived().TransformTagType(TLB, TL);
7309}
7310
7311template <typename Derived>
7312QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7313 RecordTypeLoc TL) {
7314 return getDerived().TransformTagType(TLB, TL);
7315}
7316
7317template<typename Derived>
7319 TypeLocBuilder &TLB,
7321 return getDerived().TransformTagType(TLB, TL);
7322}
7323
7324template<typename Derived>
7326 TypeLocBuilder &TLB,
7328 return getDerived().TransformTemplateTypeParmType(
7329 TLB, TL,
7330 /*SuppressObjCLifetime=*/false);
7331}
7332
7333template <typename Derived>
7335 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7336 return TransformTypeSpecType(TLB, TL);
7337}
7338
7339template<typename Derived>
7340QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7341 TypeLocBuilder &TLB,
7342 SubstTemplateTypeParmTypeLoc TL) {
7343 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7344
7345 Decl *NewReplaced =
7346 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7347
7348 // Substitute into the replacement type, which itself might involve something
7349 // that needs to be transformed. This only tends to occur with default
7350 // template arguments of template template parameters.
7351 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7352 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7353 if (Replacement.isNull())
7354 return QualType();
7355
7356 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7357 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7358 T->getFinal());
7359
7360 // Propagate type-source information.
7361 SubstTemplateTypeParmTypeLoc NewTL
7362 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7363 NewTL.setNameLoc(TL.getNameLoc());
7364 return Result;
7365
7366}
7367template <typename Derived>
7370 return TransformTypeSpecType(TLB, TL);
7371}
7372
7373template<typename Derived>
7375 TypeLocBuilder &TLB,
7377 return getDerived().TransformSubstTemplateTypeParmPackType(
7378 TLB, TL, /*SuppressObjCLifetime=*/false);
7379}
7380
7381template <typename Derived>
7384 return TransformTypeSpecType(TLB, TL);
7385}
7386
7387template<typename Derived>
7388QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7389 AtomicTypeLoc TL) {
7390 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7391 if (ValueType.isNull())
7392 return QualType();
7393
7394 QualType Result = TL.getType();
7395 if (getDerived().AlwaysRebuild() ||
7396 ValueType != TL.getValueLoc().getType()) {
7397 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7398 if (Result.isNull())
7399 return QualType();
7400 }
7401
7402 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7403 NewTL.setKWLoc(TL.getKWLoc());
7404 NewTL.setLParenLoc(TL.getLParenLoc());
7405 NewTL.setRParenLoc(TL.getRParenLoc());
7406
7407 return Result;
7408}
7409
7410template <typename Derived>
7412 PipeTypeLoc TL) {
7413 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7414 if (ValueType.isNull())
7415 return QualType();
7416
7417 QualType Result = TL.getType();
7418 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7419 const PipeType *PT = Result->castAs<PipeType>();
7420 bool isReadPipe = PT->isReadOnly();
7421 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7422 if (Result.isNull())
7423 return QualType();
7424 }
7425
7426 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7427 NewTL.setKWLoc(TL.getKWLoc());
7428
7429 return Result;
7430}
7431
7432template <typename Derived>
7434 BitIntTypeLoc TL) {
7435 const BitIntType *EIT = TL.getTypePtr();
7436 QualType Result = TL.getType();
7437
7438 if (getDerived().AlwaysRebuild()) {
7439 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7440 EIT->getNumBits(), TL.getNameLoc());
7441 if (Result.isNull())
7442 return QualType();
7443 }
7444
7445 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7446 NewTL.setNameLoc(TL.getNameLoc());
7447 return Result;
7448}
7449
7450template <typename Derived>
7453 const DependentBitIntType *EIT = TL.getTypePtr();
7454
7457 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7458 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7459
7460 if (BitsExpr.isInvalid())
7461 return QualType();
7462
7463 QualType Result = TL.getType();
7464
7465 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7466 Result = getDerived().RebuildDependentBitIntType(
7467 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7468
7469 if (Result.isNull())
7470 return QualType();
7471 }
7472
7475 NewTL.setNameLoc(TL.getNameLoc());
7476 } else {
7477 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7478 NewTL.setNameLoc(TL.getNameLoc());
7479 }
7480 return Result;
7481}
7482
7483template <typename Derived>
7486 llvm_unreachable("This type does not need to be transformed.");
7487}
7488
7489 /// Simple iterator that traverses the template arguments in a
7490 /// container that provides a \c getArgLoc() member function.
7491 ///
7492 /// This iterator is intended to be used with the iterator form of
7493 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7494 template<typename ArgLocContainer>
7496 ArgLocContainer *Container;
7497 unsigned Index;
7498
7499 public:
7502 typedef int difference_type;
7503 typedef std::input_iterator_tag iterator_category;
7504
7505 class pointer {
7507
7508 public:
7509 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7510
7512 return &Arg;
7513 }
7514 };
7515
7516
7518
7519 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7520 unsigned Index)
7521 : Container(&Container), Index(Index) { }
7522
7524 ++Index;
7525 return *this;
7526 }
7527
7530 ++(*this);
7531 return Old;
7532 }
7533
7535 return Container->getArgLoc(Index);
7536 }
7537
7539 return pointer(Container->getArgLoc(Index));
7540 }
7541
7544 return X.Container == Y.Container && X.Index == Y.Index;
7545 }
7546
7549 return !(X == Y);
7550 }
7551 };
7552
7553template<typename Derived>
7554QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7555 AutoTypeLoc TL) {
7556 const AutoType *T = TL.getTypePtr();
7557 QualType OldDeduced = T->getDeducedType();
7558 QualType NewDeduced;
7559 if (!OldDeduced.isNull()) {
7560 NewDeduced = getDerived().TransformType(OldDeduced);
7561 if (NewDeduced.isNull())
7562 return QualType();
7563 }
7564
7565 ConceptDecl *NewCD = nullptr;
7566 TemplateArgumentListInfo NewTemplateArgs;
7567 NestedNameSpecifierLoc NewNestedNameSpec;
7568 if (T->isConstrained()) {
7569 assert(TL.getConceptReference());
7570 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7571 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7572
7573 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7574 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7576 if (getDerived().TransformTemplateArguments(
7577 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7578 NewTemplateArgs))
7579 return QualType();
7580
7581 if (TL.getNestedNameSpecifierLoc()) {
7582 NewNestedNameSpec
7583 = getDerived().TransformNestedNameSpecifierLoc(
7584 TL.getNestedNameSpecifierLoc());
7585 if (!NewNestedNameSpec)
7586 return QualType();
7587 }
7588 }
7589
7590 QualType Result = TL.getType();
7591 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7592 T->isDependentType() || T->isConstrained()) {
7593 // FIXME: Maybe don't rebuild if all template arguments are the same.
7595 NewArgList.reserve(NewTemplateArgs.size());
7596 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7597 NewArgList.push_back(ArgLoc.getArgument());
7598 Result = getDerived().RebuildAutoType(
7599 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7600 NewDeduced, T->getKeyword(), NewCD, NewArgList);
7601 if (Result.isNull())
7602 return QualType();
7603 }
7604
7605 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7606 NewTL.setNameLoc(TL.getNameLoc());
7607 NewTL.setRParenLoc(TL.getRParenLoc());
7608 NewTL.setConceptReference(nullptr);
7609
7610 if (T->isConstrained()) {
7612 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7613 TL.getConceptNameLoc(),
7614 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7615 auto *CR = ConceptReference::Create(
7616 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7617 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7618 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7619 NewTL.setConceptReference(CR);
7620 }
7621
7622 return Result;
7623}
7624
7625template <typename Derived>
7628 return getDerived().TransformTemplateSpecializationType(
7629 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7630 /*AllowInjectedClassName=*/false);
7631}
7632
7633template <typename Derived>
7636 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7637 const TemplateSpecializationType *T = TL.getTypePtr();
7638
7639 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7640 TemplateName Template = getDerived().TransformTemplateName(
7641 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7642 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7643 AllowInjectedClassName);
7644 if (Template.isNull())
7645 return QualType();
7646
7647 TemplateArgumentListInfo NewTemplateArgs;
7648 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7649 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7651 ArgIterator;
7652 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7653 ArgIterator(TL, TL.getNumArgs()),
7654 NewTemplateArgs))
7655 return QualType();
7656
7657 // This needs to be rebuilt if either the arguments changed, or if the
7658 // original template changed. If the template changed, and even if the
7659 // arguments didn't change, these arguments might not correspond to their
7660 // respective parameters, therefore needing conversions.
7661 QualType Result = getDerived().RebuildTemplateSpecializationType(
7662 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7663 NewTemplateArgs);
7664
7665 if (!Result.isNull()) {
7667 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7668 TL.getTemplateNameLoc(), NewTemplateArgs);
7669 }
7670
7671 return Result;
7672}
7673
7674template <typename Derived>
7676 AttributedTypeLoc TL) {
7677 const AttributedType *oldType = TL.getTypePtr();
7678 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7679 if (modifiedType.isNull())
7680 return QualType();
7681
7682 // HLSL: re-validate matrix-layout markers after substitution. If the
7683 // post-substitution type is no longer a matrix, diagnose now.
7684 if (SemaRef.getLangOpts().HLSL &&
7686 oldType->getAttrKind(), modifiedType,
7687 TL.getAttr() ? TL.getAttr()->getLocation()
7688 : TL.getModifiedLoc().getBeginLoc()))
7689 return QualType();
7690
7691 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7692 const Attr *oldAttr = TL.getAttr();
7693 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7694 if (oldAttr && !newAttr)
7695 return QualType();
7696
7697 QualType result = TL.getType();
7698
7699 // FIXME: dependent operand expressions?
7700 if (getDerived().AlwaysRebuild() ||
7701 modifiedType != oldType->getModifiedType()) {
7702 // If the equivalent type is equal to the modified type, we don't want to
7703 // transform it as well because:
7704 //
7705 // 1. The transformation would yield the same result and is therefore
7706 // superfluous, and
7707 //
7708 // 2. Transforming the same type twice can cause problems, e.g. if it
7709 // is a FunctionProtoType, we may end up instantiating the function
7710 // parameters twice, which causes an assertion since the parameters
7711 // are already bound to their counterparts in the template for this
7712 // instantiation.
7713 //
7714 QualType equivalentType = modifiedType;
7715 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7716 TypeLocBuilder AuxiliaryTLB;
7717 AuxiliaryTLB.reserve(TL.getFullDataSize());
7718 equivalentType =
7719 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7720 if (equivalentType.isNull())
7721 return QualType();
7722 }
7723
7724 // Check whether we can add nullability; it is only represented as
7725 // type sugar, and therefore cannot be diagnosed in any other way.
7726 if (auto nullability = oldType->getImmediateNullability()) {
7727 if (!modifiedType->canHaveNullability()) {
7728 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7729 : TL.getModifiedLoc().getBeginLoc()),
7730 diag::err_nullability_nonpointer)
7731 << DiagNullabilityKind(*nullability, false) << modifiedType;
7732 return QualType();
7733 }
7734 }
7735
7736 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7737 modifiedType,
7738 equivalentType,
7739 TL.getAttr());
7740 }
7741
7742 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7743 newTL.setAttr(newAttr);
7744 return result;
7745}
7746
7747template <typename Derived>
7750 const CountAttributedType *OldTy = TL.getTypePtr();
7751 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7752 if (InnerTy.isNull())
7753 return QualType();
7754
7755 Expr *OldCount = TL.getCountExpr();
7756 Expr *NewCount = nullptr;
7757 if (OldCount) {
7758 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7759 if (CountResult.isInvalid())
7760 return QualType();
7761 NewCount = CountResult.get();
7762 }
7763
7764 QualType Result = TL.getType();
7765 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7766 OldCount != NewCount) {
7767 // Currently, CountAttributedType can only wrap incomplete array types.
7769 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7770 }
7771
7772 TLB.push<CountAttributedTypeLoc>(Result);
7773 return Result;
7774}
7775
7776template <typename Derived>
7780 const LateParsedAttrType *OldTy = TL.getTypePtr();
7781 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7782 if (InnerTy.isNull())
7783 return QualType();
7784
7785 QualType Result = TL.getType();
7786 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getWrappedType()) {
7788 InnerTy, OldTy->getLateParsedAttribute());
7789 }
7790
7792 newTL.setAttrNameLoc(TL.getAttrNameLoc());
7793 return Result;
7794}
7795
7796template <typename Derived>
7799 // The BTFTagAttributedType is available for C only.
7800 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7801}
7802
7803template <typename Derived>
7806 const OverflowBehaviorType *OldTy = TL.getTypePtr();
7807 QualType InnerTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7808 if (InnerTy.isNull())
7809 return QualType();
7810
7811 QualType Result = TL.getType();
7812 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getUnderlyingType()) {
7813 Result = SemaRef.Context.getOverflowBehaviorType(OldTy->getBehaviorKind(),
7814 InnerTy);
7815 if (Result.isNull())
7816 return QualType();
7817 }
7818
7820 NewTL.initializeLocal(SemaRef.Context, TL.getAttrLoc());
7821 return Result;
7822}
7823
7824template <typename Derived>
7827
7828 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7829
7830 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7831 if (WrappedTy.isNull())
7832 return QualType();
7833
7834 QualType ContainedTy = QualType();
7835 QualType OldContainedTy = oldType->getContainedType();
7836 TypeSourceInfo *ContainedTSI = nullptr;
7837 if (!OldContainedTy.isNull()) {
7838 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7839 if (!oldContainedTSI)
7840 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7841 OldContainedTy, SourceLocation());
7842 ContainedTSI = getDerived().TransformType(oldContainedTSI);
7843 if (!ContainedTSI)
7844 return QualType();
7845 ContainedTy = ContainedTSI->getType();
7846 }
7847
7848 QualType Result = TL.getType();
7849 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7850 ContainedTy != oldType->getContainedType()) {
7852 WrappedTy, ContainedTy, oldType->getAttrs());
7853 }
7854
7857 NewTL.setSourceRange(TL.getLocalSourceRange());
7858 NewTL.setContainedTypeSourceInfo(ContainedTSI);
7859 return Result;
7860}
7861
7862template <typename Derived>
7865 // No transformations needed.
7866 return TL.getType();
7867}
7868
7869template<typename Derived>
7872 ParenTypeLoc TL) {
7873 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7874 if (Inner.isNull())
7875 return QualType();
7876
7877 QualType Result = TL.getType();
7878 if (getDerived().AlwaysRebuild() ||
7879 Inner != TL.getInnerLoc().getType()) {
7880 Result = getDerived().RebuildParenType(Inner);
7881 if (Result.isNull())
7882 return QualType();
7883 }
7884
7885 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7886 NewTL.setLParenLoc(TL.getLParenLoc());
7887 NewTL.setRParenLoc(TL.getRParenLoc());
7888 return Result;
7889}
7890
7891template <typename Derived>
7895 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7896 if (Inner.isNull())
7897 return QualType();
7898
7899 QualType Result = TL.getType();
7900 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7901 Result =
7902 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7903 if (Result.isNull())
7904 return QualType();
7905 }
7906
7908 NewTL.setExpansionLoc(TL.getExpansionLoc());
7909 return Result;
7910}
7911
7912template<typename Derived>
7913QualType TreeTransform<Derived>::TransformDependentNameType(
7915 return TransformDependentNameType(TLB, TL, false);
7916}
7917
7918template <typename Derived>
7919QualType TreeTransform<Derived>::TransformDependentNameType(
7920 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7921 QualType ObjectType, NamedDecl *UnqualLookup) {
7922 const DependentNameType *T = TL.getTypePtr();
7923
7924 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7925 if (QualifierLoc) {
7926 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7927 QualifierLoc, ObjectType, UnqualLookup);
7928 if (!QualifierLoc)
7929 return QualType();
7930 } else {
7931 assert((ObjectType.isNull() && !UnqualLookup) &&
7932 "must be transformed by TransformNestedNameSpecifierLoc");
7933 }
7934
7936 = getDerived().RebuildDependentNameType(T->getKeyword(),
7937 TL.getElaboratedKeywordLoc(),
7938 QualifierLoc,
7939 T->getIdentifier(),
7940 TL.getNameLoc(),
7941 DeducedTSTContext);
7942 if (Result.isNull())
7943 return QualType();
7944
7945 if (isa<TagType>(Result)) {
7946 auto NewTL = TLB.push<TagTypeLoc>(Result);
7947 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7948 NewTL.setQualifierLoc(QualifierLoc);
7949 NewTL.setNameLoc(TL.getNameLoc());
7951 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7952 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7953 NewTL.setTemplateNameLoc(TL.getNameLoc());
7954 NewTL.setQualifierLoc(QualifierLoc);
7955 } else if (isa<TypedefType>(Result)) {
7956 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7957 QualifierLoc, TL.getNameLoc());
7958 } else if (isa<UnresolvedUsingType>(Result)) {
7959 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7960 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7961 } else {
7962 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7963 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7964 NewTL.setQualifierLoc(QualifierLoc);
7965 NewTL.setNameLoc(TL.getNameLoc());
7966 }
7967 return Result;
7968}
7969
7970template<typename Derived>
7973 QualType Pattern
7974 = getDerived().TransformType(TLB, TL.getPatternLoc());
7975 if (Pattern.isNull())
7976 return QualType();
7977
7978 QualType Result = TL.getType();
7979 if (getDerived().AlwaysRebuild() ||
7980 Pattern != TL.getPatternLoc().getType()) {
7981 Result = getDerived().RebuildPackExpansionType(Pattern,
7982 TL.getPatternLoc().getSourceRange(),
7983 TL.getEllipsisLoc(),
7984 TL.getTypePtr()->getNumExpansions());
7985 if (Result.isNull())
7986 return QualType();
7987 }
7988
7990 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7991 return Result;
7992}
7993
7994template<typename Derived>
7998 // ObjCInterfaceType is never dependent.
7999 TLB.pushFullCopy(TL);
8000 return TL.getType();
8001}
8002
8003template<typename Derived>
8007 const ObjCTypeParamType *T = TL.getTypePtr();
8008 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
8009 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
8010 if (!OTP)
8011 return QualType();
8012
8013 QualType Result = TL.getType();
8014 if (getDerived().AlwaysRebuild() ||
8015 OTP != T->getDecl()) {
8016 Result = getDerived().RebuildObjCTypeParamType(
8017 OTP, TL.getProtocolLAngleLoc(),
8018 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8019 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8020 if (Result.isNull())
8021 return QualType();
8022 }
8023
8025 if (TL.getNumProtocols()) {
8026 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8027 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8028 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
8029 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8030 }
8031 return Result;
8032}
8033
8034template<typename Derived>
8037 ObjCObjectTypeLoc TL) {
8038 // Transform base type.
8039 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
8040 if (BaseType.isNull())
8041 return QualType();
8042
8043 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
8044
8045 // Transform type arguments.
8046 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
8047 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
8048 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
8049 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
8050 QualType TypeArg = TypeArgInfo->getType();
8051 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
8052 AnyChanged = true;
8053
8054 // We have a pack expansion. Instantiate it.
8055 const auto *PackExpansion = PackExpansionLoc.getType()
8056 ->castAs<PackExpansionType>();
8058 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
8059 Unexpanded);
8060 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8061
8062 // Determine whether the set of unexpanded parameter packs can
8063 // and should be expanded.
8064 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
8065 bool Expand = false;
8066 bool RetainExpansion = false;
8067 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
8068 if (getDerived().TryExpandParameterPacks(
8069 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
8070 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
8071 RetainExpansion, NumExpansions))
8072 return QualType();
8073
8074 if (!Expand) {
8075 // We can't expand this pack expansion into separate arguments yet;
8076 // just substitute into the pattern and create a new pack expansion
8077 // type.
8078 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
8079
8080 TypeLocBuilder TypeArgBuilder;
8081 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8082 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
8083 PatternLoc);
8084 if (NewPatternType.isNull())
8085 return QualType();
8086
8087 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
8088 NewPatternType, NumExpansions);
8089 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
8090 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
8091 NewTypeArgInfos.push_back(
8092 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
8093 continue;
8094 }
8095
8096 // Substitute into the pack expansion pattern for each slice of the
8097 // pack.
8098 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
8099 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
8100
8101 TypeLocBuilder TypeArgBuilder;
8102 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8103
8104 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
8105 PatternLoc);
8106 if (NewTypeArg.isNull())
8107 return QualType();
8108
8109 NewTypeArgInfos.push_back(
8110 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8111 }
8112
8113 continue;
8114 }
8115
8116 TypeLocBuilder TypeArgBuilder;
8117 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
8118 QualType NewTypeArg =
8119 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
8120 if (NewTypeArg.isNull())
8121 return QualType();
8122
8123 // If nothing changed, just keep the old TypeSourceInfo.
8124 if (NewTypeArg == TypeArg) {
8125 NewTypeArgInfos.push_back(TypeArgInfo);
8126 continue;
8127 }
8128
8129 NewTypeArgInfos.push_back(
8130 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8131 AnyChanged = true;
8132 }
8133
8134 QualType Result = TL.getType();
8135 if (getDerived().AlwaysRebuild() || AnyChanged) {
8136 // Rebuild the type.
8137 Result = getDerived().RebuildObjCObjectType(
8138 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8139 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8140 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8141 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8142
8143 if (Result.isNull())
8144 return QualType();
8145 }
8146
8147 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8148 NewT.setHasBaseTypeAsWritten(true);
8149 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8150 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8151 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8152 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8153 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8154 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8155 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8156 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8157 return Result;
8158}
8159
8160template<typename Derived>
8164 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8165 if (PointeeType.isNull())
8166 return QualType();
8167
8168 QualType Result = TL.getType();
8169 if (getDerived().AlwaysRebuild() ||
8170 PointeeType != TL.getPointeeLoc().getType()) {
8171 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8172 TL.getStarLoc());
8173 if (Result.isNull())
8174 return QualType();
8175 }
8176
8178 NewT.setStarLoc(TL.getStarLoc());
8179 return Result;
8180}
8181
8182//===----------------------------------------------------------------------===//
8183// Statement transformation
8184//===----------------------------------------------------------------------===//
8185template<typename Derived>
8188 return S;
8189}
8190
8191template<typename Derived>
8194 return getDerived().TransformCompoundStmt(S, false);
8195}
8196
8197template<typename Derived>
8200 bool IsStmtExpr) {
8201 Sema::CompoundScopeRAII CompoundScope(getSema());
8202 Sema::FPFeaturesStateRAII FPSave(getSema());
8203 if (S->hasStoredFPFeatures())
8204 getSema().resetFPOptions(
8205 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8206
8207 bool SubStmtInvalid = false;
8208 bool SubStmtChanged = false;
8209 SmallVector<Stmt*, 8> Statements;
8210 for (auto *B : S->body()) {
8211 StmtResult Result = getDerived().TransformStmt(
8212 B, IsStmtExpr && B == S->body_back() ? StmtDiscardKind::StmtExprResult
8213 : StmtDiscardKind::Discarded);
8214
8215 if (Result.isInvalid()) {
8216 // Immediately fail if this was a DeclStmt, since it's very
8217 // likely that this will cause problems for future statements.
8218 if (isa<DeclStmt>(B))
8219 return StmtError();
8220
8221 // Otherwise, just keep processing substatements and fail later.
8222 SubStmtInvalid = true;
8223 continue;
8224 }
8225
8226 SubStmtChanged = SubStmtChanged || Result.get() != B;
8227 Statements.push_back(Result.getAs<Stmt>());
8228 }
8229
8230 if (SubStmtInvalid)
8231 return StmtError();
8232
8233 if (!getDerived().AlwaysRebuild() &&
8234 !SubStmtChanged)
8235 return S;
8236
8237 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8238 Statements,
8239 S->getRBracLoc(),
8240 IsStmtExpr);
8241}
8242
8243template<typename Derived>
8246 ExprResult LHS, RHS;
8247 {
8250
8251 // Transform the left-hand case value.
8252 LHS = getDerived().TransformExpr(S->getLHS());
8253 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8254 if (LHS.isInvalid())
8255 return StmtError();
8256
8257 // Transform the right-hand case value (for the GNU case-range extension).
8258 RHS = getDerived().TransformExpr(S->getRHS());
8259 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8260 if (RHS.isInvalid())
8261 return StmtError();
8262 }
8263
8264 // Build the case statement.
8265 // Case statements are always rebuilt so that they will attached to their
8266 // transformed switch statement.
8267 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8268 LHS.get(),
8269 S->getEllipsisLoc(),
8270 RHS.get(),
8271 S->getColonLoc());
8272 if (Case.isInvalid())
8273 return StmtError();
8274
8275 // Transform the statement following the case
8276 StmtResult SubStmt =
8277 getDerived().TransformStmt(S->getSubStmt());
8278 if (SubStmt.isInvalid())
8279 return StmtError();
8280
8281 // Attach the body to the case statement
8282 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8283}
8284
8285template <typename Derived>
8287 // Transform the statement following the default case
8288 StmtResult SubStmt =
8289 getDerived().TransformStmt(S->getSubStmt());
8290 if (SubStmt.isInvalid())
8291 return StmtError();
8292
8293 // Default statements are always rebuilt
8294 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8295 SubStmt.get());
8296}
8297
8298template<typename Derived>
8301 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8302 if (SubStmt.isInvalid())
8303 return StmtError();
8304
8305 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8306 S->getDecl());
8307 if (!LD)
8308 return StmtError();
8309
8310 // If we're transforming "in-place" (we're not creating new local
8311 // declarations), assume we're replacing the old label statement
8312 // and clear out the reference to it.
8313 if (LD == S->getDecl())
8314 S->getDecl()->setStmt(nullptr);
8315
8316 // FIXME: Pass the real colon location in.
8317 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8319 SubStmt.get());
8320}
8321
8322template <typename Derived>
8324 if (!R)
8325 return R;
8326
8327 switch (R->getKind()) {
8328// Transform attributes by calling TransformXXXAttr.
8329#define ATTR(X) \
8330 case attr::X: \
8331 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8332#include "clang/Basic/AttrList.inc"
8333 }
8334 return R;
8335}
8336
8337template <typename Derived>
8339 const Stmt *InstS,
8340 const Attr *R) {
8341 if (!R)
8342 return R;
8343
8344 switch (R->getKind()) {
8345// Transform attributes by calling TransformStmtXXXAttr.
8346#define ATTR(X) \
8347 case attr::X: \
8348 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8349#include "clang/Basic/AttrList.inc"
8350 }
8351 return TransformAttr(R);
8352}
8353
8354template <typename Derived>
8357 StmtDiscardKind SDK) {
8358 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8359 if (SubStmt.isInvalid())
8360 return StmtError();
8361
8362 bool AttrsChanged = false;
8364
8365 // Visit attributes and keep track if any are transformed.
8366 for (const auto *I : S->getAttrs()) {
8367 const Attr *R =
8368 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8369 AttrsChanged |= (I != R);
8370 if (R)
8371 Attrs.push_back(R);
8372 }
8373
8374 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8375 return S;
8376
8377 // If transforming the attributes failed for all of the attributes in the
8378 // statement, don't make an AttributedStmt without attributes.
8379 if (Attrs.empty())
8380 return SubStmt;
8381
8382 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8383 SubStmt.get());
8384}
8385
8386template<typename Derived>
8389 // Transform the initialization statement
8390 StmtResult Init = getDerived().TransformStmt(S->getInit());
8391 if (Init.isInvalid())
8392 return StmtError();
8393
8395 if (!S->isConsteval()) {
8396 // Transform the condition
8397 Cond = getDerived().TransformCondition(
8398 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8399 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8401 if (Cond.isInvalid())
8402 return StmtError();
8403 }
8404
8405 // If this is a constexpr if, determine which arm we should instantiate.
8406 std::optional<bool> ConstexprConditionValue;
8407 if (S->isConstexpr())
8408 ConstexprConditionValue = Cond.getKnownValue();
8409
8410 // Transform the "then" branch.
8411 StmtResult Then;
8412 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8416 S->isNonNegatedConsteval());
8417
8418 Then = getDerived().TransformStmt(S->getThen());
8419 if (Then.isInvalid())
8420 return StmtError();
8421 } else {
8422 // Discarded branch is replaced with empty CompoundStmt so we can keep
8423 // proper source location for start and end of original branch, so
8424 // subsequent transformations like CoverageMapping work properly
8425 Then = new (getSema().Context)
8426 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8427 }
8428
8429 // Transform the "else" branch.
8430 StmtResult Else;
8431 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8435 S->isNegatedConsteval());
8436
8437 Else = getDerived().TransformStmt(S->getElse());
8438 if (Else.isInvalid())
8439 return StmtError();
8440 } else if (S->getElse() && ConstexprConditionValue &&
8441 *ConstexprConditionValue) {
8442 // Same thing here as with <then> branch, we are discarding it, we can't
8443 // replace it with NULL nor NullStmt as we need to keep for source location
8444 // range, for CoverageMapping
8445 Else = new (getSema().Context)
8446 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8447 }
8448
8449 if (!getDerived().AlwaysRebuild() &&
8450 Init.get() == S->getInit() &&
8451 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8452 Then.get() == S->getThen() &&
8453 Else.get() == S->getElse())
8454 return S;
8455
8456 return getDerived().RebuildIfStmt(
8457 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8458 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8459}
8460
8461template<typename Derived>
8464 // Transform the initialization statement
8465 StmtResult Init = getDerived().TransformStmt(S->getInit());
8466 if (Init.isInvalid())
8467 return StmtError();
8468
8469 // Transform the condition.
8470 Sema::ConditionResult Cond = getDerived().TransformCondition(
8471 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8473 if (Cond.isInvalid())
8474 return StmtError();
8475
8476 // Rebuild the switch statement.
8478 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8479 Init.get(), Cond, S->getRParenLoc());
8480 if (Switch.isInvalid())
8481 return StmtError();
8482
8483 // Transform the body of the switch statement.
8484 StmtResult Body = getDerived().TransformStmt(S->getBody());
8485 if (Body.isInvalid())
8486 return StmtError();
8487
8488 // Complete the switch statement.
8489 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8490 Body.get());
8491}
8492
8493template<typename Derived>
8496 // Transform the condition
8497 Sema::ConditionResult Cond = getDerived().TransformCondition(
8498 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8500 if (Cond.isInvalid())
8501 return StmtError();
8502
8503 // OpenACC Restricts a while-loop inside of certain construct/clause
8504 // combinations, so diagnose that here in OpenACC mode.
8506 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8507
8508 // Transform the body
8509 StmtResult Body = getDerived().TransformStmt(S->getBody());
8510 if (Body.isInvalid())
8511 return StmtError();
8512
8513 if (!getDerived().AlwaysRebuild() &&
8514 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8515 Body.get() == S->getBody())
8516 return Owned(S);
8517
8518 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8519 Cond, S->getRParenLoc(), Body.get());
8520}
8521
8522template<typename Derived>
8525 // OpenACC Restricts a do-loop inside of certain construct/clause
8526 // combinations, so diagnose that here in OpenACC mode.
8528 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8529
8530 // Transform the body
8531 StmtResult Body = getDerived().TransformStmt(S->getBody());
8532 if (Body.isInvalid())
8533 return StmtError();
8534
8535 // Transform the condition
8536 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8537 if (Cond.isInvalid())
8538 return StmtError();
8539
8540 if (!getDerived().AlwaysRebuild() &&
8541 Cond.get() == S->getCond() &&
8542 Body.get() == S->getBody())
8543 return S;
8544
8545 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8546 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8547 S->getRParenLoc());
8548}
8549
8550template<typename Derived>
8553 if (getSema().getLangOpts().OpenMP)
8554 getSema().OpenMP().startOpenMPLoop();
8555
8556 // Transform the initialization statement
8557 StmtResult Init = getDerived().TransformStmt(S->getInit());
8558 if (Init.isInvalid())
8559 return StmtError();
8560
8561 // In OpenMP loop region loop control variable must be captured and be
8562 // private. Perform analysis of first part (if any).
8563 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8564 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8565 Init.get());
8566
8567 // Transform the condition
8568 Sema::ConditionResult Cond = getDerived().TransformCondition(
8569 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8571 if (Cond.isInvalid())
8572 return StmtError();
8573
8574 // Transform the increment
8575 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8576 if (Inc.isInvalid())
8577 return StmtError();
8578
8579 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8580 if (S->getInc() && !FullInc.get())
8581 return StmtError();
8582
8583 // OpenACC Restricts a for-loop inside of certain construct/clause
8584 // combinations, so diagnose that here in OpenACC mode.
8586 SemaRef.OpenACC().ActOnForStmtBegin(
8587 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8588 Cond.get().second, S->getInc(), Inc.get());
8589
8590 // Transform the body
8591 StmtResult Body = getDerived().TransformStmt(S->getBody());
8592 if (Body.isInvalid())
8593 return StmtError();
8594
8595 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8596
8597 if (!getDerived().AlwaysRebuild() &&
8598 Init.get() == S->getInit() &&
8599 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8600 Inc.get() == S->getInc() &&
8601 Body.get() == S->getBody())
8602 return S;
8603
8604 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8605 Init.get(), Cond, FullInc,
8606 S->getRParenLoc(), Body.get());
8607}
8608
8609template<typename Derived>
8612 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8613 S->getLabel());
8614 if (!LD)
8615 return StmtError();
8616
8617 // Goto statements must always be rebuilt, to resolve the label.
8618 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8619 cast<LabelDecl>(LD));
8620}
8621
8622template<typename Derived>
8625 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8626 if (Target.isInvalid())
8627 return StmtError();
8628 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8629
8630 if (!getDerived().AlwaysRebuild() &&
8631 Target.get() == S->getTarget())
8632 return S;
8633
8634 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8635 Target.get());
8636}
8637
8638template<typename Derived>
8641 if (!S->hasLabelTarget())
8642 return S;
8643
8644 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8645 S->getLabelDecl());
8646 if (!LD)
8647 return StmtError();
8648
8649 return new (SemaRef.Context)
8650 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8651}
8652
8653template<typename Derived>
8656 if (!S->hasLabelTarget())
8657 return S;
8658
8659 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8660 S->getLabelDecl());
8661 if (!LD)
8662 return StmtError();
8663
8664 return new (SemaRef.Context)
8665 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8666}
8667
8668template <typename Derived>
8670 StmtResult Result = getDerived().TransformStmt(S->getBody());
8671 if (!Result.isUsable())
8672 return StmtError();
8673 return DeferStmt::Create(getSema().Context, S->getDeferLoc(), Result.get());
8674}
8675
8676template<typename Derived>
8679 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8680 /*NotCopyInit*/false);
8681 if (Result.isInvalid())
8682 return StmtError();
8683
8684 // FIXME: We always rebuild the return statement because there is no way
8685 // to tell whether the return type of the function has changed.
8686 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8687}
8688
8689template<typename Derived>
8692 bool DeclChanged = false;
8694 LambdaScopeInfo *LSI = getSema().getCurLambda();
8695 for (auto *D : S->decls()) {
8696 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8697 if (!Transformed)
8698 return StmtError();
8699
8700 if (Transformed != D)
8701 DeclChanged = true;
8702
8703 if (LSI) {
8704 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8705 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8706 LSI->ContainsUnexpandedParameterPack |=
8707 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8708 } else {
8709 LSI->ContainsUnexpandedParameterPack |=
8710 getSema()
8711 .getASTContext()
8712 .getTypeDeclType(TD)
8713 ->containsUnexpandedParameterPack();
8714 }
8715 }
8716 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8717 LSI->ContainsUnexpandedParameterPack |=
8718 VD->getType()->containsUnexpandedParameterPack();
8719 }
8720
8721 Decls.push_back(Transformed);
8722 }
8723
8724 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8725 return S;
8726
8727 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8728}
8729
8730template<typename Derived>
8733
8734 SmallVector<Expr*, 8> Constraints;
8737
8738 SmallVector<Expr*, 8> Clobbers;
8739
8740 bool ExprsChanged = false;
8741
8742 auto RebuildString = [&](Expr *E) {
8743 ExprResult Result = getDerived().TransformExpr(E);
8744 if (!Result.isUsable())
8745 return Result;
8746 if (Result.get() != E) {
8747 ExprsChanged = true;
8748 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8749 }
8750 return Result;
8751 };
8752
8753 // Go through the outputs.
8754 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8755 Names.push_back(S->getOutputIdentifier(I));
8756
8757 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8758 if (Result.isInvalid())
8759 return StmtError();
8760
8761 Constraints.push_back(Result.get());
8762
8763 // Transform the output expr.
8764 Expr *OutputExpr = S->getOutputExpr(I);
8765 Result = getDerived().TransformExpr(OutputExpr);
8766 if (Result.isInvalid())
8767 return StmtError();
8768
8769 ExprsChanged |= Result.get() != OutputExpr;
8770
8771 Exprs.push_back(Result.get());
8772 }
8773
8774 // Go through the inputs.
8775 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8776 Names.push_back(S->getInputIdentifier(I));
8777
8778 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8779 if (Result.isInvalid())
8780 return StmtError();
8781
8782 Constraints.push_back(Result.get());
8783
8784 // Transform the input expr.
8785 Expr *InputExpr = S->getInputExpr(I);
8786 Result = getDerived().TransformExpr(InputExpr);
8787 if (Result.isInvalid())
8788 return StmtError();
8789
8790 ExprsChanged |= Result.get() != InputExpr;
8791
8792 Exprs.push_back(Result.get());
8793 }
8794
8795 // Go through the Labels.
8796 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8797 Names.push_back(S->getLabelIdentifier(I));
8798
8799 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8800 if (Result.isInvalid())
8801 return StmtError();
8802 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8803 Exprs.push_back(Result.get());
8804 }
8805
8806 // Go through the clobbers.
8807 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8808 ExprResult Result = RebuildString(S->getClobberExpr(I));
8809 if (Result.isInvalid())
8810 return StmtError();
8811 Clobbers.push_back(Result.get());
8812 }
8813
8814 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8815 if (AsmString.isInvalid())
8816 return StmtError();
8817
8818 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8819 return S;
8820
8821 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8822 S->isVolatile(), S->getNumOutputs(),
8823 S->getNumInputs(), Names.data(),
8824 Constraints, Exprs, AsmString.get(),
8825 Clobbers, S->getNumLabels(),
8826 S->getRParenLoc());
8827}
8828
8829template<typename Derived>
8832 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8833
8834 bool HadError = false, HadChange = false;
8835
8836 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8837 SmallVector<Expr*, 8> TransformedExprs;
8838 TransformedExprs.reserve(SrcExprs.size());
8839 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8840 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8841 if (!Result.isUsable()) {
8842 HadError = true;
8843 } else {
8844 HadChange |= (Result.get() != SrcExprs[i]);
8845 TransformedExprs.push_back(Result.get());
8846 }
8847 }
8848
8849 if (HadError) return StmtError();
8850 if (!HadChange && !getDerived().AlwaysRebuild())
8851 return Owned(S);
8852
8853 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8854 AsmToks, S->getAsmString(),
8855 S->getNumOutputs(), S->getNumInputs(),
8856 S->getAllConstraints(), S->getClobbers(),
8857 TransformedExprs, S->getEndLoc());
8858}
8859
8860// C++ Coroutines
8861template<typename Derived>
8864 auto *ScopeInfo = SemaRef.getCurFunction();
8865 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8866 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8867 ScopeInfo->NeedsCoroutineSuspends &&
8868 ScopeInfo->CoroutineSuspends.first == nullptr &&
8869 ScopeInfo->CoroutineSuspends.second == nullptr &&
8870 "expected clean scope info");
8871
8872 // Set that we have (possibly-invalid) suspend points before we do anything
8873 // that may fail.
8874 ScopeInfo->setNeedsCoroutineSuspends(false);
8875
8876 // We re-build the coroutine promise object (and the coroutine parameters its
8877 // type and constructor depend on) based on the types used in our current
8878 // function. We must do so, and set it on the current FunctionScopeInfo,
8879 // before attempting to transform the other parts of the coroutine body
8880 // statement, such as the implicit suspend statements (because those
8881 // statements reference the FunctionScopeInfo::CoroutinePromise).
8882 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8883 return StmtError();
8884 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8885 if (!Promise)
8886 return StmtError();
8887 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8888 ScopeInfo->CoroutinePromise = Promise;
8889
8890 // Transform the implicit coroutine statements constructed using dependent
8891 // types during the previous parse: initial and final suspensions, the return
8892 // object, and others. We also transform the coroutine function's body.
8893 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8894 if (InitSuspend.isInvalid())
8895 return StmtError();
8896 StmtResult FinalSuspend =
8897 getDerived().TransformStmt(S->getFinalSuspendStmt());
8898 if (FinalSuspend.isInvalid() ||
8899 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8900 return StmtError();
8901 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8902 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8903
8904 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8905 if (BodyRes.isInvalid())
8906 return StmtError();
8907
8908 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8909 if (Builder.isInvalid())
8910 return StmtError();
8911
8912 Expr *ReturnObject = S->getReturnValueInit();
8913 assert(ReturnObject && "the return object is expected to be valid");
8914 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8915 /*NoCopyInit*/ false);
8916 if (Res.isInvalid())
8917 return StmtError();
8918 Builder.ReturnValue = Res.get();
8919
8920 // If during the previous parse the coroutine still had a dependent promise
8921 // statement, we may need to build some implicit coroutine statements
8922 // (such as exception and fallthrough handlers) for the first time.
8923 if (S->hasDependentPromiseType()) {
8924 // We can only build these statements, however, if the current promise type
8925 // is not dependent.
8926 if (!Promise->getType()->isDependentType()) {
8927 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8928 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8929 "these nodes should not have been built yet");
8930 if (!Builder.buildDependentStatements())
8931 return StmtError();
8932 }
8933 } else {
8934 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8935 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8936 if (Res.isInvalid())
8937 return StmtError();
8938 Builder.OnFallthrough = Res.get();
8939 }
8940
8941 if (auto *OnException = S->getExceptionHandler()) {
8942 StmtResult Res = getDerived().TransformStmt(OnException);
8943 if (Res.isInvalid())
8944 return StmtError();
8945 Builder.OnException = Res.get();
8946 }
8947
8948 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8949 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8950 if (Res.isInvalid())
8951 return StmtError();
8952 Builder.ReturnStmtOnAllocFailure = Res.get();
8953 }
8954
8955 // Transform any additional statements we may have already built
8956 assert(S->getAllocate() && S->getDeallocate() &&
8957 "allocation and deallocation calls must already be built");
8958 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8959 if (AllocRes.isInvalid())
8960 return StmtError();
8961 Builder.Allocate = AllocRes.get();
8962
8963 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8964 if (DeallocRes.isInvalid())
8965 return StmtError();
8966 Builder.Deallocate = DeallocRes.get();
8967
8968 if (auto *ResultDecl = S->getResultDecl()) {
8969 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8970 if (Res.isInvalid())
8971 return StmtError();
8972 Builder.ResultDecl = Res.get();
8973 }
8974
8975 if (auto *ReturnStmt = S->getReturnStmt()) {
8976 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8977 if (Res.isInvalid())
8978 return StmtError();
8979 Builder.ReturnStmt = Res.get();
8980 }
8981 }
8982
8983 return getDerived().RebuildCoroutineBodyStmt(Builder);
8984}
8985
8986template<typename Derived>
8989 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8990 /*NotCopyInit*/false);
8991 if (Result.isInvalid())
8992 return StmtError();
8993
8994 // Always rebuild; we don't know if this needs to be injected into a new
8995 // context or if the promise type has changed.
8996 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8997 S->isImplicit());
8998}
8999
9000template <typename Derived>
9002 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
9003 /*NotCopyInit*/ false);
9004 if (Operand.isInvalid())
9005 return ExprError();
9006
9007 // Rebuild the common-expr from the operand rather than transforming it
9008 // separately.
9009
9010 // FIXME: getCurScope() should not be used during template instantiation.
9011 // We should pick up the set of unqualified lookup results for operator
9012 // co_await during the initial parse.
9013 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
9014 getSema().getCurScope(), E->getKeywordLoc());
9015
9016 // Always rebuild; we don't know if this needs to be injected into a new
9017 // context or if the promise type has changed.
9018 return getDerived().RebuildCoawaitExpr(
9019 E->getKeywordLoc(), Operand.get(),
9020 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
9021}
9022
9023template <typename Derived>
9026 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
9027 /*NotCopyInit*/ false);
9028 if (OperandResult.isInvalid())
9029 return ExprError();
9030
9031 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
9032 E->getOperatorCoawaitLookup());
9033
9034 if (LookupResult.isInvalid())
9035 return ExprError();
9036
9037 // Always rebuild; we don't know if this needs to be injected into a new
9038 // context or if the promise type has changed.
9039 return getDerived().RebuildDependentCoawaitExpr(
9040 E->getKeywordLoc(), OperandResult.get(),
9042}
9043
9044template<typename Derived>
9047 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
9048 /*NotCopyInit*/false);
9049 if (Result.isInvalid())
9050 return ExprError();
9051
9052 // Always rebuild; we don't know if this needs to be injected into a new
9053 // context or if the promise type has changed.
9054 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
9055}
9056
9057// Objective-C Statements.
9058
9059template<typename Derived>
9062 // Transform the body of the @try.
9063 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
9064 if (TryBody.isInvalid())
9065 return StmtError();
9066
9067 // Transform the @catch statements (if present).
9068 bool AnyCatchChanged = false;
9069 SmallVector<Stmt*, 8> CatchStmts;
9070 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
9071 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
9072 if (Catch.isInvalid())
9073 return StmtError();
9074 if (Catch.get() != S->getCatchStmt(I))
9075 AnyCatchChanged = true;
9076 CatchStmts.push_back(Catch.get());
9077 }
9078
9079 // Transform the @finally statement (if present).
9080 StmtResult Finally;
9081 if (S->getFinallyStmt()) {
9082 Finally = getDerived().TransformStmt(S->getFinallyStmt());
9083 if (Finally.isInvalid())
9084 return StmtError();
9085 }
9086
9087 // If nothing changed, just retain this statement.
9088 if (!getDerived().AlwaysRebuild() &&
9089 TryBody.get() == S->getTryBody() &&
9090 !AnyCatchChanged &&
9091 Finally.get() == S->getFinallyStmt())
9092 return S;
9093
9094 // Build a new statement.
9095 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
9096 CatchStmts, Finally.get());
9097}
9098
9099template<typename Derived>
9102 // Transform the @catch parameter, if there is one.
9103 VarDecl *Var = nullptr;
9104 if (VarDecl *FromVar = S->getCatchParamDecl()) {
9105 TypeSourceInfo *TSInfo = nullptr;
9106 if (FromVar->getTypeSourceInfo()) {
9107 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
9108 if (!TSInfo)
9109 return StmtError();
9110 }
9111
9112 QualType T;
9113 if (TSInfo)
9114 T = TSInfo->getType();
9115 else {
9116 T = getDerived().TransformType(FromVar->getType());
9117 if (T.isNull())
9118 return StmtError();
9119 }
9120
9121 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
9122 if (!Var)
9123 return StmtError();
9124 }
9125
9126 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
9127 if (Body.isInvalid())
9128 return StmtError();
9129
9130 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9131 S->getRParenLoc(),
9132 Var, Body.get());
9133}
9134
9135template<typename Derived>
9138 // Transform the body.
9139 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9140 if (Body.isInvalid())
9141 return StmtError();
9142
9143 // If nothing changed, just retain this statement.
9144 if (!getDerived().AlwaysRebuild() &&
9145 Body.get() == S->getFinallyBody())
9146 return S;
9147
9148 // Build a new statement.
9149 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9150 Body.get());
9151}
9152
9153template<typename Derived>
9157 if (S->getThrowExpr()) {
9158 Operand = getDerived().TransformExpr(S->getThrowExpr());
9159 if (Operand.isInvalid())
9160 return StmtError();
9161 }
9162
9163 if (!getDerived().AlwaysRebuild() &&
9164 Operand.get() == S->getThrowExpr())
9165 return S;
9166
9167 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9168}
9169
9170template<typename Derived>
9174 // Transform the object we are locking.
9175 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9176 if (Object.isInvalid())
9177 return StmtError();
9178 Object =
9179 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9180 Object.get());
9181 if (Object.isInvalid())
9182 return StmtError();
9183
9184 // Transform the body.
9185 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9186 if (Body.isInvalid())
9187 return StmtError();
9188
9189 // If nothing change, just retain the current statement.
9190 if (!getDerived().AlwaysRebuild() &&
9191 Object.get() == S->getSynchExpr() &&
9192 Body.get() == S->getSynchBody())
9193 return S;
9194
9195 // Build a new statement.
9196 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9197 Object.get(), Body.get());
9198}
9199
9200template<typename Derived>
9204 // Transform the body.
9205 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9206 if (Body.isInvalid())
9207 return StmtError();
9208
9209 // If nothing changed, just retain this statement.
9210 if (!getDerived().AlwaysRebuild() &&
9211 Body.get() == S->getSubStmt())
9212 return S;
9213
9214 // Build a new statement.
9215 return getDerived().RebuildObjCAutoreleasePoolStmt(
9216 S->getAtLoc(), Body.get());
9217}
9218
9219template<typename Derived>
9223 // Transform the element statement.
9224 StmtResult Element = getDerived().TransformStmt(
9225 S->getElement(), StmtDiscardKind::NotDiscarded);
9226 if (Element.isInvalid())
9227 return StmtError();
9228
9229 // Transform the collection expression.
9230 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9231 if (Collection.isInvalid())
9232 return StmtError();
9233
9234 // Transform the body.
9235 StmtResult Body = getDerived().TransformStmt(S->getBody());
9236 if (Body.isInvalid())
9237 return StmtError();
9238
9239 // If nothing changed, just retain this statement.
9240 if (!getDerived().AlwaysRebuild() &&
9241 Element.get() == S->getElement() &&
9242 Collection.get() == S->getCollection() &&
9243 Body.get() == S->getBody())
9244 return S;
9245
9246 // Build a new statement.
9247 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9248 Element.get(),
9249 Collection.get(),
9250 S->getRParenLoc(),
9251 Body.get());
9252}
9253
9254template <typename Derived>
9256 // Transform the exception declaration, if any.
9257 VarDecl *Var = nullptr;
9258 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9259 TypeSourceInfo *T =
9260 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9261 if (!T)
9262 return StmtError();
9263
9264 Var = getDerived().RebuildExceptionDecl(
9265 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9266 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9267 if (!Var || Var->isInvalidDecl())
9268 return StmtError();
9269 }
9270
9271 // Transform the actual exception handler.
9272 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9273 if (Handler.isInvalid())
9274 return StmtError();
9275
9276 if (!getDerived().AlwaysRebuild() && !Var &&
9277 Handler.get() == S->getHandlerBlock())
9278 return S;
9279
9280 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9281}
9282
9283template <typename Derived>
9285 // Transform the try block itself.
9286 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9287 if (TryBlock.isInvalid())
9288 return StmtError();
9289
9290 // Transform the handlers.
9291 bool HandlerChanged = false;
9292 SmallVector<Stmt *, 8> Handlers;
9293 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9294 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9295 if (Handler.isInvalid())
9296 return StmtError();
9297
9298 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9299 Handlers.push_back(Handler.getAs<Stmt>());
9300 }
9301
9302 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9303
9304 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9305 !HandlerChanged)
9306 return S;
9307
9308 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9309 Handlers);
9310}
9311
9312template<typename Derived>
9315 EnterExpressionEvaluationContext ForRangeInitContext(
9317 /*LambdaContextDecl=*/nullptr,
9319 getSema().getLangOpts().CPlusPlus23);
9320
9321 // P2718R0 - Lifetime extension in range-based for loops.
9322 if (getSema().getLangOpts().CPlusPlus23) {
9323 auto &LastRecord = getSema().currentEvaluationContext();
9324 LastRecord.InLifetimeExtendingContext = true;
9325 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9326 }
9328 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9329 if (Init.isInvalid())
9330 return StmtError();
9331
9332 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9333 if (Range.isInvalid())
9334 return StmtError();
9335
9336 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9337 assert(getSema().getLangOpts().CPlusPlus23 ||
9338 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9339 auto ForRangeLifetimeExtendTemps =
9340 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9341
9342 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9343 if (Begin.isInvalid())
9344 return StmtError();
9345 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9346 if (End.isInvalid())
9347 return StmtError();
9348
9349 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9350 if (Cond.isInvalid())
9351 return StmtError();
9352 if (Cond.get())
9353 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9354 if (Cond.isInvalid())
9355 return StmtError();
9356 if (Cond.get())
9357 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9358
9359 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9360 if (Inc.isInvalid())
9361 return StmtError();
9362 if (Inc.get())
9363 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9364
9365 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9366 if (LoopVar.isInvalid())
9367 return StmtError();
9368
9369 StmtResult NewStmt = S;
9370 if (getDerived().AlwaysRebuild() ||
9371 Init.get() != S->getInit() ||
9372 Range.get() != S->getRangeStmt() ||
9373 Begin.get() != S->getBeginStmt() ||
9374 End.get() != S->getEndStmt() ||
9375 Cond.get() != S->getCond() ||
9376 Inc.get() != S->getInc() ||
9377 LoopVar.get() != S->getLoopVarStmt()) {
9378 NewStmt = getDerived().RebuildCXXForRangeStmt(
9379 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9380 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9381 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9382 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9383 // Might not have attached any initializer to the loop variable.
9384 getSema().ActOnInitializerError(
9385 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9386 return StmtError();
9387 }
9388 }
9389
9390 // OpenACC Restricts a while-loop inside of certain construct/clause
9391 // combinations, so diagnose that here in OpenACC mode.
9393 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9394
9395 StmtResult Body = getDerived().TransformStmt(S->getBody());
9396 if (Body.isInvalid())
9397 return StmtError();
9398
9399 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9400
9401 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9402 // it now so we have a new statement to attach the body to.
9403 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9404 NewStmt = getDerived().RebuildCXXForRangeStmt(
9405 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9406 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9407 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9408 if (NewStmt.isInvalid())
9409 return StmtError();
9410 }
9411
9412 if (NewStmt.get() == S)
9413 return S;
9414
9415 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9416}
9417
9418template <typename Derived>
9421 assert(SemaRef.CurContext->isExpansionStmt());
9422
9423 Decl *ESD =
9424 getDerived().TransformDecl(S->getDecl()->getLocation(), S->getDecl());
9425 if (!ESD || ESD->isInvalidDecl())
9426 return StmtError();
9428
9429 // This is required because some parts of an expansion statement (e.g. the
9430 // init-statement) are not in a dependent context and must thus be transformed
9431 // in the parent context.
9432 auto TransformStmtInParentContext = [&](Stmt *SubStmt) -> StmtResult {
9433 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9434 /*NewThis=*/false);
9435 return getDerived().TransformStmt(SubStmt);
9436 };
9437
9438 Stmt *Init = S->getInit();
9439 if (Init) {
9440 StmtResult SR = TransformStmtInParentContext(Init);
9441 if (SR.isInvalid())
9442 return StmtError();
9443 Init = SR.get();
9444 }
9445
9446 // Collect lifetime-extended temporaries in case this ends up being a
9447 // destructuring or iterating expansion statement.
9448 //
9449 // CWG 3140: Additionally, for iterating expansions statements, we need to
9450 // apply lifetime extension to the initializer of the range.
9451 ExprResult ExpansionInitializer;
9454 if (S->isDependent() || S->isIterating()) {
9456 SemaRef, SemaRef.currentEvaluationContext().Context);
9459
9460 if (S->isDependent()) {
9461 // The expansion initializer should not be in the context of the expansion
9462 // statement because it isn't instantiated when the expansion statement is
9463 // expanded.
9464 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9465 /*NewThis=*/false);
9466 ExpansionInitializer =
9467 getDerived().TransformExpr(S->getExpansionInitializer());
9468 if (ExpansionInitializer.isInvalid())
9469 return StmtError();
9470 } else if (S->isIterating()) {
9471 Range = TransformStmtInParentContext(S->getRangeVarStmt());
9472 if (Range.isInvalid())
9473 return StmtError();
9474 }
9475
9476 ExpansionInitializer =
9477 SemaRef.MaybeCreateExprWithCleanups(ExpansionInitializer);
9478
9479 LifetimeExtendTemps =
9481 }
9482
9483 CXXExpansionStmtPattern *NewPattern = nullptr;
9484 if (S->isEnumerating()) {
9485 StmtResult ExpansionVar =
9486 getDerived().TransformStmt(S->getExpansionVarStmt());
9487 if (ExpansionVar.isInvalid())
9488 return StmtError();
9489
9491 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9492 S->getLParenLoc(), S->getColonLoc(), S->getRParenLoc());
9493 } else if (S->isIterating()) {
9494 StmtResult Begin = TransformStmtInParentContext(S->getBeginVarStmt());
9495 StmtResult Iter = TransformStmtInParentContext(S->getIterVarStmt());
9496 if (Begin.isInvalid() || Iter.isInvalid())
9497 return StmtError();
9498
9499 // The expansion variable is part of the pattern only and never ends
9500 // up in the instantiations, so keep it in the expansion statement's
9501 // DeclContext.
9502 StmtResult ExpansionVar =
9503 getDerived().TransformStmt(S->getExpansionVarStmt());
9504 if (ExpansionVar.isInvalid())
9505 return StmtError();
9506
9508 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9509 Range.getAs<DeclStmt>(), Begin.getAs<DeclStmt>(),
9510 Iter.getAs<DeclStmt>(), S->getLParenLoc(), S->getColonLoc(),
9511 S->getRParenLoc());
9512
9514 NewPattern->getRangeVar(), LifetimeExtendTemps);
9515 } else if (S->isDependent()) {
9516 StmtResult ExpansionVar =
9517 getDerived().TransformStmt(S->getExpansionVarStmt());
9518 if (ExpansionVar.isInvalid())
9519 return StmtError();
9520
9522 NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9523 ExpansionInitializer.get(), S->getLParenLoc(), S->getColonLoc(),
9524 S->getRParenLoc(), LifetimeExtendTemps);
9525
9526 if (Res.isInvalid())
9527 return StmtError();
9528
9529 NewPattern = cast<CXXExpansionStmtPattern>(Res.get());
9530 } else {
9531 // The only time we instantiate an expansion statement is if its expansion
9532 // size is dependent (otherwise, we only instantiate the expansions and
9533 // leave the underlying CXXExpansionStmtPattern as-is). Since destructuring
9534 // expansion statements never have a dependent size, we should never get
9535 // here.
9536 llvm_unreachable("destructuring pattern should never be instantiated");
9537 }
9538
9539 StmtResult Body = getDerived().TransformStmt(S->getBody());
9540 if (Body.isInvalid())
9541 return StmtError();
9542
9543 return SemaRef.FinishCXXExpansionStmt(NewPattern, Body.get());
9544}
9545
9546template <typename Derived>
9549 bool SubStmtChanged = false;
9550 auto TransformStmts = [&](SmallVectorImpl<Stmt *> &NewStmts,
9551 ArrayRef<Stmt *> OldStmts) {
9552 for (Stmt *OldDS : OldStmts) {
9553 StmtResult NewDS = getDerived().TransformStmt(OldDS);
9554 if (NewDS.isInvalid())
9555 return true;
9556
9557 SubStmtChanged |= NewDS.get() != OldDS;
9558 NewStmts.push_back(NewDS.get());
9559 }
9560
9561 return false;
9562 };
9563
9564 Decl *ESD =
9565 getDerived().TransformDecl(S->getParent()->getLocation(), S->getParent());
9566 if (!ESD || ESD->isInvalidDecl())
9567 return StmtError();
9569
9570 SmallVector<Stmt *> PreambleStmts;
9571 SmallVector<Stmt *> Instantiations;
9572
9573 // Apply lifetime extension to the preamble statements if this was a
9574 // destructuring expansion statement.
9575 {
9577 SemaRef, SemaRef.currentEvaluationContext().Context);
9580 if (TransformStmts(PreambleStmts, S->getPreambleStmts()))
9581 return StmtError();
9582
9583 if (S->shouldApplyLifetimeExtensionToPreamble()) {
9584 auto *VD =
9585 cast<VarDecl>(cast<DeclStmt>(PreambleStmts.front())->getSingleDecl());
9588 }
9589 }
9590
9591 if (TransformStmts(Instantiations, S->getInstantiations()))
9592 return StmtError();
9593
9594 if (!getDerived().AlwaysRebuild() && !SubStmtChanged)
9595 return S;
9596
9598 SemaRef.Context, NewESD, Instantiations, PreambleStmts,
9599 S->shouldApplyLifetimeExtensionToPreamble());
9600}
9601
9602template <typename Derived>
9605 ExprResult Range = getDerived().TransformExpr(E->getRangeExpr());
9606 ExprResult Idx = getDerived().TransformExpr(E->getIndexExpr());
9607 if (Range.isInvalid() || Idx.isInvalid())
9608 return ExprError();
9609
9610 if (!getDerived().AlwaysRebuild() && Range.get() == E->getRangeExpr() &&
9611 Idx.get() == E->getIndexExpr())
9612 return E;
9613
9614 return SemaRef.BuildCXXExpansionSelectExpr(Range.getAs<InitListExpr>(),
9615 Idx.get());
9616}
9617
9618template<typename Derived>
9622 // Transform the nested-name-specifier, if any.
9623 NestedNameSpecifierLoc QualifierLoc;
9624 if (S->getQualifierLoc()) {
9625 QualifierLoc
9626 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9627 if (!QualifierLoc)
9628 return StmtError();
9629 }
9630
9631 // Transform the declaration name.
9632 DeclarationNameInfo NameInfo = S->getNameInfo();
9633 if (NameInfo.getName()) {
9634 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9635 if (!NameInfo.getName())
9636 return StmtError();
9637 }
9638
9639 // Check whether anything changed.
9640 if (!getDerived().AlwaysRebuild() &&
9641 QualifierLoc == S->getQualifierLoc() &&
9642 NameInfo.getName() == S->getNameInfo().getName())
9643 return S;
9644
9645 // Determine whether this name exists, if we can.
9646 CXXScopeSpec SS;
9647 SS.Adopt(QualifierLoc);
9648 bool Dependent = false;
9649 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9651 if (S->isIfExists())
9652 break;
9653
9654 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9655
9657 if (S->isIfNotExists())
9658 break;
9659
9660 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9661
9663 Dependent = true;
9664 break;
9665
9667 return StmtError();
9668 }
9669
9670 // We need to continue with the instantiation, so do so now.
9671 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9672 if (SubStmt.isInvalid())
9673 return StmtError();
9674
9675 // If we have resolved the name, just transform to the substatement.
9676 if (!Dependent)
9677 return SubStmt;
9678
9679 // The name is still dependent, so build a dependent expression again.
9680 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9681 S->isIfExists(),
9682 QualifierLoc,
9683 NameInfo,
9684 SubStmt.get());
9685}
9686
9687template<typename Derived>
9690 NestedNameSpecifierLoc QualifierLoc;
9691 if (E->getQualifierLoc()) {
9692 QualifierLoc
9693 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9694 if (!QualifierLoc)
9695 return ExprError();
9696 }
9697
9698 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9699 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9700 if (!PD)
9701 return ExprError();
9702
9703 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9704 if (Base.isInvalid())
9705 return ExprError();
9706
9707 return new (SemaRef.getASTContext())
9708 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9710 QualifierLoc, E->getMemberLoc());
9711}
9712
9713template <typename Derived>
9716 auto BaseRes = getDerived().TransformExpr(E->getBase());
9717 if (BaseRes.isInvalid())
9718 return ExprError();
9719 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9720 if (IdxRes.isInvalid())
9721 return ExprError();
9722
9723 if (!getDerived().AlwaysRebuild() &&
9724 BaseRes.get() == E->getBase() &&
9725 IdxRes.get() == E->getIdx())
9726 return E;
9727
9728 return getDerived().RebuildArraySubscriptExpr(
9729 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9730}
9731
9732template <typename Derived>
9734 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9735 if (TryBlock.isInvalid())
9736 return StmtError();
9737
9738 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9739 if (Handler.isInvalid())
9740 return StmtError();
9741
9742 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9743 Handler.get() == S->getHandler())
9744 return S;
9745
9746 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9747 TryBlock.get(), Handler.get());
9748}
9749
9750template <typename Derived>
9752 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9753 if (Block.isInvalid())
9754 return StmtError();
9755
9756 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9757}
9758
9759template <typename Derived>
9761 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9762 if (FilterExpr.isInvalid())
9763 return StmtError();
9764
9765 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9766 if (Block.isInvalid())
9767 return StmtError();
9768
9769 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9770 Block.get());
9771}
9772
9773template <typename Derived>
9775 if (isa<SEHFinallyStmt>(Handler))
9776 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9777 else
9778 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9779}
9780
9781template<typename Derived>
9784 return S;
9785}
9786
9787//===----------------------------------------------------------------------===//
9788// OpenMP directive transformation
9789//===----------------------------------------------------------------------===//
9790
9791template <typename Derived>
9792StmtResult
9793TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9794 // OMPCanonicalLoops are eliminated during transformation, since they will be
9795 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9796 // after transformation.
9797 return getDerived().TransformStmt(L->getLoopStmt());
9798}
9799
9800template <typename Derived>
9803
9804 // Transform the clauses
9806 ArrayRef<OMPClause *> Clauses = D->clauses();
9807 TClauses.reserve(Clauses.size());
9808 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9809 I != E; ++I) {
9810 if (*I) {
9811 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9812 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9813 getDerived().getSema().OpenMP().EndOpenMPClause();
9814 if (Clause)
9815 TClauses.push_back(Clause);
9816 } else {
9817 TClauses.push_back(nullptr);
9818 }
9819 }
9820 StmtResult AssociatedStmt;
9821 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9822 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9823 D->getDirectiveKind(),
9824 /*CurScope=*/nullptr);
9825 StmtResult Body;
9826 {
9827 Sema::CompoundScopeRAII CompoundScope(getSema());
9828 Stmt *CS;
9829 if (D->getDirectiveKind() == OMPD_atomic ||
9830 D->getDirectiveKind() == OMPD_critical ||
9831 D->getDirectiveKind() == OMPD_section ||
9832 D->getDirectiveKind() == OMPD_master)
9833 CS = D->getAssociatedStmt();
9834 else
9835 CS = D->getRawStmt();
9836 Body = getDerived().TransformStmt(CS);
9837 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9838 getSema().getLangOpts().OpenMPIRBuilder)
9839 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9840 }
9841 AssociatedStmt =
9842 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9843 if (AssociatedStmt.isInvalid()) {
9844 return StmtError();
9845 }
9846 }
9847 if (TClauses.size() != Clauses.size()) {
9848 return StmtError();
9849 }
9850
9851 // Transform directive name for 'omp critical' directive.
9852 DeclarationNameInfo DirName;
9853 if (D->getDirectiveKind() == OMPD_critical) {
9854 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9855 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9856 }
9857 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9858 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9859 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9860 } else if (D->getDirectiveKind() == OMPD_cancel) {
9861 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9862 }
9863
9864 return getDerived().RebuildOMPExecutableDirective(
9865 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9866 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9867}
9868
9869/// This is mostly the same as above, but allows 'informational' class
9870/// directives when rebuilding the stmt. It still takes an
9871/// OMPExecutableDirective-type argument because we're reusing that as the
9872/// superclass for the 'assume' directive at present, instead of defining a
9873/// mostly-identical OMPInformationalDirective parent class.
9874template <typename Derived>
9877
9878 // Transform the clauses
9880 ArrayRef<OMPClause *> Clauses = D->clauses();
9881 TClauses.reserve(Clauses.size());
9882 for (OMPClause *C : Clauses) {
9883 if (C) {
9884 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9885 OMPClause *Clause = getDerived().TransformOMPClause(C);
9886 getDerived().getSema().OpenMP().EndOpenMPClause();
9887 if (Clause)
9888 TClauses.push_back(Clause);
9889 } else {
9890 TClauses.push_back(nullptr);
9891 }
9892 }
9893 StmtResult AssociatedStmt;
9894 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9895 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9896 D->getDirectiveKind(),
9897 /*CurScope=*/nullptr);
9898 StmtResult Body;
9899 {
9900 Sema::CompoundScopeRAII CompoundScope(getSema());
9901 assert(D->getDirectiveKind() == OMPD_assume &&
9902 "Unexpected informational directive");
9903 Stmt *CS = D->getAssociatedStmt();
9904 Body = getDerived().TransformStmt(CS);
9905 }
9906 AssociatedStmt =
9907 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9908 if (AssociatedStmt.isInvalid())
9909 return StmtError();
9910 }
9911 if (TClauses.size() != Clauses.size())
9912 return StmtError();
9913
9914 DeclarationNameInfo DirName;
9915
9916 return getDerived().RebuildOMPInformationalDirective(
9917 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9918 D->getBeginLoc(), D->getEndLoc());
9919}
9920
9921template <typename Derived>
9924 // TODO: Fix This
9925 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9926 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9927 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9928 return StmtError();
9929}
9930
9931template <typename Derived>
9932StmtResult
9933TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9934 DeclarationNameInfo DirName;
9935 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9936 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9937 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9938 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9939 return Res;
9940}
9941
9942template <typename Derived>
9945 DeclarationNameInfo DirName;
9946 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9947 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9948 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9949 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9950 return Res;
9951}
9952
9953template <typename Derived>
9956 DeclarationNameInfo DirName;
9957 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9958 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9959 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9960 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9961 return Res;
9962}
9963
9964template <typename Derived>
9967 DeclarationNameInfo DirName;
9968 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9969 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9970 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9971 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9972 return Res;
9973}
9974
9975template <typename Derived>
9978 DeclarationNameInfo DirName;
9979 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9980 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9981 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9982 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9983 return Res;
9984}
9985
9986template <typename Derived>
9989 DeclarationNameInfo DirName;
9990 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9991 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9992 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9993 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9994 return Res;
9995}
9996
9997template <typename Derived>
9999 OMPInterchangeDirective *D) {
10000 DeclarationNameInfo DirName;
10001 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10002 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10003 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10004 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10005 return Res;
10006}
10007
10008template <typename Derived>
10011 DeclarationNameInfo DirName;
10012 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10013 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10014 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10015 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10016 return Res;
10017}
10018
10019template <typename Derived>
10022 DeclarationNameInfo DirName;
10023 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10024 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10025 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10026 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10027 return Res;
10028}
10029
10030template <typename Derived>
10033 DeclarationNameInfo DirName;
10034 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10035 OMPD_for, DirName, nullptr, D->getBeginLoc());
10036 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10037 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10038 return Res;
10039}
10040
10041template <typename Derived>
10044 DeclarationNameInfo DirName;
10045 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10046 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
10047 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10048 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10049 return Res;
10050}
10051
10052template <typename Derived>
10055 DeclarationNameInfo DirName;
10056 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10057 OMPD_sections, DirName, nullptr, D->getBeginLoc());
10058 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10059 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10060 return Res;
10061}
10062
10063template <typename Derived>
10066 DeclarationNameInfo DirName;
10067 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10068 OMPD_section, DirName, nullptr, D->getBeginLoc());
10069 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10070 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10071 return Res;
10072}
10073
10074template <typename Derived>
10077 DeclarationNameInfo DirName;
10078 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10079 OMPD_scope, DirName, nullptr, D->getBeginLoc());
10080 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10081 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10082 return Res;
10083}
10084
10085template <typename Derived>
10088 DeclarationNameInfo DirName;
10089 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10090 OMPD_single, DirName, nullptr, D->getBeginLoc());
10091 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10092 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10093 return Res;
10094}
10095
10096template <typename Derived>
10099 DeclarationNameInfo DirName;
10100 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10101 OMPD_master, DirName, nullptr, D->getBeginLoc());
10102 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10103 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10104 return Res;
10105}
10106
10107template <typename Derived>
10110 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10111 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
10112 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10113 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10114 return Res;
10115}
10116
10117template <typename Derived>
10119 OMPParallelForDirective *D) {
10120 DeclarationNameInfo DirName;
10121 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10122 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
10123 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10124 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10125 return Res;
10126}
10127
10128template <typename Derived>
10130 OMPParallelForSimdDirective *D) {
10131 DeclarationNameInfo DirName;
10132 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10133 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10134 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10135 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10136 return Res;
10137}
10138
10139template <typename Derived>
10141 OMPParallelMasterDirective *D) {
10142 DeclarationNameInfo DirName;
10143 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10144 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
10145 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10146 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10147 return Res;
10148}
10149
10150template <typename Derived>
10152 OMPParallelMaskedDirective *D) {
10153 DeclarationNameInfo DirName;
10154 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10155 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
10156 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10157 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10158 return Res;
10159}
10160
10161template <typename Derived>
10163 OMPParallelSectionsDirective *D) {
10164 DeclarationNameInfo DirName;
10165 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10166 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
10167 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10168 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10169 return Res;
10170}
10171
10172template <typename Derived>
10175 DeclarationNameInfo DirName;
10176 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10177 OMPD_task, 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>
10185 OMPTaskyieldDirective *D) {
10186 DeclarationNameInfo DirName;
10187 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10188 OMPD_taskyield, 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 OMPD_barrier, 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 OMPD_taskwait, 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 OMPD_assume, DirName, nullptr, D->getBeginLoc());
10222 StmtResult Res = getDerived().TransformOMPInformationalDirective(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 OMPD_error, 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 OMPTaskgroupDirective *D) {
10241 DeclarationNameInfo DirName;
10242 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10243 OMPD_taskgroup, 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 OMPD_flush, 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 OMPD_depobj, 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 OMPD_scan, 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>
10284 OMPOrderedStandaloneDirective *D) {
10285 DeclarationNameInfo DirName;
10286 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10287 OMPD_ordered_standalone, 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>
10295 OMPOrderedBlockAssocDirective *D) {
10296 DeclarationNameInfo DirName;
10297 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10298 OMPD_ordered_blockassoc, 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_atomic, 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_target, 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>
10328 OMPTargetDataDirective *D) {
10329 DeclarationNameInfo DirName;
10330 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10331 OMPD_target_data, 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>
10339 OMPTargetEnterDataDirective *D) {
10340 DeclarationNameInfo DirName;
10341 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10342 OMPD_target_enter_data, 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>
10350 OMPTargetExitDataDirective *D) {
10351 DeclarationNameInfo DirName;
10352 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10353 OMPD_target_exit_data, 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>
10361 OMPTargetParallelDirective *D) {
10362 DeclarationNameInfo DirName;
10363 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10364 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10365 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10366 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10367 return Res;
10368}
10369
10370template <typename Derived>
10372 OMPTargetParallelForDirective *D) {
10373 DeclarationNameInfo DirName;
10374 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10375 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10376 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10377 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10378 return Res;
10379}
10380
10381template <typename Derived>
10383 OMPTargetUpdateDirective *D) {
10384 DeclarationNameInfo DirName;
10385 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10386 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10387 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10388 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10389 return Res;
10390}
10391
10392template <typename Derived>
10395 DeclarationNameInfo DirName;
10396 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10397 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10398 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10399 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10400 return Res;
10401}
10402
10403template <typename Derived>
10405 OMPCancellationPointDirective *D) {
10406 DeclarationNameInfo DirName;
10407 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10408 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10409 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10410 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10411 return Res;
10412}
10413
10414template <typename Derived>
10417 DeclarationNameInfo DirName;
10418 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10419 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10420 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10421 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10422 return Res;
10423}
10424
10425template <typename Derived>
10428 DeclarationNameInfo DirName;
10429 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10430 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10431 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10432 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10433 return Res;
10434}
10435
10436template <typename Derived>
10438 OMPTaskLoopSimdDirective *D) {
10439 DeclarationNameInfo DirName;
10440 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10441 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10442 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10443 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10444 return Res;
10445}
10446
10447template <typename Derived>
10449 OMPMasterTaskLoopDirective *D) {
10450 DeclarationNameInfo DirName;
10451 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10452 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10453 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10454 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10455 return Res;
10456}
10457
10458template <typename Derived>
10460 OMPMaskedTaskLoopDirective *D) {
10461 DeclarationNameInfo DirName;
10462 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10463 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10464 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10465 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10466 return Res;
10467}
10468
10469template <typename Derived>
10471 OMPMasterTaskLoopSimdDirective *D) {
10472 DeclarationNameInfo DirName;
10473 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10474 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10475 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10476 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10477 return Res;
10478}
10479
10480template <typename Derived>
10482 OMPMaskedTaskLoopSimdDirective *D) {
10483 DeclarationNameInfo DirName;
10484 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10485 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10486 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10487 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10488 return Res;
10489}
10490
10491template <typename Derived>
10493 OMPParallelMasterTaskLoopDirective *D) {
10494 DeclarationNameInfo DirName;
10495 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10496 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10498 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10499 return Res;
10500}
10501
10502template <typename Derived>
10504 OMPParallelMaskedTaskLoopDirective *D) {
10505 DeclarationNameInfo DirName;
10506 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10507 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10509 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10510 return Res;
10511}
10512
10513template <typename Derived>
10516 OMPParallelMasterTaskLoopSimdDirective *D) {
10517 DeclarationNameInfo DirName;
10518 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10519 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10520 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10521 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10522 return Res;
10523}
10524
10525template <typename Derived>
10528 OMPParallelMaskedTaskLoopSimdDirective *D) {
10529 DeclarationNameInfo DirName;
10530 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10531 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10532 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10533 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10534 return Res;
10535}
10536
10537template <typename Derived>
10539 OMPDistributeDirective *D) {
10540 DeclarationNameInfo DirName;
10541 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10542 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10543 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10544 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10545 return Res;
10546}
10547
10548template <typename Derived>
10550 OMPDistributeParallelForDirective *D) {
10551 DeclarationNameInfo DirName;
10552 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10553 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10555 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10556 return Res;
10557}
10558
10559template <typename Derived>
10562 OMPDistributeParallelForSimdDirective *D) {
10563 DeclarationNameInfo DirName;
10564 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10565 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10566 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10567 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10568 return Res;
10569}
10570
10571template <typename Derived>
10573 OMPDistributeSimdDirective *D) {
10574 DeclarationNameInfo DirName;
10575 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10576 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10577 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10578 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10579 return Res;
10580}
10581
10582template <typename Derived>
10584 OMPTargetParallelForSimdDirective *D) {
10585 DeclarationNameInfo DirName;
10586 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10587 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10588 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10589 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10590 return Res;
10591}
10592
10593template <typename Derived>
10595 OMPTargetSimdDirective *D) {
10596 DeclarationNameInfo DirName;
10597 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10598 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10599 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10600 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10601 return Res;
10602}
10603
10604template <typename Derived>
10606 OMPTeamsDistributeDirective *D) {
10607 DeclarationNameInfo DirName;
10608 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10609 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10610 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10611 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10612 return Res;
10613}
10614
10615template <typename Derived>
10617 OMPTeamsDistributeSimdDirective *D) {
10618 DeclarationNameInfo DirName;
10619 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10620 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10621 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10622 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10623 return Res;
10624}
10625
10626template <typename Derived>
10628 OMPTeamsDistributeParallelForSimdDirective *D) {
10629 DeclarationNameInfo DirName;
10630 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10631 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10632 D->getBeginLoc());
10633 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10634 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10635 return Res;
10636}
10637
10638template <typename Derived>
10640 OMPTeamsDistributeParallelForDirective *D) {
10641 DeclarationNameInfo DirName;
10642 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10643 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10644 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10645 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10646 return Res;
10647}
10648
10649template <typename Derived>
10651 OMPTargetTeamsDirective *D) {
10652 DeclarationNameInfo DirName;
10653 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10654 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10655 auto Res = getDerived().TransformOMPExecutableDirective(D);
10656 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10657 return Res;
10658}
10659
10660template <typename Derived>
10662 OMPTargetTeamsDistributeDirective *D) {
10663 DeclarationNameInfo DirName;
10664 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10665 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10666 auto Res = getDerived().TransformOMPExecutableDirective(D);
10667 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10668 return Res;
10669}
10670
10671template <typename Derived>
10674 OMPTargetTeamsDistributeParallelForDirective *D) {
10675 DeclarationNameInfo DirName;
10676 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10677 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10678 D->getBeginLoc());
10679 auto Res = getDerived().TransformOMPExecutableDirective(D);
10680 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10681 return Res;
10682}
10683
10684template <typename Derived>
10687 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10688 DeclarationNameInfo DirName;
10689 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10690 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10691 D->getBeginLoc());
10692 auto Res = getDerived().TransformOMPExecutableDirective(D);
10693 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10694 return Res;
10695}
10696
10697template <typename Derived>
10700 OMPTargetTeamsDistributeSimdDirective *D) {
10701 DeclarationNameInfo DirName;
10702 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10703 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10704 auto Res = getDerived().TransformOMPExecutableDirective(D);
10705 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10706 return Res;
10707}
10708
10709template <typename Derived>
10712 DeclarationNameInfo DirName;
10713 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10714 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10715 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10716 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10717 return Res;
10718}
10719
10720template <typename Derived>
10723 DeclarationNameInfo DirName;
10724 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10725 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10726 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10727 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10728 return Res;
10729}
10730
10731template <typename Derived>
10734 DeclarationNameInfo DirName;
10735 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10736 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10737 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10738 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10739 return Res;
10740}
10741
10742template <typename Derived>
10744 OMPGenericLoopDirective *D) {
10745 DeclarationNameInfo DirName;
10746 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10747 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10748 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10749 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10750 return Res;
10751}
10752
10753template <typename Derived>
10755 OMPTeamsGenericLoopDirective *D) {
10756 DeclarationNameInfo DirName;
10757 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10758 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10759 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10760 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10761 return Res;
10762}
10763
10764template <typename Derived>
10766 OMPTargetTeamsGenericLoopDirective *D) {
10767 DeclarationNameInfo DirName;
10768 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10769 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10770 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10771 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10772 return Res;
10773}
10774
10775template <typename Derived>
10777 OMPParallelGenericLoopDirective *D) {
10778 DeclarationNameInfo DirName;
10779 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10780 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10781 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10782 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10783 return Res;
10784}
10785
10786template <typename Derived>
10789 OMPTargetParallelGenericLoopDirective *D) {
10790 DeclarationNameInfo DirName;
10791 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10792 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10793 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10794 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10795 return Res;
10796}
10797
10798//===----------------------------------------------------------------------===//
10799// OpenMP clause transformation
10800//===----------------------------------------------------------------------===//
10801template <typename Derived>
10803 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10804 if (Cond.isInvalid())
10805 return nullptr;
10806 return getDerived().RebuildOMPIfClause(
10807 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10808 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10809}
10810
10811template <typename Derived>
10813 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10814 if (Cond.isInvalid())
10815 return nullptr;
10816 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10817 C->getLParenLoc(), C->getEndLoc());
10818}
10819
10820template <typename Derived>
10821OMPClause *
10823 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10824 if (NumThreads.isInvalid())
10825 return nullptr;
10826 return getDerived().RebuildOMPNumThreadsClause(
10827 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10828 C->getModifierLoc(), C->getEndLoc());
10829}
10830
10831template <typename Derived>
10832OMPClause *
10834 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10835 if (E.isInvalid())
10836 return nullptr;
10837 return getDerived().RebuildOMPSafelenClause(
10838 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10839}
10840
10841template <typename Derived>
10842OMPClause *
10844 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10845 if (E.isInvalid())
10846 return nullptr;
10847 return getDerived().RebuildOMPAllocatorClause(
10848 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10849}
10850
10851template <typename Derived>
10852OMPClause *
10854 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10855 if (E.isInvalid())
10856 return nullptr;
10857 return getDerived().RebuildOMPSimdlenClause(
10858 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10859}
10860
10861template <typename Derived>
10863 SmallVector<Expr *, 4> TransformedSizes;
10864 TransformedSizes.reserve(C->getNumSizes());
10865 bool Changed = false;
10866 for (Expr *E : C->getSizesRefs()) {
10867 if (!E) {
10868 TransformedSizes.push_back(nullptr);
10869 continue;
10870 }
10871
10872 ExprResult T = getDerived().TransformExpr(E);
10873 if (T.isInvalid())
10874 return nullptr;
10875 if (E != T.get())
10876 Changed = true;
10877 TransformedSizes.push_back(T.get());
10878 }
10879
10880 if (!Changed && !getDerived().AlwaysRebuild())
10881 return C;
10882 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10883 C->getLParenLoc(), C->getEndLoc());
10884}
10885
10886template <typename Derived>
10887OMPClause *
10889 SmallVector<Expr *, 4> TransformedCounts;
10890 TransformedCounts.reserve(C->getNumCounts());
10891 for (Expr *E : C->getCountsRefs()) {
10892 if (!E) {
10893 TransformedCounts.push_back(nullptr);
10894 continue;
10895 }
10896
10897 ExprResult T = getDerived().TransformExpr(E);
10898 if (T.isInvalid())
10899 return nullptr;
10900 TransformedCounts.push_back(T.get());
10901 }
10902
10903 return RebuildOMPCountsClause(TransformedCounts, C->getBeginLoc(),
10904 C->getLParenLoc(), C->getEndLoc(),
10905 C->getOmpFillIndex(), C->getOmpFillLoc());
10906}
10907
10908template <typename Derived>
10909OMPClause *
10911 SmallVector<Expr *> TransformedArgs;
10912 TransformedArgs.reserve(C->getNumLoops());
10913 bool Changed = false;
10914 for (Expr *E : C->getArgsRefs()) {
10915 if (!E) {
10916 TransformedArgs.push_back(nullptr);
10917 continue;
10918 }
10919
10920 ExprResult T = getDerived().TransformExpr(E);
10921 if (T.isInvalid())
10922 return nullptr;
10923 if (E != T.get())
10924 Changed = true;
10925 TransformedArgs.push_back(T.get());
10926 }
10927
10928 if (!Changed && !getDerived().AlwaysRebuild())
10929 return C;
10930 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10931 C->getLParenLoc(), C->getEndLoc());
10932}
10933
10934template <typename Derived>
10936 if (!getDerived().AlwaysRebuild())
10937 return C;
10938 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10939}
10940
10941template <typename Derived>
10942OMPClause *
10944 ExprResult T = getDerived().TransformExpr(C->getFactor());
10945 if (T.isInvalid())
10946 return nullptr;
10947 Expr *Factor = T.get();
10948 bool Changed = Factor != C->getFactor();
10949
10950 if (!Changed && !getDerived().AlwaysRebuild())
10951 return C;
10952 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10953 C->getEndLoc());
10954}
10955
10956template <typename Derived>
10957OMPClause *
10959 ExprResult F = getDerived().TransformExpr(C->getFirst());
10960 if (F.isInvalid())
10961 return nullptr;
10962
10963 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10964 if (Cn.isInvalid())
10965 return nullptr;
10966
10967 Expr *First = F.get();
10968 Expr *Count = Cn.get();
10969
10970 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10971
10972 // If no changes and AlwaysRebuild() is false, return the original clause
10973 if (!Changed && !getDerived().AlwaysRebuild())
10974 return C;
10975
10976 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10977 C->getLParenLoc(), C->getFirstLoc(),
10978 C->getCountLoc(), C->getEndLoc());
10979}
10980
10981template <typename Derived>
10982OMPClause *
10984 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10985 if (E.isInvalid())
10986 return nullptr;
10987 return getDerived().RebuildOMPCollapseClause(
10988 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10989}
10990
10991template <typename Derived>
10992OMPClause *
10994 return getDerived().RebuildOMPDefaultClause(
10995 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10996 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10997 C->getEndLoc());
10998}
10999
11000template <typename Derived>
11001OMPClause *
11003 // No need to rebuild this clause, no template-dependent parameters.
11004 return C;
11005}
11006
11007template <typename Derived>
11008OMPClause *
11010 Expr *Impex = C->getImpexType();
11011 ExprResult TransformedImpex = getDerived().TransformExpr(Impex);
11012
11013 if (TransformedImpex.isInvalid())
11014 return nullptr;
11015
11016 return getDerived().RebuildOMPTransparentClause(
11017 TransformedImpex.get(), C->getBeginLoc(), C->getLParenLoc(),
11018 C->getEndLoc());
11019}
11020
11021template <typename Derived>
11022OMPClause *
11024 return getDerived().RebuildOMPProcBindClause(
11025 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
11026 C->getLParenLoc(), C->getEndLoc());
11027}
11028
11029template <typename Derived>
11030OMPClause *
11032 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11033 if (E.isInvalid())
11034 return nullptr;
11035 return getDerived().RebuildOMPScheduleClause(
11036 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
11037 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11038 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
11039 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11040}
11041
11042template <typename Derived>
11043OMPClause *
11045 ExprResult E;
11046 if (auto *Num = C->getNumForLoops()) {
11047 E = getDerived().TransformExpr(Num);
11048 if (E.isInvalid())
11049 return nullptr;
11050 }
11051 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
11052 C->getLParenLoc(), E.get());
11053}
11054
11055template <typename Derived>
11056OMPClause *
11058 ExprResult E;
11059 if (Expr *Evt = C->getEventHandler()) {
11060 E = getDerived().TransformExpr(Evt);
11061 if (E.isInvalid())
11062 return nullptr;
11063 }
11064 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
11065 C->getLParenLoc(), C->getEndLoc());
11066}
11067
11068template <typename Derived>
11069OMPClause *
11072 if (auto *Condition = C->getCondition()) {
11073 Cond = getDerived().TransformExpr(Condition);
11074 if (Cond.isInvalid())
11075 return nullptr;
11076 }
11077 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
11078 C->getLParenLoc(), C->getEndLoc());
11079}
11080
11081template <typename Derived>
11082OMPClause *
11084 // No need to rebuild this clause, no template-dependent parameters.
11085 return C;
11086}
11087
11088template <typename Derived>
11089OMPClause *
11091 // No need to rebuild this clause, no template-dependent parameters.
11092 return C;
11093}
11094
11095template <typename Derived>
11097 // No need to rebuild this clause, no template-dependent parameters.
11098 return C;
11099}
11100
11101template <typename Derived>
11103 // No need to rebuild this clause, no template-dependent parameters.
11104 return C;
11105}
11106
11107template <typename Derived>
11108OMPClause *
11110 // No need to rebuild this clause, no template-dependent parameters.
11111 return C;
11112}
11113
11114template <typename Derived>
11116 OMPUpdateDependObjectsClause *C) {
11117 // No need to rebuild this clause, no template-dependent parameters.
11118 return C;
11119}
11120
11121template <typename Derived>
11122OMPClause *
11124 // No need to rebuild this clause, no template-dependent parameters.
11125 return C;
11126}
11127
11128template <typename Derived>
11129OMPClause *
11131 // No need to rebuild this clause, no template-dependent parameters.
11132 return C;
11133}
11134
11135template <typename Derived>
11137 // No need to rebuild this clause, no template-dependent parameters.
11138 return C;
11139}
11140
11141template <typename Derived>
11142OMPClause *
11144 return C;
11145}
11146
11147template <typename Derived>
11149 ExprResult E = getDerived().TransformExpr(C->getExpr());
11150 if (E.isInvalid())
11151 return nullptr;
11152 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
11153 C->getLParenLoc(), C->getEndLoc());
11154}
11155
11156template <typename Derived>
11157OMPClause *
11159 return C;
11160}
11161
11162template <typename Derived>
11163OMPClause *
11165 return C;
11166}
11167template <typename Derived>
11169 OMPNoOpenMPRoutinesClause *C) {
11170 return C;
11171}
11172template <typename Derived>
11174 OMPNoOpenMPConstructsClause *C) {
11175 return C;
11176}
11177template <typename Derived>
11179 OMPNoParallelismClause *C) {
11180 return C;
11181}
11182
11183template <typename Derived>
11184OMPClause *
11186 // No need to rebuild this clause, no template-dependent parameters.
11187 return C;
11188}
11189
11190template <typename Derived>
11191OMPClause *
11193 // No need to rebuild this clause, no template-dependent parameters.
11194 return C;
11195}
11196
11197template <typename Derived>
11198OMPClause *
11200 // No need to rebuild this clause, no template-dependent parameters.
11201 return C;
11202}
11203
11204template <typename Derived>
11205OMPClause *
11207 // No need to rebuild this clause, no template-dependent parameters.
11208 return C;
11209}
11210
11211template <typename Derived>
11212OMPClause *
11214 // No need to rebuild this clause, no template-dependent parameters.
11215 return C;
11216}
11217
11218template <typename Derived>
11220 // No need to rebuild this clause, no template-dependent parameters.
11221 return C;
11222}
11223
11224template <typename Derived>
11225OMPClause *
11227 // No need to rebuild this clause, no template-dependent parameters.
11228 return C;
11229}
11230
11231template <typename Derived>
11233 // No need to rebuild this clause, no template-dependent parameters.
11234 return C;
11235}
11236
11237template <typename Derived>
11238OMPClause *
11240 // No need to rebuild this clause, no template-dependent parameters.
11241 return C;
11242}
11243
11244template <typename Derived>
11246 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
11247 if (IVR.isInvalid())
11248 return nullptr;
11249
11250 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
11251 for (OMPInitClause::PrefView P : C->prefs()) {
11252 Expr *NewFr = nullptr;
11253 if (P.Fr) {
11254 ExprResult ER = getDerived().TransformExpr(P.Fr);
11255 if (ER.isInvalid())
11256 return nullptr;
11257 NewFr = ER.get();
11258 }
11259 SmallVector<Expr *, 2> NewAttrs;
11260 NewAttrs.reserve(P.Attrs.size());
11261 for (Expr *A : P.Attrs) {
11262 ExprResult ER = getDerived().TransformExpr(A);
11263 if (ER.isInvalid())
11264 return nullptr;
11265 NewAttrs.push_back(ER.get());
11266 }
11267 InteropInfo.Prefs.emplace_back(NewFr, std::move(NewAttrs));
11268 }
11269 InteropInfo.HasPreferAttrs = C->hasPreferAttrs();
11270 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
11271 C->getBeginLoc(), C->getLParenLoc(),
11272 C->getVarLoc(), C->getEndLoc());
11273}
11274
11275template <typename Derived>
11277 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
11278 if (ER.isInvalid())
11279 return nullptr;
11280 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
11281 C->getLParenLoc(), C->getVarLoc(),
11282 C->getEndLoc());
11283}
11284
11285template <typename Derived>
11286OMPClause *
11288 ExprResult ER;
11289 if (Expr *IV = C->getInteropVar()) {
11290 ER = getDerived().TransformExpr(IV);
11291 if (ER.isInvalid())
11292 return nullptr;
11293 }
11294 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
11295 C->getLParenLoc(), C->getVarLoc(),
11296 C->getEndLoc());
11297}
11298
11299template <typename Derived>
11300OMPClause *
11302 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11303 if (Cond.isInvalid())
11304 return nullptr;
11305 return getDerived().RebuildOMPNovariantsClause(
11306 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11307}
11308
11309template <typename Derived>
11310OMPClause *
11312 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11313 if (Cond.isInvalid())
11314 return nullptr;
11315 return getDerived().RebuildOMPNocontextClause(
11316 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11317}
11318
11319template <typename Derived>
11320OMPClause *
11322 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
11323 if (ThreadID.isInvalid())
11324 return nullptr;
11325 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
11326 C->getLParenLoc(), C->getEndLoc());
11327}
11328
11329template <typename Derived>
11331 ExprResult E = getDerived().TransformExpr(C->getAlignment());
11332 if (E.isInvalid())
11333 return nullptr;
11334 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
11335 C->getLParenLoc(), C->getEndLoc());
11336}
11337
11338template <typename Derived>
11340 OMPUnifiedAddressClause *C) {
11341 llvm_unreachable("unified_address clause cannot appear in dependent context");
11342}
11343
11344template <typename Derived>
11346 OMPUnifiedSharedMemoryClause *C) {
11347 llvm_unreachable(
11348 "unified_shared_memory clause cannot appear in dependent context");
11349}
11350
11351template <typename Derived>
11353 OMPReverseOffloadClause *C) {
11354 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
11355}
11356
11357template <typename Derived>
11359 OMPDynamicAllocatorsClause *C) {
11360 llvm_unreachable(
11361 "dynamic_allocators clause cannot appear in dependent context");
11362}
11363
11364template <typename Derived>
11366 OMPAtomicDefaultMemOrderClause *C) {
11367 llvm_unreachable(
11368 "atomic_default_mem_order clause cannot appear in dependent context");
11369}
11370
11371template <typename Derived>
11372OMPClause *
11374 llvm_unreachable("self_maps clause cannot appear in dependent context");
11375}
11376
11377template <typename Derived>
11379 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
11380 C->getBeginLoc(), C->getLParenLoc(),
11381 C->getEndLoc());
11382}
11383
11384template <typename Derived>
11385OMPClause *
11387 return getDerived().RebuildOMPSeverityClause(
11388 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
11389 C->getLParenLoc(), C->getEndLoc());
11390}
11391
11392template <typename Derived>
11393OMPClause *
11395 ExprResult E = getDerived().TransformExpr(C->getMessageString());
11396 if (E.isInvalid())
11397 return nullptr;
11398 return getDerived().RebuildOMPMessageClause(
11399 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11400}
11401
11402template <typename Derived>
11403OMPClause *
11406 Vars.reserve(C->varlist_size());
11407 for (auto *VE : C->varlist()) {
11408 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11409 if (EVar.isInvalid())
11410 return nullptr;
11411 Vars.push_back(EVar.get());
11412 }
11413 return getDerived().RebuildOMPPrivateClause(
11414 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11415}
11416
11417template <typename Derived>
11419 OMPFirstprivateClause *C) {
11421 Vars.reserve(C->varlist_size());
11422 for (auto *VE : C->varlist()) {
11423 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11424 if (EVar.isInvalid())
11425 return nullptr;
11426 Vars.push_back(EVar.get());
11427 }
11428 return getDerived().RebuildOMPFirstprivateClause(
11429 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11430}
11431
11432template <typename Derived>
11433OMPClause *
11436 Vars.reserve(C->varlist_size());
11437 for (auto *VE : C->varlist()) {
11438 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11439 if (EVar.isInvalid())
11440 return nullptr;
11441 Vars.push_back(EVar.get());
11442 }
11443 return getDerived().RebuildOMPLastprivateClause(
11444 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11445 C->getLParenLoc(), C->getEndLoc());
11446}
11447
11448template <typename Derived>
11449OMPClause *
11452 Vars.reserve(C->varlist_size());
11453 for (auto *VE : C->varlist()) {
11454 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11455 if (EVar.isInvalid())
11456 return nullptr;
11457 Vars.push_back(EVar.get());
11458 }
11459 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11460 C->getLParenLoc(), C->getEndLoc());
11461}
11462
11463template <typename Derived>
11464OMPClause *
11467 Vars.reserve(C->varlist_size());
11468 for (auto *VE : C->varlist()) {
11469 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11470 if (EVar.isInvalid())
11471 return nullptr;
11472 Vars.push_back(EVar.get());
11473 }
11474 CXXScopeSpec ReductionIdScopeSpec;
11475 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11476
11477 DeclarationNameInfo NameInfo = C->getNameInfo();
11478 if (NameInfo.getName()) {
11479 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11480 if (!NameInfo.getName())
11481 return nullptr;
11482 }
11483 // Build a list of all UDR decls with the same names ranged by the Scopes.
11484 // The Scope boundary is a duplication of the previous decl.
11485 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11486 for (auto *E : C->reduction_ops()) {
11487 // Transform all the decls.
11488 if (E) {
11489 auto *ULE = cast<UnresolvedLookupExpr>(E);
11490 UnresolvedSet<8> Decls;
11491 for (auto *D : ULE->decls()) {
11492 NamedDecl *InstD =
11493 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11494 Decls.addDecl(InstD, InstD->getAccess());
11495 }
11496 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11497 SemaRef.Context, /*NamingClass=*/nullptr,
11498 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11499 /*ADL=*/true, Decls.begin(), Decls.end(),
11500 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11501 } else
11502 UnresolvedReductions.push_back(nullptr);
11503 }
11504 return getDerived().RebuildOMPReductionClause(
11505 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11506 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11507 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11508}
11509
11510template <typename Derived>
11512 OMPTaskReductionClause *C) {
11514 Vars.reserve(C->varlist_size());
11515 for (auto *VE : C->varlist()) {
11516 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11517 if (EVar.isInvalid())
11518 return nullptr;
11519 Vars.push_back(EVar.get());
11520 }
11521 CXXScopeSpec ReductionIdScopeSpec;
11522 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11523
11524 DeclarationNameInfo NameInfo = C->getNameInfo();
11525 if (NameInfo.getName()) {
11526 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11527 if (!NameInfo.getName())
11528 return nullptr;
11529 }
11530 // Build a list of all UDR decls with the same names ranged by the Scopes.
11531 // The Scope boundary is a duplication of the previous decl.
11532 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11533 for (auto *E : C->reduction_ops()) {
11534 // Transform all the decls.
11535 if (E) {
11536 auto *ULE = cast<UnresolvedLookupExpr>(E);
11537 UnresolvedSet<8> Decls;
11538 for (auto *D : ULE->decls()) {
11539 NamedDecl *InstD =
11540 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11541 Decls.addDecl(InstD, InstD->getAccess());
11542 }
11543 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11544 SemaRef.Context, /*NamingClass=*/nullptr,
11545 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11546 /*ADL=*/true, Decls.begin(), Decls.end(),
11547 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11548 } else
11549 UnresolvedReductions.push_back(nullptr);
11550 }
11551 return getDerived().RebuildOMPTaskReductionClause(
11552 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11553 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11554}
11555
11556template <typename Derived>
11557OMPClause *
11560 Vars.reserve(C->varlist_size());
11561 for (auto *VE : C->varlist()) {
11562 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11563 if (EVar.isInvalid())
11564 return nullptr;
11565 Vars.push_back(EVar.get());
11566 }
11567 CXXScopeSpec ReductionIdScopeSpec;
11568 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11569
11570 DeclarationNameInfo NameInfo = C->getNameInfo();
11571 if (NameInfo.getName()) {
11572 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11573 if (!NameInfo.getName())
11574 return nullptr;
11575 }
11576 // Build a list of all UDR decls with the same names ranged by the Scopes.
11577 // The Scope boundary is a duplication of the previous decl.
11578 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11579 for (auto *E : C->reduction_ops()) {
11580 // Transform all the decls.
11581 if (E) {
11582 auto *ULE = cast<UnresolvedLookupExpr>(E);
11583 UnresolvedSet<8> Decls;
11584 for (auto *D : ULE->decls()) {
11585 NamedDecl *InstD =
11586 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11587 Decls.addDecl(InstD, InstD->getAccess());
11588 }
11589 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11590 SemaRef.Context, /*NamingClass=*/nullptr,
11591 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11592 /*ADL=*/true, Decls.begin(), Decls.end(),
11593 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11594 } else
11595 UnresolvedReductions.push_back(nullptr);
11596 }
11597 return getDerived().RebuildOMPInReductionClause(
11598 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11599 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11600}
11601
11602template <typename Derived>
11603OMPClause *
11606 Vars.reserve(C->varlist_size());
11607 for (auto *VE : C->varlist()) {
11608 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11609 if (EVar.isInvalid())
11610 return nullptr;
11611 Vars.push_back(EVar.get());
11612 }
11613 ExprResult Step = getDerived().TransformExpr(C->getStep());
11614 if (Step.isInvalid())
11615 return nullptr;
11616 return getDerived().RebuildOMPLinearClause(
11617 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11618 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11619 C->getEndLoc());
11620}
11621
11622template <typename Derived>
11623OMPClause *
11626 Vars.reserve(C->varlist_size());
11627 for (auto *VE : C->varlist()) {
11628 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11629 if (EVar.isInvalid())
11630 return nullptr;
11631 Vars.push_back(EVar.get());
11632 }
11633 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11634 if (Alignment.isInvalid())
11635 return nullptr;
11636 return getDerived().RebuildOMPAlignedClause(
11637 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11638 C->getColonLoc(), C->getEndLoc());
11639}
11640
11641template <typename Derived>
11642OMPClause *
11645 Vars.reserve(C->varlist_size());
11646 for (auto *VE : C->varlist()) {
11647 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11648 if (EVar.isInvalid())
11649 return nullptr;
11650 Vars.push_back(EVar.get());
11651 }
11652 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11653 C->getLParenLoc(), C->getEndLoc());
11654}
11655
11656template <typename Derived>
11657OMPClause *
11660 Vars.reserve(C->varlist_size());
11661 for (auto *VE : C->varlist()) {
11662 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11663 if (EVar.isInvalid())
11664 return nullptr;
11665 Vars.push_back(EVar.get());
11666 }
11667 return getDerived().RebuildOMPCopyprivateClause(
11668 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11669}
11670
11671template <typename Derived>
11674 Vars.reserve(C->varlist_size());
11675 for (auto *VE : C->varlist()) {
11676 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11677 if (EVar.isInvalid())
11678 return nullptr;
11679 Vars.push_back(EVar.get());
11680 }
11681 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11682 C->getLParenLoc(), C->getEndLoc());
11683}
11684
11685template <typename Derived>
11686OMPClause *
11688 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11689 if (E.isInvalid())
11690 return nullptr;
11691 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11692 C->getLParenLoc(), C->getEndLoc());
11693}
11694
11695template <typename Derived>
11696OMPClause *
11699 Expr *DepModifier = C->getModifier();
11700 if (DepModifier) {
11701 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11702 if (DepModRes.isInvalid())
11703 return nullptr;
11704 DepModifier = DepModRes.get();
11705 }
11706 Vars.reserve(C->varlist_size());
11707 for (auto *VE : C->varlist()) {
11708 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11709 if (EVar.isInvalid())
11710 return nullptr;
11711 Vars.push_back(EVar.get());
11712 }
11713 return getDerived().RebuildOMPDependClause(
11714 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11715 C->getOmpAllMemoryLoc()},
11716 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11717}
11718
11719template <typename Derived>
11720OMPClause *
11722 ExprResult E = getDerived().TransformExpr(C->getDevice());
11723 if (E.isInvalid())
11724 return nullptr;
11725 return getDerived().RebuildOMPDeviceClause(
11726 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11727 C->getModifierLoc(), C->getEndLoc());
11728}
11729
11730template <typename Derived, class T>
11733 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11734 DeclarationNameInfo &MapperIdInfo,
11735 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11736 // Transform expressions in the list.
11737 Vars.reserve(C->varlist_size());
11738 for (auto *VE : C->varlist()) {
11739 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11740 if (EVar.isInvalid())
11741 return true;
11742 Vars.push_back(EVar.get());
11743 }
11744 // Transform mapper scope specifier and identifier.
11745 NestedNameSpecifierLoc QualifierLoc;
11746 if (C->getMapperQualifierLoc()) {
11747 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11748 C->getMapperQualifierLoc());
11749 if (!QualifierLoc)
11750 return true;
11751 }
11752 MapperIdScopeSpec.Adopt(QualifierLoc);
11753 MapperIdInfo = C->getMapperIdInfo();
11754 if (MapperIdInfo.getName()) {
11755 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11756 if (!MapperIdInfo.getName())
11757 return true;
11758 }
11759 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11760 // the previous user-defined mapper lookup in dependent environment.
11761 for (auto *E : C->mapperlists()) {
11762 // Transform all the decls.
11763 if (E) {
11764 auto *ULE = cast<UnresolvedLookupExpr>(E);
11765 UnresolvedSet<8> Decls;
11766 for (auto *D : ULE->decls()) {
11767 NamedDecl *InstD =
11768 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11769 Decls.addDecl(InstD, InstD->getAccess());
11770 }
11771 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11772 TT.getSema().Context, /*NamingClass=*/nullptr,
11773 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11774 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11775 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11776 } else {
11777 UnresolvedMappers.push_back(nullptr);
11778 }
11779 }
11780 return false;
11781}
11782
11783template <typename Derived>
11784OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11785 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11787 Expr *IteratorModifier = C->getIteratorModifier();
11788 if (IteratorModifier) {
11789 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11790 if (MapModRes.isInvalid())
11791 return nullptr;
11792 IteratorModifier = MapModRes.get();
11793 }
11794 CXXScopeSpec MapperIdScopeSpec;
11795 DeclarationNameInfo MapperIdInfo;
11796 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11798 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11799 return nullptr;
11800 return getDerived().RebuildOMPMapClause(
11801 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11802 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11803 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11804}
11805
11806template <typename Derived>
11807OMPClause *
11809 Expr *Allocator = C->getAllocator();
11810 if (Allocator) {
11811 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11812 if (AllocatorRes.isInvalid())
11813 return nullptr;
11814 Allocator = AllocatorRes.get();
11815 }
11816 Expr *Alignment = C->getAlignment();
11817 if (Alignment) {
11818 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11819 if (AlignmentRes.isInvalid())
11820 return nullptr;
11821 Alignment = AlignmentRes.get();
11822 }
11824 Vars.reserve(C->varlist_size());
11825 for (auto *VE : C->varlist()) {
11826 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11827 if (EVar.isInvalid())
11828 return nullptr;
11829 Vars.push_back(EVar.get());
11830 }
11831 return getDerived().RebuildOMPAllocateClause(
11832 Allocator, Alignment, C->getFirstAllocateModifier(),
11833 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11834 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11835 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11836}
11837
11838template <typename Derived>
11839OMPClause *
11842 Vars.reserve(C->varlist_size());
11843 for (auto *VE : C->varlist()) {
11844 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11845 if (EVar.isInvalid())
11846 return nullptr;
11847 Vars.push_back(EVar.get());
11848 }
11849 Expr *ModifierExpr = C->getModifierExpr();
11850 if (ModifierExpr) {
11851 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
11852 if (EVar.isInvalid())
11853 return nullptr;
11854 ModifierExpr = EVar.get();
11855 }
11856 return getDerived().RebuildOMPNumTeamsClause(
11857 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
11858 OMPC_NUMTEAMS_unknown, nullptr, SourceLocation(), C->getBeginLoc(),
11859 C->getLParenLoc(), C->getEndLoc());
11860}
11861
11862template <typename Derived>
11863OMPClause *
11866 Vars.reserve(C->varlist_size());
11867 for (auto *VE : C->varlist()) {
11868 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11869 if (EVar.isInvalid())
11870 return nullptr;
11871 Vars.push_back(EVar.get());
11872 }
11873 Expr *ModifierExpr = C->getModifierExpr();
11874 if (ModifierExpr) {
11875 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
11876 if (EVar.isInvalid())
11877 return nullptr;
11878 ModifierExpr = EVar.get();
11879 }
11880 return getDerived().RebuildOMPThreadLimitClause(
11881 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
11882 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11883}
11884
11885template <typename Derived>
11886OMPClause *
11888 ExprResult E = getDerived().TransformExpr(C->getPriority());
11889 if (E.isInvalid())
11890 return nullptr;
11891 return getDerived().RebuildOMPPriorityClause(
11892 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11893}
11894
11895template <typename Derived>
11896OMPClause *
11898 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11899 if (E.isInvalid())
11900 return nullptr;
11901 return getDerived().RebuildOMPGrainsizeClause(
11902 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11903 C->getModifierLoc(), C->getEndLoc());
11904}
11905
11906template <typename Derived>
11907OMPClause *
11909 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11910 if (E.isInvalid())
11911 return nullptr;
11912 return getDerived().RebuildOMPNumTasksClause(
11913 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11914 C->getModifierLoc(), C->getEndLoc());
11915}
11916
11917template <typename Derived>
11919 ExprResult E = getDerived().TransformExpr(C->getHint());
11920 if (E.isInvalid())
11921 return nullptr;
11922 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11923 C->getLParenLoc(), C->getEndLoc());
11924}
11925
11926template <typename Derived>
11928 OMPDistScheduleClause *C) {
11929 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11930 if (E.isInvalid())
11931 return nullptr;
11932 return getDerived().RebuildOMPDistScheduleClause(
11933 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11934 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11935}
11936
11937template <typename Derived>
11938OMPClause *
11940 // Rebuild Defaultmap Clause since we need to invoke the checking of
11941 // defaultmap(none:variable-category) after template initialization.
11942 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11943 C->getDefaultmapKind(),
11944 C->getBeginLoc(),
11945 C->getLParenLoc(),
11946 C->getDefaultmapModifierLoc(),
11947 C->getDefaultmapKindLoc(),
11948 C->getEndLoc());
11949}
11950
11951template <typename Derived>
11953 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11955 Expr *IteratorModifier = C->getIteratorModifier();
11956 if (IteratorModifier) {
11957 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11958 if (MapModRes.isInvalid())
11959 return nullptr;
11960 IteratorModifier = MapModRes.get();
11961 }
11962 CXXScopeSpec MapperIdScopeSpec;
11963 DeclarationNameInfo MapperIdInfo;
11964 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11966 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11967 return nullptr;
11968 return getDerived().RebuildOMPToClause(
11969 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11970 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11971 UnresolvedMappers);
11972}
11973
11974template <typename Derived>
11976 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11978 Expr *IteratorModifier = C->getIteratorModifier();
11979 if (IteratorModifier) {
11980 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11981 if (MapModRes.isInvalid())
11982 return nullptr;
11983 IteratorModifier = MapModRes.get();
11984 }
11985 CXXScopeSpec MapperIdScopeSpec;
11986 DeclarationNameInfo MapperIdInfo;
11987 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11989 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11990 return nullptr;
11991 return getDerived().RebuildOMPFromClause(
11992 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11993 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11994 UnresolvedMappers);
11995}
11996
11997template <typename Derived>
11999 OMPUseDevicePtrClause *C) {
12001 Vars.reserve(C->varlist_size());
12002 for (auto *VE : C->varlist()) {
12003 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12004 if (EVar.isInvalid())
12005 return nullptr;
12006 Vars.push_back(EVar.get());
12007 }
12008 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12009 return getDerived().RebuildOMPUseDevicePtrClause(
12010 Vars, Locs, C->getFallbackModifier(), C->getFallbackModifierLoc());
12011}
12012
12013template <typename Derived>
12015 OMPUseDeviceAddrClause *C) {
12017 Vars.reserve(C->varlist_size());
12018 for (auto *VE : C->varlist()) {
12019 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12020 if (EVar.isInvalid())
12021 return nullptr;
12022 Vars.push_back(EVar.get());
12023 }
12024 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12025 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
12026}
12027
12028template <typename Derived>
12029OMPClause *
12032 Vars.reserve(C->varlist_size());
12033 for (auto *VE : C->varlist()) {
12034 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12035 if (EVar.isInvalid())
12036 return nullptr;
12037 Vars.push_back(EVar.get());
12038 }
12039 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12040 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
12041}
12042
12043template <typename Derived>
12045 OMPHasDeviceAddrClause *C) {
12047 Vars.reserve(C->varlist_size());
12048 for (auto *VE : C->varlist()) {
12049 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12050 if (EVar.isInvalid())
12051 return nullptr;
12052 Vars.push_back(EVar.get());
12053 }
12054 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12055 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
12056}
12057
12058template <typename Derived>
12059OMPClause *
12062 Vars.reserve(C->varlist_size());
12063 for (auto *VE : C->varlist()) {
12064 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12065 if (EVar.isInvalid())
12066 return nullptr;
12067 Vars.push_back(EVar.get());
12068 }
12069 return getDerived().RebuildOMPNontemporalClause(
12070 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12071}
12072
12073template <typename Derived>
12074OMPClause *
12077 Vars.reserve(C->varlist_size());
12078 for (auto *VE : C->varlist()) {
12079 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12080 if (EVar.isInvalid())
12081 return nullptr;
12082 Vars.push_back(EVar.get());
12083 }
12084 return getDerived().RebuildOMPInclusiveClause(
12085 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12086}
12087
12088template <typename Derived>
12089OMPClause *
12092 Vars.reserve(C->varlist_size());
12093 for (auto *VE : C->varlist()) {
12094 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12095 if (EVar.isInvalid())
12096 return nullptr;
12097 Vars.push_back(EVar.get());
12098 }
12099 return getDerived().RebuildOMPExclusiveClause(
12100 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12101}
12102
12103template <typename Derived>
12105 OMPUsesAllocatorsClause *C) {
12107 Data.reserve(C->getNumberOfAllocators());
12108 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
12109 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
12110 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
12111 if (Allocator.isInvalid())
12112 continue;
12113 ExprResult AllocatorTraits;
12114 if (Expr *AT = D.AllocatorTraits) {
12115 AllocatorTraits = getDerived().TransformExpr(AT);
12116 if (AllocatorTraits.isInvalid())
12117 continue;
12118 }
12119 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
12120 NewD.Allocator = Allocator.get();
12121 NewD.AllocatorTraits = AllocatorTraits.get();
12122 NewD.LParenLoc = D.LParenLoc;
12123 NewD.RParenLoc = D.RParenLoc;
12124 }
12125 return getDerived().RebuildOMPUsesAllocatorsClause(
12126 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12127}
12128
12129template <typename Derived>
12130OMPClause *
12132 SmallVector<Expr *, 4> Locators;
12133 Locators.reserve(C->varlist_size());
12134 ExprResult ModifierRes;
12135 if (Expr *Modifier = C->getModifier()) {
12136 ModifierRes = getDerived().TransformExpr(Modifier);
12137 if (ModifierRes.isInvalid())
12138 return nullptr;
12139 }
12140 for (Expr *E : C->varlist()) {
12141 ExprResult Locator = getDerived().TransformExpr(E);
12142 if (Locator.isInvalid())
12143 continue;
12144 Locators.push_back(Locator.get());
12145 }
12146 return getDerived().RebuildOMPAffinityClause(
12147 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
12148 ModifierRes.get(), Locators);
12149}
12150
12151template <typename Derived>
12153 return getDerived().RebuildOMPOrderClause(
12154 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
12155 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
12156}
12157
12158template <typename Derived>
12160 return getDerived().RebuildOMPBindClause(
12161 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
12162 C->getLParenLoc(), C->getEndLoc());
12163}
12164
12165template <typename Derived>
12167 OMPXDynCGroupMemClause *C) {
12168 ExprResult Size = getDerived().TransformExpr(C->getSize());
12169 if (Size.isInvalid())
12170 return nullptr;
12171 return getDerived().RebuildOMPXDynCGroupMemClause(
12172 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12173}
12174
12175template <typename Derived>
12177 OMPDynGroupprivateClause *C) {
12178 ExprResult Size = getDerived().TransformExpr(C->getSize());
12179 if (Size.isInvalid())
12180 return nullptr;
12181 return getDerived().RebuildOMPDynGroupprivateClause(
12182 C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(),
12183 Size.get(), C->getBeginLoc(), C->getLParenLoc(),
12184 C->getDynGroupprivateModifierLoc(),
12185 C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc());
12186}
12187
12188template <typename Derived>
12189OMPClause *
12192 Vars.reserve(C->varlist_size());
12193 for (auto *VE : C->varlist()) {
12194 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12195 if (EVar.isInvalid())
12196 return nullptr;
12197 Vars.push_back(EVar.get());
12198 }
12199 return getDerived().RebuildOMPDoacrossClause(
12200 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
12201 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12202}
12203
12204template <typename Derived>
12205OMPClause *
12208 for (auto *A : C->getAttrs())
12209 NewAttrs.push_back(getDerived().TransformAttr(A));
12210 return getDerived().RebuildOMPXAttributeClause(
12211 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12212}
12213
12214template <typename Derived>
12216 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
12217}
12218
12219//===----------------------------------------------------------------------===//
12220// OpenACC transformation
12221//===----------------------------------------------------------------------===//
12222namespace {
12223template <typename Derived>
12224class OpenACCClauseTransform final
12225 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
12226 TreeTransform<Derived> &Self;
12227 ArrayRef<const OpenACCClause *> ExistingClauses;
12228 SemaOpenACC::OpenACCParsedClause &ParsedClause;
12229 OpenACCClause *NewClause = nullptr;
12230
12231 ExprResult VisitVar(Expr *VarRef) {
12232 ExprResult Res = Self.TransformExpr(VarRef);
12233
12234 if (!Res.isUsable())
12235 return Res;
12236
12237 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12238 ParsedClause.getClauseKind(),
12239 Res.get());
12240
12241 return Res;
12242 }
12243
12244 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
12245 llvm::SmallVector<Expr *> InstantiatedVarList;
12246 for (Expr *CurVar : VarList) {
12247 ExprResult VarRef = VisitVar(CurVar);
12248
12249 if (VarRef.isUsable())
12250 InstantiatedVarList.push_back(VarRef.get());
12251 }
12252
12253 return InstantiatedVarList;
12254 }
12255
12256public:
12257 OpenACCClauseTransform(TreeTransform<Derived> &Self,
12258 ArrayRef<const OpenACCClause *> ExistingClauses,
12259 SemaOpenACC::OpenACCParsedClause &PC)
12260 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
12261
12262 OpenACCClause *CreatedClause() const { return NewClause; }
12263
12264#define VISIT_CLAUSE(CLAUSE_NAME) \
12265 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
12266#include "clang/Basic/OpenACCClauses.def"
12267};
12268
12269template <typename Derived>
12270void OpenACCClauseTransform<Derived>::VisitDefaultClause(
12271 const OpenACCDefaultClause &C) {
12272 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
12273
12274 NewClause = OpenACCDefaultClause::Create(
12275 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
12276 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12277 ParsedClause.getEndLoc());
12278}
12279
12280template <typename Derived>
12281void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
12282 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12283 assert(Cond && "If constructed with invalid Condition");
12284 Sema::ConditionResult Res = Self.TransformCondition(
12285 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
12286
12287 if (Res.isInvalid() || !Res.get().second)
12288 return;
12289
12290 ParsedClause.setConditionDetails(Res.get().second);
12291
12292 NewClause = OpenACCIfClause::Create(
12293 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12294 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12295 ParsedClause.getEndLoc());
12296}
12297
12298template <typename Derived>
12299void OpenACCClauseTransform<Derived>::VisitSelfClause(
12300 const OpenACCSelfClause &C) {
12301
12302 // If this is an 'update' 'self' clause, this is actually a var list instead.
12303 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
12304 llvm::SmallVector<Expr *> InstantiatedVarList;
12305 for (Expr *CurVar : C.getVarList()) {
12306 ExprResult Res = Self.TransformExpr(CurVar);
12307
12308 if (!Res.isUsable())
12309 continue;
12310
12311 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12312 ParsedClause.getClauseKind(),
12313 Res.get());
12314
12315 if (Res.isUsable())
12316 InstantiatedVarList.push_back(Res.get());
12317 }
12318
12319 ParsedClause.setVarListDetails(InstantiatedVarList,
12321
12322 NewClause = OpenACCSelfClause::Create(
12323 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12324 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12325 ParsedClause.getEndLoc());
12326 } else {
12327
12328 if (C.hasConditionExpr()) {
12329 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12331 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
12333
12334 if (Res.isInvalid() || !Res.get().second)
12335 return;
12336
12337 ParsedClause.setConditionDetails(Res.get().second);
12338 }
12339
12340 NewClause = OpenACCSelfClause::Create(
12341 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12342 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12343 ParsedClause.getEndLoc());
12344 }
12345}
12346
12347template <typename Derived>
12348void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
12349 const OpenACCNumGangsClause &C) {
12350 llvm::SmallVector<Expr *> InstantiatedIntExprs;
12351
12352 for (Expr *CurIntExpr : C.getIntExprs()) {
12353 ExprResult Res = Self.TransformExpr(CurIntExpr);
12354
12355 if (!Res.isUsable())
12356 return;
12357
12358 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12359 C.getClauseKind(),
12360 C.getBeginLoc(), Res.get());
12361 if (!Res.isUsable())
12362 return;
12363
12364 InstantiatedIntExprs.push_back(Res.get());
12365 }
12366
12367 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
12369 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12370 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12371 ParsedClause.getEndLoc());
12372}
12373
12374template <typename Derived>
12375void OpenACCClauseTransform<Derived>::VisitPrivateClause(
12376 const OpenACCPrivateClause &C) {
12377 llvm::SmallVector<Expr *> InstantiatedVarList;
12379
12380 for (const auto [RefExpr, InitRecipe] :
12381 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12382 ExprResult VarRef = VisitVar(RefExpr);
12383
12384 if (VarRef.isUsable()) {
12385 InstantiatedVarList.push_back(VarRef.get());
12386
12387 // We only have to create a new one if it is dependent, and Sema won't
12388 // make one of these unless the type is non-dependent.
12389 if (InitRecipe.isSet())
12390 InitRecipes.push_back(InitRecipe);
12391 else
12392 InitRecipes.push_back(
12393 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
12394 }
12395 }
12396 ParsedClause.setVarListDetails(InstantiatedVarList,
12398
12399 NewClause = OpenACCPrivateClause::Create(
12400 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12401 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12402 ParsedClause.getEndLoc());
12403}
12404
12405template <typename Derived>
12406void OpenACCClauseTransform<Derived>::VisitHostClause(
12407 const OpenACCHostClause &C) {
12408 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12410
12411 NewClause = OpenACCHostClause::Create(
12412 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12413 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12414 ParsedClause.getEndLoc());
12415}
12416
12417template <typename Derived>
12418void OpenACCClauseTransform<Derived>::VisitDeviceClause(
12419 const OpenACCDeviceClause &C) {
12420 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12422
12423 NewClause = OpenACCDeviceClause::Create(
12424 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12425 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12426 ParsedClause.getEndLoc());
12427}
12428
12429template <typename Derived>
12430void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
12432 llvm::SmallVector<Expr *> InstantiatedVarList;
12434
12435 for (const auto [RefExpr, InitRecipe] :
12436 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12437 ExprResult VarRef = VisitVar(RefExpr);
12438
12439 if (VarRef.isUsable()) {
12440 InstantiatedVarList.push_back(VarRef.get());
12441
12442 // We only have to create a new one if it is dependent, and Sema won't
12443 // make one of these unless the type is non-dependent.
12444 if (InitRecipe.isSet())
12445 InitRecipes.push_back(InitRecipe);
12446 else
12447 InitRecipes.push_back(
12448 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
12449 VarRef.get()));
12450 }
12451 }
12452 ParsedClause.setVarListDetails(InstantiatedVarList,
12454
12456 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12457 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12458 ParsedClause.getEndLoc());
12459}
12460
12461template <typename Derived>
12462void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12463 const OpenACCNoCreateClause &C) {
12464 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12466
12468 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12469 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12470 ParsedClause.getEndLoc());
12471}
12472
12473template <typename Derived>
12474void OpenACCClauseTransform<Derived>::VisitPresentClause(
12475 const OpenACCPresentClause &C) {
12476 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12478
12479 NewClause = OpenACCPresentClause::Create(
12480 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12481 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12482 ParsedClause.getEndLoc());
12483}
12484
12485template <typename Derived>
12486void OpenACCClauseTransform<Derived>::VisitCopyClause(
12487 const OpenACCCopyClause &C) {
12488 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12489 C.getModifierList());
12490
12491 NewClause = OpenACCCopyClause::Create(
12492 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12493 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12494 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12495 ParsedClause.getEndLoc());
12496}
12497
12498template <typename Derived>
12499void OpenACCClauseTransform<Derived>::VisitLinkClause(
12500 const OpenACCLinkClause &C) {
12501 llvm_unreachable("link clause not valid unless a decl transform");
12502}
12503
12504template <typename Derived>
12505void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12507 llvm_unreachable("device_resident clause not valid unless a decl transform");
12508}
12509template <typename Derived>
12510void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12511 const OpenACCNoHostClause &C) {
12512 llvm_unreachable("nohost clause not valid unless a decl transform");
12513}
12514template <typename Derived>
12515void OpenACCClauseTransform<Derived>::VisitBindClause(
12516 const OpenACCBindClause &C) {
12517 llvm_unreachable("bind clause not valid unless a decl transform");
12518}
12519
12520template <typename Derived>
12521void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12522 const OpenACCCopyInClause &C) {
12523 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12524 C.getModifierList());
12525
12526 NewClause = OpenACCCopyInClause::Create(
12527 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12528 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12529 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12530 ParsedClause.getEndLoc());
12531}
12532
12533template <typename Derived>
12534void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12535 const OpenACCCopyOutClause &C) {
12536 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12537 C.getModifierList());
12538
12539 NewClause = OpenACCCopyOutClause::Create(
12540 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12541 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12542 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12543 ParsedClause.getEndLoc());
12544}
12545
12546template <typename Derived>
12547void OpenACCClauseTransform<Derived>::VisitCreateClause(
12548 const OpenACCCreateClause &C) {
12549 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12550 C.getModifierList());
12551
12552 NewClause = OpenACCCreateClause::Create(
12553 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12554 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12555 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12556 ParsedClause.getEndLoc());
12557}
12558template <typename Derived>
12559void OpenACCClauseTransform<Derived>::VisitAttachClause(
12560 const OpenACCAttachClause &C) {
12561 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12562
12563 // Ensure each var is a pointer type.
12564 llvm::erase_if(VarList, [&](Expr *E) {
12565 return Self.getSema().OpenACC().CheckVarIsPointerType(
12567 });
12568
12569 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12570 NewClause = OpenACCAttachClause::Create(
12571 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12572 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12573 ParsedClause.getEndLoc());
12574}
12575
12576template <typename Derived>
12577void OpenACCClauseTransform<Derived>::VisitDetachClause(
12578 const OpenACCDetachClause &C) {
12579 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12580
12581 // Ensure each var is a pointer type.
12582 llvm::erase_if(VarList, [&](Expr *E) {
12583 return Self.getSema().OpenACC().CheckVarIsPointerType(
12585 });
12586
12587 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12588 NewClause = OpenACCDetachClause::Create(
12589 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12590 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12591 ParsedClause.getEndLoc());
12592}
12593
12594template <typename Derived>
12595void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12596 const OpenACCDeleteClause &C) {
12597 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12599 NewClause = OpenACCDeleteClause::Create(
12600 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12601 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12602 ParsedClause.getEndLoc());
12603}
12604
12605template <typename Derived>
12606void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12607 const OpenACCUseDeviceClause &C) {
12608 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12611 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12612 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12613 ParsedClause.getEndLoc());
12614}
12615
12616template <typename Derived>
12617void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12618 const OpenACCDevicePtrClause &C) {
12619 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12620
12621 // Ensure each var is a pointer type.
12622 llvm::erase_if(VarList, [&](Expr *E) {
12623 return Self.getSema().OpenACC().CheckVarIsPointerType(
12625 });
12626
12627 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12629 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12630 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12631 ParsedClause.getEndLoc());
12632}
12633
12634template <typename Derived>
12635void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12636 const OpenACCNumWorkersClause &C) {
12637 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12638 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12639
12640 ExprResult Res = Self.TransformExpr(IntExpr);
12641 if (!Res.isUsable())
12642 return;
12643
12644 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12645 C.getClauseKind(),
12646 C.getBeginLoc(), Res.get());
12647 if (!Res.isUsable())
12648 return;
12649
12650 ParsedClause.setIntExprDetails(Res.get());
12652 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12653 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12654 ParsedClause.getEndLoc());
12655}
12656
12657template <typename Derived>
12658void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12659 const OpenACCDeviceNumClause &C) {
12660 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12661 assert(IntExpr && "device_num clause constructed with invalid int expr");
12662
12663 ExprResult Res = Self.TransformExpr(IntExpr);
12664 if (!Res.isUsable())
12665 return;
12666
12667 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12668 C.getClauseKind(),
12669 C.getBeginLoc(), Res.get());
12670 if (!Res.isUsable())
12671 return;
12672
12673 ParsedClause.setIntExprDetails(Res.get());
12675 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12676 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12677 ParsedClause.getEndLoc());
12678}
12679
12680template <typename Derived>
12681void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12683 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12684 assert(IntExpr && "default_async clause constructed with invalid int expr");
12685
12686 ExprResult Res = Self.TransformExpr(IntExpr);
12687 if (!Res.isUsable())
12688 return;
12689
12690 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12691 C.getClauseKind(),
12692 C.getBeginLoc(), Res.get());
12693 if (!Res.isUsable())
12694 return;
12695
12696 ParsedClause.setIntExprDetails(Res.get());
12698 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12699 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12700 ParsedClause.getEndLoc());
12701}
12702
12703template <typename Derived>
12704void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12706 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12707 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12708
12709 ExprResult Res = Self.TransformExpr(IntExpr);
12710 if (!Res.isUsable())
12711 return;
12712
12713 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12714 C.getClauseKind(),
12715 C.getBeginLoc(), Res.get());
12716 if (!Res.isUsable())
12717 return;
12718
12719 ParsedClause.setIntExprDetails(Res.get());
12721 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12722 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12723 ParsedClause.getEndLoc());
12724}
12725
12726template <typename Derived>
12727void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12728 const OpenACCAsyncClause &C) {
12729 if (C.hasIntExpr()) {
12730 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12731 if (!Res.isUsable())
12732 return;
12733
12734 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12735 C.getClauseKind(),
12736 C.getBeginLoc(), Res.get());
12737 if (!Res.isUsable())
12738 return;
12739 ParsedClause.setIntExprDetails(Res.get());
12740 }
12741
12742 NewClause = OpenACCAsyncClause::Create(
12743 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12744 ParsedClause.getLParenLoc(),
12745 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12746 : nullptr,
12747 ParsedClause.getEndLoc());
12748}
12749
12750template <typename Derived>
12751void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12752 const OpenACCWorkerClause &C) {
12753 if (C.hasIntExpr()) {
12754 // restrictions on this expression are all "does it exist in certain
12755 // situations" that are not possible to be dependent, so the only check we
12756 // have is that it transforms, and is an int expression.
12757 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12758 if (!Res.isUsable())
12759 return;
12760
12761 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12762 C.getClauseKind(),
12763 C.getBeginLoc(), Res.get());
12764 if (!Res.isUsable())
12765 return;
12766 ParsedClause.setIntExprDetails(Res.get());
12767 }
12768
12769 NewClause = OpenACCWorkerClause::Create(
12770 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12771 ParsedClause.getLParenLoc(),
12772 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12773 : nullptr,
12774 ParsedClause.getEndLoc());
12775}
12776
12777template <typename Derived>
12778void OpenACCClauseTransform<Derived>::VisitVectorClause(
12779 const OpenACCVectorClause &C) {
12780 if (C.hasIntExpr()) {
12781 // restrictions on this expression are all "does it exist in certain
12782 // situations" that are not possible to be dependent, so the only check we
12783 // have is that it transforms, and is an int expression.
12784 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12785 if (!Res.isUsable())
12786 return;
12787
12788 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12789 C.getClauseKind(),
12790 C.getBeginLoc(), Res.get());
12791 if (!Res.isUsable())
12792 return;
12793 ParsedClause.setIntExprDetails(Res.get());
12794 }
12795
12796 NewClause = OpenACCVectorClause::Create(
12797 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12798 ParsedClause.getLParenLoc(),
12799 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12800 : nullptr,
12801 ParsedClause.getEndLoc());
12802}
12803
12804template <typename Derived>
12805void OpenACCClauseTransform<Derived>::VisitWaitClause(
12806 const OpenACCWaitClause &C) {
12807 if (C.hasExprs()) {
12808 Expr *DevNumExpr = nullptr;
12809 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12810
12811 // Instantiate devnum expr if it exists.
12812 if (C.getDevNumExpr()) {
12813 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12814 if (!Res.isUsable())
12815 return;
12816 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12817 C.getClauseKind(),
12818 C.getBeginLoc(), Res.get());
12819 if (!Res.isUsable())
12820 return;
12821
12822 DevNumExpr = Res.get();
12823 }
12824
12825 // Instantiate queue ids.
12826 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12827 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12828 if (!Res.isUsable())
12829 return;
12830 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12831 C.getClauseKind(),
12832 C.getBeginLoc(), Res.get());
12833 if (!Res.isUsable())
12834 return;
12835
12836 InstantiatedQueueIdExprs.push_back(Res.get());
12837 }
12838
12839 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12840 std::move(InstantiatedQueueIdExprs));
12841 }
12842
12843 NewClause = OpenACCWaitClause::Create(
12844 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12845 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12846 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12847 ParsedClause.getEndLoc());
12848}
12849
12850template <typename Derived>
12851void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12852 const OpenACCDeviceTypeClause &C) {
12853 // Nothing to transform here, just create a new version of 'C'.
12855 Self.getSema().getASTContext(), C.getClauseKind(),
12856 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12857 C.getArchitectures(), ParsedClause.getEndLoc());
12858}
12859
12860template <typename Derived>
12861void OpenACCClauseTransform<Derived>::VisitAutoClause(
12862 const OpenACCAutoClause &C) {
12863 // Nothing to do, so just create a new node.
12864 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12865 ParsedClause.getBeginLoc(),
12866 ParsedClause.getEndLoc());
12867}
12868
12869template <typename Derived>
12870void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12871 const OpenACCIndependentClause &C) {
12872 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12873 ParsedClause.getBeginLoc(),
12874 ParsedClause.getEndLoc());
12875}
12876
12877template <typename Derived>
12878void OpenACCClauseTransform<Derived>::VisitSeqClause(
12879 const OpenACCSeqClause &C) {
12880 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12881 ParsedClause.getBeginLoc(),
12882 ParsedClause.getEndLoc());
12883}
12884template <typename Derived>
12885void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12886 const OpenACCFinalizeClause &C) {
12887 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12888 ParsedClause.getBeginLoc(),
12889 ParsedClause.getEndLoc());
12890}
12891
12892template <typename Derived>
12893void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12894 const OpenACCIfPresentClause &C) {
12895 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12896 ParsedClause.getBeginLoc(),
12897 ParsedClause.getEndLoc());
12898}
12899
12900template <typename Derived>
12901void OpenACCClauseTransform<Derived>::VisitReductionClause(
12902 const OpenACCReductionClause &C) {
12903 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12904 SmallVector<Expr *> ValidVars;
12906
12907 for (const auto [Var, OrigRecipe] :
12908 llvm::zip(TransformedVars, C.getRecipes())) {
12909 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12910 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12911 if (Res.isUsable()) {
12912 ValidVars.push_back(Res.get());
12913
12914 if (OrigRecipe.isSet())
12915 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
12916 else
12917 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12918 C.getReductionOp(), Res.get()));
12919 }
12920 }
12921
12922 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12923 ExistingClauses, ParsedClause.getDirectiveKind(),
12924 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12925 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12926}
12927
12928template <typename Derived>
12929void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12930 const OpenACCCollapseClause &C) {
12931 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12932 assert(LoopCount && "collapse clause constructed with invalid loop count");
12933
12934 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12935
12936 if (!NewLoopCount.isUsable())
12937 return;
12938
12939 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12940 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12941 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12942
12943 // FIXME: It isn't clear whether this is properly tested here, we should
12944 // probably see if we can come up with a test for this.
12945 if (!NewLoopCount.isUsable())
12946 return;
12947
12948 NewLoopCount =
12949 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12950
12951 // FIXME: It isn't clear whether this is properly tested here, we should
12952 // probably see if we can come up with a test for this.
12953 if (!NewLoopCount.isUsable())
12954 return;
12955
12956 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12958 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12959 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12960 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12961}
12962
12963template <typename Derived>
12964void OpenACCClauseTransform<Derived>::VisitTileClause(
12965 const OpenACCTileClause &C) {
12966
12967 llvm::SmallVector<Expr *> TransformedExprs;
12968
12969 for (Expr *E : C.getSizeExprs()) {
12970 ExprResult NewSizeExpr = Self.TransformExpr(E);
12971
12972 if (!NewSizeExpr.isUsable())
12973 return;
12974
12975 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12976 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12977 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12978
12979 // FIXME: It isn't clear whether this is properly tested here, we should
12980 // probably see if we can come up with a test for this.
12981 if (!NewSizeExpr.isUsable())
12982 return;
12983
12984 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12985
12986 if (!NewSizeExpr.isUsable())
12987 return;
12988 TransformedExprs.push_back(NewSizeExpr.get());
12989 }
12990
12991 ParsedClause.setIntExprDetails(TransformedExprs);
12992 NewClause = OpenACCTileClause::Create(
12993 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12994 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12995 ParsedClause.getEndLoc());
12996}
12997template <typename Derived>
12998void OpenACCClauseTransform<Derived>::VisitGangClause(
12999 const OpenACCGangClause &C) {
13000 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
13001 llvm::SmallVector<Expr *> TransformedIntExprs;
13002
13003 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
13004 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
13005 if (!ER.isUsable())
13006 continue;
13007
13008 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
13009 ParsedClause.getDirectiveKind(),
13010 C.getExpr(I).first, ER.get());
13011 if (!ER.isUsable())
13012 continue;
13013 TransformedGangKinds.push_back(C.getExpr(I).first);
13014 TransformedIntExprs.push_back(ER.get());
13015 }
13016
13017 NewClause = Self.getSema().OpenACC().CheckGangClause(
13018 ParsedClause.getDirectiveKind(), ExistingClauses,
13019 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13020 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
13021}
13022} // namespace
13023template <typename Derived>
13024OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
13025 ArrayRef<const OpenACCClause *> ExistingClauses,
13026 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
13027
13029 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
13030 ParsedClause.setEndLoc(OldClause->getEndLoc());
13031
13032 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
13033 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
13034
13035 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
13036 ParsedClause};
13037 Transform.Visit(OldClause);
13038
13039 return Transform.CreatedClause();
13040}
13041
13042template <typename Derived>
13044TreeTransform<Derived>::TransformOpenACCClauseList(
13046 llvm::SmallVector<OpenACCClause *> TransformedClauses;
13047 for (const auto *Clause : OldClauses) {
13048 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
13049 TransformedClauses, DirKind, Clause))
13050 TransformedClauses.push_back(TransformedClause);
13051 }
13052 return TransformedClauses;
13053}
13054
13055template <typename Derived>
13058 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13059
13060 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13061 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13062 C->clauses());
13063
13064 if (getSema().OpenACC().ActOnStartStmtDirective(
13065 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13066 return StmtError();
13067
13068 // Transform Structured Block.
13069 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13070 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13071 C->clauses(), TransformedClauses);
13072 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13073 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13074 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13075
13076 return getDerived().RebuildOpenACCComputeConstruct(
13077 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13078 C->getEndLoc(), TransformedClauses, StrBlock);
13079}
13080
13081template <typename Derived>
13084
13085 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13086
13087 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13088 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13089 C->clauses());
13090
13091 if (getSema().OpenACC().ActOnStartStmtDirective(
13092 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13093 return StmtError();
13094
13095 // Transform Loop.
13096 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13097 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13098 C->clauses(), TransformedClauses);
13099 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13100 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13101 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13102
13103 return getDerived().RebuildOpenACCLoopConstruct(
13104 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13105 TransformedClauses, Loop);
13106}
13107
13108template <typename Derived>
13110 OpenACCCombinedConstruct *C) {
13111 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13112
13113 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13114 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13115 C->clauses());
13116
13117 if (getSema().OpenACC().ActOnStartStmtDirective(
13118 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13119 return StmtError();
13120
13121 // Transform Loop.
13122 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13123 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13124 C->clauses(), TransformedClauses);
13125 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13126 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13127 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13128
13129 return getDerived().RebuildOpenACCCombinedConstruct(
13130 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13131 C->getEndLoc(), TransformedClauses, Loop);
13132}
13133
13134template <typename Derived>
13137 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13138
13139 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13140 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13141 C->clauses());
13142 if (getSema().OpenACC().ActOnStartStmtDirective(
13143 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13144 return StmtError();
13145
13146 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13147 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13148 C->clauses(), TransformedClauses);
13149 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13150 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13151 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13152
13153 return getDerived().RebuildOpenACCDataConstruct(
13154 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13155 TransformedClauses, StrBlock);
13156}
13157
13158template <typename Derived>
13160 OpenACCEnterDataConstruct *C) {
13161 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13162
13163 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13164 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13165 C->clauses());
13166 if (getSema().OpenACC().ActOnStartStmtDirective(
13167 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13168 return StmtError();
13169
13170 return getDerived().RebuildOpenACCEnterDataConstruct(
13171 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13172 TransformedClauses);
13173}
13174
13175template <typename Derived>
13177 OpenACCExitDataConstruct *C) {
13178 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13179
13180 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13181 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13182 C->clauses());
13183 if (getSema().OpenACC().ActOnStartStmtDirective(
13184 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13185 return StmtError();
13186
13187 return getDerived().RebuildOpenACCExitDataConstruct(
13188 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13189 TransformedClauses);
13190}
13191
13192template <typename Derived>
13194 OpenACCHostDataConstruct *C) {
13195 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13196
13197 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13198 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13199 C->clauses());
13200 if (getSema().OpenACC().ActOnStartStmtDirective(
13201 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13202 return StmtError();
13203
13204 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13205 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13206 C->clauses(), TransformedClauses);
13207 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13208 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13209 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13210
13211 return getDerived().RebuildOpenACCHostDataConstruct(
13212 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13213 TransformedClauses, StrBlock);
13214}
13215
13216template <typename Derived>
13219 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13220
13221 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13222 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13223 C->clauses());
13224 if (getSema().OpenACC().ActOnStartStmtDirective(
13225 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13226 return StmtError();
13227
13228 return getDerived().RebuildOpenACCInitConstruct(
13229 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13230 TransformedClauses);
13231}
13232
13233template <typename Derived>
13235 OpenACCShutdownConstruct *C) {
13236 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13237
13238 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13239 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13240 C->clauses());
13241 if (getSema().OpenACC().ActOnStartStmtDirective(
13242 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13243 return StmtError();
13244
13245 return getDerived().RebuildOpenACCShutdownConstruct(
13246 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13247 TransformedClauses);
13248}
13249template <typename Derived>
13252 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13253
13254 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13255 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13256 C->clauses());
13257 if (getSema().OpenACC().ActOnStartStmtDirective(
13258 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13259 return StmtError();
13260
13261 return getDerived().RebuildOpenACCSetConstruct(
13262 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13263 TransformedClauses);
13264}
13265
13266template <typename Derived>
13268 OpenACCUpdateConstruct *C) {
13269 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13270
13271 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13272 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13273 C->clauses());
13274 if (getSema().OpenACC().ActOnStartStmtDirective(
13275 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13276 return StmtError();
13277
13278 return getDerived().RebuildOpenACCUpdateConstruct(
13279 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13280 TransformedClauses);
13281}
13282
13283template <typename Derived>
13286 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13287
13288 ExprResult DevNumExpr;
13289 if (C->hasDevNumExpr()) {
13290 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
13291
13292 if (DevNumExpr.isUsable())
13293 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
13295 C->getBeginLoc(), DevNumExpr.get());
13296 }
13297
13298 llvm::SmallVector<Expr *> QueueIdExprs;
13299
13300 for (Expr *QE : C->getQueueIdExprs()) {
13301 assert(QE && "Null queue id expr?");
13302 ExprResult NewEQ = getDerived().TransformExpr(QE);
13303
13304 if (!NewEQ.isUsable())
13305 break;
13306 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
13308 C->getBeginLoc(), NewEQ.get());
13309 if (NewEQ.isUsable())
13310 QueueIdExprs.push_back(NewEQ.get());
13311 }
13312
13313 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13314 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13315 C->clauses());
13316
13317 if (getSema().OpenACC().ActOnStartStmtDirective(
13318 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13319 return StmtError();
13320
13321 return getDerived().RebuildOpenACCWaitConstruct(
13322 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13323 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
13324 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
13325}
13326template <typename Derived>
13328 OpenACCCacheConstruct *C) {
13329 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13330
13331 llvm::SmallVector<Expr *> TransformedVarList;
13332 for (Expr *Var : C->getVarList()) {
13333 assert(Var && "Null var listexpr?");
13334
13335 ExprResult NewVar = getDerived().TransformExpr(Var);
13336
13337 if (!NewVar.isUsable())
13338 break;
13339
13340 NewVar = getSema().OpenACC().ActOnVar(
13341 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
13342 if (!NewVar.isUsable())
13343 break;
13344
13345 TransformedVarList.push_back(NewVar.get());
13346 }
13347
13348 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13349 C->getBeginLoc(), {}))
13350 return StmtError();
13351
13352 return getDerived().RebuildOpenACCCacheConstruct(
13353 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13354 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
13355 C->getEndLoc());
13356}
13357
13358template <typename Derived>
13360 OpenACCAtomicConstruct *C) {
13361 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13362
13363 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13364 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13365 C->clauses());
13366
13367 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13368 C->getBeginLoc(), {}))
13369 return StmtError();
13370
13371 // Transform Associated Stmt.
13372 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13373 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
13374
13375 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
13376 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
13377 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
13378 AssocStmt);
13379
13380 return getDerived().RebuildOpenACCAtomicConstruct(
13381 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
13382 C->getEndLoc(), TransformedClauses, AssocStmt);
13383}
13384
13385template <typename Derived>
13388 if (getDerived().AlwaysRebuild())
13389 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
13390 // Nothing can ever change, so there is never anything to transform.
13391 return E;
13392}
13393
13394//===----------------------------------------------------------------------===//
13395// Expression transformation
13396//===----------------------------------------------------------------------===//
13397template<typename Derived>
13400 return TransformExpr(E->getSubExpr());
13401}
13402
13403template <typename Derived>
13406 if (!E->isTypeDependent())
13407 return E;
13408
13409 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
13410
13411 if (!NewT)
13412 return ExprError();
13413
13414 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
13415 return E;
13416
13417 return getDerived().RebuildSYCLUniqueStableNameExpr(
13418 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
13419}
13420
13421template <typename Derived>
13424 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
13425 const auto *SKEPAttr = FD->template getAttr<SYCLKernelEntryPointAttr>();
13426 if (!SKEPAttr || SKEPAttr->isInvalidAttr())
13427 return StmtError();
13428
13429 ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
13430 if (IdExpr.isInvalid())
13431 return StmtError();
13432
13433 StmtResult Body = getDerived().TransformStmt(S->getOriginalStmt());
13434 if (Body.isInvalid())
13435 return StmtError();
13436
13438 cast<FunctionDecl>(SemaRef.CurContext), cast<CompoundStmt>(Body.get()),
13439 IdExpr.get());
13440 if (SR.isInvalid())
13441 return StmtError();
13442
13443 return SR;
13444}
13445
13446template <typename Derived>
13448 // TODO(reflection): Implement its transform
13449 assert(false && "not implemented yet");
13450 return ExprError();
13451}
13452
13453template<typename Derived>
13456 if (!E->isTypeDependent())
13457 return E;
13458
13459 return getDerived().RebuildPredefinedExpr(E->getLocation(),
13460 E->getIdentKind());
13461}
13462
13463template<typename Derived>
13466 NestedNameSpecifierLoc QualifierLoc;
13467 if (E->getQualifierLoc()) {
13468 QualifierLoc
13469 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13470 if (!QualifierLoc)
13471 return ExprError();
13472 }
13473
13474 ValueDecl *ND
13475 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
13476 E->getDecl()));
13477 if (!ND || ND->isInvalidDecl())
13478 return ExprError();
13479
13480 NamedDecl *Found = ND;
13481 if (E->getFoundDecl() != E->getDecl()) {
13482 Found = cast_or_null<NamedDecl>(
13483 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
13484 if (!Found)
13485 return ExprError();
13486 }
13487
13488 DeclarationNameInfo NameInfo = E->getNameInfo();
13489 if (NameInfo.getName()) {
13490 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
13491 if (!NameInfo.getName())
13492 return ExprError();
13493 }
13494
13495 if (!getDerived().AlwaysRebuild() &&
13496 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
13497 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
13498 Found == E->getFoundDecl() &&
13499 NameInfo.getName() == E->getDecl()->getDeclName() &&
13500 !E->hasExplicitTemplateArgs()) {
13501
13502 // Mark it referenced in the new context regardless.
13503 // FIXME: this is a bit instantiation-specific.
13504 SemaRef.MarkDeclRefReferenced(E);
13505
13506 return E;
13507 }
13508
13509 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
13510 if (E->hasExplicitTemplateArgs()) {
13511 TemplateArgs = &TransArgs;
13512 TransArgs.setLAngleLoc(E->getLAngleLoc());
13513 TransArgs.setRAngleLoc(E->getRAngleLoc());
13514 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13515 E->getNumTemplateArgs(),
13516 TransArgs))
13517 return ExprError();
13518 }
13519
13520 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13521 Found, TemplateArgs);
13522}
13523
13524template<typename Derived>
13527 return E;
13528}
13529
13530template <typename Derived>
13532 FixedPointLiteral *E) {
13533 return E;
13534}
13535
13536template<typename Derived>
13539 return E;
13540}
13541
13542template<typename Derived>
13545 return E;
13546}
13547
13548template<typename Derived>
13551 return E;
13552}
13553
13554template<typename Derived>
13557 return E;
13558}
13559
13560template<typename Derived>
13563 return getDerived().TransformCallExpr(E);
13564}
13565
13566template<typename Derived>
13569 ExprResult ControllingExpr;
13570 TypeSourceInfo *ControllingType = nullptr;
13571 if (E->isExprPredicate())
13572 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13573 else
13574 ControllingType = getDerived().TransformType(E->getControllingType());
13575
13576 if (ControllingExpr.isInvalid() && !ControllingType)
13577 return ExprError();
13578
13579 SmallVector<Expr *, 4> AssocExprs;
13581 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13582 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13583 if (TSI) {
13584 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13585 if (!AssocType)
13586 return ExprError();
13587 AssocTypes.push_back(AssocType);
13588 } else {
13589 AssocTypes.push_back(nullptr);
13590 }
13591
13592 ExprResult AssocExpr =
13593 getDerived().TransformExpr(Assoc.getAssociationExpr());
13594 if (AssocExpr.isInvalid())
13595 return ExprError();
13596 AssocExprs.push_back(AssocExpr.get());
13597 }
13598
13599 if (!ControllingType)
13600 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13601 E->getDefaultLoc(),
13602 E->getRParenLoc(),
13603 ControllingExpr.get(),
13604 AssocTypes,
13605 AssocExprs);
13606 return getDerived().RebuildGenericSelectionExpr(
13607 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13608 ControllingType, AssocTypes, AssocExprs);
13609}
13610
13611template<typename Derived>
13614 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13615 if (SubExpr.isInvalid())
13616 return ExprError();
13617
13618 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13619 return E;
13620
13621 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13622 E->getRParen());
13623}
13624
13625/// The operand of a unary address-of operator has special rules: it's
13626/// allowed to refer to a non-static member of a class even if there's no 'this'
13627/// object available.
13628template<typename Derived>
13631 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13632 return getDerived().TransformDependentScopeDeclRefExpr(
13633 DRE, /*IsAddressOfOperand=*/true, nullptr);
13634 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13635 return getDerived().TransformUnresolvedLookupExpr(
13636 ULE, /*IsAddressOfOperand=*/true);
13637 else
13638 return getDerived().TransformExpr(E);
13639}
13640
13641template<typename Derived>
13644 ExprResult SubExpr;
13645 if (E->getOpcode() == UO_AddrOf)
13646 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13647 else
13648 SubExpr = TransformExpr(E->getSubExpr());
13649 if (SubExpr.isInvalid())
13650 return ExprError();
13651
13652 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13653 return E;
13654
13655 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13656 E->getOpcode(),
13657 SubExpr.get());
13658}
13659
13660template<typename Derived>
13662TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13663 // Transform the type.
13664 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13665 if (!Type)
13666 return ExprError();
13667
13668 // Transform all of the components into a Designation similar to what the
13669 // parser builds.
13670 // FIXME: It would be slightly more efficient in the non-dependent case to
13671 // just map FieldDecls, rather than requiring the rebuilder to look for
13672 // the fields again. However, __builtin_offsetof is rare enough in
13673 // template code that we don't care.
13674 bool ExprChanged = false;
13675 Designation Desig;
13676 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13677 const OffsetOfNode &ON = E->getComponent(I);
13678 switch (ON.getKind()) {
13679 case OffsetOfNode::Array: {
13680 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13681 ExprResult Index = getDerived().TransformExpr(FromIndex);
13682 if (Index.isInvalid())
13683 return ExprError();
13684
13685 ExprChanged = ExprChanged || Index.get() != FromIndex;
13686 Designator AD =
13687 Designator::CreateArrayDesignator(Index.get(), ON.getBeginLoc());
13688 AD.setRBracketLoc(ON.getEndLoc());
13689 Desig.AddDesignator(AD);
13690 break;
13691 }
13692
13695 const IdentifierInfo *Name = ON.getFieldName();
13696 if (!Name)
13697 continue;
13698 // The leading designator has no '.'; subsequent ones do.
13699 SourceLocation DotLoc =
13700 Desig.empty() ? SourceLocation() : ON.getBeginLoc();
13701 Desig.AddDesignator(
13702 Designator::CreateFieldDesignator(Name, DotLoc, ON.getEndLoc()));
13703 break;
13704 }
13705
13706 case OffsetOfNode::Base:
13707 // Will be recomputed during the rebuild.
13708 continue;
13709 }
13710 }
13711
13712 // If nothing changed, retain the existing expression.
13713 if (!getDerived().AlwaysRebuild() &&
13714 Type == E->getTypeSourceInfo() &&
13715 !ExprChanged)
13716 return E;
13717
13718 // Build a new offsetof expression.
13719 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, Desig,
13720 E->getRParenLoc());
13721}
13722
13723template<typename Derived>
13726 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13727 "opaque value expression requires transformation");
13728 return E;
13729}
13730
13731template <typename Derived>
13734 bool Changed = false;
13735 for (Expr *C : E->subExpressions()) {
13736 ExprResult NewC = getDerived().TransformExpr(C);
13737 if (NewC.isInvalid())
13738 return ExprError();
13739 Children.push_back(NewC.get());
13740
13741 Changed |= NewC.get() != C;
13742 }
13743 if (!getDerived().AlwaysRebuild() && !Changed)
13744 return E;
13745 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13746 Children, E->getType());
13747}
13748
13749template<typename Derived>
13752 // Rebuild the syntactic form. The original syntactic form has
13753 // opaque-value expressions in it, so strip those away and rebuild
13754 // the result. This is a really awful way of doing this, but the
13755 // better solution (rebuilding the semantic expressions and
13756 // rebinding OVEs as necessary) doesn't work; we'd need
13757 // TreeTransform to not strip away implicit conversions.
13758 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13759 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13760 if (result.isInvalid()) return ExprError();
13761
13762 // If that gives us a pseudo-object result back, the pseudo-object
13763 // expression must have been an lvalue-to-rvalue conversion which we
13764 // should reapply.
13765 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13766 result = SemaRef.PseudoObject().checkRValue(result.get());
13767
13768 return result;
13769}
13770
13771template<typename Derived>
13775 if (E->isArgumentType()) {
13776 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13777
13778 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13779 if (!NewT)
13780 return ExprError();
13781
13782 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13783 return E;
13784
13785 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13786 E->getKind(),
13787 E->getSourceRange());
13788 }
13789
13790 // C++0x [expr.sizeof]p1:
13791 // The operand is either an expression, which is an unevaluated operand
13792 // [...]
13796
13797 // Try to recover if we have something like sizeof(T::X) where X is a type.
13798 // Notably, there must be *exactly* one set of parens if X is a type.
13799 TypeSourceInfo *RecoveryTSI = nullptr;
13800 ExprResult SubExpr;
13801 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13802 if (auto *DRE =
13803 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13804 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13805 PE, DRE, false, &RecoveryTSI);
13806 else
13807 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13808
13809 if (RecoveryTSI) {
13810 return getDerived().RebuildUnaryExprOrTypeTrait(
13811 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13812 } else if (SubExpr.isInvalid())
13813 return ExprError();
13814
13815 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13816 return E;
13817
13818 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13819 E->getOperatorLoc(),
13820 E->getKind(),
13821 E->getSourceRange());
13822}
13823
13824template<typename Derived>
13827 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13828 if (LHS.isInvalid())
13829 return ExprError();
13830
13831 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13832 if (RHS.isInvalid())
13833 return ExprError();
13834
13835
13836 if (!getDerived().AlwaysRebuild() &&
13837 LHS.get() == E->getLHS() &&
13838 RHS.get() == E->getRHS())
13839 return E;
13840
13841 return getDerived().RebuildArraySubscriptExpr(
13842 LHS.get(),
13843 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13844}
13845
13846template <typename Derived>
13849 ExprResult Base = getDerived().TransformExpr(E->getBase());
13850 if (Base.isInvalid())
13851 return ExprError();
13852
13853 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13854 if (RowIdx.isInvalid())
13855 return ExprError();
13856
13857 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13858 RowIdx.get() == E->getRowIdx())
13859 return E;
13860
13861 return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(),
13862 E->getRBracketLoc());
13863}
13864
13865template <typename Derived>
13868 ExprResult Base = getDerived().TransformExpr(E->getBase());
13869 if (Base.isInvalid())
13870 return ExprError();
13871
13872 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13873 if (RowIdx.isInvalid())
13874 return ExprError();
13875
13876 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13877 if (ColumnIdx.isInvalid())
13878 return ExprError();
13879
13880 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13881 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13882 return E;
13883
13884 return getDerived().RebuildMatrixSubscriptExpr(
13885 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13886}
13887
13888template <typename Derived>
13891 ExprResult Base = getDerived().TransformExpr(E->getBase());
13892 if (Base.isInvalid())
13893 return ExprError();
13894
13895 ExprResult LowerBound;
13896 if (E->getLowerBound()) {
13897 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13898 if (LowerBound.isInvalid())
13899 return ExprError();
13900 }
13901
13902 ExprResult Length;
13903 if (E->getLength()) {
13904 Length = getDerived().TransformExpr(E->getLength());
13905 if (Length.isInvalid())
13906 return ExprError();
13907 }
13908
13909 ExprResult Stride;
13910 if (E->isOMPArraySection()) {
13911 if (Expr *Str = E->getStride()) {
13912 Stride = getDerived().TransformExpr(Str);
13913 if (Stride.isInvalid())
13914 return ExprError();
13915 }
13916 }
13917
13918 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13919 LowerBound.get() == E->getLowerBound() &&
13920 Length.get() == E->getLength() &&
13921 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13922 return E;
13923
13924 return getDerived().RebuildArraySectionExpr(
13925 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13926 LowerBound.get(), E->getColonLocFirst(),
13927 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13928 Length.get(), Stride.get(), E->getRBracketLoc());
13929}
13930
13931template <typename Derived>
13934 ExprResult Base = getDerived().TransformExpr(E->getBase());
13935 if (Base.isInvalid())
13936 return ExprError();
13937
13939 bool ErrorFound = false;
13940 for (Expr *Dim : E->getDimensions()) {
13941 ExprResult DimRes = getDerived().TransformExpr(Dim);
13942 if (DimRes.isInvalid()) {
13943 ErrorFound = true;
13944 continue;
13945 }
13946 Dims.push_back(DimRes.get());
13947 }
13948
13949 if (ErrorFound)
13950 return ExprError();
13951 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13952 E->getRParenLoc(), Dims,
13953 E->getBracketsRanges());
13954}
13955
13956template <typename Derived>
13959 unsigned NumIterators = E->numOfIterators();
13961
13962 bool ErrorFound = false;
13963 bool NeedToRebuild = getDerived().AlwaysRebuild();
13964 for (unsigned I = 0; I < NumIterators; ++I) {
13965 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13966 Data[I].DeclIdent = D->getIdentifier();
13967 Data[I].DeclIdentLoc = D->getLocation();
13968 if (D->getLocation() == D->getBeginLoc()) {
13969 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13970 "Implicit type must be int.");
13971 } else {
13972 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13973 QualType DeclTy = getDerived().TransformType(D->getType());
13974 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13975 }
13976 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13977 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13978 ExprResult End = getDerived().TransformExpr(Range.End);
13979 ExprResult Step = getDerived().TransformExpr(Range.Step);
13980 ErrorFound = ErrorFound ||
13981 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13982 !Data[I].Type.get().isNull())) ||
13983 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13984 if (ErrorFound)
13985 continue;
13986 Data[I].Range.Begin = Begin.get();
13987 Data[I].Range.End = End.get();
13988 Data[I].Range.Step = Step.get();
13989 Data[I].AssignLoc = E->getAssignLoc(I);
13990 Data[I].ColonLoc = E->getColonLoc(I);
13991 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13992 NeedToRebuild =
13993 NeedToRebuild ||
13994 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13995 D->getType().getTypePtrOrNull()) ||
13996 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13997 Range.Step != Data[I].Range.Step;
13998 }
13999 if (ErrorFound)
14000 return ExprError();
14001 if (!NeedToRebuild)
14002 return E;
14003
14004 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
14005 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
14006 if (!Res.isUsable())
14007 return Res;
14008 auto *IE = cast<OMPIteratorExpr>(Res.get());
14009 for (unsigned I = 0; I < NumIterators; ++I)
14010 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
14011 IE->getIteratorDecl(I));
14012 return Res;
14013}
14014
14015template<typename Derived>
14018 // Transform the callee.
14019 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14020 if (Callee.isInvalid())
14021 return ExprError();
14022
14023 // Transform arguments.
14024 bool ArgChanged = false;
14026 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14027 &ArgChanged))
14028 return ExprError();
14029
14030 if (!getDerived().AlwaysRebuild() &&
14031 Callee.get() == E->getCallee() &&
14032 !ArgChanged)
14033 return SemaRef.MaybeBindToTemporary(E);
14034
14035 // FIXME: Wrong source location information for the '('.
14036 SourceLocation FakeLParenLoc
14037 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14038
14039 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14040 if (E->hasStoredFPFeatures()) {
14041 FPOptionsOverride NewOverrides = E->getFPFeatures();
14042 getSema().CurFPFeatures =
14043 NewOverrides.applyOverrides(getSema().getLangOpts());
14044 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14045 }
14046
14047 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14048 Args,
14049 E->getRParenLoc());
14050}
14051
14052template<typename Derived>
14055 ExprResult Base = getDerived().TransformExpr(E->getBase());
14056 if (Base.isInvalid())
14057 return ExprError();
14058
14059 NestedNameSpecifierLoc QualifierLoc;
14060 if (E->hasQualifier()) {
14061 QualifierLoc
14062 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14063
14064 if (!QualifierLoc)
14065 return ExprError();
14066 }
14067 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14068
14070 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
14071 E->getMemberDecl()));
14072 if (!Member)
14073 return ExprError();
14074
14075 NamedDecl *FoundDecl = E->getFoundDecl();
14076 if (FoundDecl == E->getMemberDecl()) {
14077 FoundDecl = Member;
14078 } else {
14079 FoundDecl = cast_or_null<NamedDecl>(
14080 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
14081 if (!FoundDecl)
14082 return ExprError();
14083 }
14084
14085 if (!getDerived().AlwaysRebuild() &&
14086 Base.get() == E->getBase() &&
14087 QualifierLoc == E->getQualifierLoc() &&
14088 Member == E->getMemberDecl() &&
14089 FoundDecl == E->getFoundDecl() &&
14090 !E->hasExplicitTemplateArgs()) {
14091
14092 // Skip for member expression of (this->f), rebuilt thisi->f is needed
14093 // for Openmp where the field need to be privatizized in the case.
14094 if (!(isa<CXXThisExpr>(E->getBase()) &&
14095 getSema().OpenMP().isOpenMPRebuildMemberExpr(
14097 // Mark it referenced in the new context regardless.
14098 // FIXME: this is a bit instantiation-specific.
14099 SemaRef.MarkMemberReferenced(E);
14100 return E;
14101 }
14102 }
14103
14104 TemplateArgumentListInfo TransArgs;
14105 if (E->hasExplicitTemplateArgs()) {
14106 TransArgs.setLAngleLoc(E->getLAngleLoc());
14107 TransArgs.setRAngleLoc(E->getRAngleLoc());
14108 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14109 E->getNumTemplateArgs(),
14110 TransArgs))
14111 return ExprError();
14112 }
14113
14114 // FIXME: Bogus source location for the operator
14115 SourceLocation FakeOperatorLoc =
14116 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
14117
14118 // FIXME: to do this check properly, we will need to preserve the
14119 // first-qualifier-in-scope here, just in case we had a dependent
14120 // base (and therefore couldn't do the check) and a
14121 // nested-name-qualifier (and therefore could do the lookup).
14122 NamedDecl *FirstQualifierInScope = nullptr;
14123 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
14124 if (MemberNameInfo.getName()) {
14125 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
14126 if (!MemberNameInfo.getName())
14127 return ExprError();
14128 }
14129
14130 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
14131 E->isArrow(),
14132 QualifierLoc,
14133 TemplateKWLoc,
14134 MemberNameInfo,
14135 Member,
14136 FoundDecl,
14137 (E->hasExplicitTemplateArgs()
14138 ? &TransArgs : nullptr),
14139 FirstQualifierInScope);
14140}
14141
14142template<typename Derived>
14145 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14146 if (LHS.isInvalid())
14147 return ExprError();
14148
14149 ExprResult RHS =
14150 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
14151 if (RHS.isInvalid())
14152 return ExprError();
14153
14154 if (!getDerived().AlwaysRebuild() &&
14155 LHS.get() == E->getLHS() &&
14156 RHS.get() == E->getRHS())
14157 return E;
14158
14159 if (E->isCompoundAssignmentOp())
14160 // FPFeatures has already been established from trailing storage
14161 return getDerived().RebuildBinaryOperator(
14162 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
14163 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14164 FPOptionsOverride NewOverrides(E->getFPFeatures());
14165 getSema().CurFPFeatures =
14166 NewOverrides.applyOverrides(getSema().getLangOpts());
14167 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14168 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
14169 LHS.get(), RHS.get());
14170}
14171
14172template <typename Derived>
14175 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
14176
14177 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
14178 if (LHS.isInvalid())
14179 return ExprError();
14180
14181 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
14182 if (RHS.isInvalid())
14183 return ExprError();
14184
14185 // Extract the already-resolved callee declarations so that we can restrict
14186 // ourselves to using them as the unqualified lookup results when rebuilding.
14187 UnresolvedSet<2> UnqualLookups;
14188 bool ChangedAnyLookups = false;
14189 Expr *PossibleBinOps[] = {E->getSemanticForm(),
14190 const_cast<Expr *>(Decomp.InnerBinOp)};
14191 for (Expr *PossibleBinOp : PossibleBinOps) {
14192 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
14193 if (!Op)
14194 continue;
14195 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
14196 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
14197 continue;
14198
14199 // Transform the callee in case we built a call to a local extern
14200 // declaration.
14201 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
14202 E->getOperatorLoc(), Callee->getFoundDecl()));
14203 if (!Found)
14204 return ExprError();
14205 if (Found != Callee->getFoundDecl())
14206 ChangedAnyLookups = true;
14207 UnqualLookups.addDecl(Found);
14208 }
14209
14210 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
14211 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
14212 // Mark all functions used in the rewrite as referenced. Note that when
14213 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
14214 // function calls, and/or there might be a user-defined conversion sequence
14215 // applied to the operands of the <.
14216 // FIXME: this is a bit instantiation-specific.
14217 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
14218 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
14219 return E;
14220 }
14221
14222 return getDerived().RebuildCXXRewrittenBinaryOperator(
14223 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
14224}
14225
14226template<typename Derived>
14230 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14231 FPOptionsOverride NewOverrides(E->getFPFeatures());
14232 getSema().CurFPFeatures =
14233 NewOverrides.applyOverrides(getSema().getLangOpts());
14234 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14235 return getDerived().TransformBinaryOperator(E);
14236}
14237
14238template<typename Derived>
14241 // Just rebuild the common and RHS expressions and see whether we
14242 // get any changes.
14243
14244 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
14245 if (commonExpr.isInvalid())
14246 return ExprError();
14247
14248 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
14249 if (rhs.isInvalid())
14250 return ExprError();
14251
14252 if (!getDerived().AlwaysRebuild() &&
14253 commonExpr.get() == e->getCommon() &&
14254 rhs.get() == e->getFalseExpr())
14255 return e;
14256
14257 return getDerived().RebuildConditionalOperator(commonExpr.get(),
14258 e->getQuestionLoc(),
14259 nullptr,
14260 e->getColonLoc(),
14261 rhs.get());
14262}
14263
14264template<typename Derived>
14267 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14268 if (Cond.isInvalid())
14269 return ExprError();
14270
14271 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14272 if (LHS.isInvalid())
14273 return ExprError();
14274
14275 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14276 if (RHS.isInvalid())
14277 return ExprError();
14278
14279 if (!getDerived().AlwaysRebuild() &&
14280 Cond.get() == E->getCond() &&
14281 LHS.get() == E->getLHS() &&
14282 RHS.get() == E->getRHS())
14283 return E;
14284
14285 return getDerived().RebuildConditionalOperator(Cond.get(),
14286 E->getQuestionLoc(),
14287 LHS.get(),
14288 E->getColonLoc(),
14289 RHS.get());
14290}
14291
14292template<typename Derived>
14295 // Implicit casts are eliminated during transformation, since they
14296 // will be recomputed by semantic analysis after transformation.
14297 return getDerived().TransformExpr(E->getSubExprAsWritten());
14298}
14299
14300template<typename Derived>
14303 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14304 if (!Type)
14305 return ExprError();
14306
14307 ExprResult SubExpr
14308 = getDerived().TransformExpr(E->getSubExprAsWritten());
14309 if (SubExpr.isInvalid())
14310 return ExprError();
14311
14312 if (!getDerived().AlwaysRebuild() &&
14313 Type == E->getTypeInfoAsWritten() &&
14314 SubExpr.get() == E->getSubExpr())
14315 return E;
14316
14317 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
14318 Type,
14319 E->getRParenLoc(),
14320 SubExpr.get());
14321}
14322
14323template<typename Derived>
14326 TypeSourceInfo *OldT = E->getTypeSourceInfo();
14327 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14328 if (!NewT)
14329 return ExprError();
14330
14331 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
14332 if (Init.isInvalid())
14333 return ExprError();
14334
14335 if (!getDerived().AlwaysRebuild() &&
14336 OldT == NewT &&
14337 Init.get() == E->getInitializer())
14338 return SemaRef.MaybeBindToTemporary(E);
14339
14340 // Note: the expression type doesn't necessarily match the
14341 // type-as-written, but that's okay, because it should always be
14342 // derivable from the initializer.
14343
14344 return getDerived().RebuildCompoundLiteralExpr(
14345 E->getLParenLoc(), NewT,
14346 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
14347}
14348
14349template<typename Derived>
14352 ExprResult Base = getDerived().TransformExpr(E->getBase());
14353 if (Base.isInvalid())
14354 return ExprError();
14355
14356 if (!getDerived().AlwaysRebuild() &&
14357 Base.get() == E->getBase())
14358 return E;
14359
14360 // FIXME: Bad source location
14361 SourceLocation FakeOperatorLoc =
14362 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14363 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14364 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
14365 E->getAccessor());
14366}
14367
14368template <typename Derived>
14371 ExprResult Base = getDerived().TransformExpr(E->getBase());
14372 if (Base.isInvalid())
14373 return ExprError();
14374
14375 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase())
14376 return E;
14377
14378 // FIXME: Bad source location
14379 SourceLocation FakeOperatorLoc =
14380 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14381 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14382 Base.get(), FakeOperatorLoc, /*isArrow*/ false, E->getAccessorLoc(),
14383 E->getAccessor());
14384}
14385
14386template<typename Derived>
14389 if (InitListExpr *Syntactic = E->getSyntacticForm())
14390 E = Syntactic;
14391
14392 bool InitChanged = false;
14393
14396
14398 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
14399 Inits, &InitChanged))
14400 return ExprError();
14401
14402 if (!getDerived().AlwaysRebuild() && !InitChanged) {
14403 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
14404 // in some cases. We can't reuse it in general, because the syntactic and
14405 // semantic forms are linked, and we can't know that semantic form will
14406 // match even if the syntactic form does.
14407 }
14408
14409 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
14410 E->getRBraceLoc(), E->isExplicit());
14411}
14412
14413template<typename Derived>
14416 Designation Desig;
14417
14418 // transform the initializer value
14419 ExprResult Init = getDerived().TransformExpr(E->getInit());
14420 if (Init.isInvalid())
14421 return ExprError();
14422
14423 // transform the designators.
14424 SmallVector<Expr*, 4> ArrayExprs;
14425 bool ExprChanged = false;
14426 for (const DesignatedInitExpr::Designator &D : E->designators()) {
14427 if (D.isFieldDesignator()) {
14428 if (D.getFieldDecl()) {
14429 FieldDecl *Field = cast_or_null<FieldDecl>(
14430 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
14431 if (Field != D.getFieldDecl())
14432 // Rebuild the expression when the transformed FieldDecl is
14433 // different to the already assigned FieldDecl.
14434 ExprChanged = true;
14435 if (Field->isAnonymousStructOrUnion())
14436 continue;
14437 } else {
14438 // Ensure that the designator expression is rebuilt when there isn't
14439 // a resolved FieldDecl in the designator as we don't want to assign
14440 // a FieldDecl to a pattern designator that will be instantiated again.
14441 ExprChanged = true;
14442 }
14443 Desig.AddDesignator(Designator::CreateFieldDesignator(
14444 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
14445 continue;
14446 }
14447
14448 if (D.isArrayDesignator()) {
14449 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
14450 if (Index.isInvalid())
14451 return ExprError();
14452
14453 Desig.AddDesignator(
14454 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
14455
14456 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
14457 ArrayExprs.push_back(Index.get());
14458 continue;
14459 }
14460
14461 assert(D.isArrayRangeDesignator() && "New kind of designator?");
14462 ExprResult Start
14463 = getDerived().TransformExpr(E->getArrayRangeStart(D));
14464 if (Start.isInvalid())
14465 return ExprError();
14466
14467 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
14468 if (End.isInvalid())
14469 return ExprError();
14470
14471 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
14472 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
14473
14474 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
14475 End.get() != E->getArrayRangeEnd(D);
14476
14477 ArrayExprs.push_back(Start.get());
14478 ArrayExprs.push_back(End.get());
14479 }
14480
14481 if (!getDerived().AlwaysRebuild() &&
14482 Init.get() == E->getInit() &&
14483 !ExprChanged)
14484 return E;
14485
14486 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
14487 E->getEqualOrColonLoc(),
14488 E->usesGNUSyntax(), Init.get());
14489}
14490
14491// Seems that if TransformInitListExpr() only works on the syntactic form of an
14492// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
14493template<typename Derived>
14497 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
14498 "initializer");
14499 return ExprError();
14500}
14501
14502template<typename Derived>
14505 NoInitExpr *E) {
14506 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
14507 return ExprError();
14508}
14509
14510template<typename Derived>
14513 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
14514 return ExprError();
14515}
14516
14517template<typename Derived>
14520 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
14521 return ExprError();
14522}
14523
14524template<typename Derived>
14528 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
14529
14530 // FIXME: Will we ever have proper type location here? Will we actually
14531 // need to transform the type?
14532 QualType T = getDerived().TransformType(E->getType());
14533 if (T.isNull())
14534 return ExprError();
14535
14536 if (!getDerived().AlwaysRebuild() &&
14537 T == E->getType())
14538 return E;
14539
14540 return getDerived().RebuildImplicitValueInitExpr(T);
14541}
14542
14543template<typename Derived>
14546 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14547 if (!TInfo)
14548 return ExprError();
14549
14550 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14551 if (SubExpr.isInvalid())
14552 return ExprError();
14553
14554 if (!getDerived().AlwaysRebuild() &&
14555 TInfo == E->getWrittenTypeInfo() &&
14556 SubExpr.get() == E->getSubExpr())
14557 return E;
14558
14559 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14560 TInfo, E->getRParenLoc());
14561}
14562
14563template<typename Derived>
14566 bool ArgumentChanged = false;
14568 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14569 &ArgumentChanged))
14570 return ExprError();
14571
14572 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14573 Inits,
14574 E->getRParenLoc());
14575}
14576
14577/// Transform an address-of-label expression.
14578///
14579/// By default, the transformation of an address-of-label expression always
14580/// rebuilds the expression, so that the label identifier can be resolved to
14581/// the corresponding label statement by semantic analysis.
14582template<typename Derived>
14585 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14586 E->getLabel());
14587 if (!LD)
14588 return ExprError();
14589
14590 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14591 cast<LabelDecl>(LD));
14592}
14593
14594template<typename Derived>
14597 SemaRef.ActOnStartStmtExpr();
14598 StmtResult SubStmt
14599 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14600 if (SubStmt.isInvalid()) {
14601 SemaRef.ActOnStmtExprError();
14602 return ExprError();
14603 }
14604
14605 unsigned OldDepth = E->getTemplateDepth();
14606 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14607
14608 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14609 SubStmt.get() == E->getSubStmt()) {
14610 // Calling this an 'error' is unintuitive, but it does the right thing.
14611 SemaRef.ActOnStmtExprError();
14612 return SemaRef.MaybeBindToTemporary(E);
14613 }
14614
14615 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14616 E->getRParenLoc(), NewDepth);
14617}
14618
14619template<typename Derived>
14622 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14623 if (Cond.isInvalid())
14624 return ExprError();
14625
14626 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14627 if (LHS.isInvalid())
14628 return ExprError();
14629
14630 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14631 if (RHS.isInvalid())
14632 return ExprError();
14633
14634 if (!getDerived().AlwaysRebuild() &&
14635 Cond.get() == E->getCond() &&
14636 LHS.get() == E->getLHS() &&
14637 RHS.get() == E->getRHS())
14638 return E;
14639
14640 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14641 Cond.get(), LHS.get(), RHS.get(),
14642 E->getRParenLoc());
14643}
14644
14645template<typename Derived>
14648 return E;
14649}
14650
14651template<typename Derived>
14654 switch (E->getOperator()) {
14655 case OO_New:
14656 case OO_Delete:
14657 case OO_Array_New:
14658 case OO_Array_Delete:
14659 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14660
14661 case OO_Subscript:
14662 case OO_Call: {
14663 // This is a call to an object's operator().
14664 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14665
14666 // Transform the object itself.
14667 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14668 if (Object.isInvalid())
14669 return ExprError();
14670
14671 // FIXME: Poor location information. Also, if the location for the end of
14672 // the token is within a macro expansion, getLocForEndOfToken() will return
14673 // an invalid source location. If that happens and we have an otherwise
14674 // valid end location, use the valid one instead of the invalid one.
14675 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14676 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14677 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14678 FakeLParenLoc = EndLoc;
14679
14680 // Transform the call arguments.
14682 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14683 Args))
14684 return ExprError();
14685
14686 if (E->getOperator() == OO_Subscript)
14687 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14688 Args, E->getEndLoc());
14689
14690 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14691 E->getEndLoc());
14692 }
14693
14694#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14695 case OO_##Name: \
14696 break;
14697
14698#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14699#include "clang/Basic/OperatorKinds.def"
14700
14701 case OO_Conditional:
14702 llvm_unreachable("conditional operator is not actually overloadable");
14703
14704 case OO_None:
14706 llvm_unreachable("not an overloaded operator?");
14707 }
14708
14710 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14711 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14712 else
14713 First = getDerived().TransformExpr(E->getArg(0));
14714 if (First.isInvalid())
14715 return ExprError();
14716
14717 ExprResult Second;
14718 if (E->getNumArgs() == 2) {
14719 Second =
14720 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14721 if (Second.isInvalid())
14722 return ExprError();
14723 }
14724
14725 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14726 FPOptionsOverride NewOverrides(E->getFPFeatures());
14727 getSema().CurFPFeatures =
14728 NewOverrides.applyOverrides(getSema().getLangOpts());
14729 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14730
14731 Expr *Callee = E->getCallee();
14732 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14733 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14735 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14736 return ExprError();
14737
14738 return getDerived().RebuildCXXOperatorCallExpr(
14739 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14740 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14741 }
14742
14743 UnresolvedSet<1> Functions;
14744 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14745 Callee = ICE->getSubExprAsWritten();
14746 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14747 ValueDecl *VD = cast_or_null<ValueDecl>(
14748 getDerived().TransformDecl(DR->getLocation(), DR));
14749 if (!VD)
14750 return ExprError();
14751
14752 if (!isa<CXXMethodDecl>(VD))
14753 Functions.addDecl(VD);
14754
14755 return getDerived().RebuildCXXOperatorCallExpr(
14756 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14757 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14758}
14759
14760template<typename Derived>
14763 return getDerived().TransformCallExpr(E);
14764}
14765
14766template <typename Derived>
14768 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14769 getSema().CurContext != E->getParentContext();
14770
14771 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14772 return E;
14773
14774 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14775 E->getBeginLoc(), E->getEndLoc(),
14776 getSema().CurContext);
14777}
14778
14779template <typename Derived>
14781 return E;
14782}
14783
14784template<typename Derived>
14787 // Transform the callee.
14788 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14789 if (Callee.isInvalid())
14790 return ExprError();
14791
14792 // Transform exec config.
14793 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14794 if (EC.isInvalid())
14795 return ExprError();
14796
14797 // Transform arguments.
14798 bool ArgChanged = false;
14800 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14801 &ArgChanged))
14802 return ExprError();
14803
14804 if (!getDerived().AlwaysRebuild() &&
14805 Callee.get() == E->getCallee() &&
14806 !ArgChanged)
14807 return SemaRef.MaybeBindToTemporary(E);
14808
14809 // FIXME: Wrong source location information for the '('.
14810 SourceLocation FakeLParenLoc
14811 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14812 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14813 Args,
14814 E->getRParenLoc(), EC.get());
14815}
14816
14817template<typename Derived>
14820 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14821 if (!Type)
14822 return ExprError();
14823
14824 ExprResult SubExpr
14825 = getDerived().TransformExpr(E->getSubExprAsWritten());
14826 if (SubExpr.isInvalid())
14827 return ExprError();
14828
14829 if (!getDerived().AlwaysRebuild() &&
14830 Type == E->getTypeInfoAsWritten() &&
14831 SubExpr.get() == E->getSubExpr())
14832 return E;
14833 return getDerived().RebuildCXXNamedCastExpr(
14836 // FIXME. this should be '(' location
14837 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14838}
14839
14840template<typename Derived>
14843 TypeSourceInfo *TSI =
14844 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14845 if (!TSI)
14846 return ExprError();
14847
14848 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14849 if (Sub.isInvalid())
14850 return ExprError();
14851
14852 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14853 Sub.get(), BCE->getEndLoc());
14854}
14855
14856template<typename Derived>
14858TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14859 return getDerived().TransformCXXNamedCastExpr(E);
14860}
14861
14862template<typename Derived>
14865 return getDerived().TransformCXXNamedCastExpr(E);
14866}
14867
14868template<typename Derived>
14872 return getDerived().TransformCXXNamedCastExpr(E);
14873}
14874
14875template<typename Derived>
14878 return getDerived().TransformCXXNamedCastExpr(E);
14879}
14880
14881template<typename Derived>
14884 return getDerived().TransformCXXNamedCastExpr(E);
14885}
14886
14887template<typename Derived>
14892 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14893 if (!Type)
14894 return ExprError();
14895
14896 ExprResult SubExpr
14897 = getDerived().TransformExpr(E->getSubExprAsWritten());
14898 if (SubExpr.isInvalid())
14899 return ExprError();
14900
14901 if (!getDerived().AlwaysRebuild() &&
14902 Type == E->getTypeInfoAsWritten() &&
14903 SubExpr.get() == E->getSubExpr())
14904 return E;
14905
14906 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14907 E->getLParenLoc(),
14908 SubExpr.get(),
14909 E->getRParenLoc(),
14910 E->isListInitialization());
14911}
14912
14913template<typename Derived>
14916 if (E->isTypeOperand()) {
14917 TypeSourceInfo *TInfo
14918 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14919 if (!TInfo)
14920 return ExprError();
14921
14922 if (!getDerived().AlwaysRebuild() &&
14923 TInfo == E->getTypeOperandSourceInfo())
14924 return E;
14925
14926 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14927 TInfo, E->getEndLoc());
14928 }
14929
14930 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14931 // type. We must not unilaterally enter unevaluated context here, as then
14932 // semantic processing can re-transform an already transformed operand.
14933 Expr *Op = E->getExprOperand();
14935 if (E->isGLValue()) {
14936 QualType OpType = Op->getType();
14937 if (auto *RD = OpType->getAsCXXRecordDecl()) {
14938 if (SemaRef.RequireCompleteType(E->getBeginLoc(), OpType,
14939 diag::err_incomplete_typeid))
14940 return ExprError();
14941
14942 if (RD->isPolymorphic())
14943 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14944 }
14945 }
14946
14949
14950 ExprResult SubExpr = getDerived().TransformExpr(Op);
14951 if (SubExpr.isInvalid())
14952 return ExprError();
14953
14954 if (!getDerived().AlwaysRebuild() &&
14955 SubExpr.get() == E->getExprOperand())
14956 return E;
14957
14958 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14959 SubExpr.get(), E->getEndLoc());
14960}
14961
14962template<typename Derived>
14965 if (E->isTypeOperand()) {
14966 TypeSourceInfo *TInfo
14967 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14968 if (!TInfo)
14969 return ExprError();
14970
14971 if (!getDerived().AlwaysRebuild() &&
14972 TInfo == E->getTypeOperandSourceInfo())
14973 return E;
14974
14975 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14976 TInfo, E->getEndLoc());
14977 }
14978
14981
14982 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14983 if (SubExpr.isInvalid())
14984 return ExprError();
14985
14986 if (!getDerived().AlwaysRebuild() &&
14987 SubExpr.get() == E->getExprOperand())
14988 return E;
14989
14990 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14991 SubExpr.get(), E->getEndLoc());
14992}
14993
14994template<typename Derived>
14997 return E;
14998}
14999
15000template<typename Derived>
15004 return E;
15005}
15006
15007template<typename Derived>
15010
15011 // In lambdas, the qualifiers of the type depends of where in
15012 // the call operator `this` appear, and we do not have a good way to
15013 // rebuild this information, so we transform the type.
15014 //
15015 // In other contexts, the type of `this` may be overrided
15016 // for type deduction, so we need to recompute it.
15017 //
15018 // Always recompute the type if we're in the body of a lambda, and
15019 // 'this' is dependent on a lambda's explicit object parameter; we
15020 // also need to always rebuild the expression in this case to clear
15021 // the flag.
15022 QualType T = [&]() {
15023 auto &S = getSema();
15024 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
15025 return S.getCurrentThisType();
15026 if (S.getCurLambda())
15027 return getDerived().TransformType(E->getType());
15028 return S.getCurrentThisType();
15029 }();
15030
15031 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
15032 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
15033 // Mark it referenced in the new context regardless.
15034 // FIXME: this is a bit instantiation-specific.
15035 getSema().MarkThisReferenced(E);
15036 return E;
15037 }
15038
15039 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
15040}
15041
15042template<typename Derived>
15045 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
15046 if (SubExpr.isInvalid())
15047 return ExprError();
15048
15049 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
15050
15051 if (!getDerived().AlwaysRebuild() &&
15052 SubExpr.get() == E->getSubExpr())
15053 return E;
15054
15055 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
15056 E->isThrownVariableInScope());
15057}
15058
15059template<typename Derived>
15062 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
15063 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
15064 if (!Param)
15065 return ExprError();
15066
15067 ExprResult InitRes;
15068 if (E->hasRewrittenInit()) {
15069 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15070 if (InitRes.isInvalid())
15071 return ExprError();
15072 }
15073
15074 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
15075 E->getUsedContext() == SemaRef.CurContext &&
15076 InitRes.get() == E->getRewrittenExpr())
15077 return E;
15078
15079 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
15080 InitRes.get());
15081}
15082
15083template<typename Derived>
15086 FieldDecl *Field = cast_or_null<FieldDecl>(
15087 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
15088 if (!Field)
15089 return ExprError();
15090
15091 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
15092 E->getUsedContext() == SemaRef.CurContext)
15093 return E;
15094
15095 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
15096}
15097
15098template<typename Derived>
15102 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
15103 if (!T)
15104 return ExprError();
15105
15106 if (!getDerived().AlwaysRebuild() &&
15107 T == E->getTypeSourceInfo())
15108 return E;
15109
15110 return getDerived().RebuildCXXScalarValueInitExpr(T,
15111 /*FIXME:*/T->getTypeLoc().getEndLoc(),
15112 E->getRParenLoc());
15113}
15114
15115template<typename Derived>
15118 // Transform the type that we're allocating
15119 TypeSourceInfo *AllocTypeInfo =
15120 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
15121 if (!AllocTypeInfo)
15122 return ExprError();
15123
15124 // Transform the size of the array we're allocating (if any).
15125 std::optional<Expr *> ArraySize;
15126 if (E->isArray()) {
15127 ExprResult NewArraySize;
15128 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
15129 NewArraySize = getDerived().TransformExpr(*OldArraySize);
15130 if (NewArraySize.isInvalid())
15131 return ExprError();
15132 }
15133 ArraySize = NewArraySize.get();
15134 }
15135
15136 // Transform the placement arguments (if any).
15137 bool ArgumentChanged = false;
15138 SmallVector<Expr*, 8> PlacementArgs;
15139 if (getDerived().TransformExprs(E->getPlacementArgs(),
15140 E->getNumPlacementArgs(), true,
15141 PlacementArgs, &ArgumentChanged))
15142 return ExprError();
15143
15144 // Transform the initializer (if any).
15145 Expr *OldInit = E->getInitializer();
15146 ExprResult NewInit;
15147 if (OldInit)
15148 NewInit = getDerived().TransformInitializer(OldInit, true);
15149 if (NewInit.isInvalid())
15150 return ExprError();
15151
15152 // Transform new operator and delete operator.
15153 FunctionDecl *OperatorNew = nullptr;
15154 if (E->getOperatorNew()) {
15155 OperatorNew = cast_or_null<FunctionDecl>(
15156 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
15157 if (!OperatorNew)
15158 return ExprError();
15159 }
15160
15161 FunctionDecl *OperatorDelete = nullptr;
15162 if (E->getOperatorDelete()) {
15163 OperatorDelete = cast_or_null<FunctionDecl>(
15164 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15165 if (!OperatorDelete)
15166 return ExprError();
15167 }
15168
15169 if (!getDerived().AlwaysRebuild() &&
15170 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
15171 ArraySize == E->getArraySize() &&
15172 NewInit.get() == OldInit &&
15173 OperatorNew == E->getOperatorNew() &&
15174 OperatorDelete == E->getOperatorDelete() &&
15175 !ArgumentChanged) {
15176 // Mark any declarations we need as referenced.
15177 // FIXME: instantiation-specific.
15178 if (OperatorNew)
15179 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
15180 if (OperatorDelete)
15181 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15182
15183 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
15184 QualType ElementType
15185 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
15186 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
15188 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
15189 }
15190 }
15191
15192 return E;
15193 }
15194
15195 QualType AllocType = AllocTypeInfo->getType();
15196 if (!ArraySize) {
15197 // If no array size was specified, but the new expression was
15198 // instantiated with an array type (e.g., "new T" where T is
15199 // instantiated with "int[4]"), extract the outer bound from the
15200 // array type as our array size. We do this with constant and
15201 // dependently-sized array types.
15202 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
15203 if (!ArrayT) {
15204 // Do nothing
15205 } else if (const ConstantArrayType *ConsArrayT
15206 = dyn_cast<ConstantArrayType>(ArrayT)) {
15207 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
15208 SemaRef.Context.getSizeType(),
15209 /*FIXME:*/ E->getBeginLoc());
15210 AllocType = ConsArrayT->getElementType();
15211 } else if (const DependentSizedArrayType *DepArrayT
15212 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
15213 if (DepArrayT->getSizeExpr()) {
15214 ArraySize = DepArrayT->getSizeExpr();
15215 AllocType = DepArrayT->getElementType();
15216 }
15217 }
15218 }
15219
15220 return getDerived().RebuildCXXNewExpr(
15221 E->getBeginLoc(), E->isGlobalNew(),
15222 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
15223 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
15224 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
15225}
15226
15227template<typename Derived>
15230 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
15231 if (Operand.isInvalid())
15232 return ExprError();
15233
15234 // Transform the delete operator, if known.
15235 FunctionDecl *OperatorDelete = nullptr;
15236 if (E->getOperatorDelete()) {
15237 OperatorDelete = cast_or_null<FunctionDecl>(
15238 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15239 if (!OperatorDelete)
15240 return ExprError();
15241 }
15242
15243 if (!getDerived().AlwaysRebuild() &&
15244 Operand.get() == E->getArgument() &&
15245 OperatorDelete == E->getOperatorDelete()) {
15246 // Mark any declarations we need as referenced.
15247 // FIXME: instantiation-specific.
15248 if (OperatorDelete)
15249 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15250
15251 if (!E->getArgument()->isTypeDependent()) {
15253 E->getDestroyedType());
15254 if (auto *Record = Destroyed->getAsCXXRecordDecl())
15255 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15256 SemaRef.LookupDestructor(Record));
15257 }
15258
15259 return E;
15260 }
15261
15262 return getDerived().RebuildCXXDeleteExpr(
15263 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
15264}
15265
15266template<typename Derived>
15270 ExprResult Base = getDerived().TransformExpr(E->getBase());
15271 if (Base.isInvalid())
15272 return ExprError();
15273
15274 ParsedType ObjectTypePtr;
15275 bool MayBePseudoDestructor = false;
15276 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15277 E->getOperatorLoc(),
15278 E->isArrow()? tok::arrow : tok::period,
15279 ObjectTypePtr,
15280 MayBePseudoDestructor);
15281 if (Base.isInvalid())
15282 return ExprError();
15283
15284 QualType ObjectType = ObjectTypePtr.get();
15285 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
15286 if (QualifierLoc) {
15287 QualifierLoc
15288 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
15289 if (!QualifierLoc)
15290 return ExprError();
15291 }
15292 CXXScopeSpec SS;
15293 SS.Adopt(QualifierLoc);
15294
15296 if (E->getDestroyedTypeInfo()) {
15297 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
15298 E->getDestroyedTypeInfo(), ObjectType,
15299 /*FirstQualifierInScope=*/nullptr);
15300 if (!DestroyedTypeInfo)
15301 return ExprError();
15302 Destroyed = DestroyedTypeInfo;
15303 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
15304 // We aren't likely to be able to resolve the identifier down to a type
15305 // now anyway, so just retain the identifier.
15306 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
15307 E->getDestroyedTypeLoc());
15308 } else {
15309 // Look for a destructor known with the given name.
15310 ParsedType T = SemaRef.getDestructorName(
15311 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
15312 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
15313 if (!T)
15314 return ExprError();
15315
15316 Destroyed
15318 E->getDestroyedTypeLoc());
15319 }
15320
15321 TypeSourceInfo *ScopeTypeInfo = nullptr;
15322 if (E->getScopeTypeInfo()) {
15323 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
15324 E->getScopeTypeInfo(), ObjectType, nullptr);
15325 if (!ScopeTypeInfo)
15326 return ExprError();
15327 }
15328
15329 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
15330 E->getOperatorLoc(),
15331 E->isArrow(),
15332 SS,
15333 ScopeTypeInfo,
15334 E->getColonColonLoc(),
15335 E->getTildeLoc(),
15336 Destroyed);
15337}
15338
15339template <typename Derived>
15341 bool RequiresADL,
15342 LookupResult &R) {
15343 // Transform all the decls.
15344 bool AllEmptyPacks = true;
15345 for (auto *OldD : Old->decls()) {
15346 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
15347 if (!InstD) {
15348 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
15349 // This can happen because of dependent hiding.
15350 if (isa<UsingShadowDecl>(OldD))
15351 continue;
15352 else {
15353 R.clear();
15354 return true;
15355 }
15356 }
15357
15358 // Expand using pack declarations.
15359 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
15360 ArrayRef<NamedDecl*> Decls = SingleDecl;
15361 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
15362 Decls = UPD->expansions();
15363
15364 // Expand using declarations.
15365 for (auto *D : Decls) {
15366 if (auto *UD = dyn_cast<UsingDecl>(D)) {
15367 for (auto *SD : UD->shadows())
15368 R.addDecl(SD);
15369 } else {
15370 R.addDecl(D);
15371 }
15372 }
15373
15374 AllEmptyPacks &= Decls.empty();
15375 }
15376
15377 // C++ [temp.res]/8.4.2:
15378 // The program is ill-formed, no diagnostic required, if [...] lookup for
15379 // a name in the template definition found a using-declaration, but the
15380 // lookup in the corresponding scope in the instantiation odoes not find
15381 // any declarations because the using-declaration was a pack expansion and
15382 // the corresponding pack is empty
15383 if (AllEmptyPacks && !RequiresADL) {
15384 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
15385 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
15386 return true;
15387 }
15388
15389 // Resolve a kind, but don't do any further analysis. If it's
15390 // ambiguous, the callee needs to deal with it.
15391 R.resolveKind();
15392
15393 if (Old->hasTemplateKeyword() && !R.empty()) {
15394 NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
15395 getSema().FilterAcceptableTemplateNames(R,
15396 /*AllowFunctionTemplates=*/true,
15397 /*AllowDependent=*/true);
15398 if (R.empty()) {
15399 // If a 'template' keyword was used, a lookup that finds only non-template
15400 // names is an error.
15401 getSema().Diag(R.getNameLoc(),
15402 diag::err_template_kw_refers_to_non_template)
15403 << R.getLookupName() << Old->getQualifierLoc().getSourceRange()
15404 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
15405 getSema().Diag(FoundDecl->getLocation(),
15406 diag::note_template_kw_refers_to_non_template)
15407 << R.getLookupName();
15408 return true;
15409 }
15410 }
15411
15412 return false;
15413}
15414
15415template <typename Derived>
15420
15421template <typename Derived>
15424 bool IsAddressOfOperand) {
15425 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
15427
15428 // Transform the declaration set.
15429 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
15430 return ExprError();
15431
15432 // Rebuild the nested-name qualifier, if present.
15433 CXXScopeSpec SS;
15434 if (Old->getQualifierLoc()) {
15435 NestedNameSpecifierLoc QualifierLoc
15436 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15437 if (!QualifierLoc)
15438 return ExprError();
15439
15440 SS.Adopt(QualifierLoc);
15441 }
15442
15443 if (Old->getNamingClass()) {
15444 CXXRecordDecl *NamingClass
15445 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
15446 Old->getNameLoc(),
15447 Old->getNamingClass()));
15448 if (!NamingClass) {
15449 R.clear();
15450 return ExprError();
15451 }
15452
15453 R.setNamingClass(NamingClass);
15454 }
15455
15456 // Rebuild the template arguments, if any.
15457 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15458 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
15459 if (Old->hasExplicitTemplateArgs() &&
15460 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15461 Old->getNumTemplateArgs(),
15462 TransArgs)) {
15463 R.clear();
15464 return ExprError();
15465 }
15466
15467 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
15468 // a non-static data member is named in an unevaluated operand, or when
15469 // a member is named in a dependent class scope function template explicit
15470 // specialization that is neither declared static nor with an explicit object
15471 // parameter.
15472 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
15473 return SemaRef.BuildPossibleImplicitMemberExpr(
15474 SS, TemplateKWLoc, R,
15475 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
15476 /*S=*/nullptr);
15477
15478 // If we have neither explicit template arguments, nor the template keyword,
15479 // it's a normal declaration name or member reference.
15480 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
15481 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
15482
15483 // If we have template arguments, then rebuild the template-id expression.
15484 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
15485 Old->requiresADL(), &TransArgs);
15486}
15487
15488template<typename Derived>
15491 bool ArgChanged = false;
15493 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
15494 TypeSourceInfo *From = E->getArg(I);
15495 TypeLoc FromTL = From->getTypeLoc();
15496 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
15497 TypeLocBuilder TLB;
15498 TLB.reserve(FromTL.getFullDataSize());
15499 QualType To = getDerived().TransformType(TLB, FromTL);
15500 if (To.isNull())
15501 return ExprError();
15502
15503 if (To == From->getType())
15504 Args.push_back(From);
15505 else {
15506 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15507 ArgChanged = true;
15508 }
15509 continue;
15510 }
15511
15512 ArgChanged = true;
15513
15514 // We have a pack expansion. Instantiate it.
15515 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
15516 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
15518 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
15519
15520 // Determine whether the set of unexpanded parameter packs can and should
15521 // be expanded.
15522 bool Expand = true;
15523 bool RetainExpansion = false;
15524 UnsignedOrNone OrigNumExpansions =
15525 ExpansionTL.getTypePtr()->getNumExpansions();
15526 UnsignedOrNone NumExpansions = OrigNumExpansions;
15527 if (getDerived().TryExpandParameterPacks(
15528 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
15529 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15530 RetainExpansion, NumExpansions))
15531 return ExprError();
15532
15533 if (!Expand) {
15534 // The transform has determined that we should perform a simple
15535 // transformation on the pack expansion, producing another pack
15536 // expansion.
15537 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
15538
15539 TypeLocBuilder TLB;
15540 TLB.reserve(From->getTypeLoc().getFullDataSize());
15541
15542 QualType To = getDerived().TransformType(TLB, PatternTL);
15543 if (To.isNull())
15544 return ExprError();
15545
15546 To = getDerived().RebuildPackExpansionType(To,
15547 PatternTL.getSourceRange(),
15548 ExpansionTL.getEllipsisLoc(),
15549 NumExpansions);
15550 if (To.isNull())
15551 return ExprError();
15552
15553 PackExpansionTypeLoc ToExpansionTL
15554 = TLB.push<PackExpansionTypeLoc>(To);
15555 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15556 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15557 continue;
15558 }
15559
15560 // Expand the pack expansion by substituting for each argument in the
15561 // pack(s).
15562 for (unsigned I = 0; I != *NumExpansions; ++I) {
15563 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15564 TypeLocBuilder TLB;
15565 TLB.reserve(PatternTL.getFullDataSize());
15566 QualType To = getDerived().TransformType(TLB, PatternTL);
15567 if (To.isNull())
15568 return ExprError();
15569
15570 if (To->containsUnexpandedParameterPack()) {
15571 To = getDerived().RebuildPackExpansionType(To,
15572 PatternTL.getSourceRange(),
15573 ExpansionTL.getEllipsisLoc(),
15574 NumExpansions);
15575 if (To.isNull())
15576 return ExprError();
15577
15578 PackExpansionTypeLoc ToExpansionTL
15579 = TLB.push<PackExpansionTypeLoc>(To);
15580 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15581 }
15582
15583 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15584 }
15585
15586 if (!RetainExpansion)
15587 continue;
15588
15589 // If we're supposed to retain a pack expansion, do so by temporarily
15590 // forgetting the partially-substituted parameter pack.
15591 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15592
15593 TypeLocBuilder TLB;
15594 TLB.reserve(From->getTypeLoc().getFullDataSize());
15595
15596 QualType To = getDerived().TransformType(TLB, PatternTL);
15597 if (To.isNull())
15598 return ExprError();
15599
15600 To = getDerived().RebuildPackExpansionType(To,
15601 PatternTL.getSourceRange(),
15602 ExpansionTL.getEllipsisLoc(),
15603 NumExpansions);
15604 if (To.isNull())
15605 return ExprError();
15606
15607 PackExpansionTypeLoc ToExpansionTL
15608 = TLB.push<PackExpansionTypeLoc>(To);
15609 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15610 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15611 }
15612
15613 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15614 return E;
15615
15616 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15617 E->getEndLoc());
15618}
15619
15620template<typename Derived>
15624 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15625 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15626 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15627 Old->NumTemplateArgs, TransArgs))
15628 return ExprError();
15629
15630 return getDerived().RebuildConceptSpecializationExpr(
15631 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15632 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15633 &TransArgs);
15634}
15635
15636template<typename Derived>
15639 SmallVector<ParmVarDecl*, 4> TransParams;
15640 SmallVector<QualType, 4> TransParamTypes;
15641 Sema::ExtParameterInfoBuilder ExtParamInfos;
15642
15643 // C++2a [expr.prim.req]p2
15644 // Expressions appearing within a requirement-body are unevaluated operands.
15648
15650 getSema().Context, getSema().CurContext,
15651 E->getBody()->getBeginLoc());
15652
15653 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15654
15655 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15656 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15657 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15658
15659 for (ParmVarDecl *Param : TransParams)
15660 if (Param)
15661 Param->setDeclContext(Body);
15662
15663 // On failure to transform, TransformRequiresTypeParams returns an expression
15664 // in the event that the transformation of the type params failed in some way.
15665 // It is expected that this will result in a 'not satisfied' Requires clause
15666 // when instantiating.
15667 if (!TypeParamResult.isUnset())
15668 return TypeParamResult;
15669
15671 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15672 TransReqs))
15673 return ExprError();
15674
15675 for (concepts::Requirement *Req : TransReqs) {
15676 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15677 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15678 ER->getReturnTypeRequirement()
15679 .getTypeConstraintTemplateParameterList()->getParam(0)
15680 ->setDeclContext(Body);
15681 }
15682 }
15683 }
15684
15685 return getDerived().RebuildRequiresExpr(
15686 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15687 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15688}
15689
15690template<typename Derived>
15694 for (concepts::Requirement *Req : Reqs) {
15695 concepts::Requirement *TransReq = nullptr;
15696 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15697 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15698 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15699 TransReq = getDerived().TransformExprRequirement(ExprReq);
15700 else
15701 TransReq = getDerived().TransformNestedRequirement(
15703 if (!TransReq)
15704 return true;
15705 Transformed.push_back(TransReq);
15706 }
15707 return false;
15708}
15709
15710template<typename Derived>
15714 if (Req->isSubstitutionFailure()) {
15715 if (getDerived().AlwaysRebuild())
15716 return getDerived().RebuildTypeRequirement(
15718 return Req;
15719 }
15720 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15721 if (!TransType)
15722 return nullptr;
15723 return getDerived().RebuildTypeRequirement(TransType);
15724}
15725
15726template<typename Derived>
15729 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15730 if (Req->isExprSubstitutionFailure())
15731 TransExpr = Req->getExprSubstitutionDiagnostic();
15732 else {
15733 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15734 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15735 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15736 if (TransExprRes.isInvalid())
15737 return nullptr;
15738 TransExpr = TransExprRes.get();
15739 }
15740
15741 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15742 const auto &RetReq = Req->getReturnTypeRequirement();
15743 if (RetReq.isEmpty())
15744 TransRetReq.emplace();
15745 else if (RetReq.isSubstitutionFailure())
15746 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15747 else if (RetReq.isTypeConstraint()) {
15748 TemplateParameterList *OrigTPL =
15749 RetReq.getTypeConstraintTemplateParameterList();
15751 getDerived().TransformTemplateParameterList(OrigTPL);
15752 if (!TPL)
15753 return nullptr;
15754 TransRetReq.emplace(TPL);
15755 }
15756 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15757 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15758 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15759 Req->getNoexceptLoc(),
15760 std::move(*TransRetReq));
15761 return getDerived().RebuildExprRequirement(
15763 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15764}
15765
15766template<typename Derived>
15770 if (Req->hasInvalidConstraint()) {
15771 if (getDerived().AlwaysRebuild())
15772 return getDerived().RebuildNestedRequirement(
15774 return Req;
15775 }
15776 ExprResult TransConstraint =
15777 getDerived().TransformExpr(Req->getConstraintExpr());
15778 if (TransConstraint.isInvalid())
15779 return nullptr;
15780 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15781}
15782
15783template<typename Derived>
15786 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15787 if (!T)
15788 return ExprError();
15789
15790 if (!getDerived().AlwaysRebuild() &&
15792 return E;
15793
15794 ExprResult SubExpr;
15795 {
15798 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15799 if (SubExpr.isInvalid())
15800 return ExprError();
15801 }
15802
15803 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15804 SubExpr.get(), E->getEndLoc());
15805}
15806
15807template<typename Derived>
15810 ExprResult SubExpr;
15811 {
15814 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15815 if (SubExpr.isInvalid())
15816 return ExprError();
15817
15818 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15819 return E;
15820 }
15821
15822 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15823 SubExpr.get(), E->getEndLoc());
15824}
15825
15826template <typename Derived>
15828 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15829 TypeSourceInfo **RecoveryTSI) {
15830 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15831 DRE, AddrTaken, RecoveryTSI);
15832
15833 // Propagate both errors and recovered types, which return ExprEmpty.
15834 if (!NewDRE.isUsable())
15835 return NewDRE;
15836
15837 // We got an expr, wrap it up in parens.
15838 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15839 return PE;
15840 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15841 PE->getRParen());
15842}
15843
15844template <typename Derived>
15850
15851template <typename Derived>
15853 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15854 TypeSourceInfo **RecoveryTSI) {
15855 assert(E->getQualifierLoc());
15856 NestedNameSpecifierLoc QualifierLoc =
15857 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15858 if (!QualifierLoc)
15859 return ExprError();
15860 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15861
15862 // TODO: If this is a conversion-function-id, verify that the
15863 // destination type name (if present) resolves the same way after
15864 // instantiation as it did in the local scope.
15865
15866 DeclarationNameInfo NameInfo =
15867 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15868 if (!NameInfo.getName())
15869 return ExprError();
15870
15871 if (!E->hasExplicitTemplateArgs()) {
15872 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15873 // Note: it is sufficient to compare the Name component of NameInfo:
15874 // if name has not changed, DNLoc has not changed either.
15875 NameInfo.getName() == E->getDeclName())
15876 return E;
15877
15878 return getDerived().RebuildDependentScopeDeclRefExpr(
15879 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15880 IsAddressOfOperand, RecoveryTSI);
15881 }
15882
15883 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15884 if (getDerived().TransformTemplateArguments(
15885 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15886 return ExprError();
15887
15888 return getDerived().RebuildDependentScopeDeclRefExpr(
15889 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15890 RecoveryTSI);
15891}
15892
15893template<typename Derived>
15896 // CXXConstructExprs other than for list-initialization and
15897 // CXXTemporaryObjectExpr are always implicit, so when we have
15898 // a 1-argument construction we just transform that argument.
15899 if (getDerived().AllowSkippingCXXConstructExpr() &&
15900 ((E->getNumArgs() == 1 ||
15901 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15902 (!getDerived().DropCallArgument(E->getArg(0))) &&
15903 !E->isListInitialization()))
15904 return getDerived().TransformInitializer(E->getArg(0),
15905 /*DirectInit*/ false);
15906
15907 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15908
15909 QualType T = getDerived().TransformType(E->getType());
15910 if (T.isNull())
15911 return ExprError();
15912
15913 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15914 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15915 if (!Constructor)
15916 return ExprError();
15917
15918 bool ArgumentChanged = false;
15920 {
15923 E->isListInitialization());
15924 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15925 &ArgumentChanged))
15926 return ExprError();
15927 }
15928
15929 if (!getDerived().AlwaysRebuild() &&
15930 T == E->getType() &&
15931 Constructor == E->getConstructor() &&
15932 !ArgumentChanged) {
15933 // Mark the constructor as referenced.
15934 // FIXME: Instantiation-specific
15935 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15936 return E;
15937 }
15938
15939 return getDerived().RebuildCXXConstructExpr(
15940 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15941 E->hadMultipleCandidates(), E->isListInitialization(),
15942 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15943 E->getConstructionKind(), E->getParenOrBraceRange());
15944}
15945
15946template<typename Derived>
15949 QualType T = getDerived().TransformType(E->getType());
15950 if (T.isNull())
15951 return ExprError();
15952
15953 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15954 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15955 if (!Constructor)
15956 return ExprError();
15957
15958 if (!getDerived().AlwaysRebuild() &&
15959 T == E->getType() &&
15960 Constructor == E->getConstructor()) {
15961 // Mark the constructor as referenced.
15962 // FIXME: Instantiation-specific
15963 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15964 return E;
15965 }
15966
15967 return getDerived().RebuildCXXInheritedCtorInitExpr(
15968 T, E->getLocation(), Constructor,
15969 E->constructsVBase(), E->inheritedFromVBase());
15970}
15971
15972/// Transform a C++ temporary-binding expression.
15973///
15974/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15975/// transform the subexpression and return that.
15976template<typename Derived>
15979 if (auto *Dtor = E->getTemporary()->getDestructor())
15980 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15981 const_cast<CXXDestructorDecl *>(Dtor));
15982 return getDerived().TransformExpr(E->getSubExpr());
15983}
15984
15985/// Transform a C++ expression that contains cleanups that should
15986/// be run after the expression is evaluated.
15987///
15988/// Since ExprWithCleanups nodes are implicitly generated, we
15989/// just transform the subexpression and return that.
15990template<typename Derived>
15993 return getDerived().TransformExpr(E->getSubExpr());
15994}
15995
15996template<typename Derived>
16000 TypeSourceInfo *T =
16001 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16002 if (!T)
16003 return ExprError();
16004
16005 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16006 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16007 if (!Constructor)
16008 return ExprError();
16009
16010 bool ArgumentChanged = false;
16012 Args.reserve(E->getNumArgs());
16013 {
16016 E->isListInitialization());
16017 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16018 &ArgumentChanged))
16019 return ExprError();
16020
16021 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
16022 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc(),
16023 /*IsExplicit=*/true);
16024 if (Res.isInvalid())
16025 return ExprError();
16026 Args = {Res.get()};
16027 }
16028 }
16029
16030 if (!getDerived().AlwaysRebuild() &&
16031 T == E->getTypeSourceInfo() &&
16032 Constructor == E->getConstructor() &&
16033 !ArgumentChanged) {
16034 // FIXME: Instantiation-specific
16035 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16036 return SemaRef.MaybeBindToTemporary(E);
16037 }
16038
16039 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
16040 return getDerived().RebuildCXXTemporaryObjectExpr(
16041 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
16042}
16043
16044template<typename Derived>
16047 // Transform any init-capture expressions before entering the scope of the
16048 // lambda body, because they are not semantically within that scope.
16049 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
16050 struct TransformedInitCapture {
16051 // The location of the ... if the result is retaining a pack expansion.
16052 SourceLocation EllipsisLoc;
16053 // Zero or more expansions of the init-capture.
16054 SmallVector<InitCaptureInfoTy, 4> Expansions;
16055 };
16057 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
16058 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16059 CEnd = E->capture_end();
16060 C != CEnd; ++C) {
16061 if (!E->isInitCapture(C))
16062 continue;
16063
16064 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
16065 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16066
16067 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
16068 UnsignedOrNone NumExpansions) {
16069 ExprResult NewExprInitResult = getDerived().TransformInitializer(
16070 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
16071
16072 if (NewExprInitResult.isInvalid()) {
16073 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
16074 return;
16075 }
16076 Expr *NewExprInit = NewExprInitResult.get();
16077
16078 QualType NewInitCaptureType =
16079 getSema().buildLambdaInitCaptureInitialization(
16080 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
16081 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
16082 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
16084 NewExprInit);
16085 Result.Expansions.push_back(
16086 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
16087 };
16088
16089 // If this is an init-capture pack, consider expanding the pack now.
16090 if (OldVD->isParameterPack()) {
16091 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
16092 ->getTypeLoc()
16095 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
16096
16097 // Determine whether the set of unexpanded parameter packs can and should
16098 // be expanded.
16099 bool Expand = true;
16100 bool RetainExpansion = false;
16101 UnsignedOrNone OrigNumExpansions =
16102 ExpansionTL.getTypePtr()->getNumExpansions();
16103 UnsignedOrNone NumExpansions = OrigNumExpansions;
16104 if (getDerived().TryExpandParameterPacks(
16105 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
16106 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
16107 RetainExpansion, NumExpansions))
16108 return ExprError();
16109 assert(!RetainExpansion && "Should not need to retain expansion after a "
16110 "capture since it cannot be extended");
16111 if (Expand) {
16112 for (unsigned I = 0; I != *NumExpansions; ++I) {
16113 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16114 SubstInitCapture(SourceLocation(), std::nullopt);
16115 }
16116 } else {
16117 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
16118 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
16119 }
16120 } else {
16121 SubstInitCapture(SourceLocation(), std::nullopt);
16122 }
16123 }
16124
16125 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
16126 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
16127
16128 // Create the local class that will describe the lambda.
16129
16130 // FIXME: DependencyKind below is wrong when substituting inside a templated
16131 // context that isn't a DeclContext (such as a variable template), or when
16132 // substituting an unevaluated lambda inside of a function's parameter's type
16133 // - as parameter types are not instantiated from within a function's DC. We
16134 // use evaluation contexts to distinguish the function parameter case.
16137 DeclContext *DC = getSema().CurContext;
16138 // A RequiresExprBodyDecl is not interesting for dependencies.
16139 // For the following case,
16140 //
16141 // template <typename>
16142 // concept C = requires { [] {}; };
16143 //
16144 // template <class F>
16145 // struct Widget;
16146 //
16147 // template <C F>
16148 // struct Widget<F> {};
16149 //
16150 // While we are substituting Widget<F>, the parent of DC would be
16151 // the template specialization itself. Thus, the lambda expression
16152 // will be deemed as dependent even if there are no dependent template
16153 // arguments.
16154 // (A ClassTemplateSpecializationDecl is always a dependent context.)
16155 while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
16156 DC = DC->getParent();
16157 if ((getSema().isUnevaluatedContext() ||
16158 getSema().isConstantEvaluatedContext()) &&
16159 !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
16160 cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
16161 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
16162 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
16163
16164 CXXRecordDecl *OldClass = E->getLambdaClass();
16165 CXXRecordDecl *Class = getSema().createLambdaClosureType(
16166 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
16167 E->getCaptureDefault());
16168 getDerived().transformedLocalDecl(OldClass, {Class});
16169
16170 CXXMethodDecl *NewCallOperator =
16171 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
16172
16173 // Enter the scope of the lambda.
16174 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
16175 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
16176 E->hasExplicitParameters(), E->isMutable());
16177
16178 // Introduce the context of the call operator.
16179 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
16180 /*NewThisContext*/false);
16181
16182 bool Invalid = false;
16183
16184 // Transform captures.
16185 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16186 CEnd = E->capture_end();
16187 C != CEnd; ++C) {
16188 // When we hit the first implicit capture, tell Sema that we've finished
16189 // the list of explicit captures.
16190 if (C->isImplicit())
16191 break;
16192
16193 // Capturing 'this' is trivial.
16194 if (C->capturesThis()) {
16195 // If this is a lambda that is part of a default member initialiser
16196 // and which we're instantiating outside the class that 'this' is
16197 // supposed to refer to, adjust the type of 'this' accordingly.
16198 //
16199 // Otherwise, leave the type of 'this' as-is.
16200 Sema::CXXThisScopeRAII ThisScope(
16201 getSema(),
16202 dyn_cast_if_present<CXXRecordDecl>(
16203 getSema().getFunctionLevelDeclContext()),
16204 Qualifiers());
16205 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16206 /*BuildAndDiagnose*/ true, nullptr,
16207 C->getCaptureKind() == LCK_StarThis);
16208 continue;
16209 }
16210 // Captured expression will be recaptured during captured variables
16211 // rebuilding.
16212 if (C->capturesVLAType())
16213 continue;
16214
16215 // Rebuild init-captures, including the implied field declaration.
16216 if (E->isInitCapture(C)) {
16217 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
16218
16219 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16221
16222 for (InitCaptureInfoTy &Info : NewC.Expansions) {
16223 ExprResult Init = Info.first;
16224 QualType InitQualType = Info.second;
16225 if (Init.isInvalid() || InitQualType.isNull()) {
16226 Invalid = true;
16227 break;
16228 }
16229 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
16230 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
16231 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
16232 getSema().CurContext);
16233 if (!NewVD) {
16234 Invalid = true;
16235 break;
16236 }
16237 NewVDs.push_back(NewVD);
16238 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
16239 // Cases we want to tackle:
16240 // ([C(Pack)] {}, ...)
16241 // But rule out cases e.g.
16242 // [...C = Pack()] {}
16243 if (NewC.EllipsisLoc.isInvalid())
16244 LSI->ContainsUnexpandedParameterPack |=
16245 Init.get()->containsUnexpandedParameterPack();
16246 }
16247
16248 if (Invalid)
16249 break;
16250
16251 getDerived().transformedLocalDecl(OldVD, NewVDs);
16252 continue;
16253 }
16254
16255 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16256
16257 // Determine the capture kind for Sema.
16259 : C->getCaptureKind() == LCK_ByCopy
16262 SourceLocation EllipsisLoc;
16263 if (C->isPackExpansion()) {
16264 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
16265 bool ShouldExpand = false;
16266 bool RetainExpansion = false;
16267 UnsignedOrNone NumExpansions = std::nullopt;
16268 if (getDerived().TryExpandParameterPacks(
16269 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
16270 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16271 RetainExpansion, NumExpansions)) {
16272 Invalid = true;
16273 continue;
16274 }
16275
16276 if (ShouldExpand) {
16277 // The transform has determined that we should perform an expansion;
16278 // transform and capture each of the arguments.
16279 // expansion of the pattern. Do so.
16280 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
16281 for (unsigned I = 0; I != *NumExpansions; ++I) {
16282 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16283 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
16284 getDerived().TransformDecl(C->getLocation(), Pack));
16285 if (!CapturedVar) {
16286 Invalid = true;
16287 continue;
16288 }
16289
16290 // Capture the transformed variable.
16291 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
16292 }
16293
16294 // FIXME: Retain a pack expansion if RetainExpansion is true.
16295
16296 continue;
16297 }
16298
16299 EllipsisLoc = C->getEllipsisLoc();
16300 }
16301
16302 // Transform the captured variable.
16303 auto *CapturedVar = cast_or_null<ValueDecl>(
16304 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16305 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
16306 Invalid = true;
16307 continue;
16308 }
16309
16310 // This is not an init-capture; however it contains an unexpanded pack e.g.
16311 // ([Pack] {}(), ...)
16312 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
16313 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
16314
16315 // Capture the transformed variable.
16316 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
16317 EllipsisLoc);
16318 }
16319 getSema().finishLambdaExplicitCaptures(LSI);
16320
16321 // Transform the template parameters, and add them to the current
16322 // instantiation scope. The null case is handled correctly.
16323 auto TPL = getDerived().TransformTemplateParameterList(
16324 E->getTemplateParameterList());
16325 LSI->GLTemplateParameterList = TPL;
16326 if (TPL) {
16327 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
16328 TPL);
16329 LSI->ContainsUnexpandedParameterPack |=
16330 TPL->containsUnexpandedParameterPack();
16331 }
16332
16333 TypeLocBuilder NewCallOpTLBuilder;
16334 TypeLoc OldCallOpTypeLoc =
16335 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
16336 QualType NewCallOpType =
16337 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
16338 if (NewCallOpType.isNull())
16339 return ExprError();
16340 LSI->ContainsUnexpandedParameterPack |=
16341 NewCallOpType->containsUnexpandedParameterPack();
16342 TypeSourceInfo *NewCallOpTSI =
16343 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
16344
16345 // The type may be an AttributedType or some other kind of sugar;
16346 // get the actual underlying FunctionProtoType.
16347 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
16348 assert(FPTL && "Not a FunctionProtoType?");
16349
16350 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
16351 if (TRC) {
16352 ExprResult E = getDerived().TransformLambdaConstraint(
16353 const_cast<Expr *>(TRC.ConstraintExpr));
16354 if (E.isInvalid())
16355 return E;
16356 TRC.ConstraintExpr = E.get();
16357 }
16358
16359 LSI->BeforeCompoundStatement = false;
16360 getSema().CompleteLambdaCallOperator(
16361 NewCallOperator, E->getCallOperator()->getLocation(),
16362 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
16363 E->getCallOperator()->getConstexprKind(),
16364 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
16365 E->hasExplicitResultType());
16366
16367 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
16368 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
16369
16370 {
16371 // Number the lambda for linkage purposes if necessary.
16372 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
16373
16374 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
16375 if (getDerived().ReplacingOriginal()) {
16376 Numbering = OldClass->getLambdaNumbering();
16377 }
16378
16379 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
16380 }
16381
16382 // FIXME: Sema's lambda-building mechanism expects us to push an expression
16383 // evaluation context even if we're not transforming the function body.
16384 getSema().PushExpressionEvaluationContextForFunction(
16386 E->getCallOperator());
16387
16388 StmtResult Body;
16389 {
16390 Sema::NonSFINAEContext _(getSema());
16393 C.PointOfInstantiation = E->getBody()->getBeginLoc();
16394 getSema().pushCodeSynthesisContext(C);
16395
16396 // Instantiate the body of the lambda expression.
16397 Body = Invalid ? StmtError()
16398 : getDerived().TransformLambdaBody(E, E->getBody());
16399
16400 getSema().popCodeSynthesisContext();
16401 }
16402
16403 // ActOnLambda* will pop the function scope for us.
16404 FuncScopeCleanup.disable();
16405
16406 if (Body.isInvalid()) {
16407 SavedContext.pop();
16408 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
16409 /*IsInstantiation=*/true);
16410 return ExprError();
16411 }
16412
16413 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
16414 /*IsInstantiation=*/true,
16415 /*RetainFunctionScopeInfo=*/true);
16416 SavedContext.pop();
16417
16418 // Recompute the dependency of the lambda so that we can defer the lambda call
16419 // construction until after we have all the necessary template arguments. For
16420 // example, given
16421 //
16422 // template <class> struct S {
16423 // template <class U>
16424 // using Type = decltype([](U){}(42.0));
16425 // };
16426 // void foo() {
16427 // using T = S<int>::Type<float>;
16428 // ^~~~~~
16429 // }
16430 //
16431 // We would end up here from instantiating S<int> when ensuring its
16432 // completeness. That would transform the lambda call expression regardless of
16433 // the absence of the corresponding argument for U.
16434 //
16435 // Going ahead with unsubstituted type U makes things worse: we would soon
16436 // compare the argument type (which is float) against the parameter U
16437 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
16438 // error suggesting unmatched types 'U' and 'float'!
16439 //
16440 // That said, everything will be fine if we defer that semantic checking.
16441 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
16442 // dependent. Since the CallExpr's dependency boils down to the lambda's
16443 // dependency in this case, we can harness that by recomputing the dependency
16444 // from the instantiation arguments.
16445 //
16446 // FIXME: Creating the type of a lambda requires us to have a dependency
16447 // value, which happens before its substitution. We update its dependency
16448 // *after* the substitution in case we can't decide the dependency
16449 // so early, e.g. because we want to see if any of the *substituted*
16450 // parameters are dependent.
16451 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
16452 Class->setLambdaDependencyKind(DependencyKind);
16453
16454 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
16455 Body.get()->getEndLoc(), LSI);
16456}
16457
16458template<typename Derived>
16463
16464template<typename Derived>
16467 // Transform captures.
16469 CEnd = E->capture_end();
16470 C != CEnd; ++C) {
16471 // When we hit the first implicit capture, tell Sema that we've finished
16472 // the list of explicit captures.
16473 if (!C->isImplicit())
16474 continue;
16475
16476 // Capturing 'this' is trivial.
16477 if (C->capturesThis()) {
16478 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16479 /*BuildAndDiagnose*/ true, nullptr,
16480 C->getCaptureKind() == LCK_StarThis);
16481 continue;
16482 }
16483 // Captured expression will be recaptured during captured variables
16484 // rebuilding.
16485 if (C->capturesVLAType())
16486 continue;
16487
16488 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16489 assert(!E->isInitCapture(C) && "implicit init-capture?");
16490
16491 // Transform the captured variable.
16492 VarDecl *CapturedVar = cast_or_null<VarDecl>(
16493 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16494 if (!CapturedVar || CapturedVar->isInvalidDecl())
16495 return StmtError();
16496
16497 // Capture the transformed variable.
16498 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
16499 }
16500
16501 return S;
16502}
16503
16504template<typename Derived>
16508 TypeSourceInfo *T =
16509 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16510 if (!T)
16511 return ExprError();
16512
16513 bool ArgumentChanged = false;
16515 Args.reserve(E->getNumArgs());
16516 {
16520 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
16521 &ArgumentChanged))
16522 return ExprError();
16523 }
16524
16525 if (!getDerived().AlwaysRebuild() &&
16526 T == E->getTypeSourceInfo() &&
16527 !ArgumentChanged)
16528 return E;
16529
16530 // FIXME: we're faking the locations of the commas
16531 return getDerived().RebuildCXXUnresolvedConstructExpr(
16532 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
16533}
16534
16535template<typename Derived>
16539 // Transform the base of the expression.
16540 ExprResult Base((Expr*) nullptr);
16541 Expr *OldBase;
16542 QualType BaseType;
16543 QualType ObjectType;
16544 if (!E->isImplicitAccess()) {
16545 OldBase = E->getBase();
16546 Base = getDerived().TransformExpr(OldBase);
16547 if (Base.isInvalid())
16548 return ExprError();
16549
16550 // Start the member reference and compute the object's type.
16551 ParsedType ObjectTy;
16552 bool MayBePseudoDestructor = false;
16553 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
16554 E->getOperatorLoc(),
16555 E->isArrow()? tok::arrow : tok::period,
16556 ObjectTy,
16557 MayBePseudoDestructor);
16558 if (Base.isInvalid())
16559 return ExprError();
16560
16561 ObjectType = ObjectTy.get();
16562 BaseType = ((Expr*) Base.get())->getType();
16563 } else {
16564 OldBase = nullptr;
16565 BaseType = getDerived().TransformType(E->getBaseType());
16566 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16567 }
16568
16569 // Transform the first part of the nested-name-specifier that qualifies
16570 // the member name.
16571 NamedDecl *FirstQualifierInScope
16572 = getDerived().TransformFirstQualifierInScope(
16573 E->getFirstQualifierFoundInScope(),
16574 E->getQualifierLoc().getBeginLoc());
16575
16576 NestedNameSpecifierLoc QualifierLoc;
16577 if (E->getQualifier()) {
16578 QualifierLoc
16579 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16580 ObjectType,
16581 FirstQualifierInScope);
16582 if (!QualifierLoc)
16583 return ExprError();
16584 }
16585
16586 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16587
16588 // TODO: If this is a conversion-function-id, verify that the
16589 // destination type name (if present) resolves the same way after
16590 // instantiation as it did in the local scope.
16591
16592 DeclarationNameInfo NameInfo
16593 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16594 if (!NameInfo.getName())
16595 return ExprError();
16596
16597 if (!E->hasExplicitTemplateArgs()) {
16598 // This is a reference to a member without an explicitly-specified
16599 // template argument list. Optimize for this common case.
16600 if (!getDerived().AlwaysRebuild() &&
16601 Base.get() == OldBase &&
16602 BaseType == E->getBaseType() &&
16603 QualifierLoc == E->getQualifierLoc() &&
16604 NameInfo.getName() == E->getMember() &&
16605 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16606 return E;
16607
16608 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16609 BaseType,
16610 E->isArrow(),
16611 E->getOperatorLoc(),
16612 QualifierLoc,
16613 TemplateKWLoc,
16614 FirstQualifierInScope,
16615 NameInfo,
16616 /*TemplateArgs*/nullptr);
16617 }
16618
16619 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16620 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16621 E->getNumTemplateArgs(),
16622 TransArgs))
16623 return ExprError();
16624
16625 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16626 BaseType,
16627 E->isArrow(),
16628 E->getOperatorLoc(),
16629 QualifierLoc,
16630 TemplateKWLoc,
16631 FirstQualifierInScope,
16632 NameInfo,
16633 &TransArgs);
16634}
16635
16636template <typename Derived>
16638 UnresolvedMemberExpr *Old) {
16639 // Transform the base of the expression.
16640 ExprResult Base((Expr *)nullptr);
16641 QualType BaseType;
16642 if (!Old->isImplicitAccess()) {
16643 Base = getDerived().TransformExpr(Old->getBase());
16644 if (Base.isInvalid())
16645 return ExprError();
16646 Base =
16647 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16648 if (Base.isInvalid())
16649 return ExprError();
16650 BaseType = Base.get()->getType();
16651 } else {
16652 BaseType = getDerived().TransformType(Old->getBaseType());
16653 }
16654
16655 NestedNameSpecifierLoc QualifierLoc;
16656 if (Old->getQualifierLoc()) {
16657 QualifierLoc =
16658 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16659 if (!QualifierLoc)
16660 return ExprError();
16661 }
16662
16663 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16664
16665 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16666
16667 // Transform the declaration set.
16668 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16669 return ExprError();
16670
16671 // Determine the naming class.
16672 if (Old->getNamingClass()) {
16673 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16674 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16675 if (!NamingClass)
16676 return ExprError();
16677
16678 R.setNamingClass(NamingClass);
16679 }
16680
16681 TemplateArgumentListInfo TransArgs;
16682 if (Old->hasExplicitTemplateArgs()) {
16683 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16684 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16685 if (getDerived().TransformTemplateArguments(
16686 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16687 return ExprError();
16688 }
16689
16690 // FIXME: to do this check properly, we will need to preserve the
16691 // first-qualifier-in-scope here, just in case we had a dependent
16692 // base (and therefore couldn't do the check) and a
16693 // nested-name-qualifier (and therefore could do the lookup).
16694 NamedDecl *FirstQualifierInScope = nullptr;
16695
16696 return getDerived().RebuildUnresolvedMemberExpr(
16697 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16698 TemplateKWLoc, FirstQualifierInScope, R,
16699 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16700}
16701
16702template<typename Derived>
16707 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16708 if (SubExpr.isInvalid())
16709 return ExprError();
16710
16711 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16712 return E;
16713
16714 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16715}
16716
16717template<typename Derived>
16720 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16721 if (Pattern.isInvalid())
16722 return ExprError();
16723
16724 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16725 return E;
16726
16727 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16728 E->getNumExpansions());
16729}
16730
16731template <typename Derived>
16733 ArrayRef<TemplateArgument> PackArgs) {
16735 for (const TemplateArgument &Arg : PackArgs) {
16736 if (!Arg.isPackExpansion()) {
16737 Result = *Result + 1;
16738 continue;
16739 }
16740
16741 TemplateArgumentLoc ArgLoc;
16742 InventTemplateArgumentLoc(Arg, ArgLoc);
16743
16744 // Find the pattern of the pack expansion.
16745 SourceLocation Ellipsis;
16746 UnsignedOrNone OrigNumExpansions = std::nullopt;
16747 TemplateArgumentLoc Pattern =
16748 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16749 OrigNumExpansions);
16750
16751 // Substitute under the pack expansion. Do not expand the pack (yet).
16752 TemplateArgumentLoc OutPattern;
16753 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16754 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16755 /*Uneval*/ true))
16756 return 1u;
16757
16758 // See if we can determine the number of arguments from the result.
16759 UnsignedOrNone NumExpansions =
16760 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16761 if (!NumExpansions) {
16762 // No: we must be in an alias template expansion, and we're going to
16763 // need to actually expand the packs.
16764 Result = std::nullopt;
16765 break;
16766 }
16767
16768 Result = *Result + *NumExpansions;
16769 }
16770 return Result;
16771}
16772
16773template<typename Derived>
16776 // If E is not value-dependent, then nothing will change when we transform it.
16777 // Note: This is an instantiation-centric view.
16778 if (!E->isValueDependent())
16779 return E;
16780
16783
16785 TemplateArgument ArgStorage;
16786
16787 // Find the argument list to transform.
16788 if (E->isPartiallySubstituted()) {
16789 PackArgs = E->getPartialArguments();
16790 } else if (E->isValueDependent()) {
16791 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16792 bool ShouldExpand = false;
16793 bool RetainExpansion = false;
16794 UnsignedOrNone NumExpansions = std::nullopt;
16795 if (getDerived().TryExpandParameterPacks(
16796 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16797 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16798 RetainExpansion, NumExpansions))
16799 return ExprError();
16800
16801 // If we need to expand the pack, build a template argument from it and
16802 // expand that.
16803 if (ShouldExpand) {
16804 auto *Pack = E->getPack();
16805 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16806 ArgStorage = getSema().Context.getPackExpansionType(
16807 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16808 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16809 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16810 } else {
16811 auto *VD = cast<ValueDecl>(Pack);
16812 ExprResult DRE = getSema().BuildDeclRefExpr(
16813 VD, VD->getType().getNonLValueExprType(getSema().Context),
16814 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16815 E->getPackLoc());
16816 if (DRE.isInvalid())
16817 return ExprError();
16818 ArgStorage = TemplateArgument(
16819 new (getSema().Context)
16820 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16821 /*IsCanonical=*/false);
16822 }
16823 PackArgs = ArgStorage;
16824 }
16825 }
16826
16827 // If we're not expanding the pack, just transform the decl.
16828 if (!PackArgs.size()) {
16829 auto *Pack = cast_or_null<NamedDecl>(
16830 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16831 if (!Pack)
16832 return ExprError();
16833 return getDerived().RebuildSizeOfPackExpr(
16834 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16835 std::nullopt, {});
16836 }
16837
16838 // Try to compute the result without performing a partial substitution.
16840 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16841
16842 // Common case: we could determine the number of expansions without
16843 // substituting.
16844 if (Result)
16845 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16846 E->getPackLoc(),
16847 E->getRParenLoc(), *Result, {});
16848
16849 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16850 E->getPackLoc());
16851 {
16852 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16854 Derived, const TemplateArgument*> PackLocIterator;
16855 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16856 PackLocIterator(*this, PackArgs.end()),
16857 TransformedPackArgs, /*Uneval*/true))
16858 return ExprError();
16859 }
16860
16861 // Check whether we managed to fully-expand the pack.
16862 // FIXME: Is it possible for us to do so and not hit the early exit path?
16864 bool PartialSubstitution = false;
16865 for (auto &Loc : TransformedPackArgs.arguments()) {
16866 Args.push_back(Loc.getArgument());
16867 if (Loc.getArgument().isPackExpansion())
16868 PartialSubstitution = true;
16869 }
16870
16871 if (PartialSubstitution)
16872 return getDerived().RebuildSizeOfPackExpr(
16873 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16874 std::nullopt, Args);
16875
16876 return getDerived().RebuildSizeOfPackExpr(
16877 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16878 /*Length=*/static_cast<unsigned>(Args.size()),
16879 /*PartialArgs=*/{});
16880}
16881
16882template <typename Derived>
16885 if (!E->isValueDependent())
16886 return E;
16887
16888 // Transform the index
16889 ExprResult IndexExpr;
16890 {
16891 EnterExpressionEvaluationContext ConstantContext(
16893 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16894 if (IndexExpr.isInvalid())
16895 return ExprError();
16896 }
16897
16898 SmallVector<Expr *, 5> ExpandedExprs;
16899 bool FullySubstituted = true;
16900 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16901 Expr *Pattern = E->getPackIdExpression();
16903 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16904 Unexpanded);
16905 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16906
16907 // Determine whether the set of unexpanded parameter packs can and should
16908 // be expanded.
16909 bool ShouldExpand = true;
16910 bool RetainExpansion = false;
16911 UnsignedOrNone OrigNumExpansions = std::nullopt,
16912 NumExpansions = std::nullopt;
16913 if (getDerived().TryExpandParameterPacks(
16914 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16915 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16916 RetainExpansion, NumExpansions))
16917 return true;
16918 if (!ShouldExpand) {
16919 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16920 ExprResult Pack = getDerived().TransformExpr(Pattern);
16921 if (Pack.isInvalid())
16922 return ExprError();
16923 return getDerived().RebuildPackIndexingExpr(
16924 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16925 {}, /*FullySubstituted=*/false);
16926 }
16927 for (unsigned I = 0; I != *NumExpansions; ++I) {
16928 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16929 ExprResult Out = getDerived().TransformExpr(Pattern);
16930 if (Out.isInvalid())
16931 return true;
16932 if (Out.get()->containsUnexpandedParameterPack()) {
16933 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16934 OrigNumExpansions);
16935 if (Out.isInvalid())
16936 return true;
16937 FullySubstituted = false;
16938 }
16939 ExpandedExprs.push_back(Out.get());
16940 }
16941 // If we're supposed to retain a pack expansion, do so by temporarily
16942 // forgetting the partially-substituted parameter pack.
16943 if (RetainExpansion) {
16944 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16945
16946 ExprResult Out = getDerived().TransformExpr(Pattern);
16947 if (Out.isInvalid())
16948 return true;
16949
16950 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16951 OrigNumExpansions);
16952 if (Out.isInvalid())
16953 return true;
16954 FullySubstituted = false;
16955 ExpandedExprs.push_back(Out.get());
16956 }
16957 } else if (!E->expandsToEmptyPack()) {
16958 if (getDerived().TransformExprs(E->getExpressions().data(),
16959 E->getExpressions().size(), false,
16960 ExpandedExprs))
16961 return ExprError();
16962 }
16963
16964 return getDerived().RebuildPackIndexingExpr(
16965 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16966 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16967}
16968
16969template <typename Derived>
16972 if (!getSema().ArgPackSubstIndex)
16973 // We aren't expanding the parameter pack, so just return ourselves.
16974 return E;
16975
16976 TemplateArgument Pack = E->getArgumentPack();
16978 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
16979 E->getAssociatedDecl(), E->getParameterPack()->getPosition(),
16980 E->getParameterPack()->getType(), E->getParameterPackLocation(), Arg,
16981 SemaRef.getPackIndex(Pack), E->getFinal());
16982}
16983
16984template <typename Derived>
16987 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16988
16989 // Insert a constant-evaluated context for the transform.
16990 // Otherwise, when a normalized constraint places the replacement inside
16991 // an unevaluated operand (e.g. decltype), entities it refers to are not
16992 // odr-used, and the constant evaluation performed by CheckTemplateArgument
16993 // below can spuriously fail for otherwise valid replacements,
16994 // e.g. when a call materializes a function parameter of class type whose
16995 // special members were never instantiated.
16996 EnterExpressionEvaluationContext ConstantEvaluated(
17000
17001 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
17002 if (Replacement.isInvalid())
17003 return true;
17004
17005 Decl *AssociatedDecl =
17006 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
17007 if (!AssociatedDecl)
17008 return true;
17009
17010 QualType ParamType = TransformType(E->getParameterType());
17011 if (ParamType.isNull())
17012 return true;
17013
17014 if (Replacement.get() == OrigReplacement &&
17015 AssociatedDecl == E->getAssociatedDecl() &&
17016 ParamType == E->getParameterType())
17017 return E;
17018
17019 if (Replacement.get() != OrigReplacement ||
17020 ParamType != E->getParameterType()) {
17021 auto *Param = cast<NonTypeTemplateParmDecl>(std::get<0>(
17022 getReplacedTemplateParameter(AssociatedDecl, E->getIndex())));
17023 // When transforming the replacement expression previously, all Sema
17024 // specific annotations, such as implicit casts, are discarded. Calling the
17025 // corresponding sema action is necessary to recover those. Otherwise,
17026 // equivalency of the result would be lost.
17027 TemplateArgument SugaredConverted, CanonicalConverted;
17028 Replacement = SemaRef.CheckTemplateArgument(
17029 Param, ParamType, Replacement.get(), SugaredConverted,
17030 CanonicalConverted,
17031 /*StrictCheck=*/false, Sema::CTAK_Specified);
17032 if (Replacement.isInvalid())
17033 return true;
17034 } else {
17035 // Otherwise, the same expression would have been produced.
17036 Replacement = E->getReplacement();
17037 }
17038
17039 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17040 AssociatedDecl, E->getIndex(), ParamType, E->getNameLoc(),
17041 TemplateArgument(Replacement.get(), /*IsCanonical=*/false),
17042 E->getPackIndex(), E->getFinal());
17043}
17044
17045template<typename Derived>
17048 // Default behavior is to do nothing with this transformation.
17049 return E;
17050}
17051
17052template<typename Derived>
17056 return getDerived().TransformExpr(E->getSubExpr());
17057}
17058
17059template<typename Derived>
17062 UnresolvedLookupExpr *Callee = nullptr;
17063 if (Expr *OldCallee = E->getCallee()) {
17064 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
17065 if (CalleeResult.isInvalid())
17066 return ExprError();
17067 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
17068 }
17069
17070 Expr *Pattern = E->getPattern();
17071
17073 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
17074 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17075
17076 // Determine whether the set of unexpanded parameter packs can and should
17077 // be expanded.
17078 bool Expand = true;
17079 bool RetainExpansion = false;
17080 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
17081 NumExpansions = OrigNumExpansions;
17082 if (getDerived().TryExpandParameterPacks(
17083 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17084 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17085 NumExpansions))
17086 return true;
17087
17088 if (!Expand) {
17089 // Do not expand any packs here, just transform and rebuild a fold
17090 // expression.
17091 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17092
17093 ExprResult LHS =
17094 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
17095 if (LHS.isInvalid())
17096 return true;
17097
17098 ExprResult RHS =
17099 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
17100 if (RHS.isInvalid())
17101 return true;
17102
17103 if (!getDerived().AlwaysRebuild() &&
17104 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
17105 return E;
17106
17107 return getDerived().RebuildCXXFoldExpr(
17108 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
17109 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
17110 }
17111
17112 // Formally a fold expression expands to nested parenthesized expressions.
17113 // Enforce this limit to avoid creating trees so deep we can't safely traverse
17114 // them.
17115 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
17116 SemaRef.Diag(E->getEllipsisLoc(),
17117 clang::diag::err_fold_expression_limit_exceeded)
17118 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
17119 << E->getSourceRange();
17120 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
17121 return ExprError();
17122 }
17123
17124 // The transform has determined that we should perform an elementwise
17125 // expansion of the pattern. Do so.
17126 ExprResult Result = getDerived().TransformExpr(E->getInit());
17127 if (Result.isInvalid())
17128 return true;
17129 bool LeftFold = E->isLeftFold();
17130
17131 // If we're retaining an expansion for a right fold, it is the innermost
17132 // component and takes the init (if any).
17133 if (!LeftFold && RetainExpansion) {
17134 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17135
17136 ExprResult Out = getDerived().TransformExpr(Pattern);
17137 if (Out.isInvalid())
17138 return true;
17139
17140 Result = getDerived().RebuildCXXFoldExpr(
17141 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
17142 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
17143 if (Result.isInvalid())
17144 return true;
17145 }
17146
17147 bool WarnedOnComparison = false;
17148 for (unsigned I = 0; I != *NumExpansions; ++I) {
17149 Sema::ArgPackSubstIndexRAII SubstIndex(
17150 getSema(), LeftFold ? I : *NumExpansions - I - 1);
17151 ExprResult Out = getDerived().TransformExpr(Pattern);
17152 if (Out.isInvalid())
17153 return true;
17154
17155 if (Out.get()->containsUnexpandedParameterPack()) {
17156 // We still have a pack; retain a pack expansion for this slice.
17157 Result = getDerived().RebuildCXXFoldExpr(
17158 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
17159 E->getOperator(), E->getEllipsisLoc(),
17160 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
17161 OrigNumExpansions);
17162 } else if (Result.isUsable()) {
17163 // We've got down to a single element; build a binary operator.
17164 Expr *LHS = LeftFold ? Result.get() : Out.get();
17165 Expr *RHS = LeftFold ? Out.get() : Result.get();
17166 if (Callee) {
17167 UnresolvedSet<16> Functions;
17168 Functions.append(Callee->decls_begin(), Callee->decls_end());
17169 Result = getDerived().RebuildCXXOperatorCallExpr(
17170 BinaryOperator::getOverloadedOperator(E->getOperator()),
17171 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
17172 Functions, LHS, RHS);
17173 } else {
17174 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
17175 E->getOperator(), LHS, RHS,
17176 /*ForFoldExpresion=*/true);
17177 if (!WarnedOnComparison && Result.isUsable()) {
17178 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
17179 BO && BO->isComparisonOp()) {
17180 WarnedOnComparison = true;
17181 SemaRef.Diag(BO->getBeginLoc(),
17182 diag::warn_comparison_in_fold_expression)
17183 << BO->getOpcodeStr();
17184 }
17185 }
17186 }
17187 } else
17188 Result = Out;
17189
17190 if (Result.isInvalid())
17191 return true;
17192 }
17193
17194 // If we're retaining an expansion for a left fold, it is the outermost
17195 // component and takes the complete expansion so far as its init (if any).
17196 if (LeftFold && RetainExpansion) {
17197 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17198
17199 ExprResult Out = getDerived().TransformExpr(Pattern);
17200 if (Out.isInvalid())
17201 return true;
17202
17203 Result = getDerived().RebuildCXXFoldExpr(
17204 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
17205 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
17206 if (Result.isInvalid())
17207 return true;
17208 }
17209
17210 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
17211 PE->setIsProducedByFoldExpansion();
17212
17213 // If we had no init and an empty pack, and we're not retaining an expansion,
17214 // then produce a fallback value or error.
17215 if (Result.isUnset())
17216 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
17217 E->getOperator());
17218 return Result;
17219}
17220
17221template <typename Derived>
17224 SmallVector<Expr *, 4> TransformedInits;
17225 ArrayRef<Expr *> InitExprs = E->getInitExprs();
17226
17227 QualType T = getDerived().TransformType(E->getType());
17228
17229 bool ArgChanged = false;
17230
17231 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
17232 TransformedInits, &ArgChanged))
17233 return ExprError();
17234
17235 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
17236 return E;
17237
17238 return getDerived().RebuildCXXParenListInitExpr(
17239 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
17240 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
17241}
17242
17243template<typename Derived>
17247 return getDerived().TransformExpr(E->getSubExpr());
17248}
17249
17250template<typename Derived>
17253 return SemaRef.MaybeBindToTemporary(E);
17254}
17255
17256template<typename Derived>
17259 return E;
17260}
17261
17262template<typename Derived>
17265 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
17266 if (SubExpr.isInvalid())
17267 return ExprError();
17268
17269 if (!getDerived().AlwaysRebuild() &&
17270 SubExpr.get() == E->getSubExpr())
17271 return E;
17272
17273 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
17274}
17275
17276template<typename Derived>
17279 // Transform each of the elements.
17280 SmallVector<Expr *, 8> Elements;
17281 bool ArgChanged = false;
17282 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
17283 /*IsCall=*/false, Elements, &ArgChanged))
17284 return ExprError();
17285
17286 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17287 return SemaRef.MaybeBindToTemporary(E);
17288
17289 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
17290 Elements.data(),
17291 Elements.size());
17292}
17293
17294template<typename Derived>
17298 // Transform each of the elements.
17300 bool ArgChanged = false;
17301 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
17302 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
17303
17304 if (OrigElement.isPackExpansion()) {
17305 // This key/value element is a pack expansion.
17307 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
17308 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
17309 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17310
17311 // Determine whether the set of unexpanded parameter packs can
17312 // and should be expanded.
17313 bool Expand = true;
17314 bool RetainExpansion = false;
17315 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
17316 UnsignedOrNone NumExpansions = OrigNumExpansions;
17317 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
17318 OrigElement.Value->getEndLoc());
17319 if (getDerived().TryExpandParameterPacks(
17320 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
17321 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17322 NumExpansions))
17323 return ExprError();
17324
17325 if (!Expand) {
17326 // The transform has determined that we should perform a simple
17327 // transformation on the pack expansion, producing another pack
17328 // expansion.
17329 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17330 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17331 if (Key.isInvalid())
17332 return ExprError();
17333
17334 if (Key.get() != OrigElement.Key)
17335 ArgChanged = true;
17336
17337 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17338 if (Value.isInvalid())
17339 return ExprError();
17340
17341 if (Value.get() != OrigElement.Value)
17342 ArgChanged = true;
17343
17344 ObjCDictionaryElement Expansion = {
17345 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
17346 };
17347 Elements.push_back(Expansion);
17348 continue;
17349 }
17350
17351 // Record right away that the argument was changed. This needs
17352 // to happen even if the array expands to nothing.
17353 ArgChanged = true;
17354
17355 // The transform has determined that we should perform an elementwise
17356 // expansion of the pattern. Do so.
17357 for (unsigned I = 0; I != *NumExpansions; ++I) {
17358 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17359 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17360 if (Key.isInvalid())
17361 return ExprError();
17362
17363 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17364 if (Value.isInvalid())
17365 return ExprError();
17366
17367 ObjCDictionaryElement Element = {
17368 Key.get(), Value.get(), SourceLocation(), NumExpansions
17369 };
17370
17371 // If any unexpanded parameter packs remain, we still have a
17372 // pack expansion.
17373 // FIXME: Can this really happen?
17374 if (Key.get()->containsUnexpandedParameterPack() ||
17375 Value.get()->containsUnexpandedParameterPack())
17376 Element.EllipsisLoc = OrigElement.EllipsisLoc;
17377
17378 Elements.push_back(Element);
17379 }
17380
17381 // FIXME: Retain a pack expansion if RetainExpansion is true.
17382
17383 // We've finished with this pack expansion.
17384 continue;
17385 }
17386
17387 // Transform and check key.
17388 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17389 if (Key.isInvalid())
17390 return ExprError();
17391
17392 if (Key.get() != OrigElement.Key)
17393 ArgChanged = true;
17394
17395 // Transform and check value.
17397 = getDerived().TransformExpr(OrigElement.Value);
17398 if (Value.isInvalid())
17399 return ExprError();
17400
17401 if (Value.get() != OrigElement.Value)
17402 ArgChanged = true;
17403
17404 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
17405 std::nullopt};
17406 Elements.push_back(Element);
17407 }
17408
17409 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17410 return SemaRef.MaybeBindToTemporary(E);
17411
17412 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
17413 Elements);
17414}
17415
17416template<typename Derived>
17419 TypeSourceInfo *EncodedTypeInfo
17420 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
17421 if (!EncodedTypeInfo)
17422 return ExprError();
17423
17424 if (!getDerived().AlwaysRebuild() &&
17425 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
17426 return E;
17427
17428 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
17429 EncodedTypeInfo,
17430 E->getRParenLoc());
17431}
17432
17433template<typename Derived>
17436 // This is a kind of implicit conversion, and it needs to get dropped
17437 // and recomputed for the same general reasons that ImplicitCastExprs
17438 // do, as well a more specific one: this expression is only valid when
17439 // it appears *immediately* as an argument expression.
17440 return getDerived().TransformExpr(E->getSubExpr());
17441}
17442
17443template<typename Derived>
17446 TypeSourceInfo *TSInfo
17447 = getDerived().TransformType(E->getTypeInfoAsWritten());
17448 if (!TSInfo)
17449 return ExprError();
17450
17451 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
17452 if (Result.isInvalid())
17453 return ExprError();
17454
17455 if (!getDerived().AlwaysRebuild() &&
17456 TSInfo == E->getTypeInfoAsWritten() &&
17457 Result.get() == E->getSubExpr())
17458 return E;
17459
17460 return SemaRef.ObjC().BuildObjCBridgedCast(
17461 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
17462 Result.get());
17463}
17464
17465template <typename Derived>
17468 return E;
17469}
17470
17471template<typename Derived>
17474 // Transform arguments.
17475 bool ArgChanged = false;
17477 Args.reserve(E->getNumArgs());
17478 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
17479 &ArgChanged))
17480 return ExprError();
17481
17482 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
17483 // Class message: transform the receiver type.
17484 TypeSourceInfo *ReceiverTypeInfo
17485 = getDerived().TransformType(E->getClassReceiverTypeInfo());
17486 if (!ReceiverTypeInfo)
17487 return ExprError();
17488
17489 // If nothing changed, just retain the existing message send.
17490 if (!getDerived().AlwaysRebuild() &&
17491 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
17492 return SemaRef.MaybeBindToTemporary(E);
17493
17494 // Build a new class message send.
17496 E->getSelectorLocs(SelLocs);
17497 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
17498 E->getSelector(),
17499 SelLocs,
17500 E->getMethodDecl(),
17501 E->getLeftLoc(),
17502 Args,
17503 E->getRightLoc());
17504 }
17505 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
17506 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
17507 if (!E->getMethodDecl())
17508 return ExprError();
17509
17510 // Build a new class message send to 'super'.
17512 E->getSelectorLocs(SelLocs);
17513 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
17514 E->getSelector(),
17515 SelLocs,
17516 E->getReceiverType(),
17517 E->getMethodDecl(),
17518 E->getLeftLoc(),
17519 Args,
17520 E->getRightLoc());
17521 }
17522
17523 // Instance message: transform the receiver
17524 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
17525 "Only class and instance messages may be instantiated");
17526 ExprResult Receiver
17527 = getDerived().TransformExpr(E->getInstanceReceiver());
17528 if (Receiver.isInvalid())
17529 return ExprError();
17530
17531 // If nothing changed, just retain the existing message send.
17532 if (!getDerived().AlwaysRebuild() &&
17533 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
17534 return SemaRef.MaybeBindToTemporary(E);
17535
17536 // Build a new instance message send.
17538 E->getSelectorLocs(SelLocs);
17539 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
17540 E->getSelector(),
17541 SelLocs,
17542 E->getMethodDecl(),
17543 E->getLeftLoc(),
17544 Args,
17545 E->getRightLoc());
17546}
17547
17548template<typename Derived>
17551 return E;
17552}
17553
17554template<typename Derived>
17557 return E;
17558}
17559
17560template<typename Derived>
17563 // Transform the base expression.
17564 ExprResult Base = getDerived().TransformExpr(E->getBase());
17565 if (Base.isInvalid())
17566 return ExprError();
17567
17568 // We don't need to transform the ivar; it will never change.
17569
17570 // If nothing changed, just retain the existing expression.
17571 if (!getDerived().AlwaysRebuild() &&
17572 Base.get() == E->getBase())
17573 return E;
17574
17575 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17576 E->getLocation(),
17577 E->isArrow(), E->isFreeIvar());
17578}
17579
17580template<typename Derived>
17583 // 'super' and types never change. Property never changes. Just
17584 // retain the existing expression.
17585 if (!E->isObjectReceiver())
17586 return E;
17587
17588 // Transform the base expression.
17589 ExprResult Base = getDerived().TransformExpr(E->getBase());
17590 if (Base.isInvalid())
17591 return ExprError();
17592
17593 // We don't need to transform the property; it will never change.
17594
17595 // If nothing changed, just retain the existing expression.
17596 if (!getDerived().AlwaysRebuild() &&
17597 Base.get() == E->getBase())
17598 return E;
17599
17600 if (E->isExplicitProperty())
17601 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17602 E->getExplicitProperty(),
17603 E->getLocation());
17604
17605 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17606 SemaRef.Context.PseudoObjectTy,
17607 E->getImplicitPropertyGetter(),
17608 E->getImplicitPropertySetter(),
17609 E->getLocation());
17610}
17611
17612template<typename Derived>
17615 // Transform the base expression.
17616 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17617 if (Base.isInvalid())
17618 return ExprError();
17619
17620 // Transform the key expression.
17621 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17622 if (Key.isInvalid())
17623 return ExprError();
17624
17625 // If nothing changed, just retain the existing expression.
17626 if (!getDerived().AlwaysRebuild() &&
17627 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17628 return E;
17629
17630 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17631 Base.get(), Key.get(),
17632 E->getAtIndexMethodDecl(),
17633 E->setAtIndexMethodDecl());
17634}
17635
17636template<typename Derived>
17639 // Transform the base expression.
17640 ExprResult Base = getDerived().TransformExpr(E->getBase());
17641 if (Base.isInvalid())
17642 return ExprError();
17643
17644 // If nothing changed, just retain the existing expression.
17645 if (!getDerived().AlwaysRebuild() &&
17646 Base.get() == E->getBase())
17647 return E;
17648
17649 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17650 E->getOpLoc(),
17651 E->isArrow());
17652}
17653
17654template<typename Derived>
17657 bool ArgumentChanged = false;
17658 SmallVector<Expr*, 8> SubExprs;
17659 SubExprs.reserve(E->getNumSubExprs());
17660 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17661 SubExprs, &ArgumentChanged))
17662 return ExprError();
17663
17664 if (!getDerived().AlwaysRebuild() &&
17665 !ArgumentChanged)
17666 return E;
17667
17668 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17669 SubExprs,
17670 E->getRParenLoc());
17671}
17672
17673template<typename Derived>
17676 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17677 if (SrcExpr.isInvalid())
17678 return ExprError();
17679
17680 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17681 if (!Type)
17682 return ExprError();
17683
17684 if (!getDerived().AlwaysRebuild() &&
17685 Type == E->getTypeSourceInfo() &&
17686 SrcExpr.get() == E->getSrcExpr())
17687 return E;
17688
17689 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17690 SrcExpr.get(), Type,
17691 E->getRParenLoc());
17692}
17693
17694template<typename Derived>
17697 BlockDecl *oldBlock = E->getBlockDecl();
17698
17699 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17700 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17701
17702 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17703 blockScope->TheDecl->setBlockMissingReturnType(
17704 oldBlock->blockMissingReturnType());
17705
17707 SmallVector<QualType, 4> paramTypes;
17708
17709 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17710
17711 // Parameter substitution.
17712 Sema::ExtParameterInfoBuilder extParamInfos;
17713 if (getDerived().TransformFunctionTypeParams(
17714 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17715 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17716 extParamInfos)) {
17717 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17718 return ExprError();
17719 }
17720
17721 QualType exprResultType =
17722 getDerived().TransformType(exprFunctionType->getReturnType());
17723
17724 auto epi = exprFunctionType->getExtProtoInfo();
17725 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17726
17728 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17729 blockScope->FunctionType = functionType;
17730
17731 // Set the parameters on the block decl.
17732 if (!params.empty())
17733 blockScope->TheDecl->setParams(params);
17734
17735 if (!oldBlock->blockMissingReturnType()) {
17736 blockScope->HasImplicitReturnType = false;
17737 blockScope->ReturnType = exprResultType;
17738 }
17739
17740 // Transform the body
17741 StmtResult body = getDerived().TransformStmt(E->getBody());
17742 if (body.isInvalid()) {
17743 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17744 return ExprError();
17745 }
17746
17747#ifndef NDEBUG
17748 // In builds with assertions, make sure that we captured everything we
17749 // captured before.
17750 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17751 for (const auto &I : oldBlock->captures()) {
17752 VarDecl *oldCapture = I.getVariable();
17753
17754 // Ignore parameter packs.
17755 if (oldCapture->isParameterPack())
17756 continue;
17757
17758 VarDecl *newCapture =
17759 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17760 oldCapture));
17761 assert(blockScope->CaptureMap.count(newCapture));
17762 }
17763
17764 // The this pointer may not be captured by the instantiated block, even when
17765 // it's captured by the original block, if the expression causing the
17766 // capture is in the discarded branch of a constexpr if statement.
17767 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17768 "this pointer isn't captured in the old block");
17769 }
17770#endif
17771
17772 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17773 /*Scope=*/nullptr);
17774}
17775
17776template<typename Derived>
17779 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17780 if (SrcExpr.isInvalid())
17781 return ExprError();
17782
17783 QualType Type = getDerived().TransformType(E->getType());
17784
17785 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17786 E->getRParenLoc());
17787}
17788
17789template<typename Derived>
17792 bool ArgumentChanged = false;
17793 SmallVector<Expr*, 8> SubExprs;
17794 SubExprs.reserve(E->getNumSubExprs());
17795 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17796 SubExprs, &ArgumentChanged))
17797 return ExprError();
17798
17799 if (!getDerived().AlwaysRebuild() &&
17800 !ArgumentChanged)
17801 return E;
17802
17803 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17804 E->getOp(), E->getRParenLoc());
17805}
17806
17807//===----------------------------------------------------------------------===//
17808// Type reconstruction
17809//===----------------------------------------------------------------------===//
17810
17811template<typename Derived>
17814 return SemaRef.BuildPointerType(PointeeType, Star,
17816}
17817
17818template<typename Derived>
17821 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17823}
17824
17825template<typename Derived>
17828 bool WrittenAsLValue,
17829 SourceLocation Sigil) {
17830 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17831 Sigil, getDerived().getBaseEntity());
17832}
17833
17834template <typename Derived>
17836 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17837 SourceLocation Sigil) {
17838 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17840}
17841
17842template<typename Derived>
17844 const ObjCTypeParamDecl *Decl,
17845 SourceLocation ProtocolLAngleLoc,
17847 ArrayRef<SourceLocation> ProtocolLocs,
17848 SourceLocation ProtocolRAngleLoc) {
17849 return SemaRef.ObjC().BuildObjCTypeParamType(
17850 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17851 /*FailOnError=*/true);
17852}
17853
17854template<typename Derived>
17856 QualType BaseType,
17857 SourceLocation Loc,
17858 SourceLocation TypeArgsLAngleLoc,
17860 SourceLocation TypeArgsRAngleLoc,
17861 SourceLocation ProtocolLAngleLoc,
17863 ArrayRef<SourceLocation> ProtocolLocs,
17864 SourceLocation ProtocolRAngleLoc) {
17865 return SemaRef.ObjC().BuildObjCObjectType(
17866 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17867 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17868 /*FailOnError=*/true,
17869 /*Rebuilding=*/true);
17870}
17871
17872template<typename Derived>
17874 QualType PointeeType,
17876 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17877}
17878
17879template <typename Derived>
17881 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17882 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17883 if (SizeExpr || !Size)
17884 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17885 IndexTypeQuals, BracketsRange,
17887
17888 QualType Types[] = {
17889 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17890 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17891 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17892 };
17893 QualType SizeType;
17894 for (const auto &T : Types)
17895 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17896 SizeType = T;
17897 break;
17898 }
17899
17900 // Note that we can return a VariableArrayType here in the case where
17901 // the element type was a dependent VariableArrayType.
17902 IntegerLiteral *ArraySize
17903 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17904 /*FIXME*/BracketsRange.getBegin());
17905 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17906 IndexTypeQuals, BracketsRange,
17908}
17909
17910template <typename Derived>
17912 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17913 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17914 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17915 IndexTypeQuals, BracketsRange);
17916}
17917
17918template <typename Derived>
17920 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17921 SourceRange BracketsRange) {
17922 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17923 IndexTypeQuals, BracketsRange);
17924}
17925
17926template <typename Derived>
17928 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17929 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17930 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17931 SizeExpr,
17932 IndexTypeQuals, BracketsRange);
17933}
17934
17935template <typename Derived>
17937 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17938 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17939 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17940 SizeExpr,
17941 IndexTypeQuals, BracketsRange);
17942}
17943
17944template <typename Derived>
17946 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17947 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17948 AttributeLoc);
17949}
17950
17951template <typename Derived>
17953 unsigned NumElements,
17954 VectorKind VecKind) {
17955 // FIXME: semantic checking!
17956 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17957}
17958
17959template <typename Derived>
17961 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17962 VectorKind VecKind) {
17963 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17964}
17965
17966template<typename Derived>
17968 unsigned NumElements,
17969 SourceLocation AttributeLoc) {
17970 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17971 NumElements, true);
17972 IntegerLiteral *VectorSize
17973 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17974 AttributeLoc);
17975 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17976}
17977
17978template<typename Derived>
17981 Expr *SizeExpr,
17982 SourceLocation AttributeLoc) {
17983 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17984}
17985
17986template <typename Derived>
17988 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17989 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17990 NumColumns);
17991}
17992
17993template <typename Derived>
17995 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17996 SourceLocation AttributeLoc) {
17997 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17998 AttributeLoc);
17999}
18000
18001template <typename Derived>
18005 return SemaRef.BuildFunctionType(T, ParamTypes,
18008 EPI);
18009}
18010
18011template<typename Derived>
18013 return SemaRef.Context.getFunctionNoProtoType(T);
18014}
18015
18016template <typename Derived>
18019 SourceLocation NameLoc, Decl *D) {
18020 assert(D && "no decl found");
18021 if (D->isInvalidDecl()) return QualType();
18022
18023 // FIXME: Doesn't account for ObjCInterfaceDecl!
18024 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
18025 // A valid resolved using typename pack expansion decl can have multiple
18026 // UsingDecls, but they must each have exactly one type, and it must be
18027 // the same type in every case. But we must have at least one expansion!
18028 if (UPD->expansions().empty()) {
18029 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
18030 << UPD->isCXXClassMember() << UPD;
18031 return QualType();
18032 }
18033
18034 // We might still have some unresolved types. Try to pick a resolved type
18035 // if we can. The final instantiation will check that the remaining
18036 // unresolved types instantiate to the type we pick.
18037 QualType FallbackT;
18038 QualType T;
18039 for (auto *E : UPD->expansions()) {
18040 QualType ThisT =
18041 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
18042 if (ThisT.isNull())
18043 continue;
18044 if (ThisT->getAs<UnresolvedUsingType>())
18045 FallbackT = ThisT;
18046 else if (T.isNull())
18047 T = ThisT;
18048 else
18049 assert(getSema().Context.hasSameType(ThisT, T) &&
18050 "mismatched resolved types in using pack expansion");
18051 }
18052 return T.isNull() ? FallbackT : T;
18053 }
18054 if (auto *Using = dyn_cast<UsingDecl>(D)) {
18055 assert(Using->hasTypename() &&
18056 "UnresolvedUsingTypenameDecl transformed to non-typename using");
18057
18058 // A valid resolved using typename decl points to exactly one type decl.
18059 assert(++Using->shadow_begin() == Using->shadow_end());
18060
18061 UsingShadowDecl *Shadow = *Using->shadow_begin();
18062 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
18063 return QualType();
18064 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
18065 }
18067 "UnresolvedUsingTypenameDecl transformed to non-using decl");
18068 return SemaRef.Context.getUnresolvedUsingType(
18070}
18071
18072template <typename Derived>
18074 TypeOfKind Kind) {
18075 return SemaRef.BuildTypeofExprType(E, Kind);
18076}
18077
18078template<typename Derived>
18080 TypeOfKind Kind) {
18081 return SemaRef.Context.getTypeOfType(Underlying, Kind);
18082}
18083
18084template <typename Derived>
18086 return SemaRef.BuildDecltypeType(E);
18087}
18088
18089template <typename Derived>
18091 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
18092 SourceLocation EllipsisLoc, bool FullySubstituted,
18093 ArrayRef<QualType> Expansions) {
18094 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
18095 FullySubstituted, Expansions);
18096}
18097
18098template<typename Derived>
18100 UnaryTransformType::UTTKind UKind,
18101 SourceLocation Loc) {
18102 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
18103}
18104
18105template <typename Derived>
18108 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
18109 return SemaRef.CheckTemplateIdType(
18110 Keyword, Template, TemplateNameLoc, TemplateArgs,
18111 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
18112}
18113
18114template<typename Derived>
18116 SourceLocation KWLoc) {
18117 return SemaRef.BuildAtomicType(ValueType, KWLoc);
18118}
18119
18120template<typename Derived>
18122 SourceLocation KWLoc,
18123 bool isReadPipe) {
18124 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
18125 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
18126}
18127
18128template <typename Derived>
18130 unsigned NumBits,
18131 SourceLocation Loc) {
18132 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18133 NumBits, true);
18134 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
18135 SemaRef.Context.IntTy, Loc);
18136 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
18137}
18138
18139template <typename Derived>
18141 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
18142 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
18143}
18144
18145template <typename Derived>
18147 bool TemplateKW,
18148 TemplateName Name) {
18149 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
18150 Name);
18151}
18152
18153template <typename Derived>
18155 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
18156 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
18158 TemplateName.setIdentifier(&Name, NameLoc);
18160 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
18161 TemplateName, ParsedType::make(ObjectType),
18162 /*EnteringContext=*/false, Template,
18163 AllowInjectedClassName);
18164 return Template.get();
18165}
18166
18167template<typename Derived>
18170 SourceLocation TemplateKWLoc,
18171 OverloadedOperatorKind Operator,
18172 SourceLocation NameLoc,
18173 QualType ObjectType,
18174 bool AllowInjectedClassName) {
18175 UnqualifiedId Name;
18176 // FIXME: Bogus location information.
18177 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
18178 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
18180 getSema().ActOnTemplateName(
18181 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
18182 /*EnteringContext=*/false, Template, AllowInjectedClassName);
18183 return Template.get();
18184}
18185
18186template <typename Derived>
18189 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
18190 Expr *Second) {
18191 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
18192
18193 if (First->getObjectKind() == OK_ObjCProperty) {
18196 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
18197 Opc, First, Second);
18198 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
18199 if (Result.isInvalid())
18200 return ExprError();
18201 First = Result.get();
18202 }
18203
18204 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
18205 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
18206 if (Result.isInvalid())
18207 return ExprError();
18208 Second = Result.get();
18209 }
18210
18211 // Determine whether this should be a builtin operation.
18212 if (Op == OO_Subscript) {
18213 if (!First->getType()->isOverloadableType() &&
18214 !Second->getType()->isOverloadableType())
18215 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
18216 OpLoc);
18217 } else if (Op == OO_Arrow) {
18218 // It is possible that the type refers to a RecoveryExpr created earlier
18219 // in the tree transformation.
18220 if (First->getType()->isDependentType())
18221 return ExprError();
18222 // -> is never a builtin operation.
18223 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
18224 } else if (Second == nullptr || isPostIncDec) {
18225 if (!First->getType()->isOverloadableType() ||
18226 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
18227 // The argument is not of overloadable type, or this is an expression
18228 // of the form &Class::member, so try to create a built-in unary
18229 // operation.
18231 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18232
18233 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
18234 }
18235 } else {
18236 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
18237 !First->getType()->isOverloadableType() &&
18238 !Second->getType()->isOverloadableType()) {
18239 // Neither of the arguments is type-dependent or has an overloadable
18240 // type, so try to create a built-in binary operation.
18243 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
18244 if (Result.isInvalid())
18245 return ExprError();
18246
18247 return Result;
18248 }
18249 }
18250
18251 // Create the overloaded operator invocation for unary operators.
18252 if (!Second || isPostIncDec) {
18254 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18255 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
18256 RequiresADL);
18257 }
18258
18259 // Create the overloaded operator invocation for binary operators.
18261 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
18262 First, Second, RequiresADL);
18263 if (Result.isInvalid())
18264 return ExprError();
18265
18266 return Result;
18267}
18268
18269template<typename Derived>
18272 SourceLocation OperatorLoc,
18273 bool isArrow,
18274 CXXScopeSpec &SS,
18275 TypeSourceInfo *ScopeType,
18276 SourceLocation CCLoc,
18277 SourceLocation TildeLoc,
18278 PseudoDestructorTypeStorage Destroyed) {
18279 QualType CanonicalBaseType = Base->getType().getCanonicalType();
18280 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
18281 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
18282 (isArrow && isa<PointerType>(CanonicalBaseType) &&
18283 !cast<PointerType>(CanonicalBaseType)
18284 ->getPointeeType()
18285 ->getAsCanonical<RecordType>())) {
18286 // This pseudo-destructor expression is still a pseudo-destructor.
18287 return SemaRef.BuildPseudoDestructorExpr(
18288 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
18289 CCLoc, TildeLoc, Destroyed);
18290 }
18291
18292 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
18293 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
18294 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
18295 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
18296 NameInfo.setNamedTypeInfo(DestroyedType);
18297
18298 // The scope type is now known to be a valid nested name specifier
18299 // component. Tack it on to the nested name specifier.
18300 if (ScopeType) {
18301 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
18302 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
18303 diag::err_expected_class_or_namespace)
18304 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
18305 return ExprError();
18306 }
18307 SS.clear();
18308 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
18309 }
18310
18311 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
18312 return getSema().BuildMemberReferenceExpr(
18313 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
18314 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
18315 /*TemplateArgs*/ nullptr,
18316 /*S*/ nullptr);
18317}
18318
18319template<typename Derived>
18322 SourceLocation Loc = S->getBeginLoc();
18323 CapturedDecl *CD = S->getCapturedDecl();
18324 unsigned NumParams = CD->getNumParams();
18325 unsigned ContextParamPos = CD->getContextParamPosition();
18327 for (unsigned I = 0; I < NumParams; ++I) {
18328 if (I != ContextParamPos) {
18329 Params.push_back(
18330 std::make_pair(
18331 CD->getParam(I)->getName(),
18332 getDerived().TransformType(CD->getParam(I)->getType())));
18333 } else {
18334 Params.push_back(std::make_pair(StringRef(), QualType()));
18335 }
18336 }
18337 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
18338 S->getCapturedRegionKind(), Params);
18339 StmtResult Body;
18340 {
18341 Sema::CompoundScopeRAII CompoundScope(getSema());
18342 Body = getDerived().TransformStmt(S->getCapturedStmt());
18343 }
18344
18345 if (Body.isInvalid()) {
18346 getSema().ActOnCapturedRegionError();
18347 return StmtError();
18348 }
18349
18350 return getSema().ActOnCapturedRegionEnd(Body.get());
18351}
18352
18353template <typename Derived>
18356 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
18357 // function definition or instantiation of a function template specialization
18358 // and will therefore never appear in a dependent context.
18359 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
18360 "context");
18361}
18362
18363template <typename Derived>
18365 // We can transform the base expression and allow argument resolution to fill
18366 // in the rest.
18367 return getDerived().TransformExpr(E->getArgLValue());
18368}
18369
18370} // end namespace clang
18371
18372#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
TokenType getType() const
Returns the token's type, e.g.
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
Result
Implement __builtin_bit_cast and related operations.
#define X(type, name)
Definition Value.h:97
llvm::MachO::Record Record
Definition MachO.h:31
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
llvm::json::Object Object
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for expressions involving.
This file declares semantic analysis for SYCL constructs.
static bool PreparePackForExpansion(Sema &S, const CXXBaseSpecifier &Base, const MultiLevelTemplateArgumentList &TemplateArgs, TypeSourceInfo *&Out, UnexpandedInfo &Info)
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
static QualType getPointeeType(const MemRegion *R)
This represents clause 'map' in the 'pragma omp ...' directives.
This represents clauses with a list of expressions that are mappable. Examples of these clauses are '...
This represents 'pragma omp metadirective' directive.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
QualType 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>.
QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr, QualType Wrapped) const
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
PtrTy get() const
Definition Ownership.h:171
bool isInvalid() const
Definition Ownership.h:167
bool isUsable() const
Definition Ownership.h:169
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4561
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6038
Represents a loop initializing the elements of an array.
Definition Expr.h:5985
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:7236
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2732
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:2999
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3037
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3039
Expr * getDimensionExpression() const
Definition ExprCXX.h:3049
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3045
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3036
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3836
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6750
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6945
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2704
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2212
Stmt * getSubStmt()
Definition Stmt.h:2248
SourceLocation getAttrLoc() const
Definition Stmt.h:2243
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2244
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:4464
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4049
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2189
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4185
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2151
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8356
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4806
void setIsVariadic(bool value)
Definition Decl.h:4882
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6689
Wrapper for source info for block pointers.
Definition TypeLoc.h:1557
BreakStmt - This represents a break.
Definition Stmt.h:3144
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5475
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5494
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5493
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:3980
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:237
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition ExprCXX.h:607
Represents binding an expression to a temporary.
Definition ExprCXX.h:1496
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:726
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:29
A C++ const_cast expression (C++ [expr.const.cast]).
Definition ExprCXX.h:569
Represents a call to a C++ constructor.
Definition ExprCXX.h:1551
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1732
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1694
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1644
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.cpp:586
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.cpp:580
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1633
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1691
Represents a C++ constructor within a class.
Definition DeclCXX.h:2637
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1273
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1046
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1380
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2629
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3869
Represents a C++ destructor within a class.
Definition DeclCXX.h:2902
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:484
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5557
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:5031
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:1834
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1754
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:182
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:378
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:409
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:416
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:412
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2358
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4308
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:771
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5140
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2748
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1874
Represents a C++26 reflect expression [expr.reflect].
Definition ExprCXX.h:5507
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:529
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:289
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2199
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:76
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition DeclSpec.cpp:51
char * location_data() const
Retrieve the data associated with the source-location information.
Definition DeclSpec.h:209
SourceRange getRange() const
Definition DeclSpec.h:82
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition DeclSpec.cpp:75
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition DeclSpec.h:97
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition DeclSpec.cpp:123
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition DeclSpec.h:213
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition DeclSpec.cpp:62
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition DeclSpec.cpp:85
bool isEmpty() const
No scope specifier.
Definition DeclSpec.h:181
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition DeclSpec.cpp:103
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:803
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1902
Represents the this expression in C++.
Definition ExprCXX.h:1157
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1211
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:851
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3743
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3787
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3798
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3781
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3792
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3801
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1071
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2954
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1523
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:5078
unsigned getNumParams() const
Definition Decl.h:5116
unsigned getContextParamPosition() const
Definition Decl.h:5145
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5118
This captures a statement into a function.
Definition Stmt.h:3946
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1493
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4050
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4141
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition Stmt.cpp:1508
CaseStmt - Represent a case statement.
Definition Stmt.h:1929
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:1988
Expr * getSubExpr()
Definition Expr.h:3737
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4859
Represents a 'co_await' expression.
Definition ExprCXX.h:5368
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4311
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3616
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1749
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1799
body_range body()
Definition Stmt.h:1812
SourceLocation getLBracLoc() const
Definition Stmt.h:1866
bool hasStoredFPFeatures() const
Definition Stmt.h:1796
Stmt * body_back()
Definition Stmt.h:1817
SourceLocation getRBracLoc() const
Definition Stmt.h:1867
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const TypeClass * getTypePtr() const
Definition TypeLoc.h:433
ConditionalOperator - The ?
Definition Expr.h:4402
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3874
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1093
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4501
ContinueStmt - This represents a continue.
Definition Stmt.h:3128
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4730
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:3516
Represents a 'co_yield' expression.
Definition ExprCXX.h:5449
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:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
DeclContextLookupResult lookup_result
Definition DeclBase.h:2607
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
void addDecl(Decl *D)
Add the declaration D into this context.
bool isExpansionStmt() const
Definition DeclBase.h:2215
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1281
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1640
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInvalidDecl() const
Definition DeclBase.h:596
SourceLocation getLocation() const
Definition DeclBase.h:447
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
The name of a declaration.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1952
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2319
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2544
DeferStmt - This represents a deferred statement.
Definition Stmt.h:3245
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:4175
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5400
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2612
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3509
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3583
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3557
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3575
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3593
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3567
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3610
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3548
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3603
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3545
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4125
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2127
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4215
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4587
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2099
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4341
Represents a single C99 designator.
Definition Expr.h:5611
Represents a C99 designated initializer expression.
Definition Expr.h:5568
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:893
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2841
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition TypeBase.h:5141
Expr * getCondition() const
Definition TypeBase.h:5148
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:744
Represents a reference to emded data.
Definition Expr.h:5146
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:3961
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3660
This represents one expression.
Definition Expr.h:112
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3093
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3225
QualType getType() const
Definition Expr.h:144
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:526
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:437
An expression trait intrinsic.
Definition ExprCXX.h:3072
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6627
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3294
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2897
Represents a function declaration or definition.
Definition Decl.h:2058
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2904
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5389
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:5034
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5803
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5789
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5255
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4999
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4840
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
param_type_iterator param_type_begin() const
Definition TypeBase.h:5865
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:4643
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3455
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4934
Represents a C11 generic selection.
Definition Expr.h:6199
AssociationTy< false > Association
Definition Expr.h:6432
GotoStmt - This represents a direct goto.
Definition Stmt.h:2978
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:7414
One of these records is kept for each identifier that is lexed.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2268
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1742
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3864
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6074
Represents a C array with an unspecified size.
Definition TypeBase.h:4023
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3017
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Describes an C or C++ initializer list.
Definition Expr.h:5319
InitListExpr * getSyntacticForm() const
Definition Expr.h:5489
Wrapper for source info for injected class names of class templates.
Definition TypeLoc.h:872
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2155
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1971
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1370
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1365
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1374
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2036
void setAttrNameLoc(SourceLocation Loc)
Definition TypeLoc.h:1373
Represents a placeholder type for late-parsed type attributes.
Definition TypeBase.h:3575
Represents the results of name lookup.
Definition Lookup.h:147
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3674
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:4374
A member reference to an MSPropertyDecl.
Definition ExprCXX.h:939
MS property subscript expression.
Definition ExprCXX.h:1009
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:4919
MatrixSingleSubscriptExpr - Matrix single subscript expression for the MatrixType extension when you ...
Definition Expr.h:2806
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2876
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2156
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3375
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:3767
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition Template.h:76
This represents a decl that may have a name.
Definition Decl.h:274
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents C++ namespaces and their aliases.
Definition Decl.h:573
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h:5894
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1712
This represents the 'align' clause in the 'pragma omp allocate' directive.
This represents clause 'allocate' in the 'pragma omp ...' directives.
This represents 'allocator' clause in the 'pragma omp ...' directive.
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition ExprOpenMP.h:24
This is a basic class for representing single OpenMP clause.
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
This represents 'collapse' clause in the 'pragma omp ...' directive.
This represents the 'counts' clause in the 'pragma omp split' directive.
This represents 'default' clause in the 'pragma omp ...' directive.
This represents 'final' clause in the 'pragma omp ...' directive.
Representation of the 'full' clause of the 'pragma omp unroll' directive.
This represents 'if' clause in the 'pragma omp ...' directive.
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition ExprOpenMP.h:151
This class represents the 'looprange' clause in the 'pragma omp fuse' directive.
This represents 'num_threads' clause in the 'pragma omp ...' directive.
Representation of the 'partial' clause of the 'pragma omp unroll' directive.
This class represents the 'permutation' clause in the 'pragma omp interchange' directive.
This represents 'safelen' clause in the 'pragma omp ...' directive.
This represents 'simdlen' clause in the 'pragma omp ...' directive.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
This represents 'threadset' clause in the 'pragma omp task ...' directive.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:220
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
A runtime availability query.
Definition ExprObjC.h:1736
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:119
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:159
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1676
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:342
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:441
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition ExprObjC.h:1615
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:1531
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:582
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:973
@ SuperInstance
The receiver is the instance of the superclass object.
Definition ExprObjC.h:987
@ Instance
The receiver is an object instance.
Definition ExprObjC.h:981
@ SuperClass
The receiver is a superclass.
Definition ExprObjC.h:984
@ Class
The receiver is a class.
Definition ExprObjC.h:978
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:650
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:538
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:486
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:84
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition ExprObjC.h:872
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:2437
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2441
@ Field
A field.
Definition Expr.h:2439
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2444
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:1189
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1239
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2101
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:3131
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3283
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3265
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3244
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3257
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3253
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3323
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3230
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3329
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3241
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3273
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3280
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4362
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2664
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2660
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2676
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2347
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2193
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2218
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2222
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1442
Represents a parameter to a function.
Definition Decl.h:1819
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1879
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1852
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.cpp:2944
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2756
PipeType - OpenCL20.
Definition TypeBase.h:8322
bool isReadOnly() const
Definition TypeBase.h:8352
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:3408
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2016
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2697
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6821
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:8504
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8536
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:7520
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3687
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3703
Represents the body of a requires-expression.
Definition DeclCXX.h:2114
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition DeclCXX.cpp:2405
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3169
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition Stmt.cpp:1361
Represents a __leave statement.
Definition Stmt.h:3907
SYCLKernelCallStmt represents the transformation that is applied to the body of a function declared w...
Definition StmtSYCL.h:36
Smart pointer class that efficiently represents Objective-C method names.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
bool diagnoseMatrixLayoutInstantiation(attr::Kind K, QualType T, SourceLocation Loc)
VarDecl * BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, bool Invalid=false)
Build a type-check a new Objective-C exception variable declaration.
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
Definition SemaObjC.cpp:36
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
Definition SemaObjC.cpp:193
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition SemaObjC.cpp:320
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression.
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
Definition SemaObjC.cpp:218
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition SemaObjC.cpp:213
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition SemaObjC.cpp:238
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition SemaObjC.cpp:282
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
Definition SemaObjC.cpp:202
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition SemaObjC.cpp:329
ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
Build an ObjC subscript pseudo-object expression, given that that's supported by the runtime.
Helper type for the registration/assignment of constructs that need to 'know' about their parent cons...
Helper type to restore the state of various 'loop' constructs when we run into a loop (for,...
A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...
void ActOnWhileStmt(SourceLocation WhileLoc)
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, OpenACCAtomicKind AK, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)
void ActOnForStmtBegin(SourceLocation ForLoc, const Stmt *First, const Stmt *Second, const Stmt *Third)
ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)
Checks and creates an Array Section used in an OpenACC construct/clause.
OMPClause * ActOnOpenMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nocontext' clause.
OMPClause * ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
OMPClause * ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'safelen' clause.
OMPClause * ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'holds' clause.
OMPClause * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPCountsClause(ArrayRef< Expr * > CountExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, std::optional< unsigned > FillIdx, SourceLocation FillLoc, unsigned FillCount)
Called on well-formed 'counts' clause after parsing its arguments.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
Called on well-form 'looprange' clause after parsing its arguments.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, OpenMPUseDevicePtrFallbackModifier FallbackModifier, SourceLocation FallbackModifierLoc)
Called on well-formed 'use_device_ptr' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Condition)
Called on well-formed 'nowait' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * 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 * ActOnOpenMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier M1, OpenMPDynGroupprivateClauseFallbackModifier M2, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation EndLoc)
Called on a well-formed 'dyn_groupprivate' clause.
void StartOpenMPDSABlock(OpenMPDirectiveKind K, const DeclarationNameInfo &DirName, Scope *CurScope, SourceLocation Loc)
Called on start of new data sharing attribute block.
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' clause.
OMPClause * ActOnOpenMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Called on well-formed 'linear' clause.
OMPClause * ActOnOpenMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'defaultmap' clause.
OMPClause * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPVarListDataTy::OpenMPReductionClauseModifiers Modifiers, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'reduction' clause.
OMPClause * ActOnOpenMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'aligned' clause.
OMPClause * ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depobj' pseudo clause.
OMPClause * ActOnOpenMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'novariants' clause.
OMPClause * ActOnOpenMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyprivate' clause.
OMPClause * ActOnOpenMPCollapseClause(Expr *NumForLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'collapse' clause.
OMPClause * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind M, SourceLocation MLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCKindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' clause.
OMPClause * ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'align' clause.
OMPClause * ActOnOpenMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_attribute' clause.
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body, Expr *LaunchIdExpr)
Builds a SYCLKernelCallStmt to wrap 'Body' and to be used as the body of 'FD'.
Definition SemaSYCL.cpp:774
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition SemaSYCL.cpp:154
RAII object used to change the argument pack substitution index within a Sema object.
Definition Sema.h:13729
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8453
A RAII object to enter scope of a compound statement.
Definition Sema.h:1314
A RAII object to temporarily push a declaration context.
Definition Sema.h:3533
A helper class for building up ExtParameterInfos.
Definition Sema.h:13098
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:13117
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:13105
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:14119
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:864
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:9351
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9359
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9354
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:1532
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:7847
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7849
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7848
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:6945
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:439
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Definition SemaStmt.cpp:486
StmtResult BuildNonEnumeratingCXXExpansionStmtPattern(CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVarStmt, Expr *ExpansionInitializer, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition Sema.h:1557
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:12045
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:1305
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:933
SemaObjC & ObjC()
Definition Sema.h:1517
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:936
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *LHS, Expr *RHS, bool RequiresADL=true, bool AllowRewrittenCandidates=true, FunctionDecl *DefaultedFn=nullptr)
Create a binary operation that may resolve to an overloaded operator.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, bool DoCheckConstraintSatisfaction=true)
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, const Designation &Desig, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:84
const LangOptions & getLangOpts() const
Definition Sema.h:929
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1522
@ ReuseLambdaContextDecl
Definition Sema.h:7036
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:1482
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11847
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:1340
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:11842
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2663
void ApplyForRangeOrExpansionStatementLifetimeExtension(VarDecl *RangeVar, ArrayRef< MaterializeTemporaryExpr * > Temporaries)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1445
VarDecl * BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id)
Perform semantic analysis for the variable declaration that occurs within a C++ catch clause,...
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
ExprResult BuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index, QualType ParamType, SourceLocation loc, TemplateArgument Replacement, UnsignedOrNone PackIndex, bool Final)
ExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, CXXConstructorDecl *Constructor, MultiExprArg Exprs, bool HadMultipleCandidates, bool IsListInitialization, bool IsStdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
BuildCXXConstructExpr - Creates a complete call to a constructor, including handling of its default a...
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?
ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, const Scope *S)
Builds an expression which might be an implicit member expression.
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Definition Sema.h:6746
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6756
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6725
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6751
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition SemaStmt.cpp:76
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition Sema.h:8322
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
ExprResult BuildCXXExpansionSelectExpr(InitListExpr *Range, Expr *Idx)
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
StmtResult FinishCXXExpansionStmt(Stmt *Expansion, Stmt *Body)
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc)
Complete a lambda-expression having processed and attached the lambda body.
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition Sema.h:11095
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:586
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParen)
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition SemaCast.cpp:338
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition SemaStmt.cpp:976
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, SourceLocation RParenLoc, MultiExprArg Args, AtomicExpr::AtomicOp Op, AtomicArgumentOrder ArgOrder=AtomicArgumentOrder::API)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
OpaquePtr< TemplateName > TemplateTy
Definition Sema.h:1297
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:7833
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:437
SemaPseudoObject & PseudoObject()
Definition Sema.h:1542
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:1296
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:591
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:552
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition Sema.h:8666
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:4654
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4440
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4502
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4525
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1715
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4530
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4499
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4505
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4508
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5037
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5097
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:4606
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:1502
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:1810
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:4663
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4753
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:2518
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3851
SourceLocation getNameLoc() const
Definition TypeLoc.h:822
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:801
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:809
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition TypeLoc.h:816
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:824
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:805
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
const TemplateArgumentLoc * operator->() const
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
TemplateArgumentLocContainerIterator operator++(int)
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator & operator++()
const TemplateArgumentLoc * operator->() const
Iterator adaptor that invents template argument location information for each of the template argumen...
TemplateArgumentLocInventIterator & operator++()
std::iterator_traits< InputIterator >::difference_type difference_type
TemplateArgumentLocInventIterator operator++(int)
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DeducedTemplateStorage * getAsDeducedTemplateName() const
Retrieve the deduced template info, if any.
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NestedNameSpecifier getQualifier() const
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceLocation getLAngleLoc() const
Definition TypeLoc.h: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:105
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(const TemporaryBase &)=delete
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
TemporaryBase & operator=(const TemporaryBase &)=delete
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
TemplateArgument TransformNamedTemplateTemplateArgument(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, TemplateName Name, SourceLocation NameLoc)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
StmtResult RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult TransformLambdaConstraint(Expr *AC)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TagDecl *Tag)
Build a new class/struct/union/enum type.
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
OMPClause * RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'use' clause.
StmtResult RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL)
Transform the given type-with-location into a new type, collecting location information in the given ...
ExprResult RebuildCXXRewrittenBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opcode, const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS)
Build a new rewritten operator expression.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new expression pack expansion.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
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)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc, bool IsExplicit)
Build a new initializer list expression.
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth)
Build a new GNU statement expression.
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
OMPClause * RebuildOpenMPTransparentClause(Expr *ImpexType, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
OMPClause * RebuildOMPNowaitClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nowait' clause.
QualType TransformType(QualType T)
Transforms the given type into another type.
UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(ArrayRef< TemplateArgument > PackArgs)
OMPClause * RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc)
Build a new OpenMP 'order' clause.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
ExprResult TransformRequiresTypeParams(SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > Params, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > &TransParams, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a requires expresison into the given vectors.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
StmtResult RebuildOpenACCWaitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
OMPClause * RebuildOMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
OMPClause * RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nocontext' clause.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorKind VecKind)
Build a new vector type given the element type and number of elements.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
QualType RebuildAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
QualType RebuildMemberPointerType(QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the qualifier it refers into.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCCacheConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation EndLoc)
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier M1, OpenMPDynGroupprivateClauseFallbackModifier M2, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation EndLoc)
Build a new OpenMP 'dyn_groupprivate' clause.
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed)
Transforms the parameters of a function type into the given vectors.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Build a new inline asm statement.
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateName Name)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool SuppressObjCLifetime)
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
StmtResult TransformSEHHandler(Stmt *Handler)
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, OverloadedOperatorKind Operator, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the overloaded operator name that is refe...
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation.
concepts::TypeRequirement * TransformTypeRequirement(concepts::TypeRequirement *Req)
const Derived & getDerived() const
Retrieves a reference to the derived class.
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
ExprResult RebuildMatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, SourceLocation RBracketLoc)
Build a new matrix single subscript expression.
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS, bool ForFoldExpression=false)
Build a new binary operator expression.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
OMPClause * RebuildOMPCountsClause(ArrayRef< Expr * > Counts, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, std::optional< unsigned > FillIdx, SourceLocation FillLoc)
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs, QualType Type)
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, LambdaScopeInfo *LSI)
QualType RebuildIncompleteArrayType(QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers.
CXXRecordDecl::LambdaDependencyKind ComputeLambdaDependency(LambdaScopeInfo *LSI)
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool FullySubstituted=false)
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc, bool ListInitialization)
Build a new C++ functional-style cast expression.
QualType RebuildCanonicalTagType(TagDecl *Tag)
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
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.
QualType RebuildDependentSizedArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression,...
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPClause * RebuildOMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'inclusive' clause.
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S)
This is mostly the same as above, but allows 'informational' class directives when rebuilding the stm...
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
OMPClause * RebuildOMPTransparentClause(Expr *ImpexTypeArg, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
Build a new C++1z fold-expression.
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
OMPClause * RebuildOMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
bool PreparePackForExpansion(TemplateArgumentLoc In, bool Uneval, TemplateArgumentLoc &Out, UnexpandedInfo &Info)
Checks if the argument pack from In will need to be expanded and does the necessary prework.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
QualType RebuildUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, UsingShadowDecl *D, QualType UnderlyingType)
Build a new type found via an alias.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=StmtDiscardKind::Discarded)
Transform the given statement.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
ExprResult RebuildExtVectorOrMatrixElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector or matrix element access expression.
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
OMPClause * RebuildOMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_addr' clause.
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc)
Build a dependent bit-precise int given its value type.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
OMPClause * RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'severity' clause.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, IdentifierOrOverloadedOperator IO, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
concepts::NestedRequirement * TransformNestedRequirement(concepts::NestedRequirement *Req)
QualType RebuildConstantArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array,...
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketsRanges)
Build a new array shaping expression.
MultiLevelTemplateArgumentList ForgetSubstitution()
"Forget" the template substitution to allow transforming the AST without any template instantiations.
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'is_device_ptr' clause.
QualType RebuildMacroQualifiedType(QualType T, const IdentifierInfo *MacroII)
Build a new MacroDefined type.
concepts::NestedRequirement * RebuildNestedRequirement(Expr *Constraint)
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBracketLoc)
Build a new matrix subscript expression.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL)
QualType RebuildTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, const Designation &Desig, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, VectorKind)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
bool AllowSkippingCXXConstructExpr()
Wether CXXConstructExpr can be skipped when they are implicit.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, SourceLocation RParenLoc)
Start building a new switch statement.
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
OMPClause * RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'filter' clause.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
QualType RebuildDeducedTemplateSpecializationType(DeducedKind DK, QualType DeducedAsType, ElaboratedTypeKeyword Keyword, TemplateName Template)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
OMPClause * RebuildOMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'bind' clause.
concepts::NestedRequirement * RebuildNestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction &Satisfaction)
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new pack expansion type.
QualType RebuildVariableArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression,...
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, TypeSourceInfo *ControllingType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with a type predicate.
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
concepts::TypeRequirement * RebuildTypeRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag)
OMPClause * RebuildOMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'permutation' clause.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< SemaOpenMP::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' clause.
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
ExprResult RebuildCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *TSI)
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
OMPClause * RebuildOMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_attribute' clause.
void RememberSubstitution(MultiLevelTemplateArgumentList)
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
OMPClause * RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'init' clause.
OMPClause * RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'detach' clause.
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, NamedDecl *Found, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known),...
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL)
Build a new qualified type given its unqualified type and type location.
OMPClause * RebuildOMPDependClause(OMPDependClause::DependDataTy Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
unsigned TransformTemplateDepth(unsigned Depth)
Transform a template parameter depth level.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType RebuildTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TypedefNameDecl *Typedef)
Build a new typedef type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, OpenMPUseDevicePtrFallbackModifier FallbackModifier, SourceLocation FallbackModifierLoc)
Build a new OpenMP 'use_device_ptr' clause.
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new template argument pack expansion.
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns)
Build a new matrix type given the element type and dimensions.
OMPClause * RebuildOMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'map' clause.
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ __builtin_bit_cast expression.
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt)
Build a new OpenMP Canonical loop.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
concepts::ExprRequirement * RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
TypeSourceInfo * TransformType(TypeSourceInfo *TSI)
Transforms the given type-with-location into a new type-with-location.
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
OMPClause * RebuildOMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'full' clause.
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
OMPClause * RebuildOMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Build a new OpenMP 'affinity' clause.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast.
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with an expression predicate.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool SuppressObjCLifetime)
Derived & getDerived()
Retrieves a reference to the derived class.
OMPClause * RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'holds' clause.
StmtResult RebuildOpenACCAtomicConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, OpenACCAtomicKind AtKind, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssociatedStmt)
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
concepts::ExprRequirement * TransformExprRequirement(concepts::ExprRequirement *Req)
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, TypeOfKind Kind)
Build a new typeof(expr) type.
bool ReplacingOriginal()
Whether the transformation is forming an expression or statement that replaces the original.
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, OpenMPOriginalSharingModifier OriginalSharingModifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
void transformedLocalDecl(Decl *Old, ArrayRef< Decl * > New)
Note that a local declaration has been transformed by this transformer.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
bool TransformRequiresExprRequirements(ArrayRef< concepts::Requirement * > Reqs, llvm::SmallVectorImpl< concepts::Requirement * > &Transformed)
TemplateName TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument.
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Build a new requires expression.
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
OMPClause * RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'doacross' clause.
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
ExprResult RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index, QualType ParamType, SourceLocation Loc, TemplateArgument Arg, UnsignedOrNone PackIndex, bool Final)
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
bool TransformConceptTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
TypeLoc getTypeLocInContext(ASTContext &Context, QualType T)
Copies the type-location information to the given AST context and returns a TypeLoc referring into th...
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
Definition TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition TypeLoc.h:349
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition TypeLoc.h:133
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:89
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition TypeLoc.h:78
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition TypeLoc.h:154
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition TypeLoc.h:165
TypeLocClass getTypeLocClass() const
Definition TypeLoc.h:116
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:2766
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition TypeBase.h:6332
A container of type source information.
Definition TypeBase.h:8475
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:8486
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:2899
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:9263
bool isObjCObjectPointerType() const
Definition TypeBase.h:8920
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9340
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3696
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2231
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2636
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2255
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2300
Expr * getSubExpr() const
Definition Expr.h:2296
Opcode getOpcode() const
Definition Expr.h:2291
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1421
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2375
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1039
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:3389
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3463
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3458
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:437
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4125
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:6137
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition ExprCXX.h:643
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3424
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3488
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:4968
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5656
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:932
@ CInit
C-style initialization with assignment.
Definition Decl.h:937
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:940
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4080
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2076
Represents a GCC generic vector type.
Definition TypeBase.h:4289
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2706
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Retains information about a block that is currently being parsed.
Definition ScopeInfo.h:791
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition ScopeInfo.h:729
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition ScopeInfo.h:872
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition ScopeInfo.h:875
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
VE builtins.
const AstTypeMatcher< FunctionType > functionType
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
Definition Interp.h:987
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
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
TryCaptureKind
Definition Sema.h:648
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition Lookup.h:64
@ NotFound
No entity found met the criteria.
Definition Lookup.h:41
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition Lookup.h:54
@ Found
Name lookup found a single declaration that met the criteria.
Definition Lookup.h:50
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition Lookup.h:59
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition Lookup.h:46
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition Specifiers.h:40
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
CXXConstructionKind
Definition ExprCXX.h:1543
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition Specifiers.h:162
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition Lambda.h:37
@ LCK_StarThis
Capturing the *this object by copy.
Definition Lambda.h:35
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition Sema.h:599
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:244
@ 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.
Expr * Cond
};
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
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:3833
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
@ Template
We are parsing a template declaration.
Definition Parser.h:81
ActionResult< CXXBaseSpecifier * > BaseResult
Definition Ownership.h:252
OpenMPGrainsizeClauseModifier
OpenMPNumTasksClauseModifier
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6045
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:557
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:136
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:140
OpenMPThreadLimitClauseModifier
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition Sema.h:807
@ Exists
The symbol exists.
Definition Sema.h:800
@ Error
An error occurred.
Definition Sema.h:810
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:803
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:846
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:5024
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6020
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6041
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6031
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6038
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:2248
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:2000
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
ActionResult< Stmt * > StmtResult
Definition Ownership.h:250
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5158
Holds information about the various types of exception specification.
Definition TypeBase.h:5478
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5494
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5480
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5483
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5486
Extra information about a function prototype.
Definition TypeBase.h:5506
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5511
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3432
const NamespaceBaseDecl * Namespace
Iterator range representation begin:end[:step].
Definition ExprOpenMP.h:154
This structure contains most locations needed for by an OMPVarListClause.
An element in an Objective-C dictionary literal.
Definition ExprObjC.h:295
Data for list of allocators.
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition Sema.h:13178
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13209
bool InLifetimeExtendingContext
Whether we are currently in a context in which all temporaries must be lifetime-extended,...
Definition Sema.h:6867
SmallVector< MaterializeTemporaryExpr *, 8 > ForRangeLifetimeExtendTemps
P2718R0 - Lifetime extension in range-based for loops.
Definition Sema.h:6835
bool RebuildDefaultArgOrDefaultInit
Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
Definition Sema.h:6873
ExpressionEvaluationContext Context
The expression evaluation context.
Definition Sema.h:6783
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1329
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3333
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions