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>
10285 DeclarationNameInfo DirName;
10286 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10287 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
10288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10289 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10290 return Res;
10291}
10292
10293template <typename Derived>
10296 DeclarationNameInfo DirName;
10297 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10298 OMPD_atomic, 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_target, 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>
10317 OMPTargetDataDirective *D) {
10318 DeclarationNameInfo DirName;
10319 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10320 OMPD_target_data, 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 OMPTargetEnterDataDirective *D) {
10329 DeclarationNameInfo DirName;
10330 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10331 OMPD_target_enter_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 OMPTargetExitDataDirective *D) {
10340 DeclarationNameInfo DirName;
10341 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10342 OMPD_target_exit_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 OMPTargetParallelDirective *D) {
10351 DeclarationNameInfo DirName;
10352 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10353 OMPD_target_parallel, 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 OMPTargetParallelForDirective *D) {
10362 DeclarationNameInfo DirName;
10363 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10364 OMPD_target_parallel_for, 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 OMPTargetUpdateDirective *D) {
10373 DeclarationNameInfo DirName;
10374 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10375 OMPD_target_update, 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>
10384 DeclarationNameInfo DirName;
10385 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10386 OMPD_teams, 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>
10394 OMPCancellationPointDirective *D) {
10395 DeclarationNameInfo DirName;
10396 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10397 OMPD_cancellation_point, 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>
10406 DeclarationNameInfo DirName;
10407 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10408 OMPD_cancel, 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_taskloop, 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>
10427 OMPTaskLoopSimdDirective *D) {
10428 DeclarationNameInfo DirName;
10429 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10430 OMPD_taskloop_simd, 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 OMPMasterTaskLoopDirective *D) {
10439 DeclarationNameInfo DirName;
10440 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10441 OMPD_master_taskloop, 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 OMPMaskedTaskLoopDirective *D) {
10450 DeclarationNameInfo DirName;
10451 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10452 OMPD_masked_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 OMPMasterTaskLoopSimdDirective *D) {
10461 DeclarationNameInfo DirName;
10462 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10463 OMPD_master_taskloop_simd, 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 OMPMaskedTaskLoopSimdDirective *D) {
10472 DeclarationNameInfo DirName;
10473 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10474 OMPD_masked_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 OMPParallelMasterTaskLoopDirective *D) {
10483 DeclarationNameInfo DirName;
10484 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10485 OMPD_parallel_master_taskloop, 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 OMPParallelMaskedTaskLoopDirective *D) {
10494 DeclarationNameInfo DirName;
10495 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10496 OMPD_parallel_masked_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>
10505 OMPParallelMasterTaskLoopSimdDirective *D) {
10506 DeclarationNameInfo DirName;
10507 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10508 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10509 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10510 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10511 return Res;
10512}
10513
10514template <typename Derived>
10517 OMPParallelMaskedTaskLoopSimdDirective *D) {
10518 DeclarationNameInfo DirName;
10519 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10520 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10521 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10522 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10523 return Res;
10524}
10525
10526template <typename Derived>
10528 OMPDistributeDirective *D) {
10529 DeclarationNameInfo DirName;
10530 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10531 OMPD_distribute, 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 OMPDistributeParallelForDirective *D) {
10540 DeclarationNameInfo DirName;
10541 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10542 OMPD_distribute_parallel_for, 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>
10551 OMPDistributeParallelForSimdDirective *D) {
10552 DeclarationNameInfo DirName;
10553 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10554 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10555 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10556 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10557 return Res;
10558}
10559
10560template <typename Derived>
10562 OMPDistributeSimdDirective *D) {
10563 DeclarationNameInfo DirName;
10564 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10565 OMPD_distribute_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 OMPTargetParallelForSimdDirective *D) {
10574 DeclarationNameInfo DirName;
10575 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10576 OMPD_target_parallel_for_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 OMPTargetSimdDirective *D) {
10585 DeclarationNameInfo DirName;
10586 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10587 OMPD_target_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 OMPTeamsDistributeDirective *D) {
10596 DeclarationNameInfo DirName;
10597 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10598 OMPD_teams_distribute, 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 OMPTeamsDistributeSimdDirective *D) {
10607 DeclarationNameInfo DirName;
10608 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10609 OMPD_teams_distribute_simd, 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 OMPTeamsDistributeParallelForSimdDirective *D) {
10618 DeclarationNameInfo DirName;
10619 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10620 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10621 D->getBeginLoc());
10622 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10623 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10624 return Res;
10625}
10626
10627template <typename Derived>
10629 OMPTeamsDistributeParallelForDirective *D) {
10630 DeclarationNameInfo DirName;
10631 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10632 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10633 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10634 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10635 return Res;
10636}
10637
10638template <typename Derived>
10640 OMPTargetTeamsDirective *D) {
10641 DeclarationNameInfo DirName;
10642 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10643 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10644 auto Res = getDerived().TransformOMPExecutableDirective(D);
10645 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10646 return Res;
10647}
10648
10649template <typename Derived>
10651 OMPTargetTeamsDistributeDirective *D) {
10652 DeclarationNameInfo DirName;
10653 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10654 OMPD_target_teams_distribute, 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>
10663 OMPTargetTeamsDistributeParallelForDirective *D) {
10664 DeclarationNameInfo DirName;
10665 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10666 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10667 D->getBeginLoc());
10668 auto Res = getDerived().TransformOMPExecutableDirective(D);
10669 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10670 return Res;
10671}
10672
10673template <typename Derived>
10676 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10677 DeclarationNameInfo DirName;
10678 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10679 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10680 D->getBeginLoc());
10681 auto Res = getDerived().TransformOMPExecutableDirective(D);
10682 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10683 return Res;
10684}
10685
10686template <typename Derived>
10689 OMPTargetTeamsDistributeSimdDirective *D) {
10690 DeclarationNameInfo DirName;
10691 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10692 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10693 auto Res = getDerived().TransformOMPExecutableDirective(D);
10694 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10695 return Res;
10696}
10697
10698template <typename Derived>
10701 DeclarationNameInfo DirName;
10702 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10703 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10704 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10705 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10706 return Res;
10707}
10708
10709template <typename Derived>
10712 DeclarationNameInfo DirName;
10713 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10714 OMPD_dispatch, 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_masked, 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>
10733 OMPGenericLoopDirective *D) {
10734 DeclarationNameInfo DirName;
10735 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10736 OMPD_loop, 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 OMPTeamsGenericLoopDirective *D) {
10745 DeclarationNameInfo DirName;
10746 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10747 OMPD_teams_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 OMPTargetTeamsGenericLoopDirective *D) {
10756 DeclarationNameInfo DirName;
10757 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10758 OMPD_target_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 OMPParallelGenericLoopDirective *D) {
10767 DeclarationNameInfo DirName;
10768 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10769 OMPD_parallel_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>
10778 OMPTargetParallelGenericLoopDirective *D) {
10779 DeclarationNameInfo DirName;
10780 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10781 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10782 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10783 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10784 return Res;
10785}
10786
10787//===----------------------------------------------------------------------===//
10788// OpenMP clause transformation
10789//===----------------------------------------------------------------------===//
10790template <typename Derived>
10792 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10793 if (Cond.isInvalid())
10794 return nullptr;
10795 return getDerived().RebuildOMPIfClause(
10796 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10797 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10798}
10799
10800template <typename Derived>
10802 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10803 if (Cond.isInvalid())
10804 return nullptr;
10805 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10806 C->getLParenLoc(), C->getEndLoc());
10807}
10808
10809template <typename Derived>
10810OMPClause *
10812 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10813 if (NumThreads.isInvalid())
10814 return nullptr;
10815 return getDerived().RebuildOMPNumThreadsClause(
10816 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10817 C->getModifierLoc(), C->getEndLoc());
10818}
10819
10820template <typename Derived>
10821OMPClause *
10823 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10824 if (E.isInvalid())
10825 return nullptr;
10826 return getDerived().RebuildOMPSafelenClause(
10827 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10828}
10829
10830template <typename Derived>
10831OMPClause *
10833 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10834 if (E.isInvalid())
10835 return nullptr;
10836 return getDerived().RebuildOMPAllocatorClause(
10837 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10838}
10839
10840template <typename Derived>
10841OMPClause *
10843 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10844 if (E.isInvalid())
10845 return nullptr;
10846 return getDerived().RebuildOMPSimdlenClause(
10847 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10848}
10849
10850template <typename Derived>
10852 SmallVector<Expr *, 4> TransformedSizes;
10853 TransformedSizes.reserve(C->getNumSizes());
10854 bool Changed = false;
10855 for (Expr *E : C->getSizesRefs()) {
10856 if (!E) {
10857 TransformedSizes.push_back(nullptr);
10858 continue;
10859 }
10860
10861 ExprResult T = getDerived().TransformExpr(E);
10862 if (T.isInvalid())
10863 return nullptr;
10864 if (E != T.get())
10865 Changed = true;
10866 TransformedSizes.push_back(T.get());
10867 }
10868
10869 if (!Changed && !getDerived().AlwaysRebuild())
10870 return C;
10871 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10872 C->getLParenLoc(), C->getEndLoc());
10873}
10874
10875template <typename Derived>
10876OMPClause *
10878 SmallVector<Expr *, 4> TransformedCounts;
10879 TransformedCounts.reserve(C->getNumCounts());
10880 for (Expr *E : C->getCountsRefs()) {
10881 if (!E) {
10882 TransformedCounts.push_back(nullptr);
10883 continue;
10884 }
10885
10886 ExprResult T = getDerived().TransformExpr(E);
10887 if (T.isInvalid())
10888 return nullptr;
10889 TransformedCounts.push_back(T.get());
10890 }
10891
10892 return RebuildOMPCountsClause(TransformedCounts, C->getBeginLoc(),
10893 C->getLParenLoc(), C->getEndLoc(),
10894 C->getOmpFillIndex(), C->getOmpFillLoc());
10895}
10896
10897template <typename Derived>
10898OMPClause *
10900 SmallVector<Expr *> TransformedArgs;
10901 TransformedArgs.reserve(C->getNumLoops());
10902 bool Changed = false;
10903 for (Expr *E : C->getArgsRefs()) {
10904 if (!E) {
10905 TransformedArgs.push_back(nullptr);
10906 continue;
10907 }
10908
10909 ExprResult T = getDerived().TransformExpr(E);
10910 if (T.isInvalid())
10911 return nullptr;
10912 if (E != T.get())
10913 Changed = true;
10914 TransformedArgs.push_back(T.get());
10915 }
10916
10917 if (!Changed && !getDerived().AlwaysRebuild())
10918 return C;
10919 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10920 C->getLParenLoc(), C->getEndLoc());
10921}
10922
10923template <typename Derived>
10925 if (!getDerived().AlwaysRebuild())
10926 return C;
10927 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10928}
10929
10930template <typename Derived>
10931OMPClause *
10933 ExprResult T = getDerived().TransformExpr(C->getFactor());
10934 if (T.isInvalid())
10935 return nullptr;
10936 Expr *Factor = T.get();
10937 bool Changed = Factor != C->getFactor();
10938
10939 if (!Changed && !getDerived().AlwaysRebuild())
10940 return C;
10941 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10942 C->getEndLoc());
10943}
10944
10945template <typename Derived>
10946OMPClause *
10948 ExprResult F = getDerived().TransformExpr(C->getFirst());
10949 if (F.isInvalid())
10950 return nullptr;
10951
10952 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10953 if (Cn.isInvalid())
10954 return nullptr;
10955
10956 Expr *First = F.get();
10957 Expr *Count = Cn.get();
10958
10959 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10960
10961 // If no changes and AlwaysRebuild() is false, return the original clause
10962 if (!Changed && !getDerived().AlwaysRebuild())
10963 return C;
10964
10965 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10966 C->getLParenLoc(), C->getFirstLoc(),
10967 C->getCountLoc(), C->getEndLoc());
10968}
10969
10970template <typename Derived>
10971OMPClause *
10973 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10974 if (E.isInvalid())
10975 return nullptr;
10976 return getDerived().RebuildOMPCollapseClause(
10977 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10978}
10979
10980template <typename Derived>
10981OMPClause *
10983 return getDerived().RebuildOMPDefaultClause(
10984 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10985 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10986 C->getEndLoc());
10987}
10988
10989template <typename Derived>
10990OMPClause *
10992 // No need to rebuild this clause, no template-dependent parameters.
10993 return C;
10994}
10995
10996template <typename Derived>
10997OMPClause *
10999 Expr *Impex = C->getImpexType();
11000 ExprResult TransformedImpex = getDerived().TransformExpr(Impex);
11001
11002 if (TransformedImpex.isInvalid())
11003 return nullptr;
11004
11005 return getDerived().RebuildOMPTransparentClause(
11006 TransformedImpex.get(), C->getBeginLoc(), C->getLParenLoc(),
11007 C->getEndLoc());
11008}
11009
11010template <typename Derived>
11011OMPClause *
11013 return getDerived().RebuildOMPProcBindClause(
11014 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
11015 C->getLParenLoc(), C->getEndLoc());
11016}
11017
11018template <typename Derived>
11019OMPClause *
11021 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11022 if (E.isInvalid())
11023 return nullptr;
11024 return getDerived().RebuildOMPScheduleClause(
11025 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
11026 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11027 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
11028 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11029}
11030
11031template <typename Derived>
11032OMPClause *
11034 ExprResult E;
11035 if (auto *Num = C->getNumForLoops()) {
11036 E = getDerived().TransformExpr(Num);
11037 if (E.isInvalid())
11038 return nullptr;
11039 }
11040 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
11041 C->getLParenLoc(), E.get());
11042}
11043
11044template <typename Derived>
11045OMPClause *
11047 ExprResult E;
11048 if (Expr *Evt = C->getEventHandler()) {
11049 E = getDerived().TransformExpr(Evt);
11050 if (E.isInvalid())
11051 return nullptr;
11052 }
11053 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
11054 C->getLParenLoc(), C->getEndLoc());
11055}
11056
11057template <typename Derived>
11058OMPClause *
11061 if (auto *Condition = C->getCondition()) {
11062 Cond = getDerived().TransformExpr(Condition);
11063 if (Cond.isInvalid())
11064 return nullptr;
11065 }
11066 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
11067 C->getLParenLoc(), C->getEndLoc());
11068}
11069
11070template <typename Derived>
11071OMPClause *
11073 // No need to rebuild this clause, no template-dependent parameters.
11074 return C;
11075}
11076
11077template <typename Derived>
11078OMPClause *
11080 // No need to rebuild this clause, no template-dependent parameters.
11081 return C;
11082}
11083
11084template <typename Derived>
11086 // No need to rebuild this clause, no template-dependent parameters.
11087 return C;
11088}
11089
11090template <typename Derived>
11092 // No need to rebuild this clause, no template-dependent parameters.
11093 return C;
11094}
11095
11096template <typename Derived>
11097OMPClause *
11099 // No need to rebuild this clause, no template-dependent parameters.
11100 return C;
11101}
11102
11103template <typename Derived>
11105 OMPUpdateDependObjectsClause *C) {
11106 // No need to rebuild this clause, no template-dependent parameters.
11107 return C;
11108}
11109
11110template <typename Derived>
11111OMPClause *
11113 // No need to rebuild this clause, no template-dependent parameters.
11114 return C;
11115}
11116
11117template <typename Derived>
11118OMPClause *
11120 // No need to rebuild this clause, no template-dependent parameters.
11121 return C;
11122}
11123
11124template <typename Derived>
11126 // No need to rebuild this clause, no template-dependent parameters.
11127 return C;
11128}
11129
11130template <typename Derived>
11131OMPClause *
11133 return C;
11134}
11135
11136template <typename Derived>
11138 ExprResult E = getDerived().TransformExpr(C->getExpr());
11139 if (E.isInvalid())
11140 return nullptr;
11141 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
11142 C->getLParenLoc(), C->getEndLoc());
11143}
11144
11145template <typename Derived>
11146OMPClause *
11148 return C;
11149}
11150
11151template <typename Derived>
11152OMPClause *
11154 return C;
11155}
11156template <typename Derived>
11158 OMPNoOpenMPRoutinesClause *C) {
11159 return C;
11160}
11161template <typename Derived>
11163 OMPNoOpenMPConstructsClause *C) {
11164 return C;
11165}
11166template <typename Derived>
11168 OMPNoParallelismClause *C) {
11169 return C;
11170}
11171
11172template <typename Derived>
11173OMPClause *
11175 // No need to rebuild this clause, no template-dependent parameters.
11176 return C;
11177}
11178
11179template <typename Derived>
11180OMPClause *
11182 // No need to rebuild this clause, no template-dependent parameters.
11183 return C;
11184}
11185
11186template <typename Derived>
11187OMPClause *
11189 // No need to rebuild this clause, no template-dependent parameters.
11190 return C;
11191}
11192
11193template <typename Derived>
11194OMPClause *
11196 // No need to rebuild this clause, no template-dependent parameters.
11197 return C;
11198}
11199
11200template <typename Derived>
11201OMPClause *
11203 // No need to rebuild this clause, no template-dependent parameters.
11204 return C;
11205}
11206
11207template <typename Derived>
11209 // No need to rebuild this clause, no template-dependent parameters.
11210 return C;
11211}
11212
11213template <typename Derived>
11214OMPClause *
11216 // No need to rebuild this clause, no template-dependent parameters.
11217 return C;
11218}
11219
11220template <typename Derived>
11222 // No need to rebuild this clause, no template-dependent parameters.
11223 return C;
11224}
11225
11226template <typename Derived>
11227OMPClause *
11229 // No need to rebuild this clause, no template-dependent parameters.
11230 return C;
11231}
11232
11233template <typename Derived>
11235 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
11236 if (IVR.isInvalid())
11237 return nullptr;
11238
11239 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
11240 for (OMPInitClause::PrefView P : C->prefs()) {
11241 Expr *NewFr = nullptr;
11242 if (P.Fr) {
11243 ExprResult ER = getDerived().TransformExpr(P.Fr);
11244 if (ER.isInvalid())
11245 return nullptr;
11246 NewFr = ER.get();
11247 }
11248 SmallVector<Expr *, 2> NewAttrs;
11249 NewAttrs.reserve(P.Attrs.size());
11250 for (Expr *A : P.Attrs) {
11251 ExprResult ER = getDerived().TransformExpr(A);
11252 if (ER.isInvalid())
11253 return nullptr;
11254 NewAttrs.push_back(ER.get());
11255 }
11256 InteropInfo.Prefs.emplace_back(NewFr, std::move(NewAttrs));
11257 }
11258 InteropInfo.HasPreferAttrs = C->hasPreferAttrs();
11259 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
11260 C->getBeginLoc(), C->getLParenLoc(),
11261 C->getVarLoc(), C->getEndLoc());
11262}
11263
11264template <typename Derived>
11266 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
11267 if (ER.isInvalid())
11268 return nullptr;
11269 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
11270 C->getLParenLoc(), C->getVarLoc(),
11271 C->getEndLoc());
11272}
11273
11274template <typename Derived>
11275OMPClause *
11277 ExprResult ER;
11278 if (Expr *IV = C->getInteropVar()) {
11279 ER = getDerived().TransformExpr(IV);
11280 if (ER.isInvalid())
11281 return nullptr;
11282 }
11283 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
11284 C->getLParenLoc(), C->getVarLoc(),
11285 C->getEndLoc());
11286}
11287
11288template <typename Derived>
11289OMPClause *
11291 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11292 if (Cond.isInvalid())
11293 return nullptr;
11294 return getDerived().RebuildOMPNovariantsClause(
11295 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11296}
11297
11298template <typename Derived>
11299OMPClause *
11301 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11302 if (Cond.isInvalid())
11303 return nullptr;
11304 return getDerived().RebuildOMPNocontextClause(
11305 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11306}
11307
11308template <typename Derived>
11309OMPClause *
11311 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
11312 if (ThreadID.isInvalid())
11313 return nullptr;
11314 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
11315 C->getLParenLoc(), C->getEndLoc());
11316}
11317
11318template <typename Derived>
11320 ExprResult E = getDerived().TransformExpr(C->getAlignment());
11321 if (E.isInvalid())
11322 return nullptr;
11323 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
11324 C->getLParenLoc(), C->getEndLoc());
11325}
11326
11327template <typename Derived>
11329 OMPUnifiedAddressClause *C) {
11330 llvm_unreachable("unified_address clause cannot appear in dependent context");
11331}
11332
11333template <typename Derived>
11335 OMPUnifiedSharedMemoryClause *C) {
11336 llvm_unreachable(
11337 "unified_shared_memory clause cannot appear in dependent context");
11338}
11339
11340template <typename Derived>
11342 OMPReverseOffloadClause *C) {
11343 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
11344}
11345
11346template <typename Derived>
11348 OMPDynamicAllocatorsClause *C) {
11349 llvm_unreachable(
11350 "dynamic_allocators clause cannot appear in dependent context");
11351}
11352
11353template <typename Derived>
11355 OMPAtomicDefaultMemOrderClause *C) {
11356 llvm_unreachable(
11357 "atomic_default_mem_order clause cannot appear in dependent context");
11358}
11359
11360template <typename Derived>
11361OMPClause *
11363 llvm_unreachable("self_maps clause cannot appear in dependent context");
11364}
11365
11366template <typename Derived>
11368 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
11369 C->getBeginLoc(), C->getLParenLoc(),
11370 C->getEndLoc());
11371}
11372
11373template <typename Derived>
11374OMPClause *
11376 return getDerived().RebuildOMPSeverityClause(
11377 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
11378 C->getLParenLoc(), C->getEndLoc());
11379}
11380
11381template <typename Derived>
11382OMPClause *
11384 ExprResult E = getDerived().TransformExpr(C->getMessageString());
11385 if (E.isInvalid())
11386 return nullptr;
11387 return getDerived().RebuildOMPMessageClause(
11388 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11389}
11390
11391template <typename Derived>
11392OMPClause *
11395 Vars.reserve(C->varlist_size());
11396 for (auto *VE : C->varlist()) {
11397 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11398 if (EVar.isInvalid())
11399 return nullptr;
11400 Vars.push_back(EVar.get());
11401 }
11402 return getDerived().RebuildOMPPrivateClause(
11403 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11404}
11405
11406template <typename Derived>
11408 OMPFirstprivateClause *C) {
11410 Vars.reserve(C->varlist_size());
11411 for (auto *VE : C->varlist()) {
11412 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11413 if (EVar.isInvalid())
11414 return nullptr;
11415 Vars.push_back(EVar.get());
11416 }
11417 return getDerived().RebuildOMPFirstprivateClause(
11418 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11419}
11420
11421template <typename Derived>
11422OMPClause *
11425 Vars.reserve(C->varlist_size());
11426 for (auto *VE : C->varlist()) {
11427 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11428 if (EVar.isInvalid())
11429 return nullptr;
11430 Vars.push_back(EVar.get());
11431 }
11432 return getDerived().RebuildOMPLastprivateClause(
11433 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11434 C->getLParenLoc(), C->getEndLoc());
11435}
11436
11437template <typename Derived>
11438OMPClause *
11441 Vars.reserve(C->varlist_size());
11442 for (auto *VE : C->varlist()) {
11443 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11444 if (EVar.isInvalid())
11445 return nullptr;
11446 Vars.push_back(EVar.get());
11447 }
11448 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11449 C->getLParenLoc(), C->getEndLoc());
11450}
11451
11452template <typename Derived>
11453OMPClause *
11456 Vars.reserve(C->varlist_size());
11457 for (auto *VE : C->varlist()) {
11458 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11459 if (EVar.isInvalid())
11460 return nullptr;
11461 Vars.push_back(EVar.get());
11462 }
11463 CXXScopeSpec ReductionIdScopeSpec;
11464 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11465
11466 DeclarationNameInfo NameInfo = C->getNameInfo();
11467 if (NameInfo.getName()) {
11468 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11469 if (!NameInfo.getName())
11470 return nullptr;
11471 }
11472 // Build a list of all UDR decls with the same names ranged by the Scopes.
11473 // The Scope boundary is a duplication of the previous decl.
11474 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11475 for (auto *E : C->reduction_ops()) {
11476 // Transform all the decls.
11477 if (E) {
11478 auto *ULE = cast<UnresolvedLookupExpr>(E);
11479 UnresolvedSet<8> Decls;
11480 for (auto *D : ULE->decls()) {
11481 NamedDecl *InstD =
11482 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11483 Decls.addDecl(InstD, InstD->getAccess());
11484 }
11485 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11486 SemaRef.Context, /*NamingClass=*/nullptr,
11487 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11488 /*ADL=*/true, Decls.begin(), Decls.end(),
11489 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11490 } else
11491 UnresolvedReductions.push_back(nullptr);
11492 }
11493 return getDerived().RebuildOMPReductionClause(
11494 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11495 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11496 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11497}
11498
11499template <typename Derived>
11501 OMPTaskReductionClause *C) {
11503 Vars.reserve(C->varlist_size());
11504 for (auto *VE : C->varlist()) {
11505 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11506 if (EVar.isInvalid())
11507 return nullptr;
11508 Vars.push_back(EVar.get());
11509 }
11510 CXXScopeSpec ReductionIdScopeSpec;
11511 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11512
11513 DeclarationNameInfo NameInfo = C->getNameInfo();
11514 if (NameInfo.getName()) {
11515 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11516 if (!NameInfo.getName())
11517 return nullptr;
11518 }
11519 // Build a list of all UDR decls with the same names ranged by the Scopes.
11520 // The Scope boundary is a duplication of the previous decl.
11521 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11522 for (auto *E : C->reduction_ops()) {
11523 // Transform all the decls.
11524 if (E) {
11525 auto *ULE = cast<UnresolvedLookupExpr>(E);
11526 UnresolvedSet<8> Decls;
11527 for (auto *D : ULE->decls()) {
11528 NamedDecl *InstD =
11529 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11530 Decls.addDecl(InstD, InstD->getAccess());
11531 }
11532 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11533 SemaRef.Context, /*NamingClass=*/nullptr,
11534 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11535 /*ADL=*/true, Decls.begin(), Decls.end(),
11536 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11537 } else
11538 UnresolvedReductions.push_back(nullptr);
11539 }
11540 return getDerived().RebuildOMPTaskReductionClause(
11541 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11542 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11543}
11544
11545template <typename Derived>
11546OMPClause *
11549 Vars.reserve(C->varlist_size());
11550 for (auto *VE : C->varlist()) {
11551 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11552 if (EVar.isInvalid())
11553 return nullptr;
11554 Vars.push_back(EVar.get());
11555 }
11556 CXXScopeSpec ReductionIdScopeSpec;
11557 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11558
11559 DeclarationNameInfo NameInfo = C->getNameInfo();
11560 if (NameInfo.getName()) {
11561 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11562 if (!NameInfo.getName())
11563 return nullptr;
11564 }
11565 // Build a list of all UDR decls with the same names ranged by the Scopes.
11566 // The Scope boundary is a duplication of the previous decl.
11567 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11568 for (auto *E : C->reduction_ops()) {
11569 // Transform all the decls.
11570 if (E) {
11571 auto *ULE = cast<UnresolvedLookupExpr>(E);
11572 UnresolvedSet<8> Decls;
11573 for (auto *D : ULE->decls()) {
11574 NamedDecl *InstD =
11575 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11576 Decls.addDecl(InstD, InstD->getAccess());
11577 }
11578 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11579 SemaRef.Context, /*NamingClass=*/nullptr,
11580 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11581 /*ADL=*/true, Decls.begin(), Decls.end(),
11582 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11583 } else
11584 UnresolvedReductions.push_back(nullptr);
11585 }
11586 return getDerived().RebuildOMPInReductionClause(
11587 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11588 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11589}
11590
11591template <typename Derived>
11592OMPClause *
11595 Vars.reserve(C->varlist_size());
11596 for (auto *VE : C->varlist()) {
11597 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11598 if (EVar.isInvalid())
11599 return nullptr;
11600 Vars.push_back(EVar.get());
11601 }
11602 ExprResult Step = getDerived().TransformExpr(C->getStep());
11603 if (Step.isInvalid())
11604 return nullptr;
11605 return getDerived().RebuildOMPLinearClause(
11606 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11607 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11608 C->getEndLoc());
11609}
11610
11611template <typename Derived>
11612OMPClause *
11615 Vars.reserve(C->varlist_size());
11616 for (auto *VE : C->varlist()) {
11617 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11618 if (EVar.isInvalid())
11619 return nullptr;
11620 Vars.push_back(EVar.get());
11621 }
11622 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11623 if (Alignment.isInvalid())
11624 return nullptr;
11625 return getDerived().RebuildOMPAlignedClause(
11626 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11627 C->getColonLoc(), C->getEndLoc());
11628}
11629
11630template <typename Derived>
11631OMPClause *
11634 Vars.reserve(C->varlist_size());
11635 for (auto *VE : C->varlist()) {
11636 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11637 if (EVar.isInvalid())
11638 return nullptr;
11639 Vars.push_back(EVar.get());
11640 }
11641 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11642 C->getLParenLoc(), C->getEndLoc());
11643}
11644
11645template <typename Derived>
11646OMPClause *
11649 Vars.reserve(C->varlist_size());
11650 for (auto *VE : C->varlist()) {
11651 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11652 if (EVar.isInvalid())
11653 return nullptr;
11654 Vars.push_back(EVar.get());
11655 }
11656 return getDerived().RebuildOMPCopyprivateClause(
11657 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11658}
11659
11660template <typename Derived>
11663 Vars.reserve(C->varlist_size());
11664 for (auto *VE : C->varlist()) {
11665 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11666 if (EVar.isInvalid())
11667 return nullptr;
11668 Vars.push_back(EVar.get());
11669 }
11670 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11671 C->getLParenLoc(), C->getEndLoc());
11672}
11673
11674template <typename Derived>
11675OMPClause *
11677 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11678 if (E.isInvalid())
11679 return nullptr;
11680 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11681 C->getLParenLoc(), C->getEndLoc());
11682}
11683
11684template <typename Derived>
11685OMPClause *
11688 Expr *DepModifier = C->getModifier();
11689 if (DepModifier) {
11690 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11691 if (DepModRes.isInvalid())
11692 return nullptr;
11693 DepModifier = DepModRes.get();
11694 }
11695 Vars.reserve(C->varlist_size());
11696 for (auto *VE : C->varlist()) {
11697 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11698 if (EVar.isInvalid())
11699 return nullptr;
11700 Vars.push_back(EVar.get());
11701 }
11702 return getDerived().RebuildOMPDependClause(
11703 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11704 C->getOmpAllMemoryLoc()},
11705 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11706}
11707
11708template <typename Derived>
11709OMPClause *
11711 ExprResult E = getDerived().TransformExpr(C->getDevice());
11712 if (E.isInvalid())
11713 return nullptr;
11714 return getDerived().RebuildOMPDeviceClause(
11715 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11716 C->getModifierLoc(), C->getEndLoc());
11717}
11718
11719template <typename Derived, class T>
11722 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11723 DeclarationNameInfo &MapperIdInfo,
11724 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11725 // Transform expressions in the list.
11726 Vars.reserve(C->varlist_size());
11727 for (auto *VE : C->varlist()) {
11728 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11729 if (EVar.isInvalid())
11730 return true;
11731 Vars.push_back(EVar.get());
11732 }
11733 // Transform mapper scope specifier and identifier.
11734 NestedNameSpecifierLoc QualifierLoc;
11735 if (C->getMapperQualifierLoc()) {
11736 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11737 C->getMapperQualifierLoc());
11738 if (!QualifierLoc)
11739 return true;
11740 }
11741 MapperIdScopeSpec.Adopt(QualifierLoc);
11742 MapperIdInfo = C->getMapperIdInfo();
11743 if (MapperIdInfo.getName()) {
11744 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11745 if (!MapperIdInfo.getName())
11746 return true;
11747 }
11748 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11749 // the previous user-defined mapper lookup in dependent environment.
11750 for (auto *E : C->mapperlists()) {
11751 // Transform all the decls.
11752 if (E) {
11753 auto *ULE = cast<UnresolvedLookupExpr>(E);
11754 UnresolvedSet<8> Decls;
11755 for (auto *D : ULE->decls()) {
11756 NamedDecl *InstD =
11757 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11758 Decls.addDecl(InstD, InstD->getAccess());
11759 }
11760 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11761 TT.getSema().Context, /*NamingClass=*/nullptr,
11762 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11763 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11764 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11765 } else {
11766 UnresolvedMappers.push_back(nullptr);
11767 }
11768 }
11769 return false;
11770}
11771
11772template <typename Derived>
11773OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11774 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11776 Expr *IteratorModifier = C->getIteratorModifier();
11777 if (IteratorModifier) {
11778 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11779 if (MapModRes.isInvalid())
11780 return nullptr;
11781 IteratorModifier = MapModRes.get();
11782 }
11783 CXXScopeSpec MapperIdScopeSpec;
11784 DeclarationNameInfo MapperIdInfo;
11785 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11787 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11788 return nullptr;
11789 return getDerived().RebuildOMPMapClause(
11790 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11791 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11792 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11793}
11794
11795template <typename Derived>
11796OMPClause *
11798 Expr *Allocator = C->getAllocator();
11799 if (Allocator) {
11800 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11801 if (AllocatorRes.isInvalid())
11802 return nullptr;
11803 Allocator = AllocatorRes.get();
11804 }
11805 Expr *Alignment = C->getAlignment();
11806 if (Alignment) {
11807 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11808 if (AlignmentRes.isInvalid())
11809 return nullptr;
11810 Alignment = AlignmentRes.get();
11811 }
11813 Vars.reserve(C->varlist_size());
11814 for (auto *VE : C->varlist()) {
11815 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11816 if (EVar.isInvalid())
11817 return nullptr;
11818 Vars.push_back(EVar.get());
11819 }
11820 return getDerived().RebuildOMPAllocateClause(
11821 Allocator, Alignment, C->getFirstAllocateModifier(),
11822 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11823 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11824 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11825}
11826
11827template <typename Derived>
11828OMPClause *
11831 Vars.reserve(C->varlist_size());
11832 for (auto *VE : C->varlist()) {
11833 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11834 if (EVar.isInvalid())
11835 return nullptr;
11836 Vars.push_back(EVar.get());
11837 }
11838 Expr *ModifierExpr = C->getModifierExpr();
11839 if (ModifierExpr) {
11840 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
11841 if (EVar.isInvalid())
11842 return nullptr;
11843 ModifierExpr = EVar.get();
11844 }
11845 return getDerived().RebuildOMPNumTeamsClause(
11846 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
11847 OMPC_NUMTEAMS_unknown, nullptr, SourceLocation(), C->getBeginLoc(),
11848 C->getLParenLoc(), C->getEndLoc());
11849}
11850
11851template <typename Derived>
11852OMPClause *
11855 Vars.reserve(C->varlist_size());
11856 for (auto *VE : C->varlist()) {
11857 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11858 if (EVar.isInvalid())
11859 return nullptr;
11860 Vars.push_back(EVar.get());
11861 }
11862 Expr *ModifierExpr = C->getModifierExpr();
11863 if (ModifierExpr) {
11864 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
11865 if (EVar.isInvalid())
11866 return nullptr;
11867 ModifierExpr = EVar.get();
11868 }
11869 return getDerived().RebuildOMPThreadLimitClause(
11870 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
11871 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11872}
11873
11874template <typename Derived>
11875OMPClause *
11877 ExprResult E = getDerived().TransformExpr(C->getPriority());
11878 if (E.isInvalid())
11879 return nullptr;
11880 return getDerived().RebuildOMPPriorityClause(
11881 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11882}
11883
11884template <typename Derived>
11885OMPClause *
11887 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11888 if (E.isInvalid())
11889 return nullptr;
11890 return getDerived().RebuildOMPGrainsizeClause(
11891 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11892 C->getModifierLoc(), C->getEndLoc());
11893}
11894
11895template <typename Derived>
11896OMPClause *
11898 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11899 if (E.isInvalid())
11900 return nullptr;
11901 return getDerived().RebuildOMPNumTasksClause(
11902 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11903 C->getModifierLoc(), C->getEndLoc());
11904}
11905
11906template <typename Derived>
11908 ExprResult E = getDerived().TransformExpr(C->getHint());
11909 if (E.isInvalid())
11910 return nullptr;
11911 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11912 C->getLParenLoc(), C->getEndLoc());
11913}
11914
11915template <typename Derived>
11917 OMPDistScheduleClause *C) {
11918 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11919 if (E.isInvalid())
11920 return nullptr;
11921 return getDerived().RebuildOMPDistScheduleClause(
11922 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11923 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11924}
11925
11926template <typename Derived>
11927OMPClause *
11929 // Rebuild Defaultmap Clause since we need to invoke the checking of
11930 // defaultmap(none:variable-category) after template initialization.
11931 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11932 C->getDefaultmapKind(),
11933 C->getBeginLoc(),
11934 C->getLParenLoc(),
11935 C->getDefaultmapModifierLoc(),
11936 C->getDefaultmapKindLoc(),
11937 C->getEndLoc());
11938}
11939
11940template <typename Derived>
11942 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11944 Expr *IteratorModifier = C->getIteratorModifier();
11945 if (IteratorModifier) {
11946 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11947 if (MapModRes.isInvalid())
11948 return nullptr;
11949 IteratorModifier = MapModRes.get();
11950 }
11951 CXXScopeSpec MapperIdScopeSpec;
11952 DeclarationNameInfo MapperIdInfo;
11953 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11955 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11956 return nullptr;
11957 return getDerived().RebuildOMPToClause(
11958 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11959 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11960 UnresolvedMappers);
11961}
11962
11963template <typename Derived>
11965 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11967 Expr *IteratorModifier = C->getIteratorModifier();
11968 if (IteratorModifier) {
11969 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11970 if (MapModRes.isInvalid())
11971 return nullptr;
11972 IteratorModifier = MapModRes.get();
11973 }
11974 CXXScopeSpec MapperIdScopeSpec;
11975 DeclarationNameInfo MapperIdInfo;
11976 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11978 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11979 return nullptr;
11980 return getDerived().RebuildOMPFromClause(
11981 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11982 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11983 UnresolvedMappers);
11984}
11985
11986template <typename Derived>
11988 OMPUseDevicePtrClause *C) {
11990 Vars.reserve(C->varlist_size());
11991 for (auto *VE : C->varlist()) {
11992 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11993 if (EVar.isInvalid())
11994 return nullptr;
11995 Vars.push_back(EVar.get());
11996 }
11997 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11998 return getDerived().RebuildOMPUseDevicePtrClause(
11999 Vars, Locs, C->getFallbackModifier(), C->getFallbackModifierLoc());
12000}
12001
12002template <typename Derived>
12004 OMPUseDeviceAddrClause *C) {
12006 Vars.reserve(C->varlist_size());
12007 for (auto *VE : C->varlist()) {
12008 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12009 if (EVar.isInvalid())
12010 return nullptr;
12011 Vars.push_back(EVar.get());
12012 }
12013 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12014 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
12015}
12016
12017template <typename Derived>
12018OMPClause *
12021 Vars.reserve(C->varlist_size());
12022 for (auto *VE : C->varlist()) {
12023 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12024 if (EVar.isInvalid())
12025 return nullptr;
12026 Vars.push_back(EVar.get());
12027 }
12028 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12029 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
12030}
12031
12032template <typename Derived>
12034 OMPHasDeviceAddrClause *C) {
12036 Vars.reserve(C->varlist_size());
12037 for (auto *VE : C->varlist()) {
12038 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12039 if (EVar.isInvalid())
12040 return nullptr;
12041 Vars.push_back(EVar.get());
12042 }
12043 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12044 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
12045}
12046
12047template <typename Derived>
12048OMPClause *
12051 Vars.reserve(C->varlist_size());
12052 for (auto *VE : C->varlist()) {
12053 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12054 if (EVar.isInvalid())
12055 return nullptr;
12056 Vars.push_back(EVar.get());
12057 }
12058 return getDerived().RebuildOMPNontemporalClause(
12059 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12060}
12061
12062template <typename Derived>
12063OMPClause *
12066 Vars.reserve(C->varlist_size());
12067 for (auto *VE : C->varlist()) {
12068 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12069 if (EVar.isInvalid())
12070 return nullptr;
12071 Vars.push_back(EVar.get());
12072 }
12073 return getDerived().RebuildOMPInclusiveClause(
12074 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12075}
12076
12077template <typename Derived>
12078OMPClause *
12081 Vars.reserve(C->varlist_size());
12082 for (auto *VE : C->varlist()) {
12083 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12084 if (EVar.isInvalid())
12085 return nullptr;
12086 Vars.push_back(EVar.get());
12087 }
12088 return getDerived().RebuildOMPExclusiveClause(
12089 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12090}
12091
12092template <typename Derived>
12094 OMPUsesAllocatorsClause *C) {
12096 Data.reserve(C->getNumberOfAllocators());
12097 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
12098 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
12099 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
12100 if (Allocator.isInvalid())
12101 continue;
12102 ExprResult AllocatorTraits;
12103 if (Expr *AT = D.AllocatorTraits) {
12104 AllocatorTraits = getDerived().TransformExpr(AT);
12105 if (AllocatorTraits.isInvalid())
12106 continue;
12107 }
12108 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
12109 NewD.Allocator = Allocator.get();
12110 NewD.AllocatorTraits = AllocatorTraits.get();
12111 NewD.LParenLoc = D.LParenLoc;
12112 NewD.RParenLoc = D.RParenLoc;
12113 }
12114 return getDerived().RebuildOMPUsesAllocatorsClause(
12115 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12116}
12117
12118template <typename Derived>
12119OMPClause *
12121 SmallVector<Expr *, 4> Locators;
12122 Locators.reserve(C->varlist_size());
12123 ExprResult ModifierRes;
12124 if (Expr *Modifier = C->getModifier()) {
12125 ModifierRes = getDerived().TransformExpr(Modifier);
12126 if (ModifierRes.isInvalid())
12127 return nullptr;
12128 }
12129 for (Expr *E : C->varlist()) {
12130 ExprResult Locator = getDerived().TransformExpr(E);
12131 if (Locator.isInvalid())
12132 continue;
12133 Locators.push_back(Locator.get());
12134 }
12135 return getDerived().RebuildOMPAffinityClause(
12136 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
12137 ModifierRes.get(), Locators);
12138}
12139
12140template <typename Derived>
12142 return getDerived().RebuildOMPOrderClause(
12143 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
12144 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
12145}
12146
12147template <typename Derived>
12149 return getDerived().RebuildOMPBindClause(
12150 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
12151 C->getLParenLoc(), C->getEndLoc());
12152}
12153
12154template <typename Derived>
12156 OMPXDynCGroupMemClause *C) {
12157 ExprResult Size = getDerived().TransformExpr(C->getSize());
12158 if (Size.isInvalid())
12159 return nullptr;
12160 return getDerived().RebuildOMPXDynCGroupMemClause(
12161 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12162}
12163
12164template <typename Derived>
12166 OMPDynGroupprivateClause *C) {
12167 ExprResult Size = getDerived().TransformExpr(C->getSize());
12168 if (Size.isInvalid())
12169 return nullptr;
12170 return getDerived().RebuildOMPDynGroupprivateClause(
12171 C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(),
12172 Size.get(), C->getBeginLoc(), C->getLParenLoc(),
12173 C->getDynGroupprivateModifierLoc(),
12174 C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc());
12175}
12176
12177template <typename Derived>
12178OMPClause *
12181 Vars.reserve(C->varlist_size());
12182 for (auto *VE : C->varlist()) {
12183 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12184 if (EVar.isInvalid())
12185 return nullptr;
12186 Vars.push_back(EVar.get());
12187 }
12188 return getDerived().RebuildOMPDoacrossClause(
12189 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
12190 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12191}
12192
12193template <typename Derived>
12194OMPClause *
12197 for (auto *A : C->getAttrs())
12198 NewAttrs.push_back(getDerived().TransformAttr(A));
12199 return getDerived().RebuildOMPXAttributeClause(
12200 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12201}
12202
12203template <typename Derived>
12205 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
12206}
12207
12208//===----------------------------------------------------------------------===//
12209// OpenACC transformation
12210//===----------------------------------------------------------------------===//
12211namespace {
12212template <typename Derived>
12213class OpenACCClauseTransform final
12214 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
12215 TreeTransform<Derived> &Self;
12216 ArrayRef<const OpenACCClause *> ExistingClauses;
12217 SemaOpenACC::OpenACCParsedClause &ParsedClause;
12218 OpenACCClause *NewClause = nullptr;
12219
12220 ExprResult VisitVar(Expr *VarRef) {
12221 ExprResult Res = Self.TransformExpr(VarRef);
12222
12223 if (!Res.isUsable())
12224 return Res;
12225
12226 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12227 ParsedClause.getClauseKind(),
12228 Res.get());
12229
12230 return Res;
12231 }
12232
12233 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
12234 llvm::SmallVector<Expr *> InstantiatedVarList;
12235 for (Expr *CurVar : VarList) {
12236 ExprResult VarRef = VisitVar(CurVar);
12237
12238 if (VarRef.isUsable())
12239 InstantiatedVarList.push_back(VarRef.get());
12240 }
12241
12242 return InstantiatedVarList;
12243 }
12244
12245public:
12246 OpenACCClauseTransform(TreeTransform<Derived> &Self,
12247 ArrayRef<const OpenACCClause *> ExistingClauses,
12248 SemaOpenACC::OpenACCParsedClause &PC)
12249 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
12250
12251 OpenACCClause *CreatedClause() const { return NewClause; }
12252
12253#define VISIT_CLAUSE(CLAUSE_NAME) \
12254 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
12255#include "clang/Basic/OpenACCClauses.def"
12256};
12257
12258template <typename Derived>
12259void OpenACCClauseTransform<Derived>::VisitDefaultClause(
12260 const OpenACCDefaultClause &C) {
12261 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
12262
12263 NewClause = OpenACCDefaultClause::Create(
12264 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
12265 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12266 ParsedClause.getEndLoc());
12267}
12268
12269template <typename Derived>
12270void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
12271 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12272 assert(Cond && "If constructed with invalid Condition");
12273 Sema::ConditionResult Res = Self.TransformCondition(
12274 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
12275
12276 if (Res.isInvalid() || !Res.get().second)
12277 return;
12278
12279 ParsedClause.setConditionDetails(Res.get().second);
12280
12281 NewClause = OpenACCIfClause::Create(
12282 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12283 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12284 ParsedClause.getEndLoc());
12285}
12286
12287template <typename Derived>
12288void OpenACCClauseTransform<Derived>::VisitSelfClause(
12289 const OpenACCSelfClause &C) {
12290
12291 // If this is an 'update' 'self' clause, this is actually a var list instead.
12292 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
12293 llvm::SmallVector<Expr *> InstantiatedVarList;
12294 for (Expr *CurVar : C.getVarList()) {
12295 ExprResult Res = Self.TransformExpr(CurVar);
12296
12297 if (!Res.isUsable())
12298 continue;
12299
12300 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12301 ParsedClause.getClauseKind(),
12302 Res.get());
12303
12304 if (Res.isUsable())
12305 InstantiatedVarList.push_back(Res.get());
12306 }
12307
12308 ParsedClause.setVarListDetails(InstantiatedVarList,
12310
12311 NewClause = OpenACCSelfClause::Create(
12312 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12313 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12314 ParsedClause.getEndLoc());
12315 } else {
12316
12317 if (C.hasConditionExpr()) {
12318 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12320 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
12322
12323 if (Res.isInvalid() || !Res.get().second)
12324 return;
12325
12326 ParsedClause.setConditionDetails(Res.get().second);
12327 }
12328
12329 NewClause = OpenACCSelfClause::Create(
12330 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12331 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12332 ParsedClause.getEndLoc());
12333 }
12334}
12335
12336template <typename Derived>
12337void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
12338 const OpenACCNumGangsClause &C) {
12339 llvm::SmallVector<Expr *> InstantiatedIntExprs;
12340
12341 for (Expr *CurIntExpr : C.getIntExprs()) {
12342 ExprResult Res = Self.TransformExpr(CurIntExpr);
12343
12344 if (!Res.isUsable())
12345 return;
12346
12347 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12348 C.getClauseKind(),
12349 C.getBeginLoc(), Res.get());
12350 if (!Res.isUsable())
12351 return;
12352
12353 InstantiatedIntExprs.push_back(Res.get());
12354 }
12355
12356 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
12358 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12359 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12360 ParsedClause.getEndLoc());
12361}
12362
12363template <typename Derived>
12364void OpenACCClauseTransform<Derived>::VisitPrivateClause(
12365 const OpenACCPrivateClause &C) {
12366 llvm::SmallVector<Expr *> InstantiatedVarList;
12368
12369 for (const auto [RefExpr, InitRecipe] :
12370 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12371 ExprResult VarRef = VisitVar(RefExpr);
12372
12373 if (VarRef.isUsable()) {
12374 InstantiatedVarList.push_back(VarRef.get());
12375
12376 // We only have to create a new one if it is dependent, and Sema won't
12377 // make one of these unless the type is non-dependent.
12378 if (InitRecipe.isSet())
12379 InitRecipes.push_back(InitRecipe);
12380 else
12381 InitRecipes.push_back(
12382 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
12383 }
12384 }
12385 ParsedClause.setVarListDetails(InstantiatedVarList,
12387
12388 NewClause = OpenACCPrivateClause::Create(
12389 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12390 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12391 ParsedClause.getEndLoc());
12392}
12393
12394template <typename Derived>
12395void OpenACCClauseTransform<Derived>::VisitHostClause(
12396 const OpenACCHostClause &C) {
12397 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12399
12400 NewClause = OpenACCHostClause::Create(
12401 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12402 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12403 ParsedClause.getEndLoc());
12404}
12405
12406template <typename Derived>
12407void OpenACCClauseTransform<Derived>::VisitDeviceClause(
12408 const OpenACCDeviceClause &C) {
12409 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12411
12412 NewClause = OpenACCDeviceClause::Create(
12413 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12414 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12415 ParsedClause.getEndLoc());
12416}
12417
12418template <typename Derived>
12419void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
12421 llvm::SmallVector<Expr *> InstantiatedVarList;
12423
12424 for (const auto [RefExpr, InitRecipe] :
12425 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12426 ExprResult VarRef = VisitVar(RefExpr);
12427
12428 if (VarRef.isUsable()) {
12429 InstantiatedVarList.push_back(VarRef.get());
12430
12431 // We only have to create a new one if it is dependent, and Sema won't
12432 // make one of these unless the type is non-dependent.
12433 if (InitRecipe.isSet())
12434 InitRecipes.push_back(InitRecipe);
12435 else
12436 InitRecipes.push_back(
12437 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
12438 VarRef.get()));
12439 }
12440 }
12441 ParsedClause.setVarListDetails(InstantiatedVarList,
12443
12445 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12446 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12447 ParsedClause.getEndLoc());
12448}
12449
12450template <typename Derived>
12451void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12452 const OpenACCNoCreateClause &C) {
12453 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12455
12457 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12458 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12459 ParsedClause.getEndLoc());
12460}
12461
12462template <typename Derived>
12463void OpenACCClauseTransform<Derived>::VisitPresentClause(
12464 const OpenACCPresentClause &C) {
12465 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12467
12468 NewClause = OpenACCPresentClause::Create(
12469 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12470 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12471 ParsedClause.getEndLoc());
12472}
12473
12474template <typename Derived>
12475void OpenACCClauseTransform<Derived>::VisitCopyClause(
12476 const OpenACCCopyClause &C) {
12477 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12478 C.getModifierList());
12479
12480 NewClause = OpenACCCopyClause::Create(
12481 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12482 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12483 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12484 ParsedClause.getEndLoc());
12485}
12486
12487template <typename Derived>
12488void OpenACCClauseTransform<Derived>::VisitLinkClause(
12489 const OpenACCLinkClause &C) {
12490 llvm_unreachable("link clause not valid unless a decl transform");
12491}
12492
12493template <typename Derived>
12494void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12496 llvm_unreachable("device_resident clause not valid unless a decl transform");
12497}
12498template <typename Derived>
12499void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12500 const OpenACCNoHostClause &C) {
12501 llvm_unreachable("nohost clause not valid unless a decl transform");
12502}
12503template <typename Derived>
12504void OpenACCClauseTransform<Derived>::VisitBindClause(
12505 const OpenACCBindClause &C) {
12506 llvm_unreachable("bind clause not valid unless a decl transform");
12507}
12508
12509template <typename Derived>
12510void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12511 const OpenACCCopyInClause &C) {
12512 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12513 C.getModifierList());
12514
12515 NewClause = OpenACCCopyInClause::Create(
12516 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12517 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12518 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12519 ParsedClause.getEndLoc());
12520}
12521
12522template <typename Derived>
12523void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12524 const OpenACCCopyOutClause &C) {
12525 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12526 C.getModifierList());
12527
12528 NewClause = OpenACCCopyOutClause::Create(
12529 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12530 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12531 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12532 ParsedClause.getEndLoc());
12533}
12534
12535template <typename Derived>
12536void OpenACCClauseTransform<Derived>::VisitCreateClause(
12537 const OpenACCCreateClause &C) {
12538 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12539 C.getModifierList());
12540
12541 NewClause = OpenACCCreateClause::Create(
12542 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12543 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12544 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12545 ParsedClause.getEndLoc());
12546}
12547template <typename Derived>
12548void OpenACCClauseTransform<Derived>::VisitAttachClause(
12549 const OpenACCAttachClause &C) {
12550 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12551
12552 // Ensure each var is a pointer type.
12553 llvm::erase_if(VarList, [&](Expr *E) {
12554 return Self.getSema().OpenACC().CheckVarIsPointerType(
12556 });
12557
12558 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12559 NewClause = OpenACCAttachClause::Create(
12560 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12561 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12562 ParsedClause.getEndLoc());
12563}
12564
12565template <typename Derived>
12566void OpenACCClauseTransform<Derived>::VisitDetachClause(
12567 const OpenACCDetachClause &C) {
12568 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12569
12570 // Ensure each var is a pointer type.
12571 llvm::erase_if(VarList, [&](Expr *E) {
12572 return Self.getSema().OpenACC().CheckVarIsPointerType(
12574 });
12575
12576 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12577 NewClause = OpenACCDetachClause::Create(
12578 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12579 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12580 ParsedClause.getEndLoc());
12581}
12582
12583template <typename Derived>
12584void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12585 const OpenACCDeleteClause &C) {
12586 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12588 NewClause = OpenACCDeleteClause::Create(
12589 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12590 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12591 ParsedClause.getEndLoc());
12592}
12593
12594template <typename Derived>
12595void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12596 const OpenACCUseDeviceClause &C) {
12597 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12600 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12601 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12602 ParsedClause.getEndLoc());
12603}
12604
12605template <typename Derived>
12606void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12607 const OpenACCDevicePtrClause &C) {
12608 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12609
12610 // Ensure each var is a pointer type.
12611 llvm::erase_if(VarList, [&](Expr *E) {
12612 return Self.getSema().OpenACC().CheckVarIsPointerType(
12614 });
12615
12616 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12618 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12619 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12620 ParsedClause.getEndLoc());
12621}
12622
12623template <typename Derived>
12624void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12625 const OpenACCNumWorkersClause &C) {
12626 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12627 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12628
12629 ExprResult Res = Self.TransformExpr(IntExpr);
12630 if (!Res.isUsable())
12631 return;
12632
12633 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12634 C.getClauseKind(),
12635 C.getBeginLoc(), Res.get());
12636 if (!Res.isUsable())
12637 return;
12638
12639 ParsedClause.setIntExprDetails(Res.get());
12641 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12642 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12643 ParsedClause.getEndLoc());
12644}
12645
12646template <typename Derived>
12647void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12648 const OpenACCDeviceNumClause &C) {
12649 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12650 assert(IntExpr && "device_num clause constructed with invalid int expr");
12651
12652 ExprResult Res = Self.TransformExpr(IntExpr);
12653 if (!Res.isUsable())
12654 return;
12655
12656 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12657 C.getClauseKind(),
12658 C.getBeginLoc(), Res.get());
12659 if (!Res.isUsable())
12660 return;
12661
12662 ParsedClause.setIntExprDetails(Res.get());
12664 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12665 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12666 ParsedClause.getEndLoc());
12667}
12668
12669template <typename Derived>
12670void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12672 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12673 assert(IntExpr && "default_async clause constructed with invalid int expr");
12674
12675 ExprResult Res = Self.TransformExpr(IntExpr);
12676 if (!Res.isUsable())
12677 return;
12678
12679 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12680 C.getClauseKind(),
12681 C.getBeginLoc(), Res.get());
12682 if (!Res.isUsable())
12683 return;
12684
12685 ParsedClause.setIntExprDetails(Res.get());
12687 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12688 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12689 ParsedClause.getEndLoc());
12690}
12691
12692template <typename Derived>
12693void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12695 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12696 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12697
12698 ExprResult Res = Self.TransformExpr(IntExpr);
12699 if (!Res.isUsable())
12700 return;
12701
12702 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12703 C.getClauseKind(),
12704 C.getBeginLoc(), Res.get());
12705 if (!Res.isUsable())
12706 return;
12707
12708 ParsedClause.setIntExprDetails(Res.get());
12710 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12711 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12712 ParsedClause.getEndLoc());
12713}
12714
12715template <typename Derived>
12716void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12717 const OpenACCAsyncClause &C) {
12718 if (C.hasIntExpr()) {
12719 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12720 if (!Res.isUsable())
12721 return;
12722
12723 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12724 C.getClauseKind(),
12725 C.getBeginLoc(), Res.get());
12726 if (!Res.isUsable())
12727 return;
12728 ParsedClause.setIntExprDetails(Res.get());
12729 }
12730
12731 NewClause = OpenACCAsyncClause::Create(
12732 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12733 ParsedClause.getLParenLoc(),
12734 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12735 : nullptr,
12736 ParsedClause.getEndLoc());
12737}
12738
12739template <typename Derived>
12740void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12741 const OpenACCWorkerClause &C) {
12742 if (C.hasIntExpr()) {
12743 // restrictions on this expression are all "does it exist in certain
12744 // situations" that are not possible to be dependent, so the only check we
12745 // have is that it transforms, and is an int expression.
12746 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12747 if (!Res.isUsable())
12748 return;
12749
12750 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12751 C.getClauseKind(),
12752 C.getBeginLoc(), Res.get());
12753 if (!Res.isUsable())
12754 return;
12755 ParsedClause.setIntExprDetails(Res.get());
12756 }
12757
12758 NewClause = OpenACCWorkerClause::Create(
12759 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12760 ParsedClause.getLParenLoc(),
12761 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12762 : nullptr,
12763 ParsedClause.getEndLoc());
12764}
12765
12766template <typename Derived>
12767void OpenACCClauseTransform<Derived>::VisitVectorClause(
12768 const OpenACCVectorClause &C) {
12769 if (C.hasIntExpr()) {
12770 // restrictions on this expression are all "does it exist in certain
12771 // situations" that are not possible to be dependent, so the only check we
12772 // have is that it transforms, and is an int expression.
12773 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12774 if (!Res.isUsable())
12775 return;
12776
12777 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12778 C.getClauseKind(),
12779 C.getBeginLoc(), Res.get());
12780 if (!Res.isUsable())
12781 return;
12782 ParsedClause.setIntExprDetails(Res.get());
12783 }
12784
12785 NewClause = OpenACCVectorClause::Create(
12786 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12787 ParsedClause.getLParenLoc(),
12788 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12789 : nullptr,
12790 ParsedClause.getEndLoc());
12791}
12792
12793template <typename Derived>
12794void OpenACCClauseTransform<Derived>::VisitWaitClause(
12795 const OpenACCWaitClause &C) {
12796 if (C.hasExprs()) {
12797 Expr *DevNumExpr = nullptr;
12798 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12799
12800 // Instantiate devnum expr if it exists.
12801 if (C.getDevNumExpr()) {
12802 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12803 if (!Res.isUsable())
12804 return;
12805 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12806 C.getClauseKind(),
12807 C.getBeginLoc(), Res.get());
12808 if (!Res.isUsable())
12809 return;
12810
12811 DevNumExpr = Res.get();
12812 }
12813
12814 // Instantiate queue ids.
12815 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12816 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12817 if (!Res.isUsable())
12818 return;
12819 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12820 C.getClauseKind(),
12821 C.getBeginLoc(), Res.get());
12822 if (!Res.isUsable())
12823 return;
12824
12825 InstantiatedQueueIdExprs.push_back(Res.get());
12826 }
12827
12828 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12829 std::move(InstantiatedQueueIdExprs));
12830 }
12831
12832 NewClause = OpenACCWaitClause::Create(
12833 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12834 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12835 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12836 ParsedClause.getEndLoc());
12837}
12838
12839template <typename Derived>
12840void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12841 const OpenACCDeviceTypeClause &C) {
12842 // Nothing to transform here, just create a new version of 'C'.
12844 Self.getSema().getASTContext(), C.getClauseKind(),
12845 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12846 C.getArchitectures(), ParsedClause.getEndLoc());
12847}
12848
12849template <typename Derived>
12850void OpenACCClauseTransform<Derived>::VisitAutoClause(
12851 const OpenACCAutoClause &C) {
12852 // Nothing to do, so just create a new node.
12853 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12854 ParsedClause.getBeginLoc(),
12855 ParsedClause.getEndLoc());
12856}
12857
12858template <typename Derived>
12859void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12860 const OpenACCIndependentClause &C) {
12861 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12862 ParsedClause.getBeginLoc(),
12863 ParsedClause.getEndLoc());
12864}
12865
12866template <typename Derived>
12867void OpenACCClauseTransform<Derived>::VisitSeqClause(
12868 const OpenACCSeqClause &C) {
12869 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12870 ParsedClause.getBeginLoc(),
12871 ParsedClause.getEndLoc());
12872}
12873template <typename Derived>
12874void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12875 const OpenACCFinalizeClause &C) {
12876 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12877 ParsedClause.getBeginLoc(),
12878 ParsedClause.getEndLoc());
12879}
12880
12881template <typename Derived>
12882void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12883 const OpenACCIfPresentClause &C) {
12884 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12885 ParsedClause.getBeginLoc(),
12886 ParsedClause.getEndLoc());
12887}
12888
12889template <typename Derived>
12890void OpenACCClauseTransform<Derived>::VisitReductionClause(
12891 const OpenACCReductionClause &C) {
12892 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12893 SmallVector<Expr *> ValidVars;
12895
12896 for (const auto [Var, OrigRecipe] :
12897 llvm::zip(TransformedVars, C.getRecipes())) {
12898 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12899 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12900 if (Res.isUsable()) {
12901 ValidVars.push_back(Res.get());
12902
12903 if (OrigRecipe.isSet())
12904 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
12905 else
12906 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12907 C.getReductionOp(), Res.get()));
12908 }
12909 }
12910
12911 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12912 ExistingClauses, ParsedClause.getDirectiveKind(),
12913 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12914 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12915}
12916
12917template <typename Derived>
12918void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12919 const OpenACCCollapseClause &C) {
12920 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12921 assert(LoopCount && "collapse clause constructed with invalid loop count");
12922
12923 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12924
12925 if (!NewLoopCount.isUsable())
12926 return;
12927
12928 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12929 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12930 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12931
12932 // FIXME: It isn't clear whether this is properly tested here, we should
12933 // probably see if we can come up with a test for this.
12934 if (!NewLoopCount.isUsable())
12935 return;
12936
12937 NewLoopCount =
12938 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12939
12940 // FIXME: It isn't clear whether this is properly tested here, we should
12941 // probably see if we can come up with a test for this.
12942 if (!NewLoopCount.isUsable())
12943 return;
12944
12945 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12947 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12948 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12949 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12950}
12951
12952template <typename Derived>
12953void OpenACCClauseTransform<Derived>::VisitTileClause(
12954 const OpenACCTileClause &C) {
12955
12956 llvm::SmallVector<Expr *> TransformedExprs;
12957
12958 for (Expr *E : C.getSizeExprs()) {
12959 ExprResult NewSizeExpr = Self.TransformExpr(E);
12960
12961 if (!NewSizeExpr.isUsable())
12962 return;
12963
12964 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12965 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12966 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12967
12968 // FIXME: It isn't clear whether this is properly tested here, we should
12969 // probably see if we can come up with a test for this.
12970 if (!NewSizeExpr.isUsable())
12971 return;
12972
12973 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12974
12975 if (!NewSizeExpr.isUsable())
12976 return;
12977 TransformedExprs.push_back(NewSizeExpr.get());
12978 }
12979
12980 ParsedClause.setIntExprDetails(TransformedExprs);
12981 NewClause = OpenACCTileClause::Create(
12982 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12983 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12984 ParsedClause.getEndLoc());
12985}
12986template <typename Derived>
12987void OpenACCClauseTransform<Derived>::VisitGangClause(
12988 const OpenACCGangClause &C) {
12989 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12990 llvm::SmallVector<Expr *> TransformedIntExprs;
12991
12992 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12993 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12994 if (!ER.isUsable())
12995 continue;
12996
12997 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12998 ParsedClause.getDirectiveKind(),
12999 C.getExpr(I).first, ER.get());
13000 if (!ER.isUsable())
13001 continue;
13002 TransformedGangKinds.push_back(C.getExpr(I).first);
13003 TransformedIntExprs.push_back(ER.get());
13004 }
13005
13006 NewClause = Self.getSema().OpenACC().CheckGangClause(
13007 ParsedClause.getDirectiveKind(), ExistingClauses,
13008 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13009 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
13010}
13011} // namespace
13012template <typename Derived>
13013OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
13014 ArrayRef<const OpenACCClause *> ExistingClauses,
13015 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
13016
13018 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
13019 ParsedClause.setEndLoc(OldClause->getEndLoc());
13020
13021 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
13022 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
13023
13024 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
13025 ParsedClause};
13026 Transform.Visit(OldClause);
13027
13028 return Transform.CreatedClause();
13029}
13030
13031template <typename Derived>
13033TreeTransform<Derived>::TransformOpenACCClauseList(
13035 llvm::SmallVector<OpenACCClause *> TransformedClauses;
13036 for (const auto *Clause : OldClauses) {
13037 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
13038 TransformedClauses, DirKind, Clause))
13039 TransformedClauses.push_back(TransformedClause);
13040 }
13041 return TransformedClauses;
13042}
13043
13044template <typename Derived>
13047 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13048
13049 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13050 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13051 C->clauses());
13052
13053 if (getSema().OpenACC().ActOnStartStmtDirective(
13054 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13055 return StmtError();
13056
13057 // Transform Structured Block.
13058 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13059 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13060 C->clauses(), TransformedClauses);
13061 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13062 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13063 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13064
13065 return getDerived().RebuildOpenACCComputeConstruct(
13066 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13067 C->getEndLoc(), TransformedClauses, StrBlock);
13068}
13069
13070template <typename Derived>
13073
13074 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13075
13076 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13077 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13078 C->clauses());
13079
13080 if (getSema().OpenACC().ActOnStartStmtDirective(
13081 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13082 return StmtError();
13083
13084 // Transform Loop.
13085 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13086 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13087 C->clauses(), TransformedClauses);
13088 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13089 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13090 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13091
13092 return getDerived().RebuildOpenACCLoopConstruct(
13093 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13094 TransformedClauses, Loop);
13095}
13096
13097template <typename Derived>
13099 OpenACCCombinedConstruct *C) {
13100 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13101
13102 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13103 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13104 C->clauses());
13105
13106 if (getSema().OpenACC().ActOnStartStmtDirective(
13107 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13108 return StmtError();
13109
13110 // Transform Loop.
13111 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13112 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13113 C->clauses(), TransformedClauses);
13114 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13115 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13116 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13117
13118 return getDerived().RebuildOpenACCCombinedConstruct(
13119 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13120 C->getEndLoc(), TransformedClauses, Loop);
13121}
13122
13123template <typename Derived>
13126 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13127
13128 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13129 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13130 C->clauses());
13131 if (getSema().OpenACC().ActOnStartStmtDirective(
13132 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13133 return StmtError();
13134
13135 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13136 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13137 C->clauses(), TransformedClauses);
13138 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13139 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13140 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13141
13142 return getDerived().RebuildOpenACCDataConstruct(
13143 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13144 TransformedClauses, StrBlock);
13145}
13146
13147template <typename Derived>
13149 OpenACCEnterDataConstruct *C) {
13150 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13151
13152 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13153 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13154 C->clauses());
13155 if (getSema().OpenACC().ActOnStartStmtDirective(
13156 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13157 return StmtError();
13158
13159 return getDerived().RebuildOpenACCEnterDataConstruct(
13160 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13161 TransformedClauses);
13162}
13163
13164template <typename Derived>
13166 OpenACCExitDataConstruct *C) {
13167 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13168
13169 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13170 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13171 C->clauses());
13172 if (getSema().OpenACC().ActOnStartStmtDirective(
13173 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13174 return StmtError();
13175
13176 return getDerived().RebuildOpenACCExitDataConstruct(
13177 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13178 TransformedClauses);
13179}
13180
13181template <typename Derived>
13183 OpenACCHostDataConstruct *C) {
13184 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13185
13186 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13187 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13188 C->clauses());
13189 if (getSema().OpenACC().ActOnStartStmtDirective(
13190 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13191 return StmtError();
13192
13193 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13194 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13195 C->clauses(), TransformedClauses);
13196 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13197 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13198 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13199
13200 return getDerived().RebuildOpenACCHostDataConstruct(
13201 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13202 TransformedClauses, StrBlock);
13203}
13204
13205template <typename Derived>
13208 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13209
13210 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13211 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13212 C->clauses());
13213 if (getSema().OpenACC().ActOnStartStmtDirective(
13214 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13215 return StmtError();
13216
13217 return getDerived().RebuildOpenACCInitConstruct(
13218 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13219 TransformedClauses);
13220}
13221
13222template <typename Derived>
13224 OpenACCShutdownConstruct *C) {
13225 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13226
13227 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13228 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13229 C->clauses());
13230 if (getSema().OpenACC().ActOnStartStmtDirective(
13231 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13232 return StmtError();
13233
13234 return getDerived().RebuildOpenACCShutdownConstruct(
13235 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13236 TransformedClauses);
13237}
13238template <typename Derived>
13241 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13242
13243 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13244 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13245 C->clauses());
13246 if (getSema().OpenACC().ActOnStartStmtDirective(
13247 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13248 return StmtError();
13249
13250 return getDerived().RebuildOpenACCSetConstruct(
13251 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13252 TransformedClauses);
13253}
13254
13255template <typename Derived>
13257 OpenACCUpdateConstruct *C) {
13258 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13259
13260 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13261 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13262 C->clauses());
13263 if (getSema().OpenACC().ActOnStartStmtDirective(
13264 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13265 return StmtError();
13266
13267 return getDerived().RebuildOpenACCUpdateConstruct(
13268 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13269 TransformedClauses);
13270}
13271
13272template <typename Derived>
13275 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13276
13277 ExprResult DevNumExpr;
13278 if (C->hasDevNumExpr()) {
13279 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
13280
13281 if (DevNumExpr.isUsable())
13282 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
13284 C->getBeginLoc(), DevNumExpr.get());
13285 }
13286
13287 llvm::SmallVector<Expr *> QueueIdExprs;
13288
13289 for (Expr *QE : C->getQueueIdExprs()) {
13290 assert(QE && "Null queue id expr?");
13291 ExprResult NewEQ = getDerived().TransformExpr(QE);
13292
13293 if (!NewEQ.isUsable())
13294 break;
13295 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
13297 C->getBeginLoc(), NewEQ.get());
13298 if (NewEQ.isUsable())
13299 QueueIdExprs.push_back(NewEQ.get());
13300 }
13301
13302 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13303 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13304 C->clauses());
13305
13306 if (getSema().OpenACC().ActOnStartStmtDirective(
13307 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13308 return StmtError();
13309
13310 return getDerived().RebuildOpenACCWaitConstruct(
13311 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13312 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
13313 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
13314}
13315template <typename Derived>
13317 OpenACCCacheConstruct *C) {
13318 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13319
13320 llvm::SmallVector<Expr *> TransformedVarList;
13321 for (Expr *Var : C->getVarList()) {
13322 assert(Var && "Null var listexpr?");
13323
13324 ExprResult NewVar = getDerived().TransformExpr(Var);
13325
13326 if (!NewVar.isUsable())
13327 break;
13328
13329 NewVar = getSema().OpenACC().ActOnVar(
13330 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
13331 if (!NewVar.isUsable())
13332 break;
13333
13334 TransformedVarList.push_back(NewVar.get());
13335 }
13336
13337 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13338 C->getBeginLoc(), {}))
13339 return StmtError();
13340
13341 return getDerived().RebuildOpenACCCacheConstruct(
13342 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13343 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
13344 C->getEndLoc());
13345}
13346
13347template <typename Derived>
13349 OpenACCAtomicConstruct *C) {
13350 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13351
13352 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13353 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13354 C->clauses());
13355
13356 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13357 C->getBeginLoc(), {}))
13358 return StmtError();
13359
13360 // Transform Associated Stmt.
13361 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13362 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
13363
13364 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
13365 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
13366 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
13367 AssocStmt);
13368
13369 return getDerived().RebuildOpenACCAtomicConstruct(
13370 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
13371 C->getEndLoc(), TransformedClauses, AssocStmt);
13372}
13373
13374template <typename Derived>
13377 if (getDerived().AlwaysRebuild())
13378 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
13379 // Nothing can ever change, so there is never anything to transform.
13380 return E;
13381}
13382
13383//===----------------------------------------------------------------------===//
13384// Expression transformation
13385//===----------------------------------------------------------------------===//
13386template<typename Derived>
13389 return TransformExpr(E->getSubExpr());
13390}
13391
13392template <typename Derived>
13395 if (!E->isTypeDependent())
13396 return E;
13397
13398 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
13399
13400 if (!NewT)
13401 return ExprError();
13402
13403 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
13404 return E;
13405
13406 return getDerived().RebuildSYCLUniqueStableNameExpr(
13407 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
13408}
13409
13410template <typename Derived>
13413 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
13414 const auto *SKEPAttr = FD->template getAttr<SYCLKernelEntryPointAttr>();
13415 if (!SKEPAttr || SKEPAttr->isInvalidAttr())
13416 return StmtError();
13417
13418 ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
13419 if (IdExpr.isInvalid())
13420 return StmtError();
13421
13422 StmtResult Body = getDerived().TransformStmt(S->getOriginalStmt());
13423 if (Body.isInvalid())
13424 return StmtError();
13425
13427 cast<FunctionDecl>(SemaRef.CurContext), cast<CompoundStmt>(Body.get()),
13428 IdExpr.get());
13429 if (SR.isInvalid())
13430 return StmtError();
13431
13432 return SR;
13433}
13434
13435template <typename Derived>
13437 // TODO(reflection): Implement its transform
13438 assert(false && "not implemented yet");
13439 return ExprError();
13440}
13441
13442template<typename Derived>
13445 if (!E->isTypeDependent())
13446 return E;
13447
13448 return getDerived().RebuildPredefinedExpr(E->getLocation(),
13449 E->getIdentKind());
13450}
13451
13452template<typename Derived>
13455 NestedNameSpecifierLoc QualifierLoc;
13456 if (E->getQualifierLoc()) {
13457 QualifierLoc
13458 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13459 if (!QualifierLoc)
13460 return ExprError();
13461 }
13462
13463 ValueDecl *ND
13464 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
13465 E->getDecl()));
13466 if (!ND || ND->isInvalidDecl())
13467 return ExprError();
13468
13469 NamedDecl *Found = ND;
13470 if (E->getFoundDecl() != E->getDecl()) {
13471 Found = cast_or_null<NamedDecl>(
13472 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
13473 if (!Found)
13474 return ExprError();
13475 }
13476
13477 DeclarationNameInfo NameInfo = E->getNameInfo();
13478 if (NameInfo.getName()) {
13479 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
13480 if (!NameInfo.getName())
13481 return ExprError();
13482 }
13483
13484 if (!getDerived().AlwaysRebuild() &&
13485 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
13486 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
13487 Found == E->getFoundDecl() &&
13488 NameInfo.getName() == E->getDecl()->getDeclName() &&
13489 !E->hasExplicitTemplateArgs()) {
13490
13491 // Mark it referenced in the new context regardless.
13492 // FIXME: this is a bit instantiation-specific.
13493 SemaRef.MarkDeclRefReferenced(E);
13494
13495 return E;
13496 }
13497
13498 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
13499 if (E->hasExplicitTemplateArgs()) {
13500 TemplateArgs = &TransArgs;
13501 TransArgs.setLAngleLoc(E->getLAngleLoc());
13502 TransArgs.setRAngleLoc(E->getRAngleLoc());
13503 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13504 E->getNumTemplateArgs(),
13505 TransArgs))
13506 return ExprError();
13507 }
13508
13509 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13510 Found, TemplateArgs);
13511}
13512
13513template<typename Derived>
13516 return E;
13517}
13518
13519template <typename Derived>
13521 FixedPointLiteral *E) {
13522 return E;
13523}
13524
13525template<typename Derived>
13528 return E;
13529}
13530
13531template<typename Derived>
13534 return E;
13535}
13536
13537template<typename Derived>
13540 return E;
13541}
13542
13543template<typename Derived>
13546 return E;
13547}
13548
13549template<typename Derived>
13552 return getDerived().TransformCallExpr(E);
13553}
13554
13555template<typename Derived>
13558 ExprResult ControllingExpr;
13559 TypeSourceInfo *ControllingType = nullptr;
13560 if (E->isExprPredicate())
13561 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13562 else
13563 ControllingType = getDerived().TransformType(E->getControllingType());
13564
13565 if (ControllingExpr.isInvalid() && !ControllingType)
13566 return ExprError();
13567
13568 SmallVector<Expr *, 4> AssocExprs;
13570 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13571 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13572 if (TSI) {
13573 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13574 if (!AssocType)
13575 return ExprError();
13576 AssocTypes.push_back(AssocType);
13577 } else {
13578 AssocTypes.push_back(nullptr);
13579 }
13580
13581 ExprResult AssocExpr =
13582 getDerived().TransformExpr(Assoc.getAssociationExpr());
13583 if (AssocExpr.isInvalid())
13584 return ExprError();
13585 AssocExprs.push_back(AssocExpr.get());
13586 }
13587
13588 if (!ControllingType)
13589 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13590 E->getDefaultLoc(),
13591 E->getRParenLoc(),
13592 ControllingExpr.get(),
13593 AssocTypes,
13594 AssocExprs);
13595 return getDerived().RebuildGenericSelectionExpr(
13596 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13597 ControllingType, AssocTypes, AssocExprs);
13598}
13599
13600template<typename Derived>
13603 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13604 if (SubExpr.isInvalid())
13605 return ExprError();
13606
13607 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13608 return E;
13609
13610 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13611 E->getRParen());
13612}
13613
13614/// The operand of a unary address-of operator has special rules: it's
13615/// allowed to refer to a non-static member of a class even if there's no 'this'
13616/// object available.
13617template<typename Derived>
13620 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13621 return getDerived().TransformDependentScopeDeclRefExpr(
13622 DRE, /*IsAddressOfOperand=*/true, nullptr);
13623 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13624 return getDerived().TransformUnresolvedLookupExpr(
13625 ULE, /*IsAddressOfOperand=*/true);
13626 else
13627 return getDerived().TransformExpr(E);
13628}
13629
13630template<typename Derived>
13633 ExprResult SubExpr;
13634 if (E->getOpcode() == UO_AddrOf)
13635 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13636 else
13637 SubExpr = TransformExpr(E->getSubExpr());
13638 if (SubExpr.isInvalid())
13639 return ExprError();
13640
13641 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13642 return E;
13643
13644 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13645 E->getOpcode(),
13646 SubExpr.get());
13647}
13648
13649template<typename Derived>
13651TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13652 // Transform the type.
13653 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13654 if (!Type)
13655 return ExprError();
13656
13657 // Transform all of the components into a Designation similar to what the
13658 // parser builds.
13659 // FIXME: It would be slightly more efficient in the non-dependent case to
13660 // just map FieldDecls, rather than requiring the rebuilder to look for
13661 // the fields again. However, __builtin_offsetof is rare enough in
13662 // template code that we don't care.
13663 bool ExprChanged = false;
13664 Designation Desig;
13665 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13666 const OffsetOfNode &ON = E->getComponent(I);
13667 switch (ON.getKind()) {
13668 case OffsetOfNode::Array: {
13669 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13670 ExprResult Index = getDerived().TransformExpr(FromIndex);
13671 if (Index.isInvalid())
13672 return ExprError();
13673
13674 ExprChanged = ExprChanged || Index.get() != FromIndex;
13675 Designator AD =
13676 Designator::CreateArrayDesignator(Index.get(), ON.getBeginLoc());
13677 AD.setRBracketLoc(ON.getEndLoc());
13678 Desig.AddDesignator(AD);
13679 break;
13680 }
13681
13684 const IdentifierInfo *Name = ON.getFieldName();
13685 if (!Name)
13686 continue;
13687 // The leading designator has no '.'; subsequent ones do.
13688 SourceLocation DotLoc =
13689 Desig.empty() ? SourceLocation() : ON.getBeginLoc();
13690 Desig.AddDesignator(
13691 Designator::CreateFieldDesignator(Name, DotLoc, ON.getEndLoc()));
13692 break;
13693 }
13694
13695 case OffsetOfNode::Base:
13696 // Will be recomputed during the rebuild.
13697 continue;
13698 }
13699 }
13700
13701 // If nothing changed, retain the existing expression.
13702 if (!getDerived().AlwaysRebuild() &&
13703 Type == E->getTypeSourceInfo() &&
13704 !ExprChanged)
13705 return E;
13706
13707 // Build a new offsetof expression.
13708 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, Desig,
13709 E->getRParenLoc());
13710}
13711
13712template<typename Derived>
13715 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13716 "opaque value expression requires transformation");
13717 return E;
13718}
13719
13720template <typename Derived>
13723 bool Changed = false;
13724 for (Expr *C : E->subExpressions()) {
13725 ExprResult NewC = getDerived().TransformExpr(C);
13726 if (NewC.isInvalid())
13727 return ExprError();
13728 Children.push_back(NewC.get());
13729
13730 Changed |= NewC.get() != C;
13731 }
13732 if (!getDerived().AlwaysRebuild() && !Changed)
13733 return E;
13734 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13735 Children, E->getType());
13736}
13737
13738template<typename Derived>
13741 // Rebuild the syntactic form. The original syntactic form has
13742 // opaque-value expressions in it, so strip those away and rebuild
13743 // the result. This is a really awful way of doing this, but the
13744 // better solution (rebuilding the semantic expressions and
13745 // rebinding OVEs as necessary) doesn't work; we'd need
13746 // TreeTransform to not strip away implicit conversions.
13747 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13748 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13749 if (result.isInvalid()) return ExprError();
13750
13751 // If that gives us a pseudo-object result back, the pseudo-object
13752 // expression must have been an lvalue-to-rvalue conversion which we
13753 // should reapply.
13754 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13755 result = SemaRef.PseudoObject().checkRValue(result.get());
13756
13757 return result;
13758}
13759
13760template<typename Derived>
13764 if (E->isArgumentType()) {
13765 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13766
13767 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13768 if (!NewT)
13769 return ExprError();
13770
13771 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13772 return E;
13773
13774 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13775 E->getKind(),
13776 E->getSourceRange());
13777 }
13778
13779 // C++0x [expr.sizeof]p1:
13780 // The operand is either an expression, which is an unevaluated operand
13781 // [...]
13785
13786 // Try to recover if we have something like sizeof(T::X) where X is a type.
13787 // Notably, there must be *exactly* one set of parens if X is a type.
13788 TypeSourceInfo *RecoveryTSI = nullptr;
13789 ExprResult SubExpr;
13790 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13791 if (auto *DRE =
13792 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13793 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13794 PE, DRE, false, &RecoveryTSI);
13795 else
13796 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13797
13798 if (RecoveryTSI) {
13799 return getDerived().RebuildUnaryExprOrTypeTrait(
13800 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13801 } else if (SubExpr.isInvalid())
13802 return ExprError();
13803
13804 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13805 return E;
13806
13807 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13808 E->getOperatorLoc(),
13809 E->getKind(),
13810 E->getSourceRange());
13811}
13812
13813template<typename Derived>
13816 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13817 if (LHS.isInvalid())
13818 return ExprError();
13819
13820 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13821 if (RHS.isInvalid())
13822 return ExprError();
13823
13824
13825 if (!getDerived().AlwaysRebuild() &&
13826 LHS.get() == E->getLHS() &&
13827 RHS.get() == E->getRHS())
13828 return E;
13829
13830 return getDerived().RebuildArraySubscriptExpr(
13831 LHS.get(),
13832 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13833}
13834
13835template <typename Derived>
13838 ExprResult Base = getDerived().TransformExpr(E->getBase());
13839 if (Base.isInvalid())
13840 return ExprError();
13841
13842 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13843 if (RowIdx.isInvalid())
13844 return ExprError();
13845
13846 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13847 RowIdx.get() == E->getRowIdx())
13848 return E;
13849
13850 return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(),
13851 E->getRBracketLoc());
13852}
13853
13854template <typename Derived>
13857 ExprResult Base = getDerived().TransformExpr(E->getBase());
13858 if (Base.isInvalid())
13859 return ExprError();
13860
13861 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13862 if (RowIdx.isInvalid())
13863 return ExprError();
13864
13865 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13866 if (ColumnIdx.isInvalid())
13867 return ExprError();
13868
13869 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13870 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13871 return E;
13872
13873 return getDerived().RebuildMatrixSubscriptExpr(
13874 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13875}
13876
13877template <typename Derived>
13880 ExprResult Base = getDerived().TransformExpr(E->getBase());
13881 if (Base.isInvalid())
13882 return ExprError();
13883
13884 ExprResult LowerBound;
13885 if (E->getLowerBound()) {
13886 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13887 if (LowerBound.isInvalid())
13888 return ExprError();
13889 }
13890
13891 ExprResult Length;
13892 if (E->getLength()) {
13893 Length = getDerived().TransformExpr(E->getLength());
13894 if (Length.isInvalid())
13895 return ExprError();
13896 }
13897
13898 ExprResult Stride;
13899 if (E->isOMPArraySection()) {
13900 if (Expr *Str = E->getStride()) {
13901 Stride = getDerived().TransformExpr(Str);
13902 if (Stride.isInvalid())
13903 return ExprError();
13904 }
13905 }
13906
13907 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13908 LowerBound.get() == E->getLowerBound() &&
13909 Length.get() == E->getLength() &&
13910 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13911 return E;
13912
13913 return getDerived().RebuildArraySectionExpr(
13914 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13915 LowerBound.get(), E->getColonLocFirst(),
13916 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13917 Length.get(), Stride.get(), E->getRBracketLoc());
13918}
13919
13920template <typename Derived>
13923 ExprResult Base = getDerived().TransformExpr(E->getBase());
13924 if (Base.isInvalid())
13925 return ExprError();
13926
13928 bool ErrorFound = false;
13929 for (Expr *Dim : E->getDimensions()) {
13930 ExprResult DimRes = getDerived().TransformExpr(Dim);
13931 if (DimRes.isInvalid()) {
13932 ErrorFound = true;
13933 continue;
13934 }
13935 Dims.push_back(DimRes.get());
13936 }
13937
13938 if (ErrorFound)
13939 return ExprError();
13940 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13941 E->getRParenLoc(), Dims,
13942 E->getBracketsRanges());
13943}
13944
13945template <typename Derived>
13948 unsigned NumIterators = E->numOfIterators();
13950
13951 bool ErrorFound = false;
13952 bool NeedToRebuild = getDerived().AlwaysRebuild();
13953 for (unsigned I = 0; I < NumIterators; ++I) {
13954 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13955 Data[I].DeclIdent = D->getIdentifier();
13956 Data[I].DeclIdentLoc = D->getLocation();
13957 if (D->getLocation() == D->getBeginLoc()) {
13958 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13959 "Implicit type must be int.");
13960 } else {
13961 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13962 QualType DeclTy = getDerived().TransformType(D->getType());
13963 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13964 }
13965 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13966 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13967 ExprResult End = getDerived().TransformExpr(Range.End);
13968 ExprResult Step = getDerived().TransformExpr(Range.Step);
13969 ErrorFound = ErrorFound ||
13970 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13971 !Data[I].Type.get().isNull())) ||
13972 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13973 if (ErrorFound)
13974 continue;
13975 Data[I].Range.Begin = Begin.get();
13976 Data[I].Range.End = End.get();
13977 Data[I].Range.Step = Step.get();
13978 Data[I].AssignLoc = E->getAssignLoc(I);
13979 Data[I].ColonLoc = E->getColonLoc(I);
13980 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13981 NeedToRebuild =
13982 NeedToRebuild ||
13983 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13984 D->getType().getTypePtrOrNull()) ||
13985 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13986 Range.Step != Data[I].Range.Step;
13987 }
13988 if (ErrorFound)
13989 return ExprError();
13990 if (!NeedToRebuild)
13991 return E;
13992
13993 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13994 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13995 if (!Res.isUsable())
13996 return Res;
13997 auto *IE = cast<OMPIteratorExpr>(Res.get());
13998 for (unsigned I = 0; I < NumIterators; ++I)
13999 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
14000 IE->getIteratorDecl(I));
14001 return Res;
14002}
14003
14004template<typename Derived>
14007 // Transform the callee.
14008 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14009 if (Callee.isInvalid())
14010 return ExprError();
14011
14012 // Transform arguments.
14013 bool ArgChanged = false;
14015 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14016 &ArgChanged))
14017 return ExprError();
14018
14019 if (!getDerived().AlwaysRebuild() &&
14020 Callee.get() == E->getCallee() &&
14021 !ArgChanged)
14022 return SemaRef.MaybeBindToTemporary(E);
14023
14024 // FIXME: Wrong source location information for the '('.
14025 SourceLocation FakeLParenLoc
14026 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14027
14028 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14029 if (E->hasStoredFPFeatures()) {
14030 FPOptionsOverride NewOverrides = E->getFPFeatures();
14031 getSema().CurFPFeatures =
14032 NewOverrides.applyOverrides(getSema().getLangOpts());
14033 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14034 }
14035
14036 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14037 Args,
14038 E->getRParenLoc());
14039}
14040
14041template<typename Derived>
14044 ExprResult Base = getDerived().TransformExpr(E->getBase());
14045 if (Base.isInvalid())
14046 return ExprError();
14047
14048 NestedNameSpecifierLoc QualifierLoc;
14049 if (E->hasQualifier()) {
14050 QualifierLoc
14051 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14052
14053 if (!QualifierLoc)
14054 return ExprError();
14055 }
14056 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14057
14059 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
14060 E->getMemberDecl()));
14061 if (!Member)
14062 return ExprError();
14063
14064 NamedDecl *FoundDecl = E->getFoundDecl();
14065 if (FoundDecl == E->getMemberDecl()) {
14066 FoundDecl = Member;
14067 } else {
14068 FoundDecl = cast_or_null<NamedDecl>(
14069 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
14070 if (!FoundDecl)
14071 return ExprError();
14072 }
14073
14074 if (!getDerived().AlwaysRebuild() &&
14075 Base.get() == E->getBase() &&
14076 QualifierLoc == E->getQualifierLoc() &&
14077 Member == E->getMemberDecl() &&
14078 FoundDecl == E->getFoundDecl() &&
14079 !E->hasExplicitTemplateArgs()) {
14080
14081 // Skip for member expression of (this->f), rebuilt thisi->f is needed
14082 // for Openmp where the field need to be privatizized in the case.
14083 if (!(isa<CXXThisExpr>(E->getBase()) &&
14084 getSema().OpenMP().isOpenMPRebuildMemberExpr(
14086 // Mark it referenced in the new context regardless.
14087 // FIXME: this is a bit instantiation-specific.
14088 SemaRef.MarkMemberReferenced(E);
14089 return E;
14090 }
14091 }
14092
14093 TemplateArgumentListInfo TransArgs;
14094 if (E->hasExplicitTemplateArgs()) {
14095 TransArgs.setLAngleLoc(E->getLAngleLoc());
14096 TransArgs.setRAngleLoc(E->getRAngleLoc());
14097 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14098 E->getNumTemplateArgs(),
14099 TransArgs))
14100 return ExprError();
14101 }
14102
14103 // FIXME: Bogus source location for the operator
14104 SourceLocation FakeOperatorLoc =
14105 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
14106
14107 // FIXME: to do this check properly, we will need to preserve the
14108 // first-qualifier-in-scope here, just in case we had a dependent
14109 // base (and therefore couldn't do the check) and a
14110 // nested-name-qualifier (and therefore could do the lookup).
14111 NamedDecl *FirstQualifierInScope = nullptr;
14112 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
14113 if (MemberNameInfo.getName()) {
14114 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
14115 if (!MemberNameInfo.getName())
14116 return ExprError();
14117 }
14118
14119 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
14120 E->isArrow(),
14121 QualifierLoc,
14122 TemplateKWLoc,
14123 MemberNameInfo,
14124 Member,
14125 FoundDecl,
14126 (E->hasExplicitTemplateArgs()
14127 ? &TransArgs : nullptr),
14128 FirstQualifierInScope);
14129}
14130
14131template<typename Derived>
14134 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14135 if (LHS.isInvalid())
14136 return ExprError();
14137
14138 ExprResult RHS =
14139 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
14140 if (RHS.isInvalid())
14141 return ExprError();
14142
14143 if (!getDerived().AlwaysRebuild() &&
14144 LHS.get() == E->getLHS() &&
14145 RHS.get() == E->getRHS())
14146 return E;
14147
14148 if (E->isCompoundAssignmentOp())
14149 // FPFeatures has already been established from trailing storage
14150 return getDerived().RebuildBinaryOperator(
14151 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
14152 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14153 FPOptionsOverride NewOverrides(E->getFPFeatures());
14154 getSema().CurFPFeatures =
14155 NewOverrides.applyOverrides(getSema().getLangOpts());
14156 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14157 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
14158 LHS.get(), RHS.get());
14159}
14160
14161template <typename Derived>
14164 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
14165
14166 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
14167 if (LHS.isInvalid())
14168 return ExprError();
14169
14170 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
14171 if (RHS.isInvalid())
14172 return ExprError();
14173
14174 // Extract the already-resolved callee declarations so that we can restrict
14175 // ourselves to using them as the unqualified lookup results when rebuilding.
14176 UnresolvedSet<2> UnqualLookups;
14177 bool ChangedAnyLookups = false;
14178 Expr *PossibleBinOps[] = {E->getSemanticForm(),
14179 const_cast<Expr *>(Decomp.InnerBinOp)};
14180 for (Expr *PossibleBinOp : PossibleBinOps) {
14181 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
14182 if (!Op)
14183 continue;
14184 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
14185 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
14186 continue;
14187
14188 // Transform the callee in case we built a call to a local extern
14189 // declaration.
14190 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
14191 E->getOperatorLoc(), Callee->getFoundDecl()));
14192 if (!Found)
14193 return ExprError();
14194 if (Found != Callee->getFoundDecl())
14195 ChangedAnyLookups = true;
14196 UnqualLookups.addDecl(Found);
14197 }
14198
14199 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
14200 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
14201 // Mark all functions used in the rewrite as referenced. Note that when
14202 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
14203 // function calls, and/or there might be a user-defined conversion sequence
14204 // applied to the operands of the <.
14205 // FIXME: this is a bit instantiation-specific.
14206 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
14207 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
14208 return E;
14209 }
14210
14211 return getDerived().RebuildCXXRewrittenBinaryOperator(
14212 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
14213}
14214
14215template<typename Derived>
14219 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14220 FPOptionsOverride NewOverrides(E->getFPFeatures());
14221 getSema().CurFPFeatures =
14222 NewOverrides.applyOverrides(getSema().getLangOpts());
14223 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14224 return getDerived().TransformBinaryOperator(E);
14225}
14226
14227template<typename Derived>
14230 // Just rebuild the common and RHS expressions and see whether we
14231 // get any changes.
14232
14233 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
14234 if (commonExpr.isInvalid())
14235 return ExprError();
14236
14237 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
14238 if (rhs.isInvalid())
14239 return ExprError();
14240
14241 if (!getDerived().AlwaysRebuild() &&
14242 commonExpr.get() == e->getCommon() &&
14243 rhs.get() == e->getFalseExpr())
14244 return e;
14245
14246 return getDerived().RebuildConditionalOperator(commonExpr.get(),
14247 e->getQuestionLoc(),
14248 nullptr,
14249 e->getColonLoc(),
14250 rhs.get());
14251}
14252
14253template<typename Derived>
14256 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14257 if (Cond.isInvalid())
14258 return ExprError();
14259
14260 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14261 if (LHS.isInvalid())
14262 return ExprError();
14263
14264 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14265 if (RHS.isInvalid())
14266 return ExprError();
14267
14268 if (!getDerived().AlwaysRebuild() &&
14269 Cond.get() == E->getCond() &&
14270 LHS.get() == E->getLHS() &&
14271 RHS.get() == E->getRHS())
14272 return E;
14273
14274 return getDerived().RebuildConditionalOperator(Cond.get(),
14275 E->getQuestionLoc(),
14276 LHS.get(),
14277 E->getColonLoc(),
14278 RHS.get());
14279}
14280
14281template<typename Derived>
14284 // Implicit casts are eliminated during transformation, since they
14285 // will be recomputed by semantic analysis after transformation.
14286 return getDerived().TransformExpr(E->getSubExprAsWritten());
14287}
14288
14289template<typename Derived>
14292 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14293 if (!Type)
14294 return ExprError();
14295
14296 ExprResult SubExpr
14297 = getDerived().TransformExpr(E->getSubExprAsWritten());
14298 if (SubExpr.isInvalid())
14299 return ExprError();
14300
14301 if (!getDerived().AlwaysRebuild() &&
14302 Type == E->getTypeInfoAsWritten() &&
14303 SubExpr.get() == E->getSubExpr())
14304 return E;
14305
14306 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
14307 Type,
14308 E->getRParenLoc(),
14309 SubExpr.get());
14310}
14311
14312template<typename Derived>
14315 TypeSourceInfo *OldT = E->getTypeSourceInfo();
14316 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14317 if (!NewT)
14318 return ExprError();
14319
14320 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
14321 if (Init.isInvalid())
14322 return ExprError();
14323
14324 if (!getDerived().AlwaysRebuild() &&
14325 OldT == NewT &&
14326 Init.get() == E->getInitializer())
14327 return SemaRef.MaybeBindToTemporary(E);
14328
14329 // Note: the expression type doesn't necessarily match the
14330 // type-as-written, but that's okay, because it should always be
14331 // derivable from the initializer.
14332
14333 return getDerived().RebuildCompoundLiteralExpr(
14334 E->getLParenLoc(), NewT,
14335 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
14336}
14337
14338template<typename Derived>
14341 ExprResult Base = getDerived().TransformExpr(E->getBase());
14342 if (Base.isInvalid())
14343 return ExprError();
14344
14345 if (!getDerived().AlwaysRebuild() &&
14346 Base.get() == E->getBase())
14347 return E;
14348
14349 // FIXME: Bad source location
14350 SourceLocation FakeOperatorLoc =
14351 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14352 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14353 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
14354 E->getAccessor());
14355}
14356
14357template <typename Derived>
14360 ExprResult Base = getDerived().TransformExpr(E->getBase());
14361 if (Base.isInvalid())
14362 return ExprError();
14363
14364 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase())
14365 return E;
14366
14367 // FIXME: Bad source location
14368 SourceLocation FakeOperatorLoc =
14369 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14370 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14371 Base.get(), FakeOperatorLoc, /*isArrow*/ false, E->getAccessorLoc(),
14372 E->getAccessor());
14373}
14374
14375template<typename Derived>
14378 if (InitListExpr *Syntactic = E->getSyntacticForm())
14379 E = Syntactic;
14380
14381 bool InitChanged = false;
14382
14385
14387 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
14388 Inits, &InitChanged))
14389 return ExprError();
14390
14391 if (!getDerived().AlwaysRebuild() && !InitChanged) {
14392 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
14393 // in some cases. We can't reuse it in general, because the syntactic and
14394 // semantic forms are linked, and we can't know that semantic form will
14395 // match even if the syntactic form does.
14396 }
14397
14398 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
14399 E->getRBraceLoc(), E->isExplicit());
14400}
14401
14402template<typename Derived>
14405 Designation Desig;
14406
14407 // transform the initializer value
14408 ExprResult Init = getDerived().TransformExpr(E->getInit());
14409 if (Init.isInvalid())
14410 return ExprError();
14411
14412 // transform the designators.
14413 SmallVector<Expr*, 4> ArrayExprs;
14414 bool ExprChanged = false;
14415 for (const DesignatedInitExpr::Designator &D : E->designators()) {
14416 if (D.isFieldDesignator()) {
14417 if (D.getFieldDecl()) {
14418 FieldDecl *Field = cast_or_null<FieldDecl>(
14419 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
14420 if (Field != D.getFieldDecl())
14421 // Rebuild the expression when the transformed FieldDecl is
14422 // different to the already assigned FieldDecl.
14423 ExprChanged = true;
14424 if (Field->isAnonymousStructOrUnion())
14425 continue;
14426 } else {
14427 // Ensure that the designator expression is rebuilt when there isn't
14428 // a resolved FieldDecl in the designator as we don't want to assign
14429 // a FieldDecl to a pattern designator that will be instantiated again.
14430 ExprChanged = true;
14431 }
14432 Desig.AddDesignator(Designator::CreateFieldDesignator(
14433 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
14434 continue;
14435 }
14436
14437 if (D.isArrayDesignator()) {
14438 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
14439 if (Index.isInvalid())
14440 return ExprError();
14441
14442 Desig.AddDesignator(
14443 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
14444
14445 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
14446 ArrayExprs.push_back(Index.get());
14447 continue;
14448 }
14449
14450 assert(D.isArrayRangeDesignator() && "New kind of designator?");
14451 ExprResult Start
14452 = getDerived().TransformExpr(E->getArrayRangeStart(D));
14453 if (Start.isInvalid())
14454 return ExprError();
14455
14456 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
14457 if (End.isInvalid())
14458 return ExprError();
14459
14460 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
14461 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
14462
14463 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
14464 End.get() != E->getArrayRangeEnd(D);
14465
14466 ArrayExprs.push_back(Start.get());
14467 ArrayExprs.push_back(End.get());
14468 }
14469
14470 if (!getDerived().AlwaysRebuild() &&
14471 Init.get() == E->getInit() &&
14472 !ExprChanged)
14473 return E;
14474
14475 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
14476 E->getEqualOrColonLoc(),
14477 E->usesGNUSyntax(), Init.get());
14478}
14479
14480// Seems that if TransformInitListExpr() only works on the syntactic form of an
14481// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
14482template<typename Derived>
14486 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
14487 "initializer");
14488 return ExprError();
14489}
14490
14491template<typename Derived>
14494 NoInitExpr *E) {
14495 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
14496 return ExprError();
14497}
14498
14499template<typename Derived>
14502 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
14503 return ExprError();
14504}
14505
14506template<typename Derived>
14509 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
14510 return ExprError();
14511}
14512
14513template<typename Derived>
14517 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
14518
14519 // FIXME: Will we ever have proper type location here? Will we actually
14520 // need to transform the type?
14521 QualType T = getDerived().TransformType(E->getType());
14522 if (T.isNull())
14523 return ExprError();
14524
14525 if (!getDerived().AlwaysRebuild() &&
14526 T == E->getType())
14527 return E;
14528
14529 return getDerived().RebuildImplicitValueInitExpr(T);
14530}
14531
14532template<typename Derived>
14535 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14536 if (!TInfo)
14537 return ExprError();
14538
14539 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14540 if (SubExpr.isInvalid())
14541 return ExprError();
14542
14543 if (!getDerived().AlwaysRebuild() &&
14544 TInfo == E->getWrittenTypeInfo() &&
14545 SubExpr.get() == E->getSubExpr())
14546 return E;
14547
14548 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14549 TInfo, E->getRParenLoc());
14550}
14551
14552template<typename Derived>
14555 bool ArgumentChanged = false;
14557 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14558 &ArgumentChanged))
14559 return ExprError();
14560
14561 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14562 Inits,
14563 E->getRParenLoc());
14564}
14565
14566/// Transform an address-of-label expression.
14567///
14568/// By default, the transformation of an address-of-label expression always
14569/// rebuilds the expression, so that the label identifier can be resolved to
14570/// the corresponding label statement by semantic analysis.
14571template<typename Derived>
14574 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14575 E->getLabel());
14576 if (!LD)
14577 return ExprError();
14578
14579 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14580 cast<LabelDecl>(LD));
14581}
14582
14583template<typename Derived>
14586 SemaRef.ActOnStartStmtExpr();
14587 StmtResult SubStmt
14588 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14589 if (SubStmt.isInvalid()) {
14590 SemaRef.ActOnStmtExprError();
14591 return ExprError();
14592 }
14593
14594 unsigned OldDepth = E->getTemplateDepth();
14595 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14596
14597 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14598 SubStmt.get() == E->getSubStmt()) {
14599 // Calling this an 'error' is unintuitive, but it does the right thing.
14600 SemaRef.ActOnStmtExprError();
14601 return SemaRef.MaybeBindToTemporary(E);
14602 }
14603
14604 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14605 E->getRParenLoc(), NewDepth);
14606}
14607
14608template<typename Derived>
14611 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14612 if (Cond.isInvalid())
14613 return ExprError();
14614
14615 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14616 if (LHS.isInvalid())
14617 return ExprError();
14618
14619 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14620 if (RHS.isInvalid())
14621 return ExprError();
14622
14623 if (!getDerived().AlwaysRebuild() &&
14624 Cond.get() == E->getCond() &&
14625 LHS.get() == E->getLHS() &&
14626 RHS.get() == E->getRHS())
14627 return E;
14628
14629 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14630 Cond.get(), LHS.get(), RHS.get(),
14631 E->getRParenLoc());
14632}
14633
14634template<typename Derived>
14637 return E;
14638}
14639
14640template<typename Derived>
14643 switch (E->getOperator()) {
14644 case OO_New:
14645 case OO_Delete:
14646 case OO_Array_New:
14647 case OO_Array_Delete:
14648 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14649
14650 case OO_Subscript:
14651 case OO_Call: {
14652 // This is a call to an object's operator().
14653 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14654
14655 // Transform the object itself.
14656 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14657 if (Object.isInvalid())
14658 return ExprError();
14659
14660 // FIXME: Poor location information. Also, if the location for the end of
14661 // the token is within a macro expansion, getLocForEndOfToken() will return
14662 // an invalid source location. If that happens and we have an otherwise
14663 // valid end location, use the valid one instead of the invalid one.
14664 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14665 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14666 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14667 FakeLParenLoc = EndLoc;
14668
14669 // Transform the call arguments.
14671 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14672 Args))
14673 return ExprError();
14674
14675 if (E->getOperator() == OO_Subscript)
14676 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14677 Args, E->getEndLoc());
14678
14679 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14680 E->getEndLoc());
14681 }
14682
14683#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14684 case OO_##Name: \
14685 break;
14686
14687#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14688#include "clang/Basic/OperatorKinds.def"
14689
14690 case OO_Conditional:
14691 llvm_unreachable("conditional operator is not actually overloadable");
14692
14693 case OO_None:
14695 llvm_unreachable("not an overloaded operator?");
14696 }
14697
14699 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14700 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14701 else
14702 First = getDerived().TransformExpr(E->getArg(0));
14703 if (First.isInvalid())
14704 return ExprError();
14705
14706 ExprResult Second;
14707 if (E->getNumArgs() == 2) {
14708 Second =
14709 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14710 if (Second.isInvalid())
14711 return ExprError();
14712 }
14713
14714 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14715 FPOptionsOverride NewOverrides(E->getFPFeatures());
14716 getSema().CurFPFeatures =
14717 NewOverrides.applyOverrides(getSema().getLangOpts());
14718 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14719
14720 Expr *Callee = E->getCallee();
14721 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14722 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14724 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14725 return ExprError();
14726
14727 return getDerived().RebuildCXXOperatorCallExpr(
14728 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14729 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14730 }
14731
14732 UnresolvedSet<1> Functions;
14733 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14734 Callee = ICE->getSubExprAsWritten();
14735 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14736 ValueDecl *VD = cast_or_null<ValueDecl>(
14737 getDerived().TransformDecl(DR->getLocation(), DR));
14738 if (!VD)
14739 return ExprError();
14740
14741 if (!isa<CXXMethodDecl>(VD))
14742 Functions.addDecl(VD);
14743
14744 return getDerived().RebuildCXXOperatorCallExpr(
14745 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14746 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14747}
14748
14749template<typename Derived>
14752 return getDerived().TransformCallExpr(E);
14753}
14754
14755template <typename Derived>
14757 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14758 getSema().CurContext != E->getParentContext();
14759
14760 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14761 return E;
14762
14763 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14764 E->getBeginLoc(), E->getEndLoc(),
14765 getSema().CurContext);
14766}
14767
14768template <typename Derived>
14770 return E;
14771}
14772
14773template<typename Derived>
14776 // Transform the callee.
14777 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14778 if (Callee.isInvalid())
14779 return ExprError();
14780
14781 // Transform exec config.
14782 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14783 if (EC.isInvalid())
14784 return ExprError();
14785
14786 // Transform arguments.
14787 bool ArgChanged = false;
14789 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14790 &ArgChanged))
14791 return ExprError();
14792
14793 if (!getDerived().AlwaysRebuild() &&
14794 Callee.get() == E->getCallee() &&
14795 !ArgChanged)
14796 return SemaRef.MaybeBindToTemporary(E);
14797
14798 // FIXME: Wrong source location information for the '('.
14799 SourceLocation FakeLParenLoc
14800 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14801 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14802 Args,
14803 E->getRParenLoc(), EC.get());
14804}
14805
14806template<typename Derived>
14809 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14810 if (!Type)
14811 return ExprError();
14812
14813 ExprResult SubExpr
14814 = getDerived().TransformExpr(E->getSubExprAsWritten());
14815 if (SubExpr.isInvalid())
14816 return ExprError();
14817
14818 if (!getDerived().AlwaysRebuild() &&
14819 Type == E->getTypeInfoAsWritten() &&
14820 SubExpr.get() == E->getSubExpr())
14821 return E;
14822 return getDerived().RebuildCXXNamedCastExpr(
14825 // FIXME. this should be '(' location
14826 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14827}
14828
14829template<typename Derived>
14832 TypeSourceInfo *TSI =
14833 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14834 if (!TSI)
14835 return ExprError();
14836
14837 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14838 if (Sub.isInvalid())
14839 return ExprError();
14840
14841 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14842 Sub.get(), BCE->getEndLoc());
14843}
14844
14845template<typename Derived>
14847TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14848 return getDerived().TransformCXXNamedCastExpr(E);
14849}
14850
14851template<typename Derived>
14854 return getDerived().TransformCXXNamedCastExpr(E);
14855}
14856
14857template<typename Derived>
14861 return getDerived().TransformCXXNamedCastExpr(E);
14862}
14863
14864template<typename Derived>
14867 return getDerived().TransformCXXNamedCastExpr(E);
14868}
14869
14870template<typename Derived>
14873 return getDerived().TransformCXXNamedCastExpr(E);
14874}
14875
14876template<typename Derived>
14881 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14882 if (!Type)
14883 return ExprError();
14884
14885 ExprResult SubExpr
14886 = getDerived().TransformExpr(E->getSubExprAsWritten());
14887 if (SubExpr.isInvalid())
14888 return ExprError();
14889
14890 if (!getDerived().AlwaysRebuild() &&
14891 Type == E->getTypeInfoAsWritten() &&
14892 SubExpr.get() == E->getSubExpr())
14893 return E;
14894
14895 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14896 E->getLParenLoc(),
14897 SubExpr.get(),
14898 E->getRParenLoc(),
14899 E->isListInitialization());
14900}
14901
14902template<typename Derived>
14905 if (E->isTypeOperand()) {
14906 TypeSourceInfo *TInfo
14907 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14908 if (!TInfo)
14909 return ExprError();
14910
14911 if (!getDerived().AlwaysRebuild() &&
14912 TInfo == E->getTypeOperandSourceInfo())
14913 return E;
14914
14915 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14916 TInfo, E->getEndLoc());
14917 }
14918
14919 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14920 // type. We must not unilaterally enter unevaluated context here, as then
14921 // semantic processing can re-transform an already transformed operand.
14922 Expr *Op = E->getExprOperand();
14924 if (E->isGLValue()) {
14925 QualType OpType = Op->getType();
14926 if (auto *RD = OpType->getAsCXXRecordDecl()) {
14927 if (SemaRef.RequireCompleteType(E->getBeginLoc(), OpType,
14928 diag::err_incomplete_typeid))
14929 return ExprError();
14930
14931 if (RD->isPolymorphic())
14932 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14933 }
14934 }
14935
14938
14939 ExprResult SubExpr = getDerived().TransformExpr(Op);
14940 if (SubExpr.isInvalid())
14941 return ExprError();
14942
14943 if (!getDerived().AlwaysRebuild() &&
14944 SubExpr.get() == E->getExprOperand())
14945 return E;
14946
14947 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14948 SubExpr.get(), E->getEndLoc());
14949}
14950
14951template<typename Derived>
14954 if (E->isTypeOperand()) {
14955 TypeSourceInfo *TInfo
14956 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14957 if (!TInfo)
14958 return ExprError();
14959
14960 if (!getDerived().AlwaysRebuild() &&
14961 TInfo == E->getTypeOperandSourceInfo())
14962 return E;
14963
14964 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14965 TInfo, E->getEndLoc());
14966 }
14967
14970
14971 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14972 if (SubExpr.isInvalid())
14973 return ExprError();
14974
14975 if (!getDerived().AlwaysRebuild() &&
14976 SubExpr.get() == E->getExprOperand())
14977 return E;
14978
14979 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14980 SubExpr.get(), E->getEndLoc());
14981}
14982
14983template<typename Derived>
14986 return E;
14987}
14988
14989template<typename Derived>
14993 return E;
14994}
14995
14996template<typename Derived>
14999
15000 // In lambdas, the qualifiers of the type depends of where in
15001 // the call operator `this` appear, and we do not have a good way to
15002 // rebuild this information, so we transform the type.
15003 //
15004 // In other contexts, the type of `this` may be overrided
15005 // for type deduction, so we need to recompute it.
15006 //
15007 // Always recompute the type if we're in the body of a lambda, and
15008 // 'this' is dependent on a lambda's explicit object parameter; we
15009 // also need to always rebuild the expression in this case to clear
15010 // the flag.
15011 QualType T = [&]() {
15012 auto &S = getSema();
15013 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
15014 return S.getCurrentThisType();
15015 if (S.getCurLambda())
15016 return getDerived().TransformType(E->getType());
15017 return S.getCurrentThisType();
15018 }();
15019
15020 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
15021 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
15022 // Mark it referenced in the new context regardless.
15023 // FIXME: this is a bit instantiation-specific.
15024 getSema().MarkThisReferenced(E);
15025 return E;
15026 }
15027
15028 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
15029}
15030
15031template<typename Derived>
15034 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
15035 if (SubExpr.isInvalid())
15036 return ExprError();
15037
15038 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
15039
15040 if (!getDerived().AlwaysRebuild() &&
15041 SubExpr.get() == E->getSubExpr())
15042 return E;
15043
15044 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
15045 E->isThrownVariableInScope());
15046}
15047
15048template<typename Derived>
15051 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
15052 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
15053 if (!Param)
15054 return ExprError();
15055
15056 ExprResult InitRes;
15057 if (E->hasRewrittenInit()) {
15058 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15059 if (InitRes.isInvalid())
15060 return ExprError();
15061 }
15062
15063 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
15064 E->getUsedContext() == SemaRef.CurContext &&
15065 InitRes.get() == E->getRewrittenExpr())
15066 return E;
15067
15068 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
15069 InitRes.get());
15070}
15071
15072template<typename Derived>
15075 FieldDecl *Field = cast_or_null<FieldDecl>(
15076 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
15077 if (!Field)
15078 return ExprError();
15079
15080 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
15081 E->getUsedContext() == SemaRef.CurContext)
15082 return E;
15083
15084 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
15085}
15086
15087template<typename Derived>
15091 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
15092 if (!T)
15093 return ExprError();
15094
15095 if (!getDerived().AlwaysRebuild() &&
15096 T == E->getTypeSourceInfo())
15097 return E;
15098
15099 return getDerived().RebuildCXXScalarValueInitExpr(T,
15100 /*FIXME:*/T->getTypeLoc().getEndLoc(),
15101 E->getRParenLoc());
15102}
15103
15104template<typename Derived>
15107 // Transform the type that we're allocating
15108 TypeSourceInfo *AllocTypeInfo =
15109 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
15110 if (!AllocTypeInfo)
15111 return ExprError();
15112
15113 // Transform the size of the array we're allocating (if any).
15114 std::optional<Expr *> ArraySize;
15115 if (E->isArray()) {
15116 ExprResult NewArraySize;
15117 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
15118 NewArraySize = getDerived().TransformExpr(*OldArraySize);
15119 if (NewArraySize.isInvalid())
15120 return ExprError();
15121 }
15122 ArraySize = NewArraySize.get();
15123 }
15124
15125 // Transform the placement arguments (if any).
15126 bool ArgumentChanged = false;
15127 SmallVector<Expr*, 8> PlacementArgs;
15128 if (getDerived().TransformExprs(E->getPlacementArgs(),
15129 E->getNumPlacementArgs(), true,
15130 PlacementArgs, &ArgumentChanged))
15131 return ExprError();
15132
15133 // Transform the initializer (if any).
15134 Expr *OldInit = E->getInitializer();
15135 ExprResult NewInit;
15136 if (OldInit)
15137 NewInit = getDerived().TransformInitializer(OldInit, true);
15138 if (NewInit.isInvalid())
15139 return ExprError();
15140
15141 // Transform new operator and delete operator.
15142 FunctionDecl *OperatorNew = nullptr;
15143 if (E->getOperatorNew()) {
15144 OperatorNew = cast_or_null<FunctionDecl>(
15145 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
15146 if (!OperatorNew)
15147 return ExprError();
15148 }
15149
15150 FunctionDecl *OperatorDelete = nullptr;
15151 if (E->getOperatorDelete()) {
15152 OperatorDelete = cast_or_null<FunctionDecl>(
15153 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15154 if (!OperatorDelete)
15155 return ExprError();
15156 }
15157
15158 if (!getDerived().AlwaysRebuild() &&
15159 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
15160 ArraySize == E->getArraySize() &&
15161 NewInit.get() == OldInit &&
15162 OperatorNew == E->getOperatorNew() &&
15163 OperatorDelete == E->getOperatorDelete() &&
15164 !ArgumentChanged) {
15165 // Mark any declarations we need as referenced.
15166 // FIXME: instantiation-specific.
15167 if (OperatorNew)
15168 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
15169 if (OperatorDelete)
15170 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15171
15172 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
15173 QualType ElementType
15174 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
15175 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
15177 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
15178 }
15179 }
15180
15181 return E;
15182 }
15183
15184 QualType AllocType = AllocTypeInfo->getType();
15185 if (!ArraySize) {
15186 // If no array size was specified, but the new expression was
15187 // instantiated with an array type (e.g., "new T" where T is
15188 // instantiated with "int[4]"), extract the outer bound from the
15189 // array type as our array size. We do this with constant and
15190 // dependently-sized array types.
15191 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
15192 if (!ArrayT) {
15193 // Do nothing
15194 } else if (const ConstantArrayType *ConsArrayT
15195 = dyn_cast<ConstantArrayType>(ArrayT)) {
15196 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
15197 SemaRef.Context.getSizeType(),
15198 /*FIXME:*/ E->getBeginLoc());
15199 AllocType = ConsArrayT->getElementType();
15200 } else if (const DependentSizedArrayType *DepArrayT
15201 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
15202 if (DepArrayT->getSizeExpr()) {
15203 ArraySize = DepArrayT->getSizeExpr();
15204 AllocType = DepArrayT->getElementType();
15205 }
15206 }
15207 }
15208
15209 return getDerived().RebuildCXXNewExpr(
15210 E->getBeginLoc(), E->isGlobalNew(),
15211 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
15212 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
15213 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
15214}
15215
15216template<typename Derived>
15219 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
15220 if (Operand.isInvalid())
15221 return ExprError();
15222
15223 // Transform the delete operator, if known.
15224 FunctionDecl *OperatorDelete = nullptr;
15225 if (E->getOperatorDelete()) {
15226 OperatorDelete = cast_or_null<FunctionDecl>(
15227 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15228 if (!OperatorDelete)
15229 return ExprError();
15230 }
15231
15232 if (!getDerived().AlwaysRebuild() &&
15233 Operand.get() == E->getArgument() &&
15234 OperatorDelete == E->getOperatorDelete()) {
15235 // Mark any declarations we need as referenced.
15236 // FIXME: instantiation-specific.
15237 if (OperatorDelete)
15238 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15239
15240 if (!E->getArgument()->isTypeDependent()) {
15242 E->getDestroyedType());
15243 if (auto *Record = Destroyed->getAsCXXRecordDecl())
15244 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15245 SemaRef.LookupDestructor(Record));
15246 }
15247
15248 return E;
15249 }
15250
15251 return getDerived().RebuildCXXDeleteExpr(
15252 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
15253}
15254
15255template<typename Derived>
15259 ExprResult Base = getDerived().TransformExpr(E->getBase());
15260 if (Base.isInvalid())
15261 return ExprError();
15262
15263 ParsedType ObjectTypePtr;
15264 bool MayBePseudoDestructor = false;
15265 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15266 E->getOperatorLoc(),
15267 E->isArrow()? tok::arrow : tok::period,
15268 ObjectTypePtr,
15269 MayBePseudoDestructor);
15270 if (Base.isInvalid())
15271 return ExprError();
15272
15273 QualType ObjectType = ObjectTypePtr.get();
15274 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
15275 if (QualifierLoc) {
15276 QualifierLoc
15277 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
15278 if (!QualifierLoc)
15279 return ExprError();
15280 }
15281 CXXScopeSpec SS;
15282 SS.Adopt(QualifierLoc);
15283
15285 if (E->getDestroyedTypeInfo()) {
15286 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
15287 E->getDestroyedTypeInfo(), ObjectType,
15288 /*FirstQualifierInScope=*/nullptr);
15289 if (!DestroyedTypeInfo)
15290 return ExprError();
15291 Destroyed = DestroyedTypeInfo;
15292 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
15293 // We aren't likely to be able to resolve the identifier down to a type
15294 // now anyway, so just retain the identifier.
15295 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
15296 E->getDestroyedTypeLoc());
15297 } else {
15298 // Look for a destructor known with the given name.
15299 ParsedType T = SemaRef.getDestructorName(
15300 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
15301 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
15302 if (!T)
15303 return ExprError();
15304
15305 Destroyed
15307 E->getDestroyedTypeLoc());
15308 }
15309
15310 TypeSourceInfo *ScopeTypeInfo = nullptr;
15311 if (E->getScopeTypeInfo()) {
15312 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
15313 E->getScopeTypeInfo(), ObjectType, nullptr);
15314 if (!ScopeTypeInfo)
15315 return ExprError();
15316 }
15317
15318 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
15319 E->getOperatorLoc(),
15320 E->isArrow(),
15321 SS,
15322 ScopeTypeInfo,
15323 E->getColonColonLoc(),
15324 E->getTildeLoc(),
15325 Destroyed);
15326}
15327
15328template <typename Derived>
15330 bool RequiresADL,
15331 LookupResult &R) {
15332 // Transform all the decls.
15333 bool AllEmptyPacks = true;
15334 for (auto *OldD : Old->decls()) {
15335 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
15336 if (!InstD) {
15337 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
15338 // This can happen because of dependent hiding.
15339 if (isa<UsingShadowDecl>(OldD))
15340 continue;
15341 else {
15342 R.clear();
15343 return true;
15344 }
15345 }
15346
15347 // Expand using pack declarations.
15348 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
15349 ArrayRef<NamedDecl*> Decls = SingleDecl;
15350 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
15351 Decls = UPD->expansions();
15352
15353 // Expand using declarations.
15354 for (auto *D : Decls) {
15355 if (auto *UD = dyn_cast<UsingDecl>(D)) {
15356 for (auto *SD : UD->shadows())
15357 R.addDecl(SD);
15358 } else {
15359 R.addDecl(D);
15360 }
15361 }
15362
15363 AllEmptyPacks &= Decls.empty();
15364 }
15365
15366 // C++ [temp.res]/8.4.2:
15367 // The program is ill-formed, no diagnostic required, if [...] lookup for
15368 // a name in the template definition found a using-declaration, but the
15369 // lookup in the corresponding scope in the instantiation odoes not find
15370 // any declarations because the using-declaration was a pack expansion and
15371 // the corresponding pack is empty
15372 if (AllEmptyPacks && !RequiresADL) {
15373 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
15374 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
15375 return true;
15376 }
15377
15378 // Resolve a kind, but don't do any further analysis. If it's
15379 // ambiguous, the callee needs to deal with it.
15380 R.resolveKind();
15381
15382 if (Old->hasTemplateKeyword() && !R.empty()) {
15383 NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
15384 getSema().FilterAcceptableTemplateNames(R,
15385 /*AllowFunctionTemplates=*/true,
15386 /*AllowDependent=*/true);
15387 if (R.empty()) {
15388 // If a 'template' keyword was used, a lookup that finds only non-template
15389 // names is an error.
15390 getSema().Diag(R.getNameLoc(),
15391 diag::err_template_kw_refers_to_non_template)
15392 << R.getLookupName() << Old->getQualifierLoc().getSourceRange()
15393 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
15394 getSema().Diag(FoundDecl->getLocation(),
15395 diag::note_template_kw_refers_to_non_template)
15396 << R.getLookupName();
15397 return true;
15398 }
15399 }
15400
15401 return false;
15402}
15403
15404template <typename Derived>
15409
15410template <typename Derived>
15413 bool IsAddressOfOperand) {
15414 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
15416
15417 // Transform the declaration set.
15418 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
15419 return ExprError();
15420
15421 // Rebuild the nested-name qualifier, if present.
15422 CXXScopeSpec SS;
15423 if (Old->getQualifierLoc()) {
15424 NestedNameSpecifierLoc QualifierLoc
15425 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15426 if (!QualifierLoc)
15427 return ExprError();
15428
15429 SS.Adopt(QualifierLoc);
15430 }
15431
15432 if (Old->getNamingClass()) {
15433 CXXRecordDecl *NamingClass
15434 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
15435 Old->getNameLoc(),
15436 Old->getNamingClass()));
15437 if (!NamingClass) {
15438 R.clear();
15439 return ExprError();
15440 }
15441
15442 R.setNamingClass(NamingClass);
15443 }
15444
15445 // Rebuild the template arguments, if any.
15446 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15447 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
15448 if (Old->hasExplicitTemplateArgs() &&
15449 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15450 Old->getNumTemplateArgs(),
15451 TransArgs)) {
15452 R.clear();
15453 return ExprError();
15454 }
15455
15456 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
15457 // a non-static data member is named in an unevaluated operand, or when
15458 // a member is named in a dependent class scope function template explicit
15459 // specialization that is neither declared static nor with an explicit object
15460 // parameter.
15461 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
15462 return SemaRef.BuildPossibleImplicitMemberExpr(
15463 SS, TemplateKWLoc, R,
15464 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
15465 /*S=*/nullptr);
15466
15467 // If we have neither explicit template arguments, nor the template keyword,
15468 // it's a normal declaration name or member reference.
15469 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
15470 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
15471
15472 // If we have template arguments, then rebuild the template-id expression.
15473 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
15474 Old->requiresADL(), &TransArgs);
15475}
15476
15477template<typename Derived>
15480 bool ArgChanged = false;
15482 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
15483 TypeSourceInfo *From = E->getArg(I);
15484 TypeLoc FromTL = From->getTypeLoc();
15485 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
15486 TypeLocBuilder TLB;
15487 TLB.reserve(FromTL.getFullDataSize());
15488 QualType To = getDerived().TransformType(TLB, FromTL);
15489 if (To.isNull())
15490 return ExprError();
15491
15492 if (To == From->getType())
15493 Args.push_back(From);
15494 else {
15495 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15496 ArgChanged = true;
15497 }
15498 continue;
15499 }
15500
15501 ArgChanged = true;
15502
15503 // We have a pack expansion. Instantiate it.
15504 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
15505 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
15507 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
15508
15509 // Determine whether the set of unexpanded parameter packs can and should
15510 // be expanded.
15511 bool Expand = true;
15512 bool RetainExpansion = false;
15513 UnsignedOrNone OrigNumExpansions =
15514 ExpansionTL.getTypePtr()->getNumExpansions();
15515 UnsignedOrNone NumExpansions = OrigNumExpansions;
15516 if (getDerived().TryExpandParameterPacks(
15517 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
15518 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15519 RetainExpansion, NumExpansions))
15520 return ExprError();
15521
15522 if (!Expand) {
15523 // The transform has determined that we should perform a simple
15524 // transformation on the pack expansion, producing another pack
15525 // expansion.
15526 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
15527
15528 TypeLocBuilder TLB;
15529 TLB.reserve(From->getTypeLoc().getFullDataSize());
15530
15531 QualType To = getDerived().TransformType(TLB, PatternTL);
15532 if (To.isNull())
15533 return ExprError();
15534
15535 To = getDerived().RebuildPackExpansionType(To,
15536 PatternTL.getSourceRange(),
15537 ExpansionTL.getEllipsisLoc(),
15538 NumExpansions);
15539 if (To.isNull())
15540 return ExprError();
15541
15542 PackExpansionTypeLoc ToExpansionTL
15543 = TLB.push<PackExpansionTypeLoc>(To);
15544 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15545 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15546 continue;
15547 }
15548
15549 // Expand the pack expansion by substituting for each argument in the
15550 // pack(s).
15551 for (unsigned I = 0; I != *NumExpansions; ++I) {
15552 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15553 TypeLocBuilder TLB;
15554 TLB.reserve(PatternTL.getFullDataSize());
15555 QualType To = getDerived().TransformType(TLB, PatternTL);
15556 if (To.isNull())
15557 return ExprError();
15558
15559 if (To->containsUnexpandedParameterPack()) {
15560 To = getDerived().RebuildPackExpansionType(To,
15561 PatternTL.getSourceRange(),
15562 ExpansionTL.getEllipsisLoc(),
15563 NumExpansions);
15564 if (To.isNull())
15565 return ExprError();
15566
15567 PackExpansionTypeLoc ToExpansionTL
15568 = TLB.push<PackExpansionTypeLoc>(To);
15569 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15570 }
15571
15572 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15573 }
15574
15575 if (!RetainExpansion)
15576 continue;
15577
15578 // If we're supposed to retain a pack expansion, do so by temporarily
15579 // forgetting the partially-substituted parameter pack.
15580 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15581
15582 TypeLocBuilder TLB;
15583 TLB.reserve(From->getTypeLoc().getFullDataSize());
15584
15585 QualType To = getDerived().TransformType(TLB, PatternTL);
15586 if (To.isNull())
15587 return ExprError();
15588
15589 To = getDerived().RebuildPackExpansionType(To,
15590 PatternTL.getSourceRange(),
15591 ExpansionTL.getEllipsisLoc(),
15592 NumExpansions);
15593 if (To.isNull())
15594 return ExprError();
15595
15596 PackExpansionTypeLoc ToExpansionTL
15597 = TLB.push<PackExpansionTypeLoc>(To);
15598 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15599 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15600 }
15601
15602 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15603 return E;
15604
15605 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15606 E->getEndLoc());
15607}
15608
15609template<typename Derived>
15613 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15614 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15615 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15616 Old->NumTemplateArgs, TransArgs))
15617 return ExprError();
15618
15619 return getDerived().RebuildConceptSpecializationExpr(
15620 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15621 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15622 &TransArgs);
15623}
15624
15625template<typename Derived>
15628 SmallVector<ParmVarDecl*, 4> TransParams;
15629 SmallVector<QualType, 4> TransParamTypes;
15630 Sema::ExtParameterInfoBuilder ExtParamInfos;
15631
15632 // C++2a [expr.prim.req]p2
15633 // Expressions appearing within a requirement-body are unevaluated operands.
15637
15639 getSema().Context, getSema().CurContext,
15640 E->getBody()->getBeginLoc());
15641
15642 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15643
15644 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15645 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15646 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15647
15648 for (ParmVarDecl *Param : TransParams)
15649 if (Param)
15650 Param->setDeclContext(Body);
15651
15652 // On failure to transform, TransformRequiresTypeParams returns an expression
15653 // in the event that the transformation of the type params failed in some way.
15654 // It is expected that this will result in a 'not satisfied' Requires clause
15655 // when instantiating.
15656 if (!TypeParamResult.isUnset())
15657 return TypeParamResult;
15658
15660 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15661 TransReqs))
15662 return ExprError();
15663
15664 for (concepts::Requirement *Req : TransReqs) {
15665 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15666 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15667 ER->getReturnTypeRequirement()
15668 .getTypeConstraintTemplateParameterList()->getParam(0)
15669 ->setDeclContext(Body);
15670 }
15671 }
15672 }
15673
15674 return getDerived().RebuildRequiresExpr(
15675 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15676 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15677}
15678
15679template<typename Derived>
15683 for (concepts::Requirement *Req : Reqs) {
15684 concepts::Requirement *TransReq = nullptr;
15685 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15686 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15687 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15688 TransReq = getDerived().TransformExprRequirement(ExprReq);
15689 else
15690 TransReq = getDerived().TransformNestedRequirement(
15692 if (!TransReq)
15693 return true;
15694 Transformed.push_back(TransReq);
15695 }
15696 return false;
15697}
15698
15699template<typename Derived>
15703 if (Req->isSubstitutionFailure()) {
15704 if (getDerived().AlwaysRebuild())
15705 return getDerived().RebuildTypeRequirement(
15707 return Req;
15708 }
15709 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15710 if (!TransType)
15711 return nullptr;
15712 return getDerived().RebuildTypeRequirement(TransType);
15713}
15714
15715template<typename Derived>
15718 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15719 if (Req->isExprSubstitutionFailure())
15720 TransExpr = Req->getExprSubstitutionDiagnostic();
15721 else {
15722 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15723 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15724 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15725 if (TransExprRes.isInvalid())
15726 return nullptr;
15727 TransExpr = TransExprRes.get();
15728 }
15729
15730 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15731 const auto &RetReq = Req->getReturnTypeRequirement();
15732 if (RetReq.isEmpty())
15733 TransRetReq.emplace();
15734 else if (RetReq.isSubstitutionFailure())
15735 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15736 else if (RetReq.isTypeConstraint()) {
15737 TemplateParameterList *OrigTPL =
15738 RetReq.getTypeConstraintTemplateParameterList();
15740 getDerived().TransformTemplateParameterList(OrigTPL);
15741 if (!TPL)
15742 return nullptr;
15743 TransRetReq.emplace(TPL);
15744 }
15745 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15746 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15747 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15748 Req->getNoexceptLoc(),
15749 std::move(*TransRetReq));
15750 return getDerived().RebuildExprRequirement(
15752 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15753}
15754
15755template<typename Derived>
15759 if (Req->hasInvalidConstraint()) {
15760 if (getDerived().AlwaysRebuild())
15761 return getDerived().RebuildNestedRequirement(
15763 return Req;
15764 }
15765 ExprResult TransConstraint =
15766 getDerived().TransformExpr(Req->getConstraintExpr());
15767 if (TransConstraint.isInvalid())
15768 return nullptr;
15769 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15770}
15771
15772template<typename Derived>
15775 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15776 if (!T)
15777 return ExprError();
15778
15779 if (!getDerived().AlwaysRebuild() &&
15781 return E;
15782
15783 ExprResult SubExpr;
15784 {
15787 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15788 if (SubExpr.isInvalid())
15789 return ExprError();
15790 }
15791
15792 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15793 SubExpr.get(), E->getEndLoc());
15794}
15795
15796template<typename Derived>
15799 ExprResult SubExpr;
15800 {
15803 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15804 if (SubExpr.isInvalid())
15805 return ExprError();
15806
15807 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15808 return E;
15809 }
15810
15811 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15812 SubExpr.get(), E->getEndLoc());
15813}
15814
15815template <typename Derived>
15817 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15818 TypeSourceInfo **RecoveryTSI) {
15819 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15820 DRE, AddrTaken, RecoveryTSI);
15821
15822 // Propagate both errors and recovered types, which return ExprEmpty.
15823 if (!NewDRE.isUsable())
15824 return NewDRE;
15825
15826 // We got an expr, wrap it up in parens.
15827 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15828 return PE;
15829 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15830 PE->getRParen());
15831}
15832
15833template <typename Derived>
15839
15840template <typename Derived>
15842 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15843 TypeSourceInfo **RecoveryTSI) {
15844 assert(E->getQualifierLoc());
15845 NestedNameSpecifierLoc QualifierLoc =
15846 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15847 if (!QualifierLoc)
15848 return ExprError();
15849 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15850
15851 // TODO: If this is a conversion-function-id, verify that the
15852 // destination type name (if present) resolves the same way after
15853 // instantiation as it did in the local scope.
15854
15855 DeclarationNameInfo NameInfo =
15856 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15857 if (!NameInfo.getName())
15858 return ExprError();
15859
15860 if (!E->hasExplicitTemplateArgs()) {
15861 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15862 // Note: it is sufficient to compare the Name component of NameInfo:
15863 // if name has not changed, DNLoc has not changed either.
15864 NameInfo.getName() == E->getDeclName())
15865 return E;
15866
15867 return getDerived().RebuildDependentScopeDeclRefExpr(
15868 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15869 IsAddressOfOperand, RecoveryTSI);
15870 }
15871
15872 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15873 if (getDerived().TransformTemplateArguments(
15874 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15875 return ExprError();
15876
15877 return getDerived().RebuildDependentScopeDeclRefExpr(
15878 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15879 RecoveryTSI);
15880}
15881
15882template<typename Derived>
15885 // CXXConstructExprs other than for list-initialization and
15886 // CXXTemporaryObjectExpr are always implicit, so when we have
15887 // a 1-argument construction we just transform that argument.
15888 if (getDerived().AllowSkippingCXXConstructExpr() &&
15889 ((E->getNumArgs() == 1 ||
15890 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15891 (!getDerived().DropCallArgument(E->getArg(0))) &&
15892 !E->isListInitialization()))
15893 return getDerived().TransformInitializer(E->getArg(0),
15894 /*DirectInit*/ false);
15895
15896 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15897
15898 QualType T = getDerived().TransformType(E->getType());
15899 if (T.isNull())
15900 return ExprError();
15901
15902 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15903 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15904 if (!Constructor)
15905 return ExprError();
15906
15907 bool ArgumentChanged = false;
15909 {
15912 E->isListInitialization());
15913 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15914 &ArgumentChanged))
15915 return ExprError();
15916 }
15917
15918 if (!getDerived().AlwaysRebuild() &&
15919 T == E->getType() &&
15920 Constructor == E->getConstructor() &&
15921 !ArgumentChanged) {
15922 // Mark the constructor as referenced.
15923 // FIXME: Instantiation-specific
15924 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15925 return E;
15926 }
15927
15928 return getDerived().RebuildCXXConstructExpr(
15929 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15930 E->hadMultipleCandidates(), E->isListInitialization(),
15931 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15932 E->getConstructionKind(), E->getParenOrBraceRange());
15933}
15934
15935template<typename Derived>
15938 QualType T = getDerived().TransformType(E->getType());
15939 if (T.isNull())
15940 return ExprError();
15941
15942 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15943 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15944 if (!Constructor)
15945 return ExprError();
15946
15947 if (!getDerived().AlwaysRebuild() &&
15948 T == E->getType() &&
15949 Constructor == E->getConstructor()) {
15950 // Mark the constructor as referenced.
15951 // FIXME: Instantiation-specific
15952 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15953 return E;
15954 }
15955
15956 return getDerived().RebuildCXXInheritedCtorInitExpr(
15957 T, E->getLocation(), Constructor,
15958 E->constructsVBase(), E->inheritedFromVBase());
15959}
15960
15961/// Transform a C++ temporary-binding expression.
15962///
15963/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15964/// transform the subexpression and return that.
15965template<typename Derived>
15968 if (auto *Dtor = E->getTemporary()->getDestructor())
15969 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15970 const_cast<CXXDestructorDecl *>(Dtor));
15971 return getDerived().TransformExpr(E->getSubExpr());
15972}
15973
15974/// Transform a C++ expression that contains cleanups that should
15975/// be run after the expression is evaluated.
15976///
15977/// Since ExprWithCleanups nodes are implicitly generated, we
15978/// just transform the subexpression and return that.
15979template<typename Derived>
15982 return getDerived().TransformExpr(E->getSubExpr());
15983}
15984
15985template<typename Derived>
15989 TypeSourceInfo *T =
15990 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15991 if (!T)
15992 return ExprError();
15993
15994 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15995 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15996 if (!Constructor)
15997 return ExprError();
15998
15999 bool ArgumentChanged = false;
16001 Args.reserve(E->getNumArgs());
16002 {
16005 E->isListInitialization());
16006 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16007 &ArgumentChanged))
16008 return ExprError();
16009
16010 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
16011 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc(),
16012 /*IsExplicit=*/true);
16013 if (Res.isInvalid())
16014 return ExprError();
16015 Args = {Res.get()};
16016 }
16017 }
16018
16019 if (!getDerived().AlwaysRebuild() &&
16020 T == E->getTypeSourceInfo() &&
16021 Constructor == E->getConstructor() &&
16022 !ArgumentChanged) {
16023 // FIXME: Instantiation-specific
16024 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16025 return SemaRef.MaybeBindToTemporary(E);
16026 }
16027
16028 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
16029 return getDerived().RebuildCXXTemporaryObjectExpr(
16030 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
16031}
16032
16033template<typename Derived>
16036 // Transform any init-capture expressions before entering the scope of the
16037 // lambda body, because they are not semantically within that scope.
16038 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
16039 struct TransformedInitCapture {
16040 // The location of the ... if the result is retaining a pack expansion.
16041 SourceLocation EllipsisLoc;
16042 // Zero or more expansions of the init-capture.
16043 SmallVector<InitCaptureInfoTy, 4> Expansions;
16044 };
16046 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
16047 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16048 CEnd = E->capture_end();
16049 C != CEnd; ++C) {
16050 if (!E->isInitCapture(C))
16051 continue;
16052
16053 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
16054 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16055
16056 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
16057 UnsignedOrNone NumExpansions) {
16058 ExprResult NewExprInitResult = getDerived().TransformInitializer(
16059 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
16060
16061 if (NewExprInitResult.isInvalid()) {
16062 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
16063 return;
16064 }
16065 Expr *NewExprInit = NewExprInitResult.get();
16066
16067 QualType NewInitCaptureType =
16068 getSema().buildLambdaInitCaptureInitialization(
16069 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
16070 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
16071 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
16073 NewExprInit);
16074 Result.Expansions.push_back(
16075 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
16076 };
16077
16078 // If this is an init-capture pack, consider expanding the pack now.
16079 if (OldVD->isParameterPack()) {
16080 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
16081 ->getTypeLoc()
16084 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
16085
16086 // Determine whether the set of unexpanded parameter packs can and should
16087 // be expanded.
16088 bool Expand = true;
16089 bool RetainExpansion = false;
16090 UnsignedOrNone OrigNumExpansions =
16091 ExpansionTL.getTypePtr()->getNumExpansions();
16092 UnsignedOrNone NumExpansions = OrigNumExpansions;
16093 if (getDerived().TryExpandParameterPacks(
16094 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
16095 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
16096 RetainExpansion, NumExpansions))
16097 return ExprError();
16098 assert(!RetainExpansion && "Should not need to retain expansion after a "
16099 "capture since it cannot be extended");
16100 if (Expand) {
16101 for (unsigned I = 0; I != *NumExpansions; ++I) {
16102 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16103 SubstInitCapture(SourceLocation(), std::nullopt);
16104 }
16105 } else {
16106 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
16107 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
16108 }
16109 } else {
16110 SubstInitCapture(SourceLocation(), std::nullopt);
16111 }
16112 }
16113
16114 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
16115 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
16116
16117 // Create the local class that will describe the lambda.
16118
16119 // FIXME: DependencyKind below is wrong when substituting inside a templated
16120 // context that isn't a DeclContext (such as a variable template), or when
16121 // substituting an unevaluated lambda inside of a function's parameter's type
16122 // - as parameter types are not instantiated from within a function's DC. We
16123 // use evaluation contexts to distinguish the function parameter case.
16126 DeclContext *DC = getSema().CurContext;
16127 // A RequiresExprBodyDecl is not interesting for dependencies.
16128 // For the following case,
16129 //
16130 // template <typename>
16131 // concept C = requires { [] {}; };
16132 //
16133 // template <class F>
16134 // struct Widget;
16135 //
16136 // template <C F>
16137 // struct Widget<F> {};
16138 //
16139 // While we are substituting Widget<F>, the parent of DC would be
16140 // the template specialization itself. Thus, the lambda expression
16141 // will be deemed as dependent even if there are no dependent template
16142 // arguments.
16143 // (A ClassTemplateSpecializationDecl is always a dependent context.)
16144 while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
16145 DC = DC->getParent();
16146 if ((getSema().isUnevaluatedContext() ||
16147 getSema().isConstantEvaluatedContext()) &&
16148 !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
16149 cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
16150 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
16151 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
16152
16153 CXXRecordDecl *OldClass = E->getLambdaClass();
16154 CXXRecordDecl *Class = getSema().createLambdaClosureType(
16155 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
16156 E->getCaptureDefault());
16157 getDerived().transformedLocalDecl(OldClass, {Class});
16158
16159 CXXMethodDecl *NewCallOperator =
16160 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
16161
16162 // Enter the scope of the lambda.
16163 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
16164 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
16165 E->hasExplicitParameters(), E->isMutable());
16166
16167 // Introduce the context of the call operator.
16168 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
16169 /*NewThisContext*/false);
16170
16171 bool Invalid = false;
16172
16173 // Transform captures.
16174 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16175 CEnd = E->capture_end();
16176 C != CEnd; ++C) {
16177 // When we hit the first implicit capture, tell Sema that we've finished
16178 // the list of explicit captures.
16179 if (C->isImplicit())
16180 break;
16181
16182 // Capturing 'this' is trivial.
16183 if (C->capturesThis()) {
16184 // If this is a lambda that is part of a default member initialiser
16185 // and which we're instantiating outside the class that 'this' is
16186 // supposed to refer to, adjust the type of 'this' accordingly.
16187 //
16188 // Otherwise, leave the type of 'this' as-is.
16189 Sema::CXXThisScopeRAII ThisScope(
16190 getSema(),
16191 dyn_cast_if_present<CXXRecordDecl>(
16192 getSema().getFunctionLevelDeclContext()),
16193 Qualifiers());
16194 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16195 /*BuildAndDiagnose*/ true, nullptr,
16196 C->getCaptureKind() == LCK_StarThis);
16197 continue;
16198 }
16199 // Captured expression will be recaptured during captured variables
16200 // rebuilding.
16201 if (C->capturesVLAType())
16202 continue;
16203
16204 // Rebuild init-captures, including the implied field declaration.
16205 if (E->isInitCapture(C)) {
16206 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
16207
16208 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16210
16211 for (InitCaptureInfoTy &Info : NewC.Expansions) {
16212 ExprResult Init = Info.first;
16213 QualType InitQualType = Info.second;
16214 if (Init.isInvalid() || InitQualType.isNull()) {
16215 Invalid = true;
16216 break;
16217 }
16218 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
16219 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
16220 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
16221 getSema().CurContext);
16222 if (!NewVD) {
16223 Invalid = true;
16224 break;
16225 }
16226 NewVDs.push_back(NewVD);
16227 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
16228 // Cases we want to tackle:
16229 // ([C(Pack)] {}, ...)
16230 // But rule out cases e.g.
16231 // [...C = Pack()] {}
16232 if (NewC.EllipsisLoc.isInvalid())
16233 LSI->ContainsUnexpandedParameterPack |=
16234 Init.get()->containsUnexpandedParameterPack();
16235 }
16236
16237 if (Invalid)
16238 break;
16239
16240 getDerived().transformedLocalDecl(OldVD, NewVDs);
16241 continue;
16242 }
16243
16244 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16245
16246 // Determine the capture kind for Sema.
16248 : C->getCaptureKind() == LCK_ByCopy
16251 SourceLocation EllipsisLoc;
16252 if (C->isPackExpansion()) {
16253 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
16254 bool ShouldExpand = false;
16255 bool RetainExpansion = false;
16256 UnsignedOrNone NumExpansions = std::nullopt;
16257 if (getDerived().TryExpandParameterPacks(
16258 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
16259 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16260 RetainExpansion, NumExpansions)) {
16261 Invalid = true;
16262 continue;
16263 }
16264
16265 if (ShouldExpand) {
16266 // The transform has determined that we should perform an expansion;
16267 // transform and capture each of the arguments.
16268 // expansion of the pattern. Do so.
16269 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
16270 for (unsigned I = 0; I != *NumExpansions; ++I) {
16271 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16272 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
16273 getDerived().TransformDecl(C->getLocation(), Pack));
16274 if (!CapturedVar) {
16275 Invalid = true;
16276 continue;
16277 }
16278
16279 // Capture the transformed variable.
16280 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
16281 }
16282
16283 // FIXME: Retain a pack expansion if RetainExpansion is true.
16284
16285 continue;
16286 }
16287
16288 EllipsisLoc = C->getEllipsisLoc();
16289 }
16290
16291 // Transform the captured variable.
16292 auto *CapturedVar = cast_or_null<ValueDecl>(
16293 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16294 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
16295 Invalid = true;
16296 continue;
16297 }
16298
16299 // This is not an init-capture; however it contains an unexpanded pack e.g.
16300 // ([Pack] {}(), ...)
16301 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
16302 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
16303
16304 // Capture the transformed variable.
16305 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
16306 EllipsisLoc);
16307 }
16308 getSema().finishLambdaExplicitCaptures(LSI);
16309
16310 // Transform the template parameters, and add them to the current
16311 // instantiation scope. The null case is handled correctly.
16312 auto TPL = getDerived().TransformTemplateParameterList(
16313 E->getTemplateParameterList());
16314 LSI->GLTemplateParameterList = TPL;
16315 if (TPL) {
16316 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
16317 TPL);
16318 LSI->ContainsUnexpandedParameterPack |=
16319 TPL->containsUnexpandedParameterPack();
16320 }
16321
16322 TypeLocBuilder NewCallOpTLBuilder;
16323 TypeLoc OldCallOpTypeLoc =
16324 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
16325 QualType NewCallOpType =
16326 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
16327 if (NewCallOpType.isNull())
16328 return ExprError();
16329 LSI->ContainsUnexpandedParameterPack |=
16330 NewCallOpType->containsUnexpandedParameterPack();
16331 TypeSourceInfo *NewCallOpTSI =
16332 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
16333
16334 // The type may be an AttributedType or some other kind of sugar;
16335 // get the actual underlying FunctionProtoType.
16336 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
16337 assert(FPTL && "Not a FunctionProtoType?");
16338
16339 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
16340 if (TRC) {
16341 ExprResult E = getDerived().TransformLambdaConstraint(
16342 const_cast<Expr *>(TRC.ConstraintExpr));
16343 if (E.isInvalid())
16344 return E;
16345 TRC.ConstraintExpr = E.get();
16346 }
16347
16348 LSI->BeforeCompoundStatement = false;
16349 getSema().CompleteLambdaCallOperator(
16350 NewCallOperator, E->getCallOperator()->getLocation(),
16351 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
16352 E->getCallOperator()->getConstexprKind(),
16353 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
16354 E->hasExplicitResultType());
16355
16356 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
16357 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
16358
16359 {
16360 // Number the lambda for linkage purposes if necessary.
16361 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
16362
16363 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
16364 if (getDerived().ReplacingOriginal()) {
16365 Numbering = OldClass->getLambdaNumbering();
16366 }
16367
16368 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
16369 }
16370
16371 // FIXME: Sema's lambda-building mechanism expects us to push an expression
16372 // evaluation context even if we're not transforming the function body.
16373 getSema().PushExpressionEvaluationContextForFunction(
16375 E->getCallOperator());
16376
16377 StmtResult Body;
16378 {
16379 Sema::NonSFINAEContext _(getSema());
16382 C.PointOfInstantiation = E->getBody()->getBeginLoc();
16383 getSema().pushCodeSynthesisContext(C);
16384
16385 // Instantiate the body of the lambda expression.
16386 Body = Invalid ? StmtError()
16387 : getDerived().TransformLambdaBody(E, E->getBody());
16388
16389 getSema().popCodeSynthesisContext();
16390 }
16391
16392 // ActOnLambda* will pop the function scope for us.
16393 FuncScopeCleanup.disable();
16394
16395 if (Body.isInvalid()) {
16396 SavedContext.pop();
16397 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
16398 /*IsInstantiation=*/true);
16399 return ExprError();
16400 }
16401
16402 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
16403 /*IsInstantiation=*/true,
16404 /*RetainFunctionScopeInfo=*/true);
16405 SavedContext.pop();
16406
16407 // Recompute the dependency of the lambda so that we can defer the lambda call
16408 // construction until after we have all the necessary template arguments. For
16409 // example, given
16410 //
16411 // template <class> struct S {
16412 // template <class U>
16413 // using Type = decltype([](U){}(42.0));
16414 // };
16415 // void foo() {
16416 // using T = S<int>::Type<float>;
16417 // ^~~~~~
16418 // }
16419 //
16420 // We would end up here from instantiating S<int> when ensuring its
16421 // completeness. That would transform the lambda call expression regardless of
16422 // the absence of the corresponding argument for U.
16423 //
16424 // Going ahead with unsubstituted type U makes things worse: we would soon
16425 // compare the argument type (which is float) against the parameter U
16426 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
16427 // error suggesting unmatched types 'U' and 'float'!
16428 //
16429 // That said, everything will be fine if we defer that semantic checking.
16430 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
16431 // dependent. Since the CallExpr's dependency boils down to the lambda's
16432 // dependency in this case, we can harness that by recomputing the dependency
16433 // from the instantiation arguments.
16434 //
16435 // FIXME: Creating the type of a lambda requires us to have a dependency
16436 // value, which happens before its substitution. We update its dependency
16437 // *after* the substitution in case we can't decide the dependency
16438 // so early, e.g. because we want to see if any of the *substituted*
16439 // parameters are dependent.
16440 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
16441 Class->setLambdaDependencyKind(DependencyKind);
16442
16443 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
16444 Body.get()->getEndLoc(), LSI);
16445}
16446
16447template<typename Derived>
16452
16453template<typename Derived>
16456 // Transform captures.
16458 CEnd = E->capture_end();
16459 C != CEnd; ++C) {
16460 // When we hit the first implicit capture, tell Sema that we've finished
16461 // the list of explicit captures.
16462 if (!C->isImplicit())
16463 continue;
16464
16465 // Capturing 'this' is trivial.
16466 if (C->capturesThis()) {
16467 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16468 /*BuildAndDiagnose*/ true, nullptr,
16469 C->getCaptureKind() == LCK_StarThis);
16470 continue;
16471 }
16472 // Captured expression will be recaptured during captured variables
16473 // rebuilding.
16474 if (C->capturesVLAType())
16475 continue;
16476
16477 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16478 assert(!E->isInitCapture(C) && "implicit init-capture?");
16479
16480 // Transform the captured variable.
16481 VarDecl *CapturedVar = cast_or_null<VarDecl>(
16482 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16483 if (!CapturedVar || CapturedVar->isInvalidDecl())
16484 return StmtError();
16485
16486 // Capture the transformed variable.
16487 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
16488 }
16489
16490 return S;
16491}
16492
16493template<typename Derived>
16497 TypeSourceInfo *T =
16498 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16499 if (!T)
16500 return ExprError();
16501
16502 bool ArgumentChanged = false;
16504 Args.reserve(E->getNumArgs());
16505 {
16509 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
16510 &ArgumentChanged))
16511 return ExprError();
16512 }
16513
16514 if (!getDerived().AlwaysRebuild() &&
16515 T == E->getTypeSourceInfo() &&
16516 !ArgumentChanged)
16517 return E;
16518
16519 // FIXME: we're faking the locations of the commas
16520 return getDerived().RebuildCXXUnresolvedConstructExpr(
16521 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
16522}
16523
16524template<typename Derived>
16528 // Transform the base of the expression.
16529 ExprResult Base((Expr*) nullptr);
16530 Expr *OldBase;
16531 QualType BaseType;
16532 QualType ObjectType;
16533 if (!E->isImplicitAccess()) {
16534 OldBase = E->getBase();
16535 Base = getDerived().TransformExpr(OldBase);
16536 if (Base.isInvalid())
16537 return ExprError();
16538
16539 // Start the member reference and compute the object's type.
16540 ParsedType ObjectTy;
16541 bool MayBePseudoDestructor = false;
16542 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
16543 E->getOperatorLoc(),
16544 E->isArrow()? tok::arrow : tok::period,
16545 ObjectTy,
16546 MayBePseudoDestructor);
16547 if (Base.isInvalid())
16548 return ExprError();
16549
16550 ObjectType = ObjectTy.get();
16551 BaseType = ((Expr*) Base.get())->getType();
16552 } else {
16553 OldBase = nullptr;
16554 BaseType = getDerived().TransformType(E->getBaseType());
16555 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16556 }
16557
16558 // Transform the first part of the nested-name-specifier that qualifies
16559 // the member name.
16560 NamedDecl *FirstQualifierInScope
16561 = getDerived().TransformFirstQualifierInScope(
16562 E->getFirstQualifierFoundInScope(),
16563 E->getQualifierLoc().getBeginLoc());
16564
16565 NestedNameSpecifierLoc QualifierLoc;
16566 if (E->getQualifier()) {
16567 QualifierLoc
16568 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16569 ObjectType,
16570 FirstQualifierInScope);
16571 if (!QualifierLoc)
16572 return ExprError();
16573 }
16574
16575 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16576
16577 // TODO: If this is a conversion-function-id, verify that the
16578 // destination type name (if present) resolves the same way after
16579 // instantiation as it did in the local scope.
16580
16581 DeclarationNameInfo NameInfo
16582 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16583 if (!NameInfo.getName())
16584 return ExprError();
16585
16586 if (!E->hasExplicitTemplateArgs()) {
16587 // This is a reference to a member without an explicitly-specified
16588 // template argument list. Optimize for this common case.
16589 if (!getDerived().AlwaysRebuild() &&
16590 Base.get() == OldBase &&
16591 BaseType == E->getBaseType() &&
16592 QualifierLoc == E->getQualifierLoc() &&
16593 NameInfo.getName() == E->getMember() &&
16594 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16595 return E;
16596
16597 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16598 BaseType,
16599 E->isArrow(),
16600 E->getOperatorLoc(),
16601 QualifierLoc,
16602 TemplateKWLoc,
16603 FirstQualifierInScope,
16604 NameInfo,
16605 /*TemplateArgs*/nullptr);
16606 }
16607
16608 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16609 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16610 E->getNumTemplateArgs(),
16611 TransArgs))
16612 return ExprError();
16613
16614 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16615 BaseType,
16616 E->isArrow(),
16617 E->getOperatorLoc(),
16618 QualifierLoc,
16619 TemplateKWLoc,
16620 FirstQualifierInScope,
16621 NameInfo,
16622 &TransArgs);
16623}
16624
16625template <typename Derived>
16627 UnresolvedMemberExpr *Old) {
16628 // Transform the base of the expression.
16629 ExprResult Base((Expr *)nullptr);
16630 QualType BaseType;
16631 if (!Old->isImplicitAccess()) {
16632 Base = getDerived().TransformExpr(Old->getBase());
16633 if (Base.isInvalid())
16634 return ExprError();
16635 Base =
16636 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16637 if (Base.isInvalid())
16638 return ExprError();
16639 BaseType = Base.get()->getType();
16640 } else {
16641 BaseType = getDerived().TransformType(Old->getBaseType());
16642 }
16643
16644 NestedNameSpecifierLoc QualifierLoc;
16645 if (Old->getQualifierLoc()) {
16646 QualifierLoc =
16647 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16648 if (!QualifierLoc)
16649 return ExprError();
16650 }
16651
16652 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16653
16654 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16655
16656 // Transform the declaration set.
16657 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16658 return ExprError();
16659
16660 // Determine the naming class.
16661 if (Old->getNamingClass()) {
16662 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16663 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16664 if (!NamingClass)
16665 return ExprError();
16666
16667 R.setNamingClass(NamingClass);
16668 }
16669
16670 TemplateArgumentListInfo TransArgs;
16671 if (Old->hasExplicitTemplateArgs()) {
16672 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16673 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16674 if (getDerived().TransformTemplateArguments(
16675 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16676 return ExprError();
16677 }
16678
16679 // FIXME: to do this check properly, we will need to preserve the
16680 // first-qualifier-in-scope here, just in case we had a dependent
16681 // base (and therefore couldn't do the check) and a
16682 // nested-name-qualifier (and therefore could do the lookup).
16683 NamedDecl *FirstQualifierInScope = nullptr;
16684
16685 return getDerived().RebuildUnresolvedMemberExpr(
16686 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16687 TemplateKWLoc, FirstQualifierInScope, R,
16688 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16689}
16690
16691template<typename Derived>
16696 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16697 if (SubExpr.isInvalid())
16698 return ExprError();
16699
16700 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16701 return E;
16702
16703 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16704}
16705
16706template<typename Derived>
16709 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16710 if (Pattern.isInvalid())
16711 return ExprError();
16712
16713 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16714 return E;
16715
16716 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16717 E->getNumExpansions());
16718}
16719
16720template <typename Derived>
16722 ArrayRef<TemplateArgument> PackArgs) {
16724 for (const TemplateArgument &Arg : PackArgs) {
16725 if (!Arg.isPackExpansion()) {
16726 Result = *Result + 1;
16727 continue;
16728 }
16729
16730 TemplateArgumentLoc ArgLoc;
16731 InventTemplateArgumentLoc(Arg, ArgLoc);
16732
16733 // Find the pattern of the pack expansion.
16734 SourceLocation Ellipsis;
16735 UnsignedOrNone OrigNumExpansions = std::nullopt;
16736 TemplateArgumentLoc Pattern =
16737 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16738 OrigNumExpansions);
16739
16740 // Substitute under the pack expansion. Do not expand the pack (yet).
16741 TemplateArgumentLoc OutPattern;
16742 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16743 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16744 /*Uneval*/ true))
16745 return 1u;
16746
16747 // See if we can determine the number of arguments from the result.
16748 UnsignedOrNone NumExpansions =
16749 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16750 if (!NumExpansions) {
16751 // No: we must be in an alias template expansion, and we're going to
16752 // need to actually expand the packs.
16753 Result = std::nullopt;
16754 break;
16755 }
16756
16757 Result = *Result + *NumExpansions;
16758 }
16759 return Result;
16760}
16761
16762template<typename Derived>
16765 // If E is not value-dependent, then nothing will change when we transform it.
16766 // Note: This is an instantiation-centric view.
16767 if (!E->isValueDependent())
16768 return E;
16769
16772
16774 TemplateArgument ArgStorage;
16775
16776 // Find the argument list to transform.
16777 if (E->isPartiallySubstituted()) {
16778 PackArgs = E->getPartialArguments();
16779 } else if (E->isValueDependent()) {
16780 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16781 bool ShouldExpand = false;
16782 bool RetainExpansion = false;
16783 UnsignedOrNone NumExpansions = std::nullopt;
16784 if (getDerived().TryExpandParameterPacks(
16785 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16786 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16787 RetainExpansion, NumExpansions))
16788 return ExprError();
16789
16790 // If we need to expand the pack, build a template argument from it and
16791 // expand that.
16792 if (ShouldExpand) {
16793 auto *Pack = E->getPack();
16794 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16795 ArgStorage = getSema().Context.getPackExpansionType(
16796 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16797 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16798 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16799 } else {
16800 auto *VD = cast<ValueDecl>(Pack);
16801 ExprResult DRE = getSema().BuildDeclRefExpr(
16802 VD, VD->getType().getNonLValueExprType(getSema().Context),
16803 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16804 E->getPackLoc());
16805 if (DRE.isInvalid())
16806 return ExprError();
16807 ArgStorage = TemplateArgument(
16808 new (getSema().Context)
16809 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16810 /*IsCanonical=*/false);
16811 }
16812 PackArgs = ArgStorage;
16813 }
16814 }
16815
16816 // If we're not expanding the pack, just transform the decl.
16817 if (!PackArgs.size()) {
16818 auto *Pack = cast_or_null<NamedDecl>(
16819 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16820 if (!Pack)
16821 return ExprError();
16822 return getDerived().RebuildSizeOfPackExpr(
16823 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16824 std::nullopt, {});
16825 }
16826
16827 // Try to compute the result without performing a partial substitution.
16829 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16830
16831 // Common case: we could determine the number of expansions without
16832 // substituting.
16833 if (Result)
16834 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16835 E->getPackLoc(),
16836 E->getRParenLoc(), *Result, {});
16837
16838 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16839 E->getPackLoc());
16840 {
16841 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16843 Derived, const TemplateArgument*> PackLocIterator;
16844 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16845 PackLocIterator(*this, PackArgs.end()),
16846 TransformedPackArgs, /*Uneval*/true))
16847 return ExprError();
16848 }
16849
16850 // Check whether we managed to fully-expand the pack.
16851 // FIXME: Is it possible for us to do so and not hit the early exit path?
16853 bool PartialSubstitution = false;
16854 for (auto &Loc : TransformedPackArgs.arguments()) {
16855 Args.push_back(Loc.getArgument());
16856 if (Loc.getArgument().isPackExpansion())
16857 PartialSubstitution = true;
16858 }
16859
16860 if (PartialSubstitution)
16861 return getDerived().RebuildSizeOfPackExpr(
16862 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16863 std::nullopt, Args);
16864
16865 return getDerived().RebuildSizeOfPackExpr(
16866 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16867 /*Length=*/static_cast<unsigned>(Args.size()),
16868 /*PartialArgs=*/{});
16869}
16870
16871template <typename Derived>
16874 if (!E->isValueDependent())
16875 return E;
16876
16877 // Transform the index
16878 ExprResult IndexExpr;
16879 {
16880 EnterExpressionEvaluationContext ConstantContext(
16882 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16883 if (IndexExpr.isInvalid())
16884 return ExprError();
16885 }
16886
16887 SmallVector<Expr *, 5> ExpandedExprs;
16888 bool FullySubstituted = true;
16889 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16890 Expr *Pattern = E->getPackIdExpression();
16892 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16893 Unexpanded);
16894 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16895
16896 // Determine whether the set of unexpanded parameter packs can and should
16897 // be expanded.
16898 bool ShouldExpand = true;
16899 bool RetainExpansion = false;
16900 UnsignedOrNone OrigNumExpansions = std::nullopt,
16901 NumExpansions = std::nullopt;
16902 if (getDerived().TryExpandParameterPacks(
16903 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16904 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16905 RetainExpansion, NumExpansions))
16906 return true;
16907 if (!ShouldExpand) {
16908 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16909 ExprResult Pack = getDerived().TransformExpr(Pattern);
16910 if (Pack.isInvalid())
16911 return ExprError();
16912 return getDerived().RebuildPackIndexingExpr(
16913 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16914 {}, /*FullySubstituted=*/false);
16915 }
16916 for (unsigned I = 0; I != *NumExpansions; ++I) {
16917 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16918 ExprResult Out = getDerived().TransformExpr(Pattern);
16919 if (Out.isInvalid())
16920 return true;
16921 if (Out.get()->containsUnexpandedParameterPack()) {
16922 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16923 OrigNumExpansions);
16924 if (Out.isInvalid())
16925 return true;
16926 FullySubstituted = false;
16927 }
16928 ExpandedExprs.push_back(Out.get());
16929 }
16930 // If we're supposed to retain a pack expansion, do so by temporarily
16931 // forgetting the partially-substituted parameter pack.
16932 if (RetainExpansion) {
16933 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16934
16935 ExprResult Out = getDerived().TransformExpr(Pattern);
16936 if (Out.isInvalid())
16937 return true;
16938
16939 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16940 OrigNumExpansions);
16941 if (Out.isInvalid())
16942 return true;
16943 FullySubstituted = false;
16944 ExpandedExprs.push_back(Out.get());
16945 }
16946 } else if (!E->expandsToEmptyPack()) {
16947 if (getDerived().TransformExprs(E->getExpressions().data(),
16948 E->getExpressions().size(), false,
16949 ExpandedExprs))
16950 return ExprError();
16951 }
16952
16953 return getDerived().RebuildPackIndexingExpr(
16954 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16955 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16956}
16957
16958template <typename Derived>
16961 if (!getSema().ArgPackSubstIndex)
16962 // We aren't expanding the parameter pack, so just return ourselves.
16963 return E;
16964
16965 TemplateArgument Pack = E->getArgumentPack();
16967 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
16968 E->getAssociatedDecl(), E->getParameterPack()->getPosition(),
16969 E->getParameterPack()->getType(), E->getParameterPackLocation(), Arg,
16970 SemaRef.getPackIndex(Pack), E->getFinal());
16971}
16972
16973template <typename Derived>
16976 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16977
16978 // Insert a constant-evaluated context for the transform.
16979 // Otherwise, when a normalized constraint places the replacement inside
16980 // an unevaluated operand (e.g. decltype), entities it refers to are not
16981 // odr-used, and the constant evaluation performed by CheckTemplateArgument
16982 // below can spuriously fail for otherwise valid replacements,
16983 // e.g. when a call materializes a function parameter of class type whose
16984 // special members were never instantiated.
16985 EnterExpressionEvaluationContext ConstantEvaluated(
16989
16990 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
16991 if (Replacement.isInvalid())
16992 return true;
16993
16994 Decl *AssociatedDecl =
16995 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
16996 if (!AssociatedDecl)
16997 return true;
16998
16999 QualType ParamType = TransformType(E->getParameterType());
17000 if (ParamType.isNull())
17001 return true;
17002
17003 if (Replacement.get() == OrigReplacement &&
17004 AssociatedDecl == E->getAssociatedDecl() &&
17005 ParamType == E->getParameterType())
17006 return E;
17007
17008 if (Replacement.get() != OrigReplacement ||
17009 ParamType != E->getParameterType()) {
17010 auto *Param = cast<NonTypeTemplateParmDecl>(std::get<0>(
17011 getReplacedTemplateParameter(AssociatedDecl, E->getIndex())));
17012 // When transforming the replacement expression previously, all Sema
17013 // specific annotations, such as implicit casts, are discarded. Calling the
17014 // corresponding sema action is necessary to recover those. Otherwise,
17015 // equivalency of the result would be lost.
17016 TemplateArgument SugaredConverted, CanonicalConverted;
17017 Replacement = SemaRef.CheckTemplateArgument(
17018 Param, ParamType, Replacement.get(), SugaredConverted,
17019 CanonicalConverted,
17020 /*StrictCheck=*/false, Sema::CTAK_Specified);
17021 if (Replacement.isInvalid())
17022 return true;
17023 } else {
17024 // Otherwise, the same expression would have been produced.
17025 Replacement = E->getReplacement();
17026 }
17027
17028 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17029 AssociatedDecl, E->getIndex(), ParamType, E->getNameLoc(),
17030 TemplateArgument(Replacement.get(), /*IsCanonical=*/false),
17031 E->getPackIndex(), E->getFinal());
17032}
17033
17034template<typename Derived>
17037 // Default behavior is to do nothing with this transformation.
17038 return E;
17039}
17040
17041template<typename Derived>
17045 return getDerived().TransformExpr(E->getSubExpr());
17046}
17047
17048template<typename Derived>
17051 UnresolvedLookupExpr *Callee = nullptr;
17052 if (Expr *OldCallee = E->getCallee()) {
17053 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
17054 if (CalleeResult.isInvalid())
17055 return ExprError();
17056 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
17057 }
17058
17059 Expr *Pattern = E->getPattern();
17060
17062 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
17063 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17064
17065 // Determine whether the set of unexpanded parameter packs can and should
17066 // be expanded.
17067 bool Expand = true;
17068 bool RetainExpansion = false;
17069 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
17070 NumExpansions = OrigNumExpansions;
17071 if (getDerived().TryExpandParameterPacks(
17072 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17073 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17074 NumExpansions))
17075 return true;
17076
17077 if (!Expand) {
17078 // Do not expand any packs here, just transform and rebuild a fold
17079 // expression.
17080 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17081
17082 ExprResult LHS =
17083 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
17084 if (LHS.isInvalid())
17085 return true;
17086
17087 ExprResult RHS =
17088 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
17089 if (RHS.isInvalid())
17090 return true;
17091
17092 if (!getDerived().AlwaysRebuild() &&
17093 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
17094 return E;
17095
17096 return getDerived().RebuildCXXFoldExpr(
17097 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
17098 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
17099 }
17100
17101 // Formally a fold expression expands to nested parenthesized expressions.
17102 // Enforce this limit to avoid creating trees so deep we can't safely traverse
17103 // them.
17104 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
17105 SemaRef.Diag(E->getEllipsisLoc(),
17106 clang::diag::err_fold_expression_limit_exceeded)
17107 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
17108 << E->getSourceRange();
17109 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
17110 return ExprError();
17111 }
17112
17113 // The transform has determined that we should perform an elementwise
17114 // expansion of the pattern. Do so.
17115 ExprResult Result = getDerived().TransformExpr(E->getInit());
17116 if (Result.isInvalid())
17117 return true;
17118 bool LeftFold = E->isLeftFold();
17119
17120 // If we're retaining an expansion for a right fold, it is the innermost
17121 // component and takes the init (if any).
17122 if (!LeftFold && RetainExpansion) {
17123 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17124
17125 ExprResult Out = getDerived().TransformExpr(Pattern);
17126 if (Out.isInvalid())
17127 return true;
17128
17129 Result = getDerived().RebuildCXXFoldExpr(
17130 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
17131 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
17132 if (Result.isInvalid())
17133 return true;
17134 }
17135
17136 bool WarnedOnComparison = false;
17137 for (unsigned I = 0; I != *NumExpansions; ++I) {
17138 Sema::ArgPackSubstIndexRAII SubstIndex(
17139 getSema(), LeftFold ? I : *NumExpansions - I - 1);
17140 ExprResult Out = getDerived().TransformExpr(Pattern);
17141 if (Out.isInvalid())
17142 return true;
17143
17144 if (Out.get()->containsUnexpandedParameterPack()) {
17145 // We still have a pack; retain a pack expansion for this slice.
17146 Result = getDerived().RebuildCXXFoldExpr(
17147 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
17148 E->getOperator(), E->getEllipsisLoc(),
17149 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
17150 OrigNumExpansions);
17151 } else if (Result.isUsable()) {
17152 // We've got down to a single element; build a binary operator.
17153 Expr *LHS = LeftFold ? Result.get() : Out.get();
17154 Expr *RHS = LeftFold ? Out.get() : Result.get();
17155 if (Callee) {
17156 UnresolvedSet<16> Functions;
17157 Functions.append(Callee->decls_begin(), Callee->decls_end());
17158 Result = getDerived().RebuildCXXOperatorCallExpr(
17159 BinaryOperator::getOverloadedOperator(E->getOperator()),
17160 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
17161 Functions, LHS, RHS);
17162 } else {
17163 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
17164 E->getOperator(), LHS, RHS,
17165 /*ForFoldExpresion=*/true);
17166 if (!WarnedOnComparison && Result.isUsable()) {
17167 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
17168 BO && BO->isComparisonOp()) {
17169 WarnedOnComparison = true;
17170 SemaRef.Diag(BO->getBeginLoc(),
17171 diag::warn_comparison_in_fold_expression)
17172 << BO->getOpcodeStr();
17173 }
17174 }
17175 }
17176 } else
17177 Result = Out;
17178
17179 if (Result.isInvalid())
17180 return true;
17181 }
17182
17183 // If we're retaining an expansion for a left fold, it is the outermost
17184 // component and takes the complete expansion so far as its init (if any).
17185 if (LeftFold && RetainExpansion) {
17186 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17187
17188 ExprResult Out = getDerived().TransformExpr(Pattern);
17189 if (Out.isInvalid())
17190 return true;
17191
17192 Result = getDerived().RebuildCXXFoldExpr(
17193 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
17194 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
17195 if (Result.isInvalid())
17196 return true;
17197 }
17198
17199 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
17200 PE->setIsProducedByFoldExpansion();
17201
17202 // If we had no init and an empty pack, and we're not retaining an expansion,
17203 // then produce a fallback value or error.
17204 if (Result.isUnset())
17205 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
17206 E->getOperator());
17207 return Result;
17208}
17209
17210template <typename Derived>
17213 SmallVector<Expr *, 4> TransformedInits;
17214 ArrayRef<Expr *> InitExprs = E->getInitExprs();
17215
17216 QualType T = getDerived().TransformType(E->getType());
17217
17218 bool ArgChanged = false;
17219
17220 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
17221 TransformedInits, &ArgChanged))
17222 return ExprError();
17223
17224 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
17225 return E;
17226
17227 return getDerived().RebuildCXXParenListInitExpr(
17228 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
17229 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
17230}
17231
17232template<typename Derived>
17236 return getDerived().TransformExpr(E->getSubExpr());
17237}
17238
17239template<typename Derived>
17242 return SemaRef.MaybeBindToTemporary(E);
17243}
17244
17245template<typename Derived>
17248 return E;
17249}
17250
17251template<typename Derived>
17254 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
17255 if (SubExpr.isInvalid())
17256 return ExprError();
17257
17258 if (!getDerived().AlwaysRebuild() &&
17259 SubExpr.get() == E->getSubExpr())
17260 return E;
17261
17262 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
17263}
17264
17265template<typename Derived>
17268 // Transform each of the elements.
17269 SmallVector<Expr *, 8> Elements;
17270 bool ArgChanged = false;
17271 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
17272 /*IsCall=*/false, Elements, &ArgChanged))
17273 return ExprError();
17274
17275 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17276 return SemaRef.MaybeBindToTemporary(E);
17277
17278 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
17279 Elements.data(),
17280 Elements.size());
17281}
17282
17283template<typename Derived>
17287 // Transform each of the elements.
17289 bool ArgChanged = false;
17290 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
17291 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
17292
17293 if (OrigElement.isPackExpansion()) {
17294 // This key/value element is a pack expansion.
17296 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
17297 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
17298 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17299
17300 // Determine whether the set of unexpanded parameter packs can
17301 // and should be expanded.
17302 bool Expand = true;
17303 bool RetainExpansion = false;
17304 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
17305 UnsignedOrNone NumExpansions = OrigNumExpansions;
17306 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
17307 OrigElement.Value->getEndLoc());
17308 if (getDerived().TryExpandParameterPacks(
17309 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
17310 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17311 NumExpansions))
17312 return ExprError();
17313
17314 if (!Expand) {
17315 // The transform has determined that we should perform a simple
17316 // transformation on the pack expansion, producing another pack
17317 // expansion.
17318 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17319 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17320 if (Key.isInvalid())
17321 return ExprError();
17322
17323 if (Key.get() != OrigElement.Key)
17324 ArgChanged = true;
17325
17326 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17327 if (Value.isInvalid())
17328 return ExprError();
17329
17330 if (Value.get() != OrigElement.Value)
17331 ArgChanged = true;
17332
17333 ObjCDictionaryElement Expansion = {
17334 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
17335 };
17336 Elements.push_back(Expansion);
17337 continue;
17338 }
17339
17340 // Record right away that the argument was changed. This needs
17341 // to happen even if the array expands to nothing.
17342 ArgChanged = true;
17343
17344 // The transform has determined that we should perform an elementwise
17345 // expansion of the pattern. Do so.
17346 for (unsigned I = 0; I != *NumExpansions; ++I) {
17347 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17348 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17349 if (Key.isInvalid())
17350 return ExprError();
17351
17352 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17353 if (Value.isInvalid())
17354 return ExprError();
17355
17356 ObjCDictionaryElement Element = {
17357 Key.get(), Value.get(), SourceLocation(), NumExpansions
17358 };
17359
17360 // If any unexpanded parameter packs remain, we still have a
17361 // pack expansion.
17362 // FIXME: Can this really happen?
17363 if (Key.get()->containsUnexpandedParameterPack() ||
17364 Value.get()->containsUnexpandedParameterPack())
17365 Element.EllipsisLoc = OrigElement.EllipsisLoc;
17366
17367 Elements.push_back(Element);
17368 }
17369
17370 // FIXME: Retain a pack expansion if RetainExpansion is true.
17371
17372 // We've finished with this pack expansion.
17373 continue;
17374 }
17375
17376 // Transform and check key.
17377 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17378 if (Key.isInvalid())
17379 return ExprError();
17380
17381 if (Key.get() != OrigElement.Key)
17382 ArgChanged = true;
17383
17384 // Transform and check value.
17386 = getDerived().TransformExpr(OrigElement.Value);
17387 if (Value.isInvalid())
17388 return ExprError();
17389
17390 if (Value.get() != OrigElement.Value)
17391 ArgChanged = true;
17392
17393 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
17394 std::nullopt};
17395 Elements.push_back(Element);
17396 }
17397
17398 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17399 return SemaRef.MaybeBindToTemporary(E);
17400
17401 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
17402 Elements);
17403}
17404
17405template<typename Derived>
17408 TypeSourceInfo *EncodedTypeInfo
17409 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
17410 if (!EncodedTypeInfo)
17411 return ExprError();
17412
17413 if (!getDerived().AlwaysRebuild() &&
17414 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
17415 return E;
17416
17417 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
17418 EncodedTypeInfo,
17419 E->getRParenLoc());
17420}
17421
17422template<typename Derived>
17425 // This is a kind of implicit conversion, and it needs to get dropped
17426 // and recomputed for the same general reasons that ImplicitCastExprs
17427 // do, as well a more specific one: this expression is only valid when
17428 // it appears *immediately* as an argument expression.
17429 return getDerived().TransformExpr(E->getSubExpr());
17430}
17431
17432template<typename Derived>
17435 TypeSourceInfo *TSInfo
17436 = getDerived().TransformType(E->getTypeInfoAsWritten());
17437 if (!TSInfo)
17438 return ExprError();
17439
17440 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
17441 if (Result.isInvalid())
17442 return ExprError();
17443
17444 if (!getDerived().AlwaysRebuild() &&
17445 TSInfo == E->getTypeInfoAsWritten() &&
17446 Result.get() == E->getSubExpr())
17447 return E;
17448
17449 return SemaRef.ObjC().BuildObjCBridgedCast(
17450 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
17451 Result.get());
17452}
17453
17454template <typename Derived>
17457 return E;
17458}
17459
17460template<typename Derived>
17463 // Transform arguments.
17464 bool ArgChanged = false;
17466 Args.reserve(E->getNumArgs());
17467 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
17468 &ArgChanged))
17469 return ExprError();
17470
17471 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
17472 // Class message: transform the receiver type.
17473 TypeSourceInfo *ReceiverTypeInfo
17474 = getDerived().TransformType(E->getClassReceiverTypeInfo());
17475 if (!ReceiverTypeInfo)
17476 return ExprError();
17477
17478 // If nothing changed, just retain the existing message send.
17479 if (!getDerived().AlwaysRebuild() &&
17480 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
17481 return SemaRef.MaybeBindToTemporary(E);
17482
17483 // Build a new class message send.
17485 E->getSelectorLocs(SelLocs);
17486 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
17487 E->getSelector(),
17488 SelLocs,
17489 E->getMethodDecl(),
17490 E->getLeftLoc(),
17491 Args,
17492 E->getRightLoc());
17493 }
17494 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
17495 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
17496 if (!E->getMethodDecl())
17497 return ExprError();
17498
17499 // Build a new class message send to 'super'.
17501 E->getSelectorLocs(SelLocs);
17502 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
17503 E->getSelector(),
17504 SelLocs,
17505 E->getReceiverType(),
17506 E->getMethodDecl(),
17507 E->getLeftLoc(),
17508 Args,
17509 E->getRightLoc());
17510 }
17511
17512 // Instance message: transform the receiver
17513 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
17514 "Only class and instance messages may be instantiated");
17515 ExprResult Receiver
17516 = getDerived().TransformExpr(E->getInstanceReceiver());
17517 if (Receiver.isInvalid())
17518 return ExprError();
17519
17520 // If nothing changed, just retain the existing message send.
17521 if (!getDerived().AlwaysRebuild() &&
17522 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
17523 return SemaRef.MaybeBindToTemporary(E);
17524
17525 // Build a new instance message send.
17527 E->getSelectorLocs(SelLocs);
17528 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
17529 E->getSelector(),
17530 SelLocs,
17531 E->getMethodDecl(),
17532 E->getLeftLoc(),
17533 Args,
17534 E->getRightLoc());
17535}
17536
17537template<typename Derived>
17540 return E;
17541}
17542
17543template<typename Derived>
17546 return E;
17547}
17548
17549template<typename Derived>
17552 // Transform the base expression.
17553 ExprResult Base = getDerived().TransformExpr(E->getBase());
17554 if (Base.isInvalid())
17555 return ExprError();
17556
17557 // We don't need to transform the ivar; it will never change.
17558
17559 // If nothing changed, just retain the existing expression.
17560 if (!getDerived().AlwaysRebuild() &&
17561 Base.get() == E->getBase())
17562 return E;
17563
17564 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17565 E->getLocation(),
17566 E->isArrow(), E->isFreeIvar());
17567}
17568
17569template<typename Derived>
17572 // 'super' and types never change. Property never changes. Just
17573 // retain the existing expression.
17574 if (!E->isObjectReceiver())
17575 return E;
17576
17577 // Transform the base expression.
17578 ExprResult Base = getDerived().TransformExpr(E->getBase());
17579 if (Base.isInvalid())
17580 return ExprError();
17581
17582 // We don't need to transform the property; it will never change.
17583
17584 // If nothing changed, just retain the existing expression.
17585 if (!getDerived().AlwaysRebuild() &&
17586 Base.get() == E->getBase())
17587 return E;
17588
17589 if (E->isExplicitProperty())
17590 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17591 E->getExplicitProperty(),
17592 E->getLocation());
17593
17594 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17595 SemaRef.Context.PseudoObjectTy,
17596 E->getImplicitPropertyGetter(),
17597 E->getImplicitPropertySetter(),
17598 E->getLocation());
17599}
17600
17601template<typename Derived>
17604 // Transform the base expression.
17605 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17606 if (Base.isInvalid())
17607 return ExprError();
17608
17609 // Transform the key expression.
17610 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17611 if (Key.isInvalid())
17612 return ExprError();
17613
17614 // If nothing changed, just retain the existing expression.
17615 if (!getDerived().AlwaysRebuild() &&
17616 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17617 return E;
17618
17619 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17620 Base.get(), Key.get(),
17621 E->getAtIndexMethodDecl(),
17622 E->setAtIndexMethodDecl());
17623}
17624
17625template<typename Derived>
17628 // Transform the base expression.
17629 ExprResult Base = getDerived().TransformExpr(E->getBase());
17630 if (Base.isInvalid())
17631 return ExprError();
17632
17633 // If nothing changed, just retain the existing expression.
17634 if (!getDerived().AlwaysRebuild() &&
17635 Base.get() == E->getBase())
17636 return E;
17637
17638 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17639 E->getOpLoc(),
17640 E->isArrow());
17641}
17642
17643template<typename Derived>
17646 bool ArgumentChanged = false;
17647 SmallVector<Expr*, 8> SubExprs;
17648 SubExprs.reserve(E->getNumSubExprs());
17649 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17650 SubExprs, &ArgumentChanged))
17651 return ExprError();
17652
17653 if (!getDerived().AlwaysRebuild() &&
17654 !ArgumentChanged)
17655 return E;
17656
17657 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17658 SubExprs,
17659 E->getRParenLoc());
17660}
17661
17662template<typename Derived>
17665 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17666 if (SrcExpr.isInvalid())
17667 return ExprError();
17668
17669 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17670 if (!Type)
17671 return ExprError();
17672
17673 if (!getDerived().AlwaysRebuild() &&
17674 Type == E->getTypeSourceInfo() &&
17675 SrcExpr.get() == E->getSrcExpr())
17676 return E;
17677
17678 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17679 SrcExpr.get(), Type,
17680 E->getRParenLoc());
17681}
17682
17683template<typename Derived>
17686 BlockDecl *oldBlock = E->getBlockDecl();
17687
17688 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17689 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17690
17691 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17692 blockScope->TheDecl->setBlockMissingReturnType(
17693 oldBlock->blockMissingReturnType());
17694
17696 SmallVector<QualType, 4> paramTypes;
17697
17698 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17699
17700 // Parameter substitution.
17701 Sema::ExtParameterInfoBuilder extParamInfos;
17702 if (getDerived().TransformFunctionTypeParams(
17703 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17704 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17705 extParamInfos)) {
17706 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17707 return ExprError();
17708 }
17709
17710 QualType exprResultType =
17711 getDerived().TransformType(exprFunctionType->getReturnType());
17712
17713 auto epi = exprFunctionType->getExtProtoInfo();
17714 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17715
17717 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17718 blockScope->FunctionType = functionType;
17719
17720 // Set the parameters on the block decl.
17721 if (!params.empty())
17722 blockScope->TheDecl->setParams(params);
17723
17724 if (!oldBlock->blockMissingReturnType()) {
17725 blockScope->HasImplicitReturnType = false;
17726 blockScope->ReturnType = exprResultType;
17727 }
17728
17729 // Transform the body
17730 StmtResult body = getDerived().TransformStmt(E->getBody());
17731 if (body.isInvalid()) {
17732 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17733 return ExprError();
17734 }
17735
17736#ifndef NDEBUG
17737 // In builds with assertions, make sure that we captured everything we
17738 // captured before.
17739 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17740 for (const auto &I : oldBlock->captures()) {
17741 VarDecl *oldCapture = I.getVariable();
17742
17743 // Ignore parameter packs.
17744 if (oldCapture->isParameterPack())
17745 continue;
17746
17747 VarDecl *newCapture =
17748 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17749 oldCapture));
17750 assert(blockScope->CaptureMap.count(newCapture));
17751 }
17752
17753 // The this pointer may not be captured by the instantiated block, even when
17754 // it's captured by the original block, if the expression causing the
17755 // capture is in the discarded branch of a constexpr if statement.
17756 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17757 "this pointer isn't captured in the old block");
17758 }
17759#endif
17760
17761 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17762 /*Scope=*/nullptr);
17763}
17764
17765template<typename Derived>
17768 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17769 if (SrcExpr.isInvalid())
17770 return ExprError();
17771
17772 QualType Type = getDerived().TransformType(E->getType());
17773
17774 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17775 E->getRParenLoc());
17776}
17777
17778template<typename Derived>
17781 bool ArgumentChanged = false;
17782 SmallVector<Expr*, 8> SubExprs;
17783 SubExprs.reserve(E->getNumSubExprs());
17784 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17785 SubExprs, &ArgumentChanged))
17786 return ExprError();
17787
17788 if (!getDerived().AlwaysRebuild() &&
17789 !ArgumentChanged)
17790 return E;
17791
17792 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17793 E->getOp(), E->getRParenLoc());
17794}
17795
17796//===----------------------------------------------------------------------===//
17797// Type reconstruction
17798//===----------------------------------------------------------------------===//
17799
17800template<typename Derived>
17803 return SemaRef.BuildPointerType(PointeeType, Star,
17805}
17806
17807template<typename Derived>
17810 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17812}
17813
17814template<typename Derived>
17817 bool WrittenAsLValue,
17818 SourceLocation Sigil) {
17819 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17820 Sigil, getDerived().getBaseEntity());
17821}
17822
17823template <typename Derived>
17825 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17826 SourceLocation Sigil) {
17827 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17829}
17830
17831template<typename Derived>
17833 const ObjCTypeParamDecl *Decl,
17834 SourceLocation ProtocolLAngleLoc,
17836 ArrayRef<SourceLocation> ProtocolLocs,
17837 SourceLocation ProtocolRAngleLoc) {
17838 return SemaRef.ObjC().BuildObjCTypeParamType(
17839 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17840 /*FailOnError=*/true);
17841}
17842
17843template<typename Derived>
17845 QualType BaseType,
17846 SourceLocation Loc,
17847 SourceLocation TypeArgsLAngleLoc,
17849 SourceLocation TypeArgsRAngleLoc,
17850 SourceLocation ProtocolLAngleLoc,
17852 ArrayRef<SourceLocation> ProtocolLocs,
17853 SourceLocation ProtocolRAngleLoc) {
17854 return SemaRef.ObjC().BuildObjCObjectType(
17855 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17856 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17857 /*FailOnError=*/true,
17858 /*Rebuilding=*/true);
17859}
17860
17861template<typename Derived>
17863 QualType PointeeType,
17865 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17866}
17867
17868template <typename Derived>
17870 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17871 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17872 if (SizeExpr || !Size)
17873 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17874 IndexTypeQuals, BracketsRange,
17876
17877 QualType Types[] = {
17878 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17879 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17880 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17881 };
17882 QualType SizeType;
17883 for (const auto &T : Types)
17884 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17885 SizeType = T;
17886 break;
17887 }
17888
17889 // Note that we can return a VariableArrayType here in the case where
17890 // the element type was a dependent VariableArrayType.
17891 IntegerLiteral *ArraySize
17892 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17893 /*FIXME*/BracketsRange.getBegin());
17894 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17895 IndexTypeQuals, BracketsRange,
17897}
17898
17899template <typename Derived>
17901 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17902 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17903 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17904 IndexTypeQuals, BracketsRange);
17905}
17906
17907template <typename Derived>
17909 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17910 SourceRange BracketsRange) {
17911 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17912 IndexTypeQuals, BracketsRange);
17913}
17914
17915template <typename Derived>
17917 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17918 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17919 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17920 SizeExpr,
17921 IndexTypeQuals, BracketsRange);
17922}
17923
17924template <typename Derived>
17926 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17927 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17928 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17929 SizeExpr,
17930 IndexTypeQuals, BracketsRange);
17931}
17932
17933template <typename Derived>
17935 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17936 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17937 AttributeLoc);
17938}
17939
17940template <typename Derived>
17942 unsigned NumElements,
17943 VectorKind VecKind) {
17944 // FIXME: semantic checking!
17945 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17946}
17947
17948template <typename Derived>
17950 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17951 VectorKind VecKind) {
17952 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17953}
17954
17955template<typename Derived>
17957 unsigned NumElements,
17958 SourceLocation AttributeLoc) {
17959 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17960 NumElements, true);
17961 IntegerLiteral *VectorSize
17962 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17963 AttributeLoc);
17964 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17965}
17966
17967template<typename Derived>
17970 Expr *SizeExpr,
17971 SourceLocation AttributeLoc) {
17972 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17973}
17974
17975template <typename Derived>
17977 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17978 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17979 NumColumns);
17980}
17981
17982template <typename Derived>
17984 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17985 SourceLocation AttributeLoc) {
17986 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17987 AttributeLoc);
17988}
17989
17990template <typename Derived>
17994 return SemaRef.BuildFunctionType(T, ParamTypes,
17997 EPI);
17998}
17999
18000template<typename Derived>
18002 return SemaRef.Context.getFunctionNoProtoType(T);
18003}
18004
18005template <typename Derived>
18008 SourceLocation NameLoc, Decl *D) {
18009 assert(D && "no decl found");
18010 if (D->isInvalidDecl()) return QualType();
18011
18012 // FIXME: Doesn't account for ObjCInterfaceDecl!
18013 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
18014 // A valid resolved using typename pack expansion decl can have multiple
18015 // UsingDecls, but they must each have exactly one type, and it must be
18016 // the same type in every case. But we must have at least one expansion!
18017 if (UPD->expansions().empty()) {
18018 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
18019 << UPD->isCXXClassMember() << UPD;
18020 return QualType();
18021 }
18022
18023 // We might still have some unresolved types. Try to pick a resolved type
18024 // if we can. The final instantiation will check that the remaining
18025 // unresolved types instantiate to the type we pick.
18026 QualType FallbackT;
18027 QualType T;
18028 for (auto *E : UPD->expansions()) {
18029 QualType ThisT =
18030 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
18031 if (ThisT.isNull())
18032 continue;
18033 if (ThisT->getAs<UnresolvedUsingType>())
18034 FallbackT = ThisT;
18035 else if (T.isNull())
18036 T = ThisT;
18037 else
18038 assert(getSema().Context.hasSameType(ThisT, T) &&
18039 "mismatched resolved types in using pack expansion");
18040 }
18041 return T.isNull() ? FallbackT : T;
18042 }
18043 if (auto *Using = dyn_cast<UsingDecl>(D)) {
18044 assert(Using->hasTypename() &&
18045 "UnresolvedUsingTypenameDecl transformed to non-typename using");
18046
18047 // A valid resolved using typename decl points to exactly one type decl.
18048 assert(++Using->shadow_begin() == Using->shadow_end());
18049
18050 UsingShadowDecl *Shadow = *Using->shadow_begin();
18051 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
18052 return QualType();
18053 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
18054 }
18056 "UnresolvedUsingTypenameDecl transformed to non-using decl");
18057 return SemaRef.Context.getUnresolvedUsingType(
18059}
18060
18061template <typename Derived>
18063 TypeOfKind Kind) {
18064 return SemaRef.BuildTypeofExprType(E, Kind);
18065}
18066
18067template<typename Derived>
18069 TypeOfKind Kind) {
18070 return SemaRef.Context.getTypeOfType(Underlying, Kind);
18071}
18072
18073template <typename Derived>
18075 return SemaRef.BuildDecltypeType(E);
18076}
18077
18078template <typename Derived>
18080 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
18081 SourceLocation EllipsisLoc, bool FullySubstituted,
18082 ArrayRef<QualType> Expansions) {
18083 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
18084 FullySubstituted, Expansions);
18085}
18086
18087template<typename Derived>
18089 UnaryTransformType::UTTKind UKind,
18090 SourceLocation Loc) {
18091 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
18092}
18093
18094template <typename Derived>
18097 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
18098 return SemaRef.CheckTemplateIdType(
18099 Keyword, Template, TemplateNameLoc, TemplateArgs,
18100 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
18101}
18102
18103template<typename Derived>
18105 SourceLocation KWLoc) {
18106 return SemaRef.BuildAtomicType(ValueType, KWLoc);
18107}
18108
18109template<typename Derived>
18111 SourceLocation KWLoc,
18112 bool isReadPipe) {
18113 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
18114 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
18115}
18116
18117template <typename Derived>
18119 unsigned NumBits,
18120 SourceLocation Loc) {
18121 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18122 NumBits, true);
18123 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
18124 SemaRef.Context.IntTy, Loc);
18125 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
18126}
18127
18128template <typename Derived>
18130 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
18131 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
18132}
18133
18134template <typename Derived>
18136 bool TemplateKW,
18137 TemplateName Name) {
18138 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
18139 Name);
18140}
18141
18142template <typename Derived>
18144 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
18145 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
18147 TemplateName.setIdentifier(&Name, NameLoc);
18149 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
18150 TemplateName, ParsedType::make(ObjectType),
18151 /*EnteringContext=*/false, Template,
18152 AllowInjectedClassName);
18153 return Template.get();
18154}
18155
18156template<typename Derived>
18159 SourceLocation TemplateKWLoc,
18160 OverloadedOperatorKind Operator,
18161 SourceLocation NameLoc,
18162 QualType ObjectType,
18163 bool AllowInjectedClassName) {
18164 UnqualifiedId Name;
18165 // FIXME: Bogus location information.
18166 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
18167 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
18169 getSema().ActOnTemplateName(
18170 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
18171 /*EnteringContext=*/false, Template, AllowInjectedClassName);
18172 return Template.get();
18173}
18174
18175template <typename Derived>
18178 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
18179 Expr *Second) {
18180 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
18181
18182 if (First->getObjectKind() == OK_ObjCProperty) {
18185 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
18186 Opc, First, Second);
18187 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
18188 if (Result.isInvalid())
18189 return ExprError();
18190 First = Result.get();
18191 }
18192
18193 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
18194 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
18195 if (Result.isInvalid())
18196 return ExprError();
18197 Second = Result.get();
18198 }
18199
18200 // Determine whether this should be a builtin operation.
18201 if (Op == OO_Subscript) {
18202 if (!First->getType()->isOverloadableType() &&
18203 !Second->getType()->isOverloadableType())
18204 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
18205 OpLoc);
18206 } else if (Op == OO_Arrow) {
18207 // It is possible that the type refers to a RecoveryExpr created earlier
18208 // in the tree transformation.
18209 if (First->getType()->isDependentType())
18210 return ExprError();
18211 // -> is never a builtin operation.
18212 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
18213 } else if (Second == nullptr || isPostIncDec) {
18214 if (!First->getType()->isOverloadableType() ||
18215 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
18216 // The argument is not of overloadable type, or this is an expression
18217 // of the form &Class::member, so try to create a built-in unary
18218 // operation.
18220 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18221
18222 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
18223 }
18224 } else {
18225 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
18226 !First->getType()->isOverloadableType() &&
18227 !Second->getType()->isOverloadableType()) {
18228 // Neither of the arguments is type-dependent or has an overloadable
18229 // type, so try to create a built-in binary operation.
18232 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
18233 if (Result.isInvalid())
18234 return ExprError();
18235
18236 return Result;
18237 }
18238 }
18239
18240 // Create the overloaded operator invocation for unary operators.
18241 if (!Second || isPostIncDec) {
18243 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18244 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
18245 RequiresADL);
18246 }
18247
18248 // Create the overloaded operator invocation for binary operators.
18250 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
18251 First, Second, RequiresADL);
18252 if (Result.isInvalid())
18253 return ExprError();
18254
18255 return Result;
18256}
18257
18258template<typename Derived>
18261 SourceLocation OperatorLoc,
18262 bool isArrow,
18263 CXXScopeSpec &SS,
18264 TypeSourceInfo *ScopeType,
18265 SourceLocation CCLoc,
18266 SourceLocation TildeLoc,
18267 PseudoDestructorTypeStorage Destroyed) {
18268 QualType CanonicalBaseType = Base->getType().getCanonicalType();
18269 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
18270 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
18271 (isArrow && isa<PointerType>(CanonicalBaseType) &&
18272 !cast<PointerType>(CanonicalBaseType)
18273 ->getPointeeType()
18274 ->getAsCanonical<RecordType>())) {
18275 // This pseudo-destructor expression is still a pseudo-destructor.
18276 return SemaRef.BuildPseudoDestructorExpr(
18277 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
18278 CCLoc, TildeLoc, Destroyed);
18279 }
18280
18281 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
18282 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
18283 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
18284 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
18285 NameInfo.setNamedTypeInfo(DestroyedType);
18286
18287 // The scope type is now known to be a valid nested name specifier
18288 // component. Tack it on to the nested name specifier.
18289 if (ScopeType) {
18290 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
18291 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
18292 diag::err_expected_class_or_namespace)
18293 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
18294 return ExprError();
18295 }
18296 SS.clear();
18297 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
18298 }
18299
18300 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
18301 return getSema().BuildMemberReferenceExpr(
18302 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
18303 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
18304 /*TemplateArgs*/ nullptr,
18305 /*S*/ nullptr);
18306}
18307
18308template<typename Derived>
18311 SourceLocation Loc = S->getBeginLoc();
18312 CapturedDecl *CD = S->getCapturedDecl();
18313 unsigned NumParams = CD->getNumParams();
18314 unsigned ContextParamPos = CD->getContextParamPosition();
18316 for (unsigned I = 0; I < NumParams; ++I) {
18317 if (I != ContextParamPos) {
18318 Params.push_back(
18319 std::make_pair(
18320 CD->getParam(I)->getName(),
18321 getDerived().TransformType(CD->getParam(I)->getType())));
18322 } else {
18323 Params.push_back(std::make_pair(StringRef(), QualType()));
18324 }
18325 }
18326 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
18327 S->getCapturedRegionKind(), Params);
18328 StmtResult Body;
18329 {
18330 Sema::CompoundScopeRAII CompoundScope(getSema());
18331 Body = getDerived().TransformStmt(S->getCapturedStmt());
18332 }
18333
18334 if (Body.isInvalid()) {
18335 getSema().ActOnCapturedRegionError();
18336 return StmtError();
18337 }
18338
18339 return getSema().ActOnCapturedRegionEnd(Body.get());
18340}
18341
18342template <typename Derived>
18345 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
18346 // function definition or instantiation of a function template specialization
18347 // and will therefore never appear in a dependent context.
18348 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
18349 "context");
18350}
18351
18352template <typename Derived>
18354 // We can transform the base expression and allow argument resolution to fill
18355 // in the rest.
18356 return getDerived().TransformExpr(E->getArgLValue());
18357}
18358
18359} // end namespace clang
18360
18361#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:4556
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6033
Represents a loop initializing the elements of an array.
Definition Expr.h:5980
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1864
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7231
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2727
Wrapper for source info for arrays.
Definition TypeLoc.h: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:3827
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6745
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6940
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h: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:4459
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4044
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2189
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4180
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2151
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8347
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4716
void setIsVariadic(bool value)
Definition Decl.h:4792
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6684
Wrapper for source info for block pointers.
Definition TypeLoc.h: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:3975
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:2633
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:2898
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:2949
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1523
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4988
unsigned getNumParams() const
Definition Decl.h:5026
unsigned getContextParamPosition() const
Definition Decl.h:5055
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5028
This captures a statement into a function.
Definition Stmt.h: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:3732
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4854
Represents a 'co_await' expression.
Definition ExprCXX.h:5368
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4306
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3611
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h: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:4397
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3865
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1088
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4492
ContinueStmt - This represents a continue.
Definition Stmt.h:3128
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4725
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition StmtCXX.h:474
Represents the body of a coroutine.
Definition StmtCXX.h:321
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3507
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:1276
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:2001
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:4166
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:4116
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2127
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4206
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4578
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2099
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4332
Represents a single C99 designator.
Definition Expr.h:5606
Represents a C99 designated initializer expression.
Definition Expr.h:5563
Designation - Represent a full designation, which is a sequence of designators.
Definition Designator.h:221
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition Designator.h:185
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition Designator.h:155
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Designator.h:115
bool hasErrorOccurred() const
Definition Diagnostic.h: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:5132
Expr * getCondition() const
Definition TypeBase.h:5139
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:744
Represents a reference to emded data.
Definition Expr.h:5141
RAII object that enters a new expression evaluation context.
Wrapper for source info for enum types.
Definition TypeLoc.h:863
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3956
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h: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:6622
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3204
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2897
Represents a function declaration or definition.
Definition Decl.h:2029
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2814
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5380
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:5025
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5771
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5757
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5246
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4990
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:5412
param_type_iterator param_type_begin() const
Definition TypeBase.h:5856
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:4634
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:4929
Represents a C11 generic selection.
Definition Expr.h:6194
AssociationTy< false > Association
Definition Expr.h:6427
GotoStmt - This represents a direct goto.
Definition Stmt.h: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:7409
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:1737
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3859
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6069
Represents a C array with an unspecified size.
Definition TypeBase.h:4014
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:5314
InitListExpr * getSyntacticForm() const
Definition Expr.h:5484
Wrapper for source info for injected class names of class templates.
Definition TypeLoc.h:872
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h: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:3566
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:4370
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:2801
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2871
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2156
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3370
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:3758
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition Template.h:76
This represents a decl that may have a name.
Definition Decl.h:274
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents C++ namespaces and their aliases.
Definition Decl.h:573
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h:5889
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h: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:2432
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2436
@ Field
A field.
Definition Expr.h:2434
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2439
static OpaquePtr make(QualType P)
Definition Ownership.h:61
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1184
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1234
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2096
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Represents a 'collapse' clause on a 'loop' construct.
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A 'default' clause, has the optional 'none' or 'present' argument.
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< OpenACCFirstPrivateRecipe > InitRecipes, SourceLocation EndLoc)
static OpenACCHostClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
An 'if' clause, which has a required condition expression.
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< OpenACCPrivateRecipe > InitRecipes, SourceLocation EndLoc)
A 'self' clause, which has an optional condition expression, or, in the event of an 'update' directiv...
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
void initializeLocal(ASTContext &Context, SourceLocation loc)
Definition TypeLoc.h:1093
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition ExprCXX.h: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:2188
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2213
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2217
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h: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:2936
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2756
PipeType - OpenCL20.
Definition TypeBase.h:8313
bool isReadOnly() const
Definition TypeBase.h:8343
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:3399
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2011
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2697
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6816
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:8495
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8527
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:7515
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3678
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3694
Represents the body of a requires-expression.
Definition DeclCXX.h: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:13805
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8541
A RAII object to enter scope of a compound statement.
Definition Sema.h:1319
A RAII object to temporarily push a declaration context.
Definition Sema.h:3538
A helper class for building up ExtParameterInfos.
Definition Sema.h:13174
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:13193
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:13181
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:14195
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
ExprResult ActOnCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression.
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition Sema.h:9427
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9435
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9430
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:1537
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:7931
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7933
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7932
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:7029
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:1562
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:12121
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
ASTContext & Context
Definition Sema.h:1310
ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a C++ typeid expression with a type operand.
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition Sema.h:938
SemaObjC & ObjC()
Definition Sema.h:1522
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool FullySubstituted=false)
ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
ASTContext & getASTContext() const
Definition Sema.h:941
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *LHS, Expr *RHS, bool RequiresADL=true, bool AllowRewrittenCandidates=true, FunctionDecl *DefaultedFn=nullptr)
Create a binary operation that may resolve to an overloaded operator.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, bool DoCheckConstraintSatisfaction=true)
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, const Designation &Desig, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:84
const LangOptions & getLangOpts() const
Definition Sema.h:934
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1527
@ ReuseLambdaContextDecl
Definition Sema.h:7120
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:1487
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11923
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:1345
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:11918
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2659
void ApplyForRangeOrExpansionStatementLifetimeExtension(VarDecl *RangeVar, ArrayRef< MaterializeTemporaryExpr * > Temporaries)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1450
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:6830
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6840
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6809
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6835
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:8410
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:11171
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:586
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParen)
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition SemaCast.cpp:338
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition SemaStmt.cpp:976
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, SourceLocation RParenLoc, MultiExprArg Args, AtomicExpr::AtomicOp Op, AtomicArgumentOrder ArgOrder=AtomicArgumentOrder::API)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
OpaquePtr< TemplateName > TemplateTy
Definition Sema.h:1302
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:7917
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:437
SemaPseudoObject & PseudoObject()
Definition Sema.h:1547
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Definition Sema.h:1301
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:591
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:552
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition Sema.h:8755
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4649
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h: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:5032
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5092
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4601
Stmt - This represents one statement.
Definition Stmt.h: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:1805
Wrapper for substituted template type parameters.
Definition TypeLoc.h:998
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h: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:3761
SourceLocation getNameLoc() const
Definition TypeLoc.h:822
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:801
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:809
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition TypeLoc.h:816
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:824
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:805
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
const TemplateArgumentLoc * operator->() const
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
TemplateArgumentLocContainerIterator operator++(int)
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator & operator++()
const TemplateArgumentLoc * operator->() const
Iterator adaptor that invents template argument location information for each of the template argumen...
TemplateArgumentLocInventIterator & operator++()
std::iterator_traits< InputIterator >::difference_type difference_type
TemplateArgumentLocInventIterator operator++(int)
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DeducedTemplateStorage * getAsDeducedTemplateName() const
Retrieve the deduced template info, if any.
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NestedNameSpecifier getQualifier() const
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceLocation getLAngleLoc() const
Definition TypeLoc.h: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:6323
A container of type source information.
Definition TypeBase.h:8466
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:8477
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:1876
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2466
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9248
bool isObjCObjectPointerType() const
Definition TypeBase.h:8911
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9325
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3606
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2231
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2631
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2250
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2295
Expr * getSubExpr() const
Definition Expr.h:2291
Opcode getOpcode() const
Definition Expr.h:2286
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1421
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2375
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1088
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h: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:6128
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:3420
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3484
Wrapper for source info for types used via transparent aliases.
Definition TypeLoc.h:785
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4963
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5593
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:4071
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2076
Represents a GCC generic vector type.
Definition TypeBase.h:4280
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:975
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
OpenACCDirectiveKind
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ CPlusPlus23
OpenACCAtomicKind
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1835
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
TryCaptureKind
Definition Sema.h:653
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition Lookup.h:64
@ NotFound
No entity found met the criteria.
Definition Lookup.h:41
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition Lookup.h:54
@ Found
Name lookup found a single declaration that met the criteria.
Definition Lookup.h:50
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition Lookup.h:59
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition Lookup.h:46
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition Specifiers.h:40
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
CXXConstructionKind
Definition ExprCXX.h: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:604
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:238
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h: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:3824
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:6036
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
OpenMPUseDevicePtrFallbackModifier
OpenMP 6.1 use_device_ptr fallback modifier.
ExprResult ExprError()
Definition Ownership.h:265
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:562
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
DeducedKind
Definition TypeBase.h:1808
@ Deduced
The normal deduced case.
Definition TypeBase.h:1815
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
Definition TypeBase.h:1810
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:812
@ Exists
The symbol exists.
Definition Sema.h:805
@ Error
An error occurred.
Definition Sema.h:815
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:808
MutableArrayRef< Stmt * > MultiStmtArg
Definition Ownership.h:260
OpenMPNumThreadsClauseModifier
U cast(CodeGen::Address addr)
Definition Address.h:327
@ PackIndex
Index of a pack indexing expression or specifier.
Definition Sema.h:851
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition OpenMPKinds.h:48
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition Ownership.h:230
SourceLocIdentKind
Definition Expr.h:5019
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6011
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6032
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6022
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6029
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:1995
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
ActionResult< Stmt * > StmtResult
Definition Ownership.h:250
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5149
Holds information about the various types of exception specification.
Definition TypeBase.h:5469
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5485
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5471
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5474
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5477
Extra information about a function prototype.
Definition TypeBase.h:5497
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5502
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3406
const NamespaceBaseDecl * Namespace
Iterator range representation begin:end[:step].
Definition ExprOpenMP.h:154
This structure contains most locations needed for by an OMPVarListClause.
An element in an Objective-C dictionary literal.
Definition ExprObjC.h:295
Data for list of allocators.
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition Sema.h:13254
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13285
bool InLifetimeExtendingContext
Whether we are currently in a context in which all temporaries must be lifetime-extended,...
Definition Sema.h:6951
SmallVector< MaterializeTemporaryExpr *, 8 > ForRangeLifetimeExtendTemps
P2718R0 - Lifetime extension in range-based for loops.
Definition Sema.h:6919
bool RebuildDefaultArgOrDefaultInit
Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
Definition Sema.h:6957
ExpressionEvaluationContext Context
The expression evaluation context.
Definition Sema.h:6867
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1334
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3338
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions