clang 22.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"
43#include "clang/Sema/SemaObjC.h"
47#include "clang/Sema/SemaSYCL.h"
48#include "clang/Sema/Template.h"
49#include "llvm/ADT/ArrayRef.h"
50#include "llvm/Support/ErrorHandling.h"
51#include <algorithm>
52#include <optional>
53
54using namespace llvm::omp;
55
56namespace clang {
57using namespace sema;
58
59// This helper class is used to facilitate pack expansion during tree transform.
69
70/// A semantic tree transformation that allows one to transform one
71/// abstract syntax tree into another.
72///
73/// A new tree transformation is defined by creating a new subclass \c X of
74/// \c TreeTransform<X> and then overriding certain operations to provide
75/// behavior specific to that transformation. For example, template
76/// instantiation is implemented as a tree transformation where the
77/// transformation of TemplateTypeParmType nodes involves substituting the
78/// template arguments for their corresponding template parameters; a similar
79/// transformation is performed for non-type template parameters and
80/// template template parameters.
81///
82/// This tree-transformation template uses static polymorphism to allow
83/// subclasses to customize any of its operations. Thus, a subclass can
84/// override any of the transformation or rebuild operators by providing an
85/// operation with the same signature as the default implementation. The
86/// overriding function should not be virtual.
87///
88/// Semantic tree transformations are split into two stages, either of which
89/// can be replaced by a subclass. The "transform" step transforms an AST node
90/// or the parts of an AST node using the various transformation functions,
91/// then passes the pieces on to the "rebuild" step, which constructs a new AST
92/// node of the appropriate kind from the pieces. The default transformation
93/// routines recursively transform the operands to composite AST nodes (e.g.,
94/// the pointee type of a PointerType node) and, if any of those operand nodes
95/// were changed by the transformation, invokes the rebuild operation to create
96/// a new AST node.
97///
98/// Subclasses can customize the transformation at various levels. The
99/// most coarse-grained transformations involve replacing TransformType(),
100/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
101/// TransformTemplateName(), or TransformTemplateArgument() with entirely
102/// new implementations.
103///
104/// For more fine-grained transformations, subclasses can replace any of the
105/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
106/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
107/// replacing TransformTemplateTypeParmType() allows template instantiation
108/// to substitute template arguments for their corresponding template
109/// parameters. Additionally, subclasses can override the \c RebuildXXX
110/// functions to control how AST nodes are rebuilt when their operands change.
111/// By default, \c TreeTransform will invoke semantic analysis to rebuild
112/// AST nodes. However, certain other tree transformations (e.g, cloning) may
113/// be able to use more efficient rebuild steps.
114///
115/// There are a handful of other functions that can be overridden, allowing one
116/// to avoid traversing nodes that don't need any transformation
117/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
118/// operands have not changed (\c AlwaysRebuild()), and customize the
119/// default locations and entity names used for type-checking
120/// (\c getBaseLocation(), \c getBaseEntity()).
121template<typename Derived>
123 /// Private RAII object that helps us forget and then re-remember
124 /// the template argument corresponding to a partially-substituted parameter
125 /// pack.
126 class ForgetPartiallySubstitutedPackRAII {
127 Derived &Self;
129 // Set the pack expansion index to -1 to avoid pack substitution and
130 // indicate that parameter packs should be instantiated as themselves.
131 Sema::ArgPackSubstIndexRAII ResetPackSubstIndex;
132
133 public:
134 ForgetPartiallySubstitutedPackRAII(Derived &Self)
135 : Self(Self), ResetPackSubstIndex(Self.getSema(), std::nullopt) {
136 Old = Self.ForgetPartiallySubstitutedPack();
137 }
138
139 ~ForgetPartiallySubstitutedPackRAII() {
140 Self.RememberPartiallySubstitutedPack(Old);
141 }
142 };
143
144protected:
146
147 /// The set of local declarations that have been transformed, for
148 /// cases where we are forced to build new declarations within the transformer
149 /// rather than in the subclass (e.g., lambda closure types).
150 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
151
152public:
153 /// Initializes a new tree transformer.
155
156 /// Retrieves a reference to the derived class.
157 Derived &getDerived() { return static_cast<Derived&>(*this); }
158
159 /// Retrieves a reference to the derived class.
160 const Derived &getDerived() const {
161 return static_cast<const Derived&>(*this);
162 }
163
164 static inline ExprResult Owned(Expr *E) { return E; }
165 static inline StmtResult Owned(Stmt *S) { return S; }
166
167 /// Retrieves a reference to the semantic analysis object used for
168 /// this tree transform.
169 Sema &getSema() const { return SemaRef; }
170
171 /// Whether the transformation should always rebuild AST nodes, even
172 /// if none of the children have changed.
173 ///
174 /// Subclasses may override this function to specify when the transformation
175 /// should rebuild all AST nodes.
176 ///
177 /// We must always rebuild all AST nodes when performing variadic template
178 /// pack expansion, in order to avoid violating the AST invariant that each
179 /// statement node appears at most once in its containing declaration.
180 bool AlwaysRebuild() { return static_cast<bool>(SemaRef.ArgPackSubstIndex); }
181
182 /// Whether the transformation is forming an expression or statement that
183 /// replaces the original. In this case, we'll reuse mangling numbers from
184 /// existing lambdas.
185 bool ReplacingOriginal() { return false; }
186
187 /// Wether CXXConstructExpr can be skipped when they are implicit.
188 /// They will be reconstructed when used if needed.
189 /// This is useful when the user that cause rebuilding of the
190 /// CXXConstructExpr is outside of the expression at which the TreeTransform
191 /// started.
192 bool AllowSkippingCXXConstructExpr() { return true; }
193
194 /// Returns the location of the entity being transformed, if that
195 /// information was not available elsewhere in the AST.
196 ///
197 /// By default, returns no source-location information. Subclasses can
198 /// provide an alternative implementation that provides better location
199 /// information.
201
202 /// Returns the name of the entity being transformed, if that
203 /// information was not available elsewhere in the AST.
204 ///
205 /// By default, returns an empty name. Subclasses can provide an alternative
206 /// implementation with a more precise name.
208
209 /// Sets the "base" location and entity when that
210 /// information is known based on another transformation.
211 ///
212 /// By default, the source location and entity are ignored. Subclasses can
213 /// override this function to provide a customized implementation.
215
216 /// RAII object that temporarily sets the base location and entity
217 /// used for reporting diagnostics in types.
219 TreeTransform &Self;
220 SourceLocation OldLocation;
221 DeclarationName OldEntity;
222
223 public:
225 DeclarationName Entity) : Self(Self) {
226 OldLocation = Self.getDerived().getBaseLocation();
227 OldEntity = Self.getDerived().getBaseEntity();
228
229 if (Location.isValid())
230 Self.getDerived().setBase(Location, Entity);
231 }
232
234 Self.getDerived().setBase(OldLocation, OldEntity);
235 }
236 };
237
238 /// Determine whether the given type \p T has already been
239 /// transformed.
240 ///
241 /// Subclasses can provide an alternative implementation of this routine
242 /// to short-circuit evaluation when it is known that a given type will
243 /// not change. For example, template instantiation need not traverse
244 /// non-dependent types.
246 return T.isNull();
247 }
248
249 /// Transform a template parameter depth level.
250 ///
251 /// During a transformation that transforms template parameters, this maps
252 /// an old template parameter depth to a new depth.
253 unsigned TransformTemplateDepth(unsigned Depth) {
254 return Depth;
255 }
256
257 /// Determine whether the given call argument should be dropped, e.g.,
258 /// because it is a default argument.
259 ///
260 /// Subclasses can provide an alternative implementation of this routine to
261 /// determine which kinds of call arguments get dropped. By default,
262 /// CXXDefaultArgument nodes are dropped (prior to transformation).
264 return E->isDefaultArgument();
265 }
266
267 /// Determine whether we should expand a pack expansion with the
268 /// given set of parameter packs into separate arguments by repeatedly
269 /// transforming the pattern.
270 ///
271 /// By default, the transformer never tries to expand pack expansions.
272 /// Subclasses can override this routine to provide different behavior.
273 ///
274 /// \param EllipsisLoc The location of the ellipsis that identifies the
275 /// pack expansion.
276 ///
277 /// \param PatternRange The source range that covers the entire pattern of
278 /// the pack expansion.
279 ///
280 /// \param Unexpanded The set of unexpanded parameter packs within the
281 /// pattern.
282 ///
283 /// \param ShouldExpand Will be set to \c true if the transformer should
284 /// expand the corresponding pack expansions into separate arguments. When
285 /// set, \c NumExpansions must also be set.
286 ///
287 /// \param RetainExpansion Whether the caller should add an unexpanded
288 /// pack expansion after all of the expanded arguments. This is used
289 /// when extending explicitly-specified template argument packs per
290 /// C++0x [temp.arg.explicit]p9.
291 ///
292 /// \param NumExpansions The number of separate arguments that will be in
293 /// the expanded form of the corresponding pack expansion. This is both an
294 /// input and an output parameter, which can be set by the caller if the
295 /// number of expansions is known a priori (e.g., due to a prior substitution)
296 /// and will be set by the callee when the number of expansions is known.
297 /// The callee must set this value when \c ShouldExpand is \c true; it may
298 /// set this value in other cases.
299 ///
300 /// \returns true if an error occurred (e.g., because the parameter packs
301 /// are to be instantiated with arguments of different lengths), false
302 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
303 /// must be set.
305 SourceRange PatternRange,
307 bool FailOnPackProducingTemplates,
308 bool &ShouldExpand, bool &RetainExpansion,
309 UnsignedOrNone &NumExpansions) {
310 ShouldExpand = false;
311 return false;
312 }
313
314 /// "Forget" about the partially-substituted pack template argument,
315 /// when performing an instantiation that must preserve the parameter pack
316 /// use.
317 ///
318 /// This routine is meant to be overridden by the template instantiator.
322
323 /// "Remember" the partially-substituted pack template argument
324 /// after performing an instantiation that must preserve the parameter pack
325 /// use.
326 ///
327 /// This routine is meant to be overridden by the template instantiator.
329
330 /// "Forget" the template substitution to allow transforming the AST without
331 /// any template instantiations. This is used to expand template packs when
332 /// their size is not known in advance (e.g. for builtins that produce type
333 /// packs).
336
337private:
338 struct ForgetSubstitutionRAII {
339 Derived &Self;
341
342 public:
343 ForgetSubstitutionRAII(Derived &Self) : Self(Self) {
344 Old = Self.ForgetSubstitution();
345 }
346
347 ~ForgetSubstitutionRAII() { Self.RememberSubstitution(std::move(Old)); }
348 };
349
350public:
351 /// Note to the derived class when a function parameter pack is
352 /// being expanded.
354
355 /// Transforms the given type into another type.
356 ///
357 /// By default, this routine transforms a type by creating a
358 /// TypeSourceInfo for it and delegating to the appropriate
359 /// function. This is expensive, but we don't mind, because
360 /// this method is deprecated anyway; all users should be
361 /// switched to storing TypeSourceInfos.
362 ///
363 /// \returns the transformed type.
365
366 /// Transforms the given type-with-location into a new
367 /// type-with-location.
368 ///
369 /// By default, this routine transforms a type by delegating to the
370 /// appropriate TransformXXXType to build a new type. Subclasses
371 /// may override this function (to take over all type
372 /// transformations) or some set of the TransformXXXType functions
373 /// to alter the transformation.
375
376 /// Transform the given type-with-location into a new
377 /// type, collecting location information in the given builder
378 /// as necessary.
379 ///
381
382 /// Transform a type that is permitted to produce a
383 /// DeducedTemplateSpecializationType.
384 ///
385 /// This is used in the (relatively rare) contexts where it is acceptable
386 /// for transformation to produce a class template type with deduced
387 /// template arguments.
388 /// @{
391 /// @}
392
393 /// The reason why the value of a statement is not discarded, if any.
399
400 /// Transform the given statement.
401 ///
402 /// By default, this routine transforms a statement by delegating to the
403 /// appropriate TransformXXXStmt function to transform a specific kind of
404 /// statement or the TransformExpr() function to transform an expression.
405 /// Subclasses may override this function to transform statements using some
406 /// other mechanism.
407 ///
408 /// \returns the transformed statement.
411
412 /// Transform the given statement.
413 ///
414 /// By default, this routine transforms a statement by delegating to the
415 /// appropriate TransformOMPXXXClause function to transform a specific kind
416 /// of clause. Subclasses may override this function to transform statements
417 /// using some other mechanism.
418 ///
419 /// \returns the transformed OpenMP clause.
421
422 /// Transform the given attribute.
423 ///
424 /// By default, this routine transforms a statement by delegating to the
425 /// appropriate TransformXXXAttr function to transform a specific kind
426 /// of attribute. Subclasses may override this function to transform
427 /// attributed statements/types using some other mechanism.
428 ///
429 /// \returns the transformed attribute
430 const Attr *TransformAttr(const Attr *S);
431
432 // Transform the given statement attribute.
433 //
434 // Delegates to the appropriate TransformXXXAttr function to transform a
435 // specific kind of statement attribute. Unlike the non-statement taking
436 // version of this, this implements all attributes, not just pragmas.
437 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
438 const Attr *A);
439
440 // Transform the specified attribute.
441 //
442 // Subclasses should override the transformation of attributes with a pragma
443 // spelling to transform expressions stored within the attribute.
444 //
445 // \returns the transformed attribute.
446#define ATTR(X) \
447 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
448#include "clang/Basic/AttrList.inc"
449
450 // Transform the specified attribute.
451 //
452 // Subclasses should override the transformation of attributes to do
453 // transformation and checking of statement attributes. By default, this
454 // delegates to the non-statement taking version.
455 //
456 // \returns the transformed attribute.
457#define ATTR(X) \
458 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
459 const X##Attr *A) { \
460 return getDerived().Transform##X##Attr(A); \
461 }
462#include "clang/Basic/AttrList.inc"
463
464 /// Transform the given expression.
465 ///
466 /// By default, this routine transforms an expression by delegating to the
467 /// appropriate TransformXXXExpr function to build a new expression.
468 /// Subclasses may override this function to transform expressions using some
469 /// other mechanism.
470 ///
471 /// \returns the transformed expression.
473
474 /// Transform the given initializer.
475 ///
476 /// By default, this routine transforms an initializer by stripping off the
477 /// semantic nodes added by initialization, then passing the result to
478 /// TransformExpr or TransformExprs.
479 ///
480 /// \returns the transformed initializer.
482
483 /// Transform the given list of expressions.
484 ///
485 /// This routine transforms a list of expressions by invoking
486 /// \c TransformExpr() for each subexpression. However, it also provides
487 /// support for variadic templates by expanding any pack expansions (if the
488 /// derived class permits such expansion) along the way. When pack expansions
489 /// are present, the number of outputs may not equal the number of inputs.
490 ///
491 /// \param Inputs The set of expressions to be transformed.
492 ///
493 /// \param NumInputs The number of expressions in \c Inputs.
494 ///
495 /// \param IsCall If \c true, then this transform is being performed on
496 /// function-call arguments, and any arguments that should be dropped, will
497 /// be.
498 ///
499 /// \param Outputs The transformed input expressions will be added to this
500 /// vector.
501 ///
502 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
503 /// due to transformation.
504 ///
505 /// \returns true if an error occurred, false otherwise.
506 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
508 bool *ArgChanged = nullptr);
509
510 /// Transform the given declaration, which is referenced from a type
511 /// or expression.
512 ///
513 /// By default, acts as the identity function on declarations, unless the
514 /// transformer has had to transform the declaration itself. Subclasses
515 /// may override this function to provide alternate behavior.
517 llvm::DenseMap<Decl *, Decl *>::iterator Known
518 = TransformedLocalDecls.find(D);
519 if (Known != TransformedLocalDecls.end())
520 return Known->second;
521
522 return D;
523 }
524
525 /// Transform the specified condition.
526 ///
527 /// By default, this transforms the variable and expression and rebuilds
528 /// the condition.
530 Expr *Expr,
532
533 /// Transform the attributes associated with the given declaration and
534 /// place them on the new declaration.
535 ///
536 /// By default, this operation does nothing. Subclasses may override this
537 /// behavior to transform attributes.
538 void transformAttrs(Decl *Old, Decl *New) { }
539
540 /// Note that a local declaration has been transformed by this
541 /// transformer.
542 ///
543 /// Local declarations are typically transformed via a call to
544 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
545 /// the transformer itself has to transform the declarations. This routine
546 /// can be overridden by a subclass that keeps track of such mappings.
548 assert(New.size() == 1 &&
549 "must override transformedLocalDecl if performing pack expansion");
550 TransformedLocalDecls[Old] = New.front();
551 }
552
553 /// Transform the definition of the given declaration.
554 ///
555 /// By default, invokes TransformDecl() to transform the declaration.
556 /// Subclasses may override this function to provide alternate behavior.
558 return getDerived().TransformDecl(Loc, D);
559 }
560
561 /// Transform the given declaration, which was the first part of a
562 /// nested-name-specifier in a member access expression.
563 ///
564 /// This specific declaration transformation only applies to the first
565 /// identifier in a nested-name-specifier of a member access expression, e.g.,
566 /// the \c T in \c x->T::member
567 ///
568 /// By default, invokes TransformDecl() to transform the declaration.
569 /// Subclasses may override this function to provide alternate behavior.
571 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
572 }
573
574 /// Transform the set of declarations in an OverloadExpr.
575 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
576 LookupResult &R);
577
578 /// Transform the given nested-name-specifier with source-location
579 /// information.
580 ///
581 /// By default, transforms all of the types and declarations within the
582 /// nested-name-specifier. Subclasses may override this function to provide
583 /// alternate behavior.
586 QualType ObjectType = QualType(),
587 NamedDecl *FirstQualifierInScope = nullptr);
588
589 /// Transform the given declaration name.
590 ///
591 /// By default, transforms the types of conversion function, constructor,
592 /// and destructor names and then (if needed) rebuilds the declaration name.
593 /// Identifiers and selectors are returned unmodified. Subclasses may
594 /// override this function to provide alternate behavior.
597
607
608 /// Transform the given template name.
609 ///
610 /// \param SS The nested-name-specifier that qualifies the template
611 /// name. This nested-name-specifier must already have been transformed.
612 ///
613 /// \param Name The template name to transform.
614 ///
615 /// \param NameLoc The source location of the template name.
616 ///
617 /// \param ObjectType If we're translating a template name within a member
618 /// access expression, this is the type of the object whose member template
619 /// is being referenced.
620 ///
621 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
622 /// also refers to a name within the current (lexical) scope, this is the
623 /// declaration it refers to.
624 ///
625 /// By default, transforms the template name by transforming the declarations
626 /// and nested-name-specifiers that occur within the template name.
627 /// Subclasses may override this function to provide alternate behavior.
629 SourceLocation TemplateKWLoc,
630 TemplateName Name, SourceLocation NameLoc,
631 QualType ObjectType = QualType(),
632 NamedDecl *FirstQualifierInScope = nullptr,
633 bool AllowInjectedClassName = false);
634
635 /// Transform the given template argument.
636 ///
637 /// By default, this operation transforms the type, expression, or
638 /// declaration stored within the template argument and constructs a
639 /// new template argument from the transformed result. Subclasses may
640 /// override this function to provide alternate behavior.
641 ///
642 /// Returns true if there was an error.
644 TemplateArgumentLoc &Output,
645 bool Uneval = false);
646
648 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
649 TemplateName Name, SourceLocation NameLoc);
650
651 /// Transform the given set of template arguments.
652 ///
653 /// By default, this operation transforms all of the template arguments
654 /// in the input set using \c TransformTemplateArgument(), and appends
655 /// the transformed arguments to the output list.
656 ///
657 /// Note that this overload of \c TransformTemplateArguments() is merely
658 /// a convenience function. Subclasses that wish to override this behavior
659 /// should override the iterator-based member template version.
660 ///
661 /// \param Inputs The set of template arguments to be transformed.
662 ///
663 /// \param NumInputs The number of template arguments in \p Inputs.
664 ///
665 /// \param Outputs The set of transformed template arguments output by this
666 /// routine.
667 ///
668 /// Returns true if an error occurred.
670 unsigned NumInputs,
672 bool Uneval = false) {
673 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
674 Uneval);
675 }
676
677 /// Transform the given set of template arguments.
678 ///
679 /// By default, this operation transforms all of the template arguments
680 /// in the input set using \c TransformTemplateArgument(), and appends
681 /// the transformed arguments to the output list.
682 ///
683 /// \param First An iterator to the first template argument.
684 ///
685 /// \param Last An iterator one step past the last template argument.
686 ///
687 /// \param Outputs The set of transformed template arguments output by this
688 /// routine.
689 ///
690 /// Returns true if an error occurred.
691 template<typename InputIterator>
693 InputIterator Last,
695 bool Uneval = false);
696
697 template <typename InputIterator>
699 InputIterator Last,
701 bool Uneval = false);
702
703 /// Checks if the argument pack from \p In will need to be expanded and does
704 /// the necessary prework.
705 /// Whether the expansion is needed is captured in Info.Expand.
706 ///
707 /// - When the expansion is required, \p Out will be a template pattern that
708 /// would need to be expanded.
709 /// - When the expansion must not happen, \p Out will be a pack that must be
710 /// returned to the outputs directly.
711 ///
712 /// \return true iff the error occurred
715
716 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
718 TemplateArgumentLoc &ArgLoc);
719
720 /// Fakes up a TypeSourceInfo for a type.
722 return SemaRef.Context.getTrivialTypeSourceInfo(T,
724 }
725
726#define ABSTRACT_TYPELOC(CLASS, PARENT)
727#define TYPELOC(CLASS, PARENT) \
728 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
729#include "clang/AST/TypeLocNodes.def"
730
733 bool SuppressObjCLifetime);
737 bool SuppressObjCLifetime);
738
739 template<typename Fn>
742 CXXRecordDecl *ThisContext,
743 Qualifiers ThisTypeQuals,
745
748 SmallVectorImpl<QualType> &Exceptions,
749 bool &Changed);
750
752
755 QualType ObjectType,
756 NamedDecl *FirstQualifierInScope,
757 bool AllowInjectedClassName);
758
760
761 /// Transforms the parameters of a function type into the
762 /// given vectors.
763 ///
764 /// The result vectors should be kept in sync; null entries in the
765 /// variables vector are acceptable.
766 ///
767 /// LastParamTransformed, if non-null, will be set to the index of the last
768 /// parameter on which transformation was started. In the event of an error,
769 /// this will contain the parameter which failed to instantiate.
770 ///
771 /// Return true on error.
774 const QualType *ParamTypes,
775 const FunctionProtoType::ExtParameterInfo *ParamInfos,
777 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
778
781 const QualType *ParamTypes,
782 const FunctionProtoType::ExtParameterInfo *ParamInfos,
785 return getDerived().TransformFunctionTypeParams(
786 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
787 }
788
789 /// Transforms the parameters of a requires expresison into the given vectors.
790 ///
791 /// The result vectors should be kept in sync; null entries in the
792 /// variables vector are acceptable.
793 ///
794 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
795 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
796 /// which are cases where transformation shouldn't continue.
798 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
804 KWLoc, Params, /*ParamTypes=*/nullptr,
805 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
806 return ExprError();
807
808 return ExprResult{};
809 }
810
811 /// Transforms a single function-type parameter. Return null
812 /// on error.
813 ///
814 /// \param indexAdjustment - A number to add to the parameter's
815 /// scope index; can be negative
817 int indexAdjustment,
818 UnsignedOrNone NumExpansions,
819 bool ExpectParameterPack);
820
821 /// Transform the body of a lambda-expression.
823 /// Alternative implementation of TransformLambdaBody that skips transforming
824 /// the body.
826
832
834
837
842
844
846 bool IsAddressOfOperand,
847 TypeSourceInfo **RecoveryTSI);
848
850 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
851 TypeSourceInfo **RecoveryTSI);
852
854 bool IsAddressOfOperand);
855
857
859
860// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
861// amount of stack usage with clang.
862#define STMT(Node, Parent) \
863 LLVM_ATTRIBUTE_NOINLINE \
864 StmtResult Transform##Node(Node *S);
865#define VALUESTMT(Node, Parent) \
866 LLVM_ATTRIBUTE_NOINLINE \
867 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
868#define EXPR(Node, Parent) \
869 LLVM_ATTRIBUTE_NOINLINE \
870 ExprResult Transform##Node(Node *E);
871#define ABSTRACT_STMT(Stmt)
872#include "clang/AST/StmtNodes.inc"
873
874#define GEN_CLANG_CLAUSE_CLASS
875#define CLAUSE_CLASS(Enum, Str, Class) \
876 LLVM_ATTRIBUTE_NOINLINE \
877 OMPClause *Transform##Class(Class *S);
878#include "llvm/Frontend/OpenMP/OMP.inc"
879
880 /// Build a new qualified type given its unqualified type and type location.
881 ///
882 /// By default, this routine adds type qualifiers only to types that can
883 /// have qualifiers, and silently suppresses those qualifiers that are not
884 /// permitted. Subclasses may override this routine to provide different
885 /// behavior.
887
888 /// Build a new pointer type given its pointee type.
889 ///
890 /// By default, performs semantic analysis when building the pointer type.
891 /// Subclasses may override this routine to provide different behavior.
893
894 /// Build a new block pointer type given its pointee type.
895 ///
896 /// By default, performs semantic analysis when building the block pointer
897 /// type. Subclasses may override this routine to provide different behavior.
899
900 /// Build a new reference type given the type it references.
901 ///
902 /// By default, performs semantic analysis when building the
903 /// reference type. Subclasses may override this routine to provide
904 /// different behavior.
905 ///
906 /// \param LValue whether the type was written with an lvalue sigil
907 /// or an rvalue sigil.
909 bool LValue,
910 SourceLocation Sigil);
911
912 /// Build a new member pointer type given the pointee type and the
913 /// qualifier it refers into.
914 ///
915 /// By default, performs semantic analysis when building the member pointer
916 /// type. Subclasses may override this routine to provide different behavior.
918 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
919 SourceLocation Sigil);
920
922 SourceLocation ProtocolLAngleLoc,
924 ArrayRef<SourceLocation> ProtocolLocs,
925 SourceLocation ProtocolRAngleLoc);
926
927 /// Build an Objective-C object type.
928 ///
929 /// By default, performs semantic analysis when building the object type.
930 /// Subclasses may override this routine to provide different behavior.
932 SourceLocation Loc,
933 SourceLocation TypeArgsLAngleLoc,
935 SourceLocation TypeArgsRAngleLoc,
936 SourceLocation ProtocolLAngleLoc,
938 ArrayRef<SourceLocation> ProtocolLocs,
939 SourceLocation ProtocolRAngleLoc);
940
941 /// Build a new Objective-C object pointer type given the pointee type.
942 ///
943 /// By default, directly builds the pointer type, with no additional semantic
944 /// analysis.
947
948 /// Build a new array type given the element type, size
949 /// modifier, size of the array (if known), size expression, and index type
950 /// qualifiers.
951 ///
952 /// By default, performs semantic analysis when building the array type.
953 /// Subclasses may override this routine to provide different behavior.
954 /// Also by default, all of the other Rebuild*Array
956 const llvm::APInt *Size, Expr *SizeExpr,
957 unsigned IndexTypeQuals, SourceRange BracketsRange);
958
959 /// Build a new constant array type given the element type, size
960 /// modifier, (known) size of the array, and index type qualifiers.
961 ///
962 /// By default, performs semantic analysis when building the array type.
963 /// Subclasses may override this routine to provide different behavior.
965 ArraySizeModifier SizeMod,
966 const llvm::APInt &Size, Expr *SizeExpr,
967 unsigned IndexTypeQuals,
968 SourceRange BracketsRange);
969
970 /// Build a new incomplete array type given the element type, size
971 /// modifier, and index type qualifiers.
972 ///
973 /// By default, performs semantic analysis when building the array type.
974 /// Subclasses may override this routine to provide different behavior.
976 ArraySizeModifier SizeMod,
977 unsigned IndexTypeQuals,
978 SourceRange BracketsRange);
979
980 /// Build a new variable-length array type given the element type,
981 /// size modifier, size expression, and index type qualifiers.
982 ///
983 /// By default, performs semantic analysis when building the array type.
984 /// Subclasses may override this routine to provide different behavior.
986 ArraySizeModifier SizeMod, Expr *SizeExpr,
987 unsigned IndexTypeQuals,
988 SourceRange BracketsRange);
989
990 /// Build a new dependent-sized array type given the element type,
991 /// size modifier, size expression, and index type qualifiers.
992 ///
993 /// By default, performs semantic analysis when building the array type.
994 /// Subclasses may override this routine to provide different behavior.
996 ArraySizeModifier SizeMod,
997 Expr *SizeExpr,
998 unsigned IndexTypeQuals,
999 SourceRange BracketsRange);
1000
1001 /// Build a new vector type given the element type and
1002 /// number of elements.
1003 ///
1004 /// By default, performs semantic analysis when building the vector type.
1005 /// Subclasses may override this routine to provide different behavior.
1006 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1007 VectorKind VecKind);
1008
1009 /// Build a new potentially dependently-sized extended vector type
1010 /// given the element type and number of elements.
1011 ///
1012 /// By default, performs semantic analysis when building the vector type.
1013 /// Subclasses may override this routine to provide different behavior.
1015 SourceLocation AttributeLoc, VectorKind);
1016
1017 /// Build a new extended vector type given the element type and
1018 /// number of elements.
1019 ///
1020 /// By default, performs semantic analysis when building the vector type.
1021 /// Subclasses may override this routine to provide different behavior.
1022 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1023 SourceLocation AttributeLoc);
1024
1025 /// Build a new potentially dependently-sized extended vector type
1026 /// given the element type and number of elements.
1027 ///
1028 /// By default, performs semantic analysis when building the vector type.
1029 /// Subclasses may override this routine to provide different behavior.
1031 Expr *SizeExpr,
1032 SourceLocation AttributeLoc);
1033
1034 /// Build a new matrix type given the element type and dimensions.
1035 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1036 unsigned NumColumns);
1037
1038 /// Build a new matrix type given the type and dependently-defined
1039 /// dimensions.
1041 Expr *ColumnExpr,
1042 SourceLocation AttributeLoc);
1043
1044 /// Build a new DependentAddressSpaceType or return the pointee
1045 /// type variable with the correct address space (retrieved from
1046 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1047 /// where the address space remains dependent.
1048 ///
1049 /// By default, performs semantic analysis when building the type with address
1050 /// space applied. Subclasses may override this routine to provide different
1051 /// behavior.
1053 Expr *AddrSpaceExpr,
1054 SourceLocation AttributeLoc);
1055
1056 /// Build a new function type.
1057 ///
1058 /// By default, performs semantic analysis when building the function type.
1059 /// Subclasses may override this routine to provide different behavior.
1061 MutableArrayRef<QualType> ParamTypes,
1063
1064 /// Build a new unprototyped function type.
1066
1067 /// Rebuild an unresolved typename type, given the decl that
1068 /// the UnresolvedUsingTypenameDecl was transformed to.
1070 NestedNameSpecifier Qualifier,
1071 SourceLocation NameLoc, Decl *D);
1072
1073 /// Build a new type found via an alias.
1076 QualType UnderlyingType) {
1077 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1078 }
1079
1080 /// Build a new typedef type.
1082 NestedNameSpecifier Qualifier,
1084 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1085 }
1086
1087 /// Build a new MacroDefined type.
1089 const IdentifierInfo *MacroII) {
1090 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1091 }
1092
1093 /// Build a new class/struct/union/enum type.
1095 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1096 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1097 /*OwnsTag=*/false);
1098 }
1100 return SemaRef.Context.getCanonicalTagType(Tag);
1101 }
1102
1103 /// Build a new typeof(expr) type.
1104 ///
1105 /// By default, performs semantic analysis when building the typeof type.
1106 /// Subclasses may override this routine to provide different behavior.
1108 TypeOfKind Kind);
1109
1110 /// Build a new typeof(type) type.
1111 ///
1112 /// By default, builds a new TypeOfType with the given underlying type.
1114
1115 /// Build a new unary transform type.
1117 UnaryTransformType::UTTKind UKind,
1118 SourceLocation Loc);
1119
1120 /// Build a new C++11 decltype type.
1121 ///
1122 /// By default, performs semantic analysis when building the decltype type.
1123 /// Subclasses may override this routine to provide different behavior.
1125
1127 SourceLocation Loc,
1128 SourceLocation EllipsisLoc,
1129 bool FullySubstituted,
1130 ArrayRef<QualType> Expansions = {});
1131
1132 /// Build a new C++11 auto type.
1133 ///
1134 /// By default, builds a new AutoType with the given deduced type.
1136 ConceptDecl *TypeConstraintConcept,
1137 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1138 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1139 // which has been deduced to a dependent type into an undeduced 'auto', so
1140 // that we'll retry deduction after the transformation.
1141 return SemaRef.Context.getAutoType(Deduced, Keyword,
1142 /*IsDependent*/ false, /*IsPack=*/false,
1143 TypeConstraintConcept,
1144 TypeConstraintArgs);
1145 }
1146
1147 /// By default, builds a new DeducedTemplateSpecializationType with the given
1148 /// deduced type.
1151 return SemaRef.Context.getDeducedTemplateSpecializationType(
1152 Keyword, Template, Deduced, /*IsDependent*/ false);
1153 }
1154
1155 /// Build a new template specialization type.
1156 ///
1157 /// By default, performs semantic analysis when building the template
1158 /// specialization type. Subclasses may override this routine to provide
1159 /// different behavior.
1162 SourceLocation TemplateLoc,
1164
1165 /// Build a new parenthesized type.
1166 ///
1167 /// By default, builds a new ParenType type from the inner type.
1168 /// Subclasses may override this routine to provide different behavior.
1170 return SemaRef.BuildParenType(InnerType);
1171 }
1172
1173 /// Build a new typename type that refers to an identifier.
1174 ///
1175 /// By default, performs semantic analysis when building the typename type
1176 /// (or elaborated type). Subclasses may override this routine to provide
1177 /// different behavior.
1179 SourceLocation KeywordLoc,
1180 NestedNameSpecifierLoc QualifierLoc,
1181 const IdentifierInfo *Id,
1182 SourceLocation IdLoc,
1183 bool DeducedTSTContext) {
1184 CXXScopeSpec SS;
1185 SS.Adopt(QualifierLoc);
1186
1187 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1188 // If the name is still dependent, just build a new dependent name type.
1189 if (!SemaRef.computeDeclContext(SS))
1190 return SemaRef.Context.getDependentNameType(Keyword,
1191 QualifierLoc.getNestedNameSpecifier(),
1192 Id);
1193 }
1194
1197 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1198 *Id, IdLoc, DeducedTSTContext);
1199 }
1200
1202
1203 // We had a dependent elaborated-type-specifier that has been transformed
1204 // into a non-dependent elaborated-type-specifier. Find the tag we're
1205 // referring to.
1207 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1208 if (!DC)
1209 return QualType();
1210
1211 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1212 return QualType();
1213
1214 TagDecl *Tag = nullptr;
1215 SemaRef.LookupQualifiedName(Result, DC);
1216 switch (Result.getResultKind()) {
1219 break;
1220
1222 Tag = Result.getAsSingle<TagDecl>();
1223 break;
1224
1227 llvm_unreachable("Tag lookup cannot find non-tags");
1228
1230 // Let the LookupResult structure handle ambiguities.
1231 return QualType();
1232 }
1233
1234 if (!Tag) {
1235 // Check where the name exists but isn't a tag type and use that to emit
1236 // better diagnostics.
1238 SemaRef.LookupQualifiedName(Result, DC);
1239 switch (Result.getResultKind()) {
1243 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1244 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1245 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1246 << SomeDecl << NTK << Kind;
1247 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1248 break;
1249 }
1250 default:
1251 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1252 << Kind << Id << DC << QualifierLoc.getSourceRange();
1253 break;
1254 }
1255 return QualType();
1256 }
1257 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1258 IdLoc, Id)) {
1259 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1260 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1261 return QualType();
1262 }
1263 return getDerived().RebuildTagType(
1264 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1265 }
1266
1267 /// Build a new pack expansion type.
1268 ///
1269 /// By default, builds a new PackExpansionType type from the given pattern.
1270 /// Subclasses may override this routine to provide different behavior.
1272 SourceLocation EllipsisLoc,
1273 UnsignedOrNone NumExpansions) {
1274 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1275 NumExpansions);
1276 }
1277
1278 /// Build a new atomic type given its value type.
1279 ///
1280 /// By default, performs semantic analysis when building the atomic type.
1281 /// Subclasses may override this routine to provide different behavior.
1283
1284 /// Build a new pipe type given its value type.
1286 bool isReadPipe);
1287
1288 /// Build a bit-precise int given its value type.
1289 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1290 SourceLocation Loc);
1291
1292 /// Build a dependent bit-precise int given its value type.
1293 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1294 SourceLocation Loc);
1295
1296 /// Build a new template name given a nested name specifier, a flag
1297 /// indicating whether the "template" keyword was provided, and the template
1298 /// that the template name refers to.
1299 ///
1300 /// By default, builds the new template name directly. Subclasses may override
1301 /// this routine to provide different behavior.
1303 TemplateName Name);
1304
1305 /// Build a new template name given a nested name specifier and the
1306 /// name that is referred to as a template.
1307 ///
1308 /// By default, performs semantic analysis to determine whether the name can
1309 /// be resolved to a specific template, then builds the appropriate kind of
1310 /// template name. Subclasses may override this routine to provide different
1311 /// behavior.
1313 SourceLocation TemplateKWLoc,
1314 const IdentifierInfo &Name,
1315 SourceLocation NameLoc, QualType ObjectType,
1316 bool AllowInjectedClassName);
1317
1318 /// Build a new template name given a nested name specifier and the
1319 /// overloaded operator name that is referred to as a template.
1320 ///
1321 /// By default, performs semantic analysis to determine whether the name can
1322 /// be resolved to a specific template, then builds the appropriate kind of
1323 /// template name. Subclasses may override this routine to provide different
1324 /// behavior.
1326 SourceLocation TemplateKWLoc,
1327 OverloadedOperatorKind Operator,
1328 SourceLocation NameLoc, QualType ObjectType,
1329 bool AllowInjectedClassName);
1330
1332 SourceLocation TemplateKWLoc,
1334 SourceLocation NameLoc, QualType ObjectType,
1335 bool AllowInjectedClassName);
1336
1337 /// Build a new template name given a template template parameter pack
1338 /// and the
1339 ///
1340 /// By default, performs semantic analysis to determine whether the name can
1341 /// be resolved to a specific template, then builds the appropriate kind of
1342 /// template name. Subclasses may override this routine to provide different
1343 /// behavior.
1345 Decl *AssociatedDecl, unsigned Index,
1346 bool Final) {
1348 ArgPack, AssociatedDecl, Index, Final);
1349 }
1350
1351 /// Build a new compound statement.
1352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
1356 MultiStmtArg Statements,
1357 SourceLocation RBraceLoc,
1358 bool IsStmtExpr) {
1359 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1360 IsStmtExpr);
1361 }
1362
1363 /// Build a new case statement.
1364 ///
1365 /// By default, performs semantic analysis to build the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
1368 Expr *LHS,
1369 SourceLocation EllipsisLoc,
1370 Expr *RHS,
1371 SourceLocation ColonLoc) {
1372 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1373 ColonLoc);
1374 }
1375
1376 /// Attach the body to a new case statement.
1377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1381 getSema().ActOnCaseStmtBody(S, Body);
1382 return S;
1383 }
1384
1385 /// Build a new default statement.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1390 SourceLocation ColonLoc,
1391 Stmt *SubStmt) {
1392 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1393 /*CurScope=*/nullptr);
1394 }
1395
1396 /// Build a new label statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
1401 SourceLocation ColonLoc, Stmt *SubStmt) {
1402 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1403 }
1404
1405 /// Build a new attributed statement.
1406 ///
1407 /// By default, performs semantic analysis to build the new statement.
1408 /// Subclasses may override this routine to provide different behavior.
1411 Stmt *SubStmt) {
1412 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1413 return StmtError();
1414 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1415 }
1416
1417 /// Build a new "if" statement.
1418 ///
1419 /// By default, performs semantic analysis to build the new statement.
1420 /// Subclasses may override this routine to provide different behavior.
1423 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1424 SourceLocation ElseLoc, Stmt *Else) {
1425 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1426 Then, ElseLoc, Else);
1427 }
1428
1429 /// Start building a new switch statement.
1430 ///
1431 /// By default, performs semantic analysis to build the new statement.
1432 /// Subclasses may override this routine to provide different behavior.
1434 SourceLocation LParenLoc, Stmt *Init,
1436 SourceLocation RParenLoc) {
1437 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1438 RParenLoc);
1439 }
1440
1441 /// Attach the body to the switch statement.
1442 ///
1443 /// By default, performs semantic analysis to build the new statement.
1444 /// Subclasses may override this routine to provide different behavior.
1446 Stmt *Switch, Stmt *Body) {
1447 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1448 }
1449
1450 /// Build a new while statement.
1451 ///
1452 /// By default, performs semantic analysis to build the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
1456 SourceLocation RParenLoc, Stmt *Body) {
1457 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1458 }
1459
1460 /// Build a new do-while statement.
1461 ///
1462 /// By default, performs semantic analysis to build the new statement.
1463 /// Subclasses may override this routine to provide different behavior.
1465 SourceLocation WhileLoc, SourceLocation LParenLoc,
1466 Expr *Cond, SourceLocation RParenLoc) {
1467 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1468 Cond, RParenLoc);
1469 }
1470
1471 /// Build a new for statement.
1472 ///
1473 /// By default, performs semantic analysis to build the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
1477 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1478 Stmt *Body) {
1479 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1480 Inc, RParenLoc, Body);
1481 }
1482
1483 /// Build a new goto statement.
1484 ///
1485 /// By default, performs semantic analysis to build the new statement.
1486 /// Subclasses may override this routine to provide different behavior.
1488 LabelDecl *Label) {
1489 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1490 }
1491
1492 /// Build a new indirect goto statement.
1493 ///
1494 /// By default, performs semantic analysis to build the new statement.
1495 /// Subclasses may override this routine to provide different behavior.
1497 SourceLocation StarLoc,
1498 Expr *Target) {
1499 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1500 }
1501
1502 /// Build a new return statement.
1503 ///
1504 /// By default, performs semantic analysis to build the new statement.
1505 /// Subclasses may override this routine to provide different behavior.
1507 return getSema().BuildReturnStmt(ReturnLoc, Result);
1508 }
1509
1510 /// Build a new declaration statement.
1511 ///
1512 /// By default, performs semantic analysis to build the new statement.
1513 /// Subclasses may override this routine to provide different behavior.
1515 SourceLocation StartLoc, SourceLocation EndLoc) {
1517 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1518 }
1519
1520 /// Build a new inline asm statement.
1521 ///
1522 /// By default, performs semantic analysis to build the new statement.
1523 /// Subclasses may override this routine to provide different behavior.
1525 bool IsVolatile, unsigned NumOutputs,
1526 unsigned NumInputs, IdentifierInfo **Names,
1527 MultiExprArg Constraints, MultiExprArg Exprs,
1528 Expr *AsmString, MultiExprArg Clobbers,
1529 unsigned NumLabels,
1530 SourceLocation RParenLoc) {
1531 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1532 NumInputs, Names, Constraints, Exprs,
1533 AsmString, Clobbers, NumLabels, RParenLoc);
1534 }
1535
1536 /// Build a new MS style inline asm statement.
1537 ///
1538 /// By default, performs semantic analysis to build the new statement.
1539 /// Subclasses may override this routine to provide different behavior.
1541 ArrayRef<Token> AsmToks,
1542 StringRef AsmString,
1543 unsigned NumOutputs, unsigned NumInputs,
1544 ArrayRef<StringRef> Constraints,
1545 ArrayRef<StringRef> Clobbers,
1546 ArrayRef<Expr*> Exprs,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1549 NumOutputs, NumInputs,
1550 Constraints, Clobbers, Exprs, EndLoc);
1551 }
1552
1553 /// Build a new co_return statement.
1554 ///
1555 /// By default, performs semantic analysis to build the new statement.
1556 /// Subclasses may override this routine to provide different behavior.
1558 bool IsImplicit) {
1559 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1560 }
1561
1562 /// Build a new co_await expression.
1563 ///
1564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
1567 UnresolvedLookupExpr *OpCoawaitLookup,
1568 bool IsImplicit) {
1569 // This function rebuilds a coawait-expr given its operator.
1570 // For an explicit coawait-expr, the rebuild involves the full set
1571 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1572 // including calling await_transform().
1573 // For an implicit coawait-expr, we need to rebuild the "operator
1574 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1575 // This mirrors how the implicit CoawaitExpr is originally created
1576 // in Sema::ActOnCoroutineBodyStart().
1577 if (IsImplicit) {
1579 CoawaitLoc, Operand, OpCoawaitLookup);
1580 if (Suspend.isInvalid())
1581 return ExprError();
1582 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1583 Suspend.get(), true);
1584 }
1585
1586 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1587 OpCoawaitLookup);
1588 }
1589
1590 /// Build a new co_await expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
1595 Expr *Result,
1596 UnresolvedLookupExpr *Lookup) {
1597 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1598 }
1599
1600 /// Build a new co_yield expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1605 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1606 }
1607
1611
1612 /// Build a new Objective-C \@try statement.
1613 ///
1614 /// By default, performs semantic analysis to build the new statement.
1615 /// Subclasses may override this routine to provide different behavior.
1617 Stmt *TryBody,
1618 MultiStmtArg CatchStmts,
1619 Stmt *Finally) {
1620 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1621 Finally);
1622 }
1623
1624 /// Rebuild an Objective-C exception declaration.
1625 ///
1626 /// By default, performs semantic analysis to build the new declaration.
1627 /// Subclasses may override this routine to provide different behavior.
1629 TypeSourceInfo *TInfo, QualType T) {
1631 TInfo, T, ExceptionDecl->getInnerLocStart(),
1632 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1633 }
1634
1635 /// Build a new Objective-C \@catch statement.
1636 ///
1637 /// By default, performs semantic analysis to build the new statement.
1638 /// Subclasses may override this routine to provide different behavior.
1640 SourceLocation RParenLoc,
1641 VarDecl *Var,
1642 Stmt *Body) {
1643 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1644 }
1645
1646 /// Build a new Objective-C \@finally statement.
1647 ///
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
1651 Stmt *Body) {
1652 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1653 }
1654
1655 /// Build a new Objective-C \@throw statement.
1656 ///
1657 /// By default, performs semantic analysis to build the new statement.
1658 /// Subclasses may override this routine to provide different behavior.
1660 Expr *Operand) {
1661 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1662 }
1663
1664 /// Build a new OpenMP Canonical loop.
1665 ///
1666 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1667 /// OMPCanonicalLoop.
1669 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1670 }
1671
1672 /// Build a new OpenMP executable directive.
1673 ///
1674 /// By default, performs semantic analysis to build the new statement.
1675 /// Subclasses may override this routine to provide different behavior.
1677 DeclarationNameInfo DirName,
1678 OpenMPDirectiveKind CancelRegion,
1679 ArrayRef<OMPClause *> Clauses,
1680 Stmt *AStmt, SourceLocation StartLoc,
1681 SourceLocation EndLoc) {
1682
1684 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1685 }
1686
1687 /// Build a new OpenMP informational directive.
1689 DeclarationNameInfo DirName,
1690 ArrayRef<OMPClause *> Clauses,
1691 Stmt *AStmt,
1692 SourceLocation StartLoc,
1693 SourceLocation EndLoc) {
1694
1696 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1697 }
1698
1699 /// Build a new OpenMP 'if' clause.
1700 ///
1701 /// By default, performs semantic analysis to build the new OpenMP clause.
1702 /// Subclasses may override this routine to provide different behavior.
1704 Expr *Condition, SourceLocation StartLoc,
1705 SourceLocation LParenLoc,
1706 SourceLocation NameModifierLoc,
1707 SourceLocation ColonLoc,
1708 SourceLocation EndLoc) {
1710 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1711 EndLoc);
1712 }
1713
1714 /// Build a new OpenMP 'final' clause.
1715 ///
1716 /// By default, performs semantic analysis to build the new OpenMP clause.
1717 /// Subclasses may override this routine to provide different behavior.
1719 SourceLocation LParenLoc,
1720 SourceLocation EndLoc) {
1721 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1722 LParenLoc, EndLoc);
1723 }
1724
1725 /// Build a new OpenMP 'num_threads' clause.
1726 ///
1727 /// By default, performs semantic analysis to build the new OpenMP clause.
1728 /// Subclasses may override this routine to provide different behavior.
1730 Expr *NumThreads,
1731 SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation ModifierLoc,
1734 SourceLocation EndLoc) {
1736 Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc);
1737 }
1738
1739 /// Build a new OpenMP 'safelen' clause.
1740 ///
1741 /// By default, performs semantic analysis to build the new OpenMP clause.
1742 /// Subclasses may override this routine to provide different behavior.
1744 SourceLocation LParenLoc,
1745 SourceLocation EndLoc) {
1746 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1747 EndLoc);
1748 }
1749
1750 /// Build a new OpenMP 'simdlen' clause.
1751 ///
1752 /// By default, performs semantic analysis to build the new OpenMP clause.
1753 /// Subclasses may override this routine to provide different behavior.
1755 SourceLocation LParenLoc,
1756 SourceLocation EndLoc) {
1757 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1758 EndLoc);
1759 }
1760
1762 SourceLocation StartLoc,
1763 SourceLocation LParenLoc,
1764 SourceLocation EndLoc) {
1765 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1766 EndLoc);
1767 }
1768
1769 /// Build a new OpenMP 'permutation' clause.
1771 SourceLocation StartLoc,
1772 SourceLocation LParenLoc,
1773 SourceLocation EndLoc) {
1774 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1775 LParenLoc, EndLoc);
1776 }
1777
1778 /// Build a new OpenMP 'full' clause.
1780 SourceLocation EndLoc) {
1781 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1782 }
1783
1784 /// Build a new OpenMP 'partial' clause.
1786 SourceLocation LParenLoc,
1787 SourceLocation EndLoc) {
1788 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1789 LParenLoc, EndLoc);
1790 }
1791
1792 OMPClause *
1794 SourceLocation LParenLoc, SourceLocation FirstLoc,
1795 SourceLocation CountLoc, SourceLocation EndLoc) {
1797 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1798 }
1799
1800 /// Build a new OpenMP 'allocator' clause.
1801 ///
1802 /// By default, performs semantic analysis to build the new OpenMP clause.
1803 /// Subclasses may override this routine to provide different behavior.
1805 SourceLocation LParenLoc,
1806 SourceLocation EndLoc) {
1807 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1808 EndLoc);
1809 }
1810
1811 /// Build a new OpenMP 'collapse' clause.
1812 ///
1813 /// By default, performs semantic analysis to build the new OpenMP clause.
1814 /// Subclasses may override this routine to provide different behavior.
1816 SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
1818 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1819 LParenLoc, EndLoc);
1820 }
1821
1822 /// Build a new OpenMP 'default' clause.
1823 ///
1824 /// By default, performs semantic analysis to build the new OpenMP clause.
1825 /// Subclasses may override this routine to provide different behavior.
1828 SourceLocation VCLoc,
1829 SourceLocation StartLoc,
1830 SourceLocation LParenLoc,
1831 SourceLocation EndLoc) {
1833 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1834 }
1835
1836 /// Build a new OpenMP 'proc_bind' clause.
1837 ///
1838 /// By default, performs semantic analysis to build the new OpenMP clause.
1839 /// Subclasses may override this routine to provide different behavior.
1841 SourceLocation KindKwLoc,
1842 SourceLocation StartLoc,
1843 SourceLocation LParenLoc,
1844 SourceLocation EndLoc) {
1846 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1847 }
1848
1849 /// Build a new OpenMP 'schedule' clause.
1850 ///
1851 /// By default, performs semantic analysis to build the new OpenMP clause.
1852 /// Subclasses may override this routine to provide different behavior.
1855 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1856 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1857 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1859 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1860 CommaLoc, EndLoc);
1861 }
1862
1863 /// Build a new OpenMP 'ordered' clause.
1864 ///
1865 /// By default, performs semantic analysis to build the new OpenMP clause.
1866 /// Subclasses may override this routine to provide different behavior.
1868 SourceLocation EndLoc,
1869 SourceLocation LParenLoc, Expr *Num) {
1870 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1871 LParenLoc, Num);
1872 }
1873
1874 /// Build a new OpenMP 'nowait' clause.
1875 ///
1876 /// By default, performs semantic analysis to build the new OpenMP clause.
1877 /// Subclasses may override this routine to provide different behavior.
1879 SourceLocation LParenLoc,
1880 SourceLocation EndLoc) {
1881 return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc,
1882 LParenLoc, Condition);
1883 }
1884
1885 /// Build a new OpenMP 'private' clause.
1886 ///
1887 /// By default, performs semantic analysis to build the new OpenMP clause.
1888 /// Subclasses may override this routine to provide different behavior.
1890 SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1893 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1894 LParenLoc, EndLoc);
1895 }
1896
1897 /// Build a new OpenMP 'firstprivate' clause.
1898 ///
1899 /// By default, performs semantic analysis to build the new OpenMP clause.
1900 /// Subclasses may override this routine to provide different behavior.
1902 SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1906 LParenLoc, EndLoc);
1907 }
1908
1909 /// Build a new OpenMP 'lastprivate' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new OpenMP clause.
1912 /// Subclasses may override this routine to provide different behavior.
1915 SourceLocation LPKindLoc,
1916 SourceLocation ColonLoc,
1917 SourceLocation StartLoc,
1918 SourceLocation LParenLoc,
1919 SourceLocation EndLoc) {
1921 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1922 }
1923
1924 /// Build a new OpenMP 'shared' clause.
1925 ///
1926 /// By default, performs semantic analysis to build the new OpenMP clause.
1927 /// Subclasses may override this routine to provide different behavior.
1929 SourceLocation StartLoc,
1930 SourceLocation LParenLoc,
1931 SourceLocation EndLoc) {
1932 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1933 LParenLoc, EndLoc);
1934 }
1935
1936 /// Build a new OpenMP 'reduction' clause.
1937 ///
1938 /// By default, performs semantic analysis to build the new statement.
1939 /// Subclasses may override this routine to provide different behavior.
1942 OpenMPOriginalSharingModifier OriginalSharingModifier,
1943 SourceLocation StartLoc, SourceLocation LParenLoc,
1944 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1945 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1946 const DeclarationNameInfo &ReductionId,
1947 ArrayRef<Expr *> UnresolvedReductions) {
1949 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1950 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1951 UnresolvedReductions);
1952 }
1953
1954 /// Build a new OpenMP 'task_reduction' clause.
1955 ///
1956 /// By default, performs semantic analysis to build the new statement.
1957 /// Subclasses may override this routine to provide different behavior.
1959 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1960 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1961 CXXScopeSpec &ReductionIdScopeSpec,
1962 const DeclarationNameInfo &ReductionId,
1963 ArrayRef<Expr *> UnresolvedReductions) {
1965 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1966 ReductionId, UnresolvedReductions);
1967 }
1968
1969 /// Build a new OpenMP 'in_reduction' clause.
1970 ///
1971 /// By default, performs semantic analysis to build the new statement.
1972 /// Subclasses may override this routine to provide different behavior.
1973 OMPClause *
1975 SourceLocation LParenLoc, SourceLocation ColonLoc,
1976 SourceLocation EndLoc,
1977 CXXScopeSpec &ReductionIdScopeSpec,
1978 const DeclarationNameInfo &ReductionId,
1979 ArrayRef<Expr *> UnresolvedReductions) {
1981 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1982 ReductionId, UnresolvedReductions);
1983 }
1984
1985 /// Build a new OpenMP 'linear' clause.
1986 ///
1987 /// By default, performs semantic analysis to build the new OpenMP clause.
1988 /// Subclasses may override this routine to provide different behavior.
1990 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1991 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1992 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1993 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1995 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1996 StepModifierLoc, EndLoc);
1997 }
1998
1999 /// Build a new OpenMP 'aligned' clause.
2000 ///
2001 /// By default, performs semantic analysis to build the new OpenMP clause.
2002 /// Subclasses may override this routine to provide different behavior.
2004 SourceLocation StartLoc,
2005 SourceLocation LParenLoc,
2006 SourceLocation ColonLoc,
2007 SourceLocation EndLoc) {
2009 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2010 }
2011
2012 /// Build a new OpenMP 'copyin' clause.
2013 ///
2014 /// By default, performs semantic analysis to build the new OpenMP clause.
2015 /// Subclasses may override this routine to provide different behavior.
2017 SourceLocation StartLoc,
2018 SourceLocation LParenLoc,
2019 SourceLocation EndLoc) {
2020 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2021 LParenLoc, EndLoc);
2022 }
2023
2024 /// Build a new OpenMP 'copyprivate' clause.
2025 ///
2026 /// By default, performs semantic analysis to build the new OpenMP clause.
2027 /// Subclasses may override this routine to provide different behavior.
2029 SourceLocation StartLoc,
2030 SourceLocation LParenLoc,
2031 SourceLocation EndLoc) {
2032 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2033 LParenLoc, EndLoc);
2034 }
2035
2036 /// Build a new OpenMP 'flush' pseudo 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().ActOnOpenMPFlushClause(VarList, StartLoc,
2045 LParenLoc, EndLoc);
2046 }
2047
2048 /// Build a new OpenMP 'depobj' pseudo 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 LParenLoc,
2054 SourceLocation EndLoc) {
2055 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2056 LParenLoc, EndLoc);
2057 }
2058
2059 /// Build a new OpenMP 'depend' pseudo clause.
2060 ///
2061 /// By default, performs semantic analysis to build the new OpenMP clause.
2062 /// Subclasses may override this routine to provide different behavior.
2064 Expr *DepModifier, ArrayRef<Expr *> VarList,
2065 SourceLocation StartLoc,
2066 SourceLocation LParenLoc,
2067 SourceLocation EndLoc) {
2069 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2070 }
2071
2072 /// Build a new OpenMP 'device' clause.
2073 ///
2074 /// By default, performs semantic analysis to build the new statement.
2075 /// Subclasses may override this routine to provide different behavior.
2077 Expr *Device, SourceLocation StartLoc,
2078 SourceLocation LParenLoc,
2079 SourceLocation ModifierLoc,
2080 SourceLocation EndLoc) {
2082 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2083 }
2084
2085 /// Build a new OpenMP 'map' clause.
2086 ///
2087 /// By default, performs semantic analysis to build the new OpenMP clause.
2088 /// Subclasses may override this routine to provide different behavior.
2090 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2091 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2092 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2093 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2094 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2095 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2097 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2098 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2099 ColonLoc, VarList, Locs,
2100 /*NoDiagnose=*/false, UnresolvedMappers);
2101 }
2102
2103 /// Build a new OpenMP 'allocate' clause.
2104 ///
2105 /// By default, performs semantic analysis to build the new OpenMP clause.
2106 /// Subclasses may override this routine to provide different behavior.
2107 OMPClause *
2108 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2109 OpenMPAllocateClauseModifier FirstModifier,
2110 SourceLocation FirstModifierLoc,
2111 OpenMPAllocateClauseModifier SecondModifier,
2112 SourceLocation SecondModifierLoc,
2113 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2114 SourceLocation LParenLoc, SourceLocation ColonLoc,
2115 SourceLocation EndLoc) {
2117 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2118 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2119 }
2120
2121 /// Build a new OpenMP 'num_teams' clause.
2122 ///
2123 /// By default, performs semantic analysis to build the new statement.
2124 /// Subclasses may override this routine to provide different behavior.
2126 SourceLocation StartLoc,
2127 SourceLocation LParenLoc,
2128 SourceLocation EndLoc) {
2129 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2130 LParenLoc, EndLoc);
2131 }
2132
2133 /// Build a new OpenMP 'thread_limit' clause.
2134 ///
2135 /// By default, performs semantic analysis to build the new statement.
2136 /// Subclasses may override this routine to provide different behavior.
2138 SourceLocation StartLoc,
2139 SourceLocation LParenLoc,
2140 SourceLocation EndLoc) {
2141 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2142 LParenLoc, EndLoc);
2143 }
2144
2145 /// Build a new OpenMP 'priority' clause.
2146 ///
2147 /// By default, performs semantic analysis to build the new statement.
2148 /// Subclasses may override this routine to provide different behavior.
2150 SourceLocation LParenLoc,
2151 SourceLocation EndLoc) {
2152 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2153 LParenLoc, EndLoc);
2154 }
2155
2156 /// Build a new OpenMP 'grainsize' clause.
2157 ///
2158 /// By default, performs semantic analysis to build the new statement.
2159 /// Subclasses may override this routine to provide different behavior.
2161 Expr *Device, SourceLocation StartLoc,
2162 SourceLocation LParenLoc,
2163 SourceLocation ModifierLoc,
2164 SourceLocation EndLoc) {
2166 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2167 }
2168
2169 /// Build a new OpenMP 'num_tasks' clause.
2170 ///
2171 /// By default, performs semantic analysis to build the new statement.
2172 /// Subclasses may override this routine to provide different behavior.
2174 Expr *NumTasks, SourceLocation StartLoc,
2175 SourceLocation LParenLoc,
2176 SourceLocation ModifierLoc,
2177 SourceLocation EndLoc) {
2179 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2180 }
2181
2182 /// Build a new OpenMP 'hint' clause.
2183 ///
2184 /// By default, performs semantic analysis to build the new statement.
2185 /// Subclasses may override this routine to provide different behavior.
2187 SourceLocation LParenLoc,
2188 SourceLocation EndLoc) {
2189 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2190 EndLoc);
2191 }
2192
2193 /// Build a new OpenMP 'detach' clause.
2194 ///
2195 /// By default, performs semantic analysis to build the new statement.
2196 /// Subclasses may override this routine to provide different behavior.
2198 SourceLocation LParenLoc,
2199 SourceLocation EndLoc) {
2200 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2201 EndLoc);
2202 }
2203
2204 /// Build a new OpenMP 'dist_schedule' clause.
2205 ///
2206 /// By default, performs semantic analysis to build the new OpenMP clause.
2207 /// Subclasses may override this routine to provide different behavior.
2208 OMPClause *
2210 Expr *ChunkSize, SourceLocation StartLoc,
2211 SourceLocation LParenLoc, SourceLocation KindLoc,
2212 SourceLocation CommaLoc, SourceLocation EndLoc) {
2214 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2215 }
2216
2217 /// Build a new OpenMP 'to' clause.
2218 ///
2219 /// By default, performs semantic analysis to build the new statement.
2220 /// Subclasses may override this routine to provide different behavior.
2221 OMPClause *
2223 ArrayRef<SourceLocation> MotionModifiersLoc,
2224 CXXScopeSpec &MapperIdScopeSpec,
2225 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2226 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2227 ArrayRef<Expr *> UnresolvedMappers) {
2229 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2230 ColonLoc, VarList, Locs, UnresolvedMappers);
2231 }
2232
2233 /// Build a new OpenMP 'from' clause.
2234 ///
2235 /// By default, performs semantic analysis to build the new statement.
2236 /// Subclasses may override this routine to provide different behavior.
2237 OMPClause *
2239 ArrayRef<SourceLocation> MotionModifiersLoc,
2240 CXXScopeSpec &MapperIdScopeSpec,
2241 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2242 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2243 ArrayRef<Expr *> UnresolvedMappers) {
2245 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2246 ColonLoc, VarList, Locs, UnresolvedMappers);
2247 }
2248
2249 /// Build a new OpenMP 'use_device_ptr' clause.
2250 ///
2251 /// By default, performs semantic analysis to build the new OpenMP clause.
2252 /// Subclasses may override this routine to provide different behavior.
2254 const OMPVarListLocTy &Locs) {
2255 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2256 }
2257
2258 /// Build a new OpenMP 'use_device_addr' clause.
2259 ///
2260 /// By default, performs semantic analysis to build the new OpenMP clause.
2261 /// Subclasses may override this routine to provide different behavior.
2266
2267 /// Build a new OpenMP 'is_device_ptr' clause.
2268 ///
2269 /// By default, performs semantic analysis to build the new OpenMP clause.
2270 /// Subclasses may override this routine to provide different behavior.
2272 const OMPVarListLocTy &Locs) {
2273 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2274 }
2275
2276 /// Build a new OpenMP 'has_device_addr' clause.
2277 ///
2278 /// By default, performs semantic analysis to build the new OpenMP clause.
2279 /// Subclasses may override this routine to provide different behavior.
2284
2285 /// Build a new OpenMP 'defaultmap' clause.
2286 ///
2287 /// By default, performs semantic analysis to build the new OpenMP clause.
2288 /// Subclasses may override this routine to provide different behavior.
2291 SourceLocation StartLoc,
2292 SourceLocation LParenLoc,
2293 SourceLocation MLoc,
2294 SourceLocation KindLoc,
2295 SourceLocation EndLoc) {
2297 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2298 }
2299
2300 /// Build a new OpenMP 'nontemporal' 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 SourceLocation StartLoc,
2306 SourceLocation LParenLoc,
2307 SourceLocation EndLoc) {
2308 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2309 LParenLoc, EndLoc);
2310 }
2311
2312 /// Build a new OpenMP 'inclusive' clause.
2313 ///
2314 /// By default, performs semantic analysis to build the new OpenMP clause.
2315 /// Subclasses may override this routine to provide different behavior.
2317 SourceLocation StartLoc,
2318 SourceLocation LParenLoc,
2319 SourceLocation EndLoc) {
2320 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2321 LParenLoc, EndLoc);
2322 }
2323
2324 /// Build a new OpenMP 'exclusive' clause.
2325 ///
2326 /// By default, performs semantic analysis to build the new OpenMP clause.
2327 /// Subclasses may override this routine to provide different behavior.
2329 SourceLocation StartLoc,
2330 SourceLocation LParenLoc,
2331 SourceLocation EndLoc) {
2332 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2333 LParenLoc, EndLoc);
2334 }
2335
2336 /// Build a new OpenMP 'uses_allocators' clause.
2337 ///
2338 /// By default, performs semantic analysis to build the new OpenMP clause.
2339 /// Subclasses may override this routine to provide different behavior.
2346
2347 /// Build a new OpenMP 'affinity' clause.
2348 ///
2349 /// By default, performs semantic analysis to build the new OpenMP clause.
2350 /// Subclasses may override this routine to provide different behavior.
2352 SourceLocation LParenLoc,
2353 SourceLocation ColonLoc,
2354 SourceLocation EndLoc, Expr *Modifier,
2355 ArrayRef<Expr *> Locators) {
2357 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2358 }
2359
2360 /// Build a new OpenMP 'order' clause.
2361 ///
2362 /// By default, performs semantic analysis to build the new OpenMP clause.
2363 /// Subclasses may override this routine to provide different behavior.
2365 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2366 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2367 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2369 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2370 }
2371
2372 /// Build a new OpenMP 'init' clause.
2373 ///
2374 /// By default, performs semantic analysis to build the new OpenMP clause.
2375 /// Subclasses may override this routine to provide different behavior.
2377 SourceLocation StartLoc,
2378 SourceLocation LParenLoc,
2379 SourceLocation VarLoc,
2380 SourceLocation EndLoc) {
2382 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2383 }
2384
2385 /// Build a new OpenMP 'use' clause.
2386 ///
2387 /// By default, performs semantic analysis to build the new OpenMP clause.
2388 /// Subclasses may override this routine to provide different behavior.
2390 SourceLocation LParenLoc,
2391 SourceLocation VarLoc, SourceLocation EndLoc) {
2392 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2393 LParenLoc, VarLoc, EndLoc);
2394 }
2395
2396 /// Build a new OpenMP 'destroy' clause.
2397 ///
2398 /// By default, performs semantic analysis to build the new OpenMP clause.
2399 /// Subclasses may override this routine to provide different behavior.
2401 SourceLocation LParenLoc,
2402 SourceLocation VarLoc,
2403 SourceLocation EndLoc) {
2405 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2406 }
2407
2408 /// Build a new OpenMP 'novariants' clause.
2409 ///
2410 /// By default, performs semantic analysis to build the new OpenMP clause.
2411 /// Subclasses may override this routine to provide different behavior.
2413 SourceLocation StartLoc,
2414 SourceLocation LParenLoc,
2415 SourceLocation EndLoc) {
2417 LParenLoc, EndLoc);
2418 }
2419
2420 /// Build a new OpenMP 'nocontext' clause.
2421 ///
2422 /// By default, performs semantic analysis to build the new OpenMP clause.
2423 /// Subclasses may override this routine to provide different behavior.
2425 SourceLocation LParenLoc,
2426 SourceLocation EndLoc) {
2428 LParenLoc, EndLoc);
2429 }
2430
2431 /// Build a new OpenMP 'filter' clause.
2432 ///
2433 /// By default, performs semantic analysis to build the new OpenMP clause.
2434 /// Subclasses may override this routine to provide different behavior.
2436 SourceLocation LParenLoc,
2437 SourceLocation EndLoc) {
2438 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2439 LParenLoc, EndLoc);
2440 }
2441
2442 /// Build a new OpenMP 'bind' clause.
2443 ///
2444 /// By default, performs semantic analysis to build the new OpenMP clause.
2445 /// Subclasses may override this routine to provide different behavior.
2447 SourceLocation KindLoc,
2448 SourceLocation StartLoc,
2449 SourceLocation LParenLoc,
2450 SourceLocation EndLoc) {
2451 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2452 LParenLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2460 SourceLocation LParenLoc,
2461 SourceLocation EndLoc) {
2462 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2463 LParenLoc, EndLoc);
2464 }
2465
2466 /// Build a new OpenMP 'ompx_attribute' clause.
2467 ///
2468 /// By default, performs semantic analysis to build the new OpenMP clause.
2469 /// Subclasses may override this routine to provide different behavior.
2471 SourceLocation StartLoc,
2472 SourceLocation LParenLoc,
2473 SourceLocation EndLoc) {
2474 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2475 LParenLoc, EndLoc);
2476 }
2477
2478 /// Build a new OpenMP 'ompx_bare' clause.
2479 ///
2480 /// By default, performs semantic analysis to build the new OpenMP clause.
2481 /// Subclasses may override this routine to provide different behavior.
2483 SourceLocation EndLoc) {
2484 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2485 }
2486
2487 /// Build a new OpenMP 'align' clause.
2488 ///
2489 /// By default, performs semantic analysis to build the new OpenMP clause.
2490 /// Subclasses may override this routine to provide different behavior.
2492 SourceLocation LParenLoc,
2493 SourceLocation EndLoc) {
2494 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2495 EndLoc);
2496 }
2497
2498 /// Build a new OpenMP 'at' clause.
2499 ///
2500 /// By default, performs semantic analysis to build the new OpenMP clause.
2501 /// Subclasses may override this routine to provide different behavior.
2503 SourceLocation StartLoc,
2504 SourceLocation LParenLoc,
2505 SourceLocation EndLoc) {
2506 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2507 LParenLoc, EndLoc);
2508 }
2509
2510 /// Build a new OpenMP 'severity' clause.
2511 ///
2512 /// By default, performs semantic analysis to build the new OpenMP clause.
2513 /// Subclasses may override this routine to provide different behavior.
2515 SourceLocation KwLoc,
2516 SourceLocation StartLoc,
2517 SourceLocation LParenLoc,
2518 SourceLocation EndLoc) {
2519 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2520 LParenLoc, EndLoc);
2521 }
2522
2523 /// Build a new OpenMP 'message' clause.
2524 ///
2525 /// By default, performs semantic analysis to build the new OpenMP clause.
2526 /// Subclasses may override this routine to provide different behavior.
2528 SourceLocation LParenLoc,
2529 SourceLocation EndLoc) {
2530 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2531 EndLoc);
2532 }
2533
2534 /// Build a new OpenMP 'doacross' clause.
2535 ///
2536 /// By default, performs semantic analysis to build the new OpenMP clause.
2537 /// Subclasses may override this routine to provide different behavior.
2538 OMPClause *
2540 SourceLocation DepLoc, SourceLocation ColonLoc,
2541 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2542 SourceLocation LParenLoc, SourceLocation EndLoc) {
2544 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2545 }
2546
2547 /// Build a new OpenMP 'holds' clause.
2549 SourceLocation LParenLoc,
2550 SourceLocation EndLoc) {
2551 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2552 EndLoc);
2553 }
2554
2555 /// Rebuild the operand to an Objective-C \@synchronized statement.
2556 ///
2557 /// By default, performs semantic analysis to build the new statement.
2558 /// Subclasses may override this routine to provide different behavior.
2563
2564 /// Build a new Objective-C \@synchronized statement.
2565 ///
2566 /// By default, performs semantic analysis to build the new statement.
2567 /// Subclasses may override this routine to provide different behavior.
2569 Expr *Object, Stmt *Body) {
2570 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2571 }
2572
2573 /// Build a new Objective-C \@autoreleasepool statement.
2574 ///
2575 /// By default, performs semantic analysis to build the new statement.
2576 /// Subclasses may override this routine to provide different behavior.
2581
2582 /// Build a new Objective-C fast enumeration statement.
2583 ///
2584 /// By default, performs semantic analysis to build the new statement.
2585 /// Subclasses may override this routine to provide different behavior.
2587 Stmt *Element,
2588 Expr *Collection,
2589 SourceLocation RParenLoc,
2590 Stmt *Body) {
2592 ForLoc, Element, Collection, RParenLoc);
2593 if (ForEachStmt.isInvalid())
2594 return StmtError();
2595
2596 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2597 Body);
2598 }
2599
2600 /// Build a new C++ exception declaration.
2601 ///
2602 /// By default, performs semantic analysis to build the new decaration.
2603 /// Subclasses may override this routine to provide different behavior.
2606 SourceLocation StartLoc,
2607 SourceLocation IdLoc,
2608 IdentifierInfo *Id) {
2610 StartLoc, IdLoc, Id);
2611 if (Var)
2612 getSema().CurContext->addDecl(Var);
2613 return Var;
2614 }
2615
2616 /// Build a new C++ catch statement.
2617 ///
2618 /// By default, performs semantic analysis to build the new statement.
2619 /// Subclasses may override this routine to provide different behavior.
2621 VarDecl *ExceptionDecl,
2622 Stmt *Handler) {
2623 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2624 Handler));
2625 }
2626
2627 /// Build a new C++ try statement.
2628 ///
2629 /// By default, performs semantic analysis to build the new statement.
2630 /// Subclasses may override this routine to provide different behavior.
2632 ArrayRef<Stmt *> Handlers) {
2633 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2634 }
2635
2636 /// Build a new C++0x range-based for statement.
2637 ///
2638 /// By default, performs semantic analysis to build the new statement.
2639 /// Subclasses may override this routine to provide different behavior.
2641 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2642 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2643 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2644 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2645 // If we've just learned that the range is actually an Objective-C
2646 // collection, treat this as an Objective-C fast enumeration loop.
2647 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2648 if (RangeStmt->isSingleDecl()) {
2649 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2650 if (RangeVar->isInvalidDecl())
2651 return StmtError();
2652
2653 Expr *RangeExpr = RangeVar->getInit();
2654 if (!RangeExpr->isTypeDependent() &&
2655 RangeExpr->getType()->isObjCObjectPointerType()) {
2656 // FIXME: Support init-statements in Objective-C++20 ranged for
2657 // statement.
2658 if (Init) {
2659 return SemaRef.Diag(Init->getBeginLoc(),
2660 diag::err_objc_for_range_init_stmt)
2661 << Init->getSourceRange();
2662 }
2664 ForLoc, LoopVar, RangeExpr, RParenLoc);
2665 }
2666 }
2667 }
2668 }
2669
2671 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2672 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2673 }
2674
2675 /// Build a new C++0x range-based for statement.
2676 ///
2677 /// By default, performs semantic analysis to build the new statement.
2678 /// Subclasses may override this routine to provide different behavior.
2680 bool IsIfExists,
2681 NestedNameSpecifierLoc QualifierLoc,
2682 DeclarationNameInfo NameInfo,
2683 Stmt *Nested) {
2684 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2685 QualifierLoc, NameInfo, Nested);
2686 }
2687
2688 /// Attach body to a C++0x range-based for statement.
2689 ///
2690 /// By default, performs semantic analysis to finish the new statement.
2691 /// Subclasses may override this routine to provide different behavior.
2693 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2694 }
2695
2697 Stmt *TryBlock, Stmt *Handler) {
2698 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2699 }
2700
2702 Stmt *Block) {
2703 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2704 }
2705
2707 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2708 }
2709
2711 SourceLocation LParen,
2712 SourceLocation RParen,
2713 TypeSourceInfo *TSI) {
2714 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2715 TSI);
2716 }
2717
2718 /// Build a new predefined expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
2725
2726 /// Build a new expression that references a declaration.
2727 ///
2728 /// By default, performs semantic analysis to build the new expression.
2729 /// Subclasses may override this routine to provide different behavior.
2731 LookupResult &R,
2732 bool RequiresADL) {
2733 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2734 }
2735
2736
2737 /// Build a new expression that references a declaration.
2738 ///
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
2742 ValueDecl *VD,
2743 const DeclarationNameInfo &NameInfo,
2745 TemplateArgumentListInfo *TemplateArgs) {
2746 CXXScopeSpec SS;
2747 SS.Adopt(QualifierLoc);
2748 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2749 TemplateArgs);
2750 }
2751
2752 /// Build a new expression in parentheses.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2757 SourceLocation RParen) {
2758 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2759 }
2760
2761 /// Build a new pseudo-destructor expression.
2762 ///
2763 /// By default, performs semantic analysis to build the new expression.
2764 /// Subclasses may override this routine to provide different behavior.
2766 SourceLocation OperatorLoc,
2767 bool isArrow,
2768 CXXScopeSpec &SS,
2769 TypeSourceInfo *ScopeType,
2770 SourceLocation CCLoc,
2771 SourceLocation TildeLoc,
2772 PseudoDestructorTypeStorage Destroyed);
2773
2774 /// Build a new unary operator expression.
2775 ///
2776 /// By default, performs semantic analysis to build the new expression.
2777 /// Subclasses may override this routine to provide different behavior.
2780 Expr *SubExpr) {
2781 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2782 }
2783
2784 /// Build a new builtin offsetof expression.
2785 ///
2786 /// By default, performs semantic analysis to build the new expression.
2787 /// Subclasses may override this routine to provide different behavior.
2791 SourceLocation RParenLoc) {
2792 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2793 RParenLoc);
2794 }
2795
2796 /// Build a new sizeof, alignof or vec_step expression with a
2797 /// type argument.
2798 ///
2799 /// By default, performs semantic analysis to build the new expression.
2800 /// Subclasses may override this routine to provide different behavior.
2802 SourceLocation OpLoc,
2803 UnaryExprOrTypeTrait ExprKind,
2804 SourceRange R) {
2805 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2806 }
2807
2808 /// Build a new sizeof, alignof or vec step expression with an
2809 /// expression argument.
2810 ///
2811 /// By default, performs semantic analysis to build the new expression.
2812 /// Subclasses may override this routine to provide different behavior.
2814 UnaryExprOrTypeTrait ExprKind,
2815 SourceRange R) {
2817 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2818 if (Result.isInvalid())
2819 return ExprError();
2820
2821 return Result;
2822 }
2823
2824 /// Build a new array subscript expression.
2825 ///
2826 /// By default, performs semantic analysis to build the new expression.
2827 /// Subclasses may override this routine to provide different behavior.
2829 SourceLocation LBracketLoc,
2830 Expr *RHS,
2831 SourceLocation RBracketLoc) {
2832 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2833 LBracketLoc, RHS,
2834 RBracketLoc);
2835 }
2836
2837 /// Build a new matrix subscript expression.
2838 ///
2839 /// By default, performs semantic analysis to build the new expression.
2840 /// Subclasses may override this routine to provide different behavior.
2842 Expr *ColumnIdx,
2843 SourceLocation RBracketLoc) {
2844 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2845 RBracketLoc);
2846 }
2847
2848 /// Build a new array section expression.
2849 ///
2850 /// By default, performs semantic analysis to build the new expression.
2851 /// Subclasses may override this routine to provide different behavior.
2853 SourceLocation LBracketLoc,
2854 Expr *LowerBound,
2855 SourceLocation ColonLocFirst,
2856 SourceLocation ColonLocSecond,
2857 Expr *Length, Expr *Stride,
2858 SourceLocation RBracketLoc) {
2859 if (IsOMPArraySection)
2861 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2862 Stride, RBracketLoc);
2863
2864 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2865 "Stride/second colon not allowed for OpenACC");
2866
2868 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2869 }
2870
2871 /// Build a new array shaping expression.
2872 ///
2873 /// By default, performs semantic analysis to build the new expression.
2874 /// Subclasses may override this routine to provide different behavior.
2876 SourceLocation RParenLoc,
2877 ArrayRef<Expr *> Dims,
2878 ArrayRef<SourceRange> BracketsRanges) {
2880 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2881 }
2882
2883 /// Build a new iterator expression.
2884 ///
2885 /// By default, performs semantic analysis to build the new expression.
2886 /// Subclasses may override this routine to provide different behavior.
2889 SourceLocation RLoc,
2892 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2893 }
2894
2895 /// Build a new call expression.
2896 ///
2897 /// By default, performs semantic analysis to build the new expression.
2898 /// Subclasses may override this routine to provide different behavior.
2900 MultiExprArg Args,
2901 SourceLocation RParenLoc,
2902 Expr *ExecConfig = nullptr) {
2903 return getSema().ActOnCallExpr(
2904 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2905 }
2906
2908 MultiExprArg Args,
2909 SourceLocation RParenLoc) {
2911 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2912 }
2913
2914 /// Build a new member access expression.
2915 ///
2916 /// By default, performs semantic analysis to build the new expression.
2917 /// Subclasses may override this routine to provide different behavior.
2919 bool isArrow,
2920 NestedNameSpecifierLoc QualifierLoc,
2921 SourceLocation TemplateKWLoc,
2922 const DeclarationNameInfo &MemberNameInfo,
2924 NamedDecl *FoundDecl,
2925 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2926 NamedDecl *FirstQualifierInScope) {
2928 isArrow);
2929 if (!Member->getDeclName()) {
2930 // We have a reference to an unnamed field. This is always the
2931 // base of an anonymous struct/union member access, i.e. the
2932 // field is always of record type.
2933 assert(Member->getType()->isRecordType() &&
2934 "unnamed member not of record type?");
2935
2936 BaseResult =
2938 QualifierLoc.getNestedNameSpecifier(),
2939 FoundDecl, Member);
2940 if (BaseResult.isInvalid())
2941 return ExprError();
2942 Base = BaseResult.get();
2943
2944 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2945 // from the AST, so we need to re-insert them if needed (since
2946 // `BuildFieldRefereneExpr()` doesn't do this).
2947 if (!isArrow && Base->isPRValue()) {
2949 if (BaseResult.isInvalid())
2950 return ExprError();
2951 Base = BaseResult.get();
2952 }
2953
2954 CXXScopeSpec EmptySS;
2956 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2957 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2958 MemberNameInfo);
2959 }
2960
2961 CXXScopeSpec SS;
2962 SS.Adopt(QualifierLoc);
2963
2964 Base = BaseResult.get();
2965 if (Base->containsErrors())
2966 return ExprError();
2967
2968 QualType BaseType = Base->getType();
2969
2970 if (isArrow && !BaseType->isPointerType())
2971 return ExprError();
2972
2973 // FIXME: this involves duplicating earlier analysis in a lot of
2974 // cases; we should avoid this when possible.
2975 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2976 R.addDecl(FoundDecl);
2977 R.resolveKind();
2978
2979 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2981 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2982 ->getType()
2983 ->getPointeeType()
2984 ->getAsCXXRecordDecl()) {
2985 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2986 // In unevaluated contexts, an expression supposed to be a member access
2987 // might reference a member in an unrelated class.
2988 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2989 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2990 VK_LValue, Member->getLocation());
2991 }
2992 }
2993
2994 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2995 SS, TemplateKWLoc,
2996 FirstQualifierInScope,
2997 R, ExplicitTemplateArgs,
2998 /*S*/nullptr);
2999 }
3000
3001 /// Build a new binary operator expression.
3002 ///
3003 /// By default, performs semantic analysis to build the new expression.
3004 /// Subclasses may override this routine to provide different behavior.
3006 Expr *LHS, Expr *RHS,
3007 bool ForFoldExpression = false) {
3008 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
3009 ForFoldExpression);
3010 }
3011
3012 /// Build a new rewritten operator expression.
3013 ///
3014 /// By default, performs semantic analysis to build the new expression.
3015 /// Subclasses may override this routine to provide different behavior.
3017 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3018 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3019 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3020 RHS, /*RequiresADL*/false);
3021 }
3022
3023 /// Build a new conditional operator expression.
3024 ///
3025 /// By default, performs semantic analysis to build the new expression.
3026 /// Subclasses may override this routine to provide different behavior.
3028 SourceLocation QuestionLoc,
3029 Expr *LHS,
3030 SourceLocation ColonLoc,
3031 Expr *RHS) {
3032 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3033 LHS, RHS);
3034 }
3035
3036 /// Build a new C-style cast expression.
3037 ///
3038 /// By default, performs semantic analysis to build the new expression.
3039 /// Subclasses may override this routine to provide different behavior.
3041 TypeSourceInfo *TInfo,
3042 SourceLocation RParenLoc,
3043 Expr *SubExpr) {
3044 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3045 SubExpr);
3046 }
3047
3048 /// Build a new compound literal expression.
3049 ///
3050 /// By default, performs semantic analysis to build the new expression.
3051 /// Subclasses may override this routine to provide different behavior.
3053 TypeSourceInfo *TInfo,
3054 SourceLocation RParenLoc,
3055 Expr *Init) {
3056 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3057 Init);
3058 }
3059
3060 /// Build a new extended vector element access expression.
3061 ///
3062 /// By default, performs semantic analysis to build the new expression.
3063 /// Subclasses may override this routine to provide different behavior.
3065 bool IsArrow,
3066 SourceLocation AccessorLoc,
3067 IdentifierInfo &Accessor) {
3068
3069 CXXScopeSpec SS;
3070 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3072 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3073 /*FirstQualifierInScope*/ nullptr, NameInfo,
3074 /* TemplateArgs */ nullptr,
3075 /*S*/ nullptr);
3076 }
3077
3078 /// Build a new initializer list expression.
3079 ///
3080 /// By default, performs semantic analysis to build the new expression.
3081 /// Subclasses may override this routine to provide different behavior.
3083 MultiExprArg Inits,
3084 SourceLocation RBraceLoc) {
3085 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3086 }
3087
3088 /// Build a new designated initializer expression.
3089 ///
3090 /// By default, performs semantic analysis to build the new expression.
3091 /// Subclasses may override this routine to provide different behavior.
3093 MultiExprArg ArrayExprs,
3094 SourceLocation EqualOrColonLoc,
3095 bool GNUSyntax,
3096 Expr *Init) {
3098 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3099 Init);
3100 if (Result.isInvalid())
3101 return ExprError();
3102
3103 return Result;
3104 }
3105
3106 /// Build a new value-initialized expression.
3107 ///
3108 /// By default, builds the implicit value initialization without performing
3109 /// any semantic analysis. Subclasses may override this routine to provide
3110 /// different behavior.
3114
3115 /// Build a new \c va_arg expression.
3116 ///
3117 /// By default, performs semantic analysis to build the new expression.
3118 /// Subclasses may override this routine to provide different behavior.
3120 Expr *SubExpr, TypeSourceInfo *TInfo,
3121 SourceLocation RParenLoc) {
3122 return getSema().BuildVAArgExpr(BuiltinLoc,
3123 SubExpr, TInfo,
3124 RParenLoc);
3125 }
3126
3127 /// Build a new expression list in parentheses.
3128 ///
3129 /// By default, performs semantic analysis to build the new expression.
3130 /// Subclasses may override this routine to provide different behavior.
3132 MultiExprArg SubExprs,
3133 SourceLocation RParenLoc) {
3134 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3135 }
3136
3138 unsigned NumUserSpecifiedExprs,
3139 SourceLocation InitLoc,
3140 SourceLocation LParenLoc,
3141 SourceLocation RParenLoc) {
3142 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3143 InitLoc, LParenLoc, RParenLoc);
3144 }
3145
3146 /// Build a new address-of-label expression.
3147 ///
3148 /// By default, performs semantic analysis, using the name of the label
3149 /// rather than attempting to map the label statement itself.
3150 /// Subclasses may override this routine to provide different behavior.
3152 SourceLocation LabelLoc, LabelDecl *Label) {
3153 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3154 }
3155
3156 /// Build a new GNU statement expression.
3157 ///
3158 /// By default, performs semantic analysis to build the new expression.
3159 /// Subclasses may override this routine to provide different behavior.
3161 SourceLocation RParenLoc, unsigned TemplateDepth) {
3162 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3163 TemplateDepth);
3164 }
3165
3166 /// Build a new __builtin_choose_expr expression.
3167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// Subclasses may override this routine to provide different behavior.
3171 Expr *Cond, Expr *LHS, Expr *RHS,
3172 SourceLocation RParenLoc) {
3173 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3174 Cond, LHS, RHS,
3175 RParenLoc);
3176 }
3177
3178 /// Build a new generic selection expression with an expression predicate.
3179 ///
3180 /// By default, performs semantic analysis to build the new expression.
3181 /// Subclasses may override this routine to provide different behavior.
3183 SourceLocation DefaultLoc,
3184 SourceLocation RParenLoc,
3185 Expr *ControllingExpr,
3187 ArrayRef<Expr *> Exprs) {
3188 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3189 /*PredicateIsExpr=*/true,
3190 ControllingExpr, Types, Exprs);
3191 }
3192
3193 /// Build a new generic selection expression with a type predicate.
3194 ///
3195 /// By default, performs semantic analysis to build the new expression.
3196 /// Subclasses may override this routine to provide different behavior.
3198 SourceLocation DefaultLoc,
3199 SourceLocation RParenLoc,
3200 TypeSourceInfo *ControllingType,
3202 ArrayRef<Expr *> Exprs) {
3203 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3204 /*PredicateIsExpr=*/false,
3205 ControllingType, Types, Exprs);
3206 }
3207
3208 /// Build a new overloaded operator call expression.
3209 ///
3210 /// By default, performs semantic analysis to build the new expression.
3211 /// The semantic analysis provides the behavior of template instantiation,
3212 /// copying with transformations that turn what looks like an overloaded
3213 /// operator call into a use of a builtin operator, performing
3214 /// argument-dependent lookup, etc. Subclasses may override this routine to
3215 /// provide different behavior.
3217 SourceLocation OpLoc,
3218 SourceLocation CalleeLoc,
3219 bool RequiresADL,
3220 const UnresolvedSetImpl &Functions,
3221 Expr *First, Expr *Second);
3222
3223 /// Build a new C++ "named" cast expression, such as static_cast or
3224 /// reinterpret_cast.
3225 ///
3226 /// By default, this routine dispatches to one of the more-specific routines
3227 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3228 /// Subclasses may override this routine to provide different behavior.
3231 SourceLocation LAngleLoc,
3232 TypeSourceInfo *TInfo,
3233 SourceLocation RAngleLoc,
3234 SourceLocation LParenLoc,
3235 Expr *SubExpr,
3236 SourceLocation RParenLoc) {
3237 switch (Class) {
3238 case Stmt::CXXStaticCastExprClass:
3239 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3240 RAngleLoc, LParenLoc,
3241 SubExpr, RParenLoc);
3242
3243 case Stmt::CXXDynamicCastExprClass:
3244 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3245 RAngleLoc, LParenLoc,
3246 SubExpr, RParenLoc);
3247
3248 case Stmt::CXXReinterpretCastExprClass:
3249 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3250 RAngleLoc, LParenLoc,
3251 SubExpr,
3252 RParenLoc);
3253
3254 case Stmt::CXXConstCastExprClass:
3255 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3256 RAngleLoc, LParenLoc,
3257 SubExpr, RParenLoc);
3258
3259 case Stmt::CXXAddrspaceCastExprClass:
3260 return getDerived().RebuildCXXAddrspaceCastExpr(
3261 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3262
3263 default:
3264 llvm_unreachable("Invalid C++ named cast");
3265 }
3266 }
3267
3268 /// Build a new C++ static_cast expression.
3269 ///
3270 /// By default, performs semantic analysis to build the new expression.
3271 /// Subclasses may override this routine to provide different behavior.
3273 SourceLocation LAngleLoc,
3274 TypeSourceInfo *TInfo,
3275 SourceLocation RAngleLoc,
3276 SourceLocation LParenLoc,
3277 Expr *SubExpr,
3278 SourceLocation RParenLoc) {
3279 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3280 TInfo, SubExpr,
3281 SourceRange(LAngleLoc, RAngleLoc),
3282 SourceRange(LParenLoc, RParenLoc));
3283 }
3284
3285 /// Build a new C++ dynamic_cast expression.
3286 ///
3287 /// By default, performs semantic analysis to build the new expression.
3288 /// Subclasses may override this routine to provide different behavior.
3290 SourceLocation LAngleLoc,
3291 TypeSourceInfo *TInfo,
3292 SourceLocation RAngleLoc,
3293 SourceLocation LParenLoc,
3294 Expr *SubExpr,
3295 SourceLocation RParenLoc) {
3296 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3297 TInfo, SubExpr,
3298 SourceRange(LAngleLoc, RAngleLoc),
3299 SourceRange(LParenLoc, RParenLoc));
3300 }
3301
3302 /// Build a new C++ reinterpret_cast expression.
3303 ///
3304 /// By default, performs semantic analysis to build the new expression.
3305 /// Subclasses may override this routine to provide different behavior.
3307 SourceLocation LAngleLoc,
3308 TypeSourceInfo *TInfo,
3309 SourceLocation RAngleLoc,
3310 SourceLocation LParenLoc,
3311 Expr *SubExpr,
3312 SourceLocation RParenLoc) {
3313 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3314 TInfo, SubExpr,
3315 SourceRange(LAngleLoc, RAngleLoc),
3316 SourceRange(LParenLoc, RParenLoc));
3317 }
3318
3319 /// Build a new C++ const_cast expression.
3320 ///
3321 /// By default, performs semantic analysis to build the new expression.
3322 /// Subclasses may override this routine to provide different behavior.
3324 SourceLocation LAngleLoc,
3325 TypeSourceInfo *TInfo,
3326 SourceLocation RAngleLoc,
3327 SourceLocation LParenLoc,
3328 Expr *SubExpr,
3329 SourceLocation RParenLoc) {
3330 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3331 TInfo, SubExpr,
3332 SourceRange(LAngleLoc, RAngleLoc),
3333 SourceRange(LParenLoc, RParenLoc));
3334 }
3335
3338 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3339 SourceLocation LParenLoc, Expr *SubExpr,
3340 SourceLocation RParenLoc) {
3341 return getSema().BuildCXXNamedCast(
3342 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3343 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3344 }
3345
3346 /// Build a new C++ functional-style cast expression.
3347 ///
3348 /// By default, performs semantic analysis to build the new expression.
3349 /// Subclasses may override this routine to provide different behavior.
3351 SourceLocation LParenLoc,
3352 Expr *Sub,
3353 SourceLocation RParenLoc,
3354 bool ListInitialization) {
3355 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3356 // CXXParenListInitExpr. Pass its expanded arguments so that the
3357 // CXXParenListInitExpr can be rebuilt.
3358 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3360 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3361 RParenLoc, ListInitialization);
3362
3363 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3365 TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
3366
3367 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3368 MultiExprArg(&Sub, 1), RParenLoc,
3369 ListInitialization);
3370 }
3371
3372 /// Build a new C++ __builtin_bit_cast expression.
3373 ///
3374 /// By default, performs semantic analysis to build the new expression.
3375 /// Subclasses may override this routine to provide different behavior.
3377 TypeSourceInfo *TSI, Expr *Sub,
3378 SourceLocation RParenLoc) {
3379 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3380 }
3381
3382 /// Build a new C++ typeid(type) expression.
3383 ///
3384 /// By default, performs semantic analysis to build the new expression.
3385 /// Subclasses may override this routine to provide different behavior.
3387 SourceLocation TypeidLoc,
3388 TypeSourceInfo *Operand,
3389 SourceLocation RParenLoc) {
3390 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3391 RParenLoc);
3392 }
3393
3394
3395 /// Build a new C++ typeid(expr) expression.
3396 ///
3397 /// By default, performs semantic analysis to build the new expression.
3398 /// Subclasses may override this routine to provide different behavior.
3400 SourceLocation TypeidLoc,
3401 Expr *Operand,
3402 SourceLocation RParenLoc) {
3403 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3404 RParenLoc);
3405 }
3406
3407 /// Build a new C++ __uuidof(type) expression.
3408 ///
3409 /// By default, performs semantic analysis to build the new expression.
3410 /// Subclasses may override this routine to provide different behavior.
3412 TypeSourceInfo *Operand,
3413 SourceLocation RParenLoc) {
3414 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3415 }
3416
3417 /// Build a new C++ __uuidof(expr) expression.
3418 ///
3419 /// By default, performs semantic analysis to build the new expression.
3420 /// Subclasses may override this routine to provide different behavior.
3422 Expr *Operand, SourceLocation RParenLoc) {
3423 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3424 }
3425
3426 /// Build a new C++ "this" expression.
3427 ///
3428 /// By default, performs semantic analysis to build a new "this" expression.
3429 /// Subclasses may override this routine to provide different behavior.
3431 QualType ThisType,
3432 bool isImplicit) {
3433 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3434 return ExprError();
3435 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3436 }
3437
3438 /// Build a new C++ throw expression.
3439 ///
3440 /// By default, performs semantic analysis to build the new expression.
3441 /// Subclasses may override this routine to provide different behavior.
3443 bool IsThrownVariableInScope) {
3444 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3445 }
3446
3447 /// Build a new C++ default-argument expression.
3448 ///
3449 /// By default, builds a new default-argument expression, which does not
3450 /// require any semantic analysis. Subclasses may override this routine to
3451 /// provide different behavior.
3453 Expr *RewrittenExpr) {
3454 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3455 RewrittenExpr, getSema().CurContext);
3456 }
3457
3458 /// Build a new C++11 default-initialization expression.
3459 ///
3460 /// By default, builds a new default field initialization expression, which
3461 /// does not require any semantic analysis. Subclasses may override this
3462 /// routine to provide different behavior.
3467
3468 /// Build a new C++ zero-initialization expression.
3469 ///
3470 /// By default, performs semantic analysis to build the new expression.
3471 /// Subclasses may override this routine to provide different behavior.
3473 SourceLocation LParenLoc,
3474 SourceLocation RParenLoc) {
3475 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3476 /*ListInitialization=*/false);
3477 }
3478
3479 /// Build a new C++ "new" expression.
3480 ///
3481 /// By default, performs semantic analysis to build the new expression.
3482 /// Subclasses may override this routine to provide different behavior.
3484 SourceLocation PlacementLParen,
3485 MultiExprArg PlacementArgs,
3486 SourceLocation PlacementRParen,
3487 SourceRange TypeIdParens, QualType AllocatedType,
3488 TypeSourceInfo *AllocatedTypeInfo,
3489 std::optional<Expr *> ArraySize,
3490 SourceRange DirectInitRange, Expr *Initializer) {
3491 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3492 PlacementLParen,
3493 PlacementArgs,
3494 PlacementRParen,
3495 TypeIdParens,
3496 AllocatedType,
3497 AllocatedTypeInfo,
3498 ArraySize,
3499 DirectInitRange,
3500 Initializer);
3501 }
3502
3503 /// Build a new C++ "delete" expression.
3504 ///
3505 /// By default, performs semantic analysis to build the new expression.
3506 /// Subclasses may override this routine to provide different behavior.
3508 bool IsGlobalDelete,
3509 bool IsArrayForm,
3510 Expr *Operand) {
3511 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3512 Operand);
3513 }
3514
3515 /// Build a new type trait expression.
3516 ///
3517 /// By default, performs semantic analysis to build the new expression.
3518 /// Subclasses may override this routine to provide different behavior.
3520 SourceLocation StartLoc,
3522 SourceLocation RParenLoc) {
3523 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3524 }
3525
3526 /// Build a new array type trait expression.
3527 ///
3528 /// By default, performs semantic analysis to build the new expression.
3529 /// Subclasses may override this routine to provide different behavior.
3531 SourceLocation StartLoc,
3532 TypeSourceInfo *TSInfo,
3533 Expr *DimExpr,
3534 SourceLocation RParenLoc) {
3535 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3536 }
3537
3538 /// Build a new expression trait expression.
3539 ///
3540 /// By default, performs semantic analysis to build the new expression.
3541 /// Subclasses may override this routine to provide different behavior.
3543 SourceLocation StartLoc,
3544 Expr *Queried,
3545 SourceLocation RParenLoc) {
3546 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3547 }
3548
3549 /// Build a new (previously unresolved) declaration reference
3550 /// expression.
3551 ///
3552 /// By default, performs semantic analysis to build the new expression.
3553 /// Subclasses may override this routine to provide different behavior.
3555 NestedNameSpecifierLoc QualifierLoc,
3556 SourceLocation TemplateKWLoc,
3557 const DeclarationNameInfo &NameInfo,
3558 const TemplateArgumentListInfo *TemplateArgs,
3559 bool IsAddressOfOperand,
3560 TypeSourceInfo **RecoveryTSI) {
3561 CXXScopeSpec SS;
3562 SS.Adopt(QualifierLoc);
3563
3564 if (TemplateArgs || TemplateKWLoc.isValid())
3566 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3567
3569 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3570 }
3571
3572 /// Build a new template-id expression.
3573 ///
3574 /// By default, performs semantic analysis to build the new expression.
3575 /// Subclasses may override this routine to provide different behavior.
3577 SourceLocation TemplateKWLoc,
3578 LookupResult &R,
3579 bool RequiresADL,
3580 const TemplateArgumentListInfo *TemplateArgs) {
3581 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3582 TemplateArgs);
3583 }
3584
3585 /// Build a new object-construction expression.
3586 ///
3587 /// By default, performs semantic analysis to build the new expression.
3588 /// Subclasses may override this routine to provide different behavior.
3591 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3592 bool ListInitialization, bool StdInitListInitialization,
3593 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3594 SourceRange ParenRange) {
3595 // Reconstruct the constructor we originally found, which might be
3596 // different if this is a call to an inherited constructor.
3597 CXXConstructorDecl *FoundCtor = Constructor;
3598 if (Constructor->isInheritingConstructor())
3599 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3600
3601 SmallVector<Expr *, 8> ConvertedArgs;
3602 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3603 ConvertedArgs))
3604 return ExprError();
3605
3607 IsElidable,
3608 ConvertedArgs,
3609 HadMultipleCandidates,
3610 ListInitialization,
3611 StdInitListInitialization,
3612 RequiresZeroInit, ConstructKind,
3613 ParenRange);
3614 }
3615
3616 /// Build a new implicit construction via inherited constructor
3617 /// expression.
3620 bool ConstructsVBase,
3621 bool InheritedFromVBase) {
3623 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3624 }
3625
3626 /// Build a new object-construction expression.
3627 ///
3628 /// By default, performs semantic analysis to build the new expression.
3629 /// Subclasses may override this routine to provide different behavior.
3631 SourceLocation LParenOrBraceLoc,
3632 MultiExprArg Args,
3633 SourceLocation RParenOrBraceLoc,
3634 bool ListInitialization) {
3636 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3637 }
3638
3639 /// Build a new object-construction expression.
3640 ///
3641 /// By default, performs semantic analysis to build the new expression.
3642 /// Subclasses may override this routine to provide different behavior.
3644 SourceLocation LParenLoc,
3645 MultiExprArg Args,
3646 SourceLocation RParenLoc,
3647 bool ListInitialization) {
3648 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3649 RParenLoc, ListInitialization);
3650 }
3651
3652 /// Build a new member reference expression.
3653 ///
3654 /// By default, performs semantic analysis to build the new expression.
3655 /// Subclasses may override this routine to provide different behavior.
3657 QualType BaseType,
3658 bool IsArrow,
3659 SourceLocation OperatorLoc,
3660 NestedNameSpecifierLoc QualifierLoc,
3661 SourceLocation TemplateKWLoc,
3662 NamedDecl *FirstQualifierInScope,
3663 const DeclarationNameInfo &MemberNameInfo,
3664 const TemplateArgumentListInfo *TemplateArgs) {
3665 CXXScopeSpec SS;
3666 SS.Adopt(QualifierLoc);
3667
3668 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3669 OperatorLoc, IsArrow,
3670 SS, TemplateKWLoc,
3671 FirstQualifierInScope,
3672 MemberNameInfo,
3673 TemplateArgs, /*S*/nullptr);
3674 }
3675
3676 /// Build a new member reference expression.
3677 ///
3678 /// By default, performs semantic analysis to build the new expression.
3679 /// Subclasses may override this routine to provide different behavior.
3681 SourceLocation OperatorLoc,
3682 bool IsArrow,
3683 NestedNameSpecifierLoc QualifierLoc,
3684 SourceLocation TemplateKWLoc,
3685 NamedDecl *FirstQualifierInScope,
3686 LookupResult &R,
3687 const TemplateArgumentListInfo *TemplateArgs) {
3688 CXXScopeSpec SS;
3689 SS.Adopt(QualifierLoc);
3690
3691 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3692 OperatorLoc, IsArrow,
3693 SS, TemplateKWLoc,
3694 FirstQualifierInScope,
3695 R, TemplateArgs, /*S*/nullptr);
3696 }
3697
3698 /// Build a new noexcept expression.
3699 ///
3700 /// By default, performs semantic analysis to build the new expression.
3701 /// Subclasses may override this routine to provide different behavior.
3703 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3704 }
3705
3708
3709 /// Build a new expression to compute the length of a parameter pack.
3711 SourceLocation PackLoc,
3712 SourceLocation RParenLoc,
3713 UnsignedOrNone Length,
3714 ArrayRef<TemplateArgument> PartialArgs) {
3715 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3716 RParenLoc, Length, PartialArgs);
3717 }
3718
3720 SourceLocation RSquareLoc,
3721 Expr *PackIdExpression, Expr *IndexExpr,
3722 ArrayRef<Expr *> ExpandedExprs,
3723 bool FullySubstituted = false) {
3724 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3725 IndexExpr, RSquareLoc, ExpandedExprs,
3726 FullySubstituted);
3727 }
3728
3729 /// Build a new expression representing a call to a source location
3730 /// builtin.
3731 ///
3732 /// By default, performs semantic analysis to build the new expression.
3733 /// Subclasses may override this routine to provide different behavior.
3735 SourceLocation BuiltinLoc,
3736 SourceLocation RPLoc,
3737 DeclContext *ParentContext) {
3738 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3739 ParentContext);
3740 }
3741
3743 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3744 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3746 CXXScopeSpec SS;
3747 SS.Adopt(NNS);
3748 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3749 ConceptNameInfo,
3750 FoundDecl,
3751 NamedConcept, TALI);
3752 if (Result.isInvalid())
3753 return ExprError();
3754 return Result;
3755 }
3756
3757 /// \brief Build a new requires expression.
3758 ///
3759 /// By default, performs semantic analysis to build the new expression.
3760 /// Subclasses may override this routine to provide different behavior.
3763 SourceLocation LParenLoc,
3764 ArrayRef<ParmVarDecl *> LocalParameters,
3765 SourceLocation RParenLoc,
3767 SourceLocation ClosingBraceLoc) {
3768 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3769 LocalParameters, RParenLoc, Requirements,
3770 ClosingBraceLoc);
3771 }
3772
3776 return SemaRef.BuildTypeRequirement(SubstDiag);
3777 }
3778
3780 return SemaRef.BuildTypeRequirement(T);
3781 }
3782
3785 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3786 SourceLocation NoexceptLoc,
3788 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3789 std::move(Ret));
3790 }
3791
3793 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3795 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3796 std::move(Ret));
3797 }
3798
3800 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3801 const ASTConstraintSatisfaction &Satisfaction) {
3802 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3803 Satisfaction);
3804 }
3805
3807 return SemaRef.BuildNestedRequirement(Constraint);
3808 }
3809
3810 /// \brief Build a new Objective-C boxed expression.
3811 ///
3812 /// By default, performs semantic analysis to build the new expression.
3813 /// Subclasses may override this routine to provide different behavior.
3815 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3816 }
3817
3818 /// Build a new Objective-C array literal.
3819 ///
3820 /// By default, performs semantic analysis to build the new expression.
3821 /// Subclasses may override this routine to provide different behavior.
3823 Expr **Elements, unsigned NumElements) {
3825 Range, MultiExprArg(Elements, NumElements));
3826 }
3827
3829 Expr *Base, Expr *Key,
3830 ObjCMethodDecl *getterMethod,
3831 ObjCMethodDecl *setterMethod) {
3833 RB, Base, Key, getterMethod, setterMethod);
3834 }
3835
3836 /// Build a new Objective-C dictionary literal.
3837 ///
3838 /// By default, performs semantic analysis to build the new expression.
3839 /// Subclasses may override this routine to provide different behavior.
3844
3845 /// Build a new Objective-C \@encode expression.
3846 ///
3847 /// By default, performs semantic analysis to build the new expression.
3848 /// Subclasses may override this routine to provide different behavior.
3850 TypeSourceInfo *EncodeTypeInfo,
3851 SourceLocation RParenLoc) {
3852 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3853 RParenLoc);
3854 }
3855
3856 /// Build a new Objective-C class message.
3858 Selector Sel,
3859 ArrayRef<SourceLocation> SelectorLocs,
3861 SourceLocation LBracLoc,
3862 MultiExprArg Args,
3863 SourceLocation RBracLoc) {
3864 return SemaRef.ObjC().BuildClassMessage(
3865 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3866 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3867 RBracLoc, Args);
3868 }
3869
3870 /// Build a new Objective-C instance message.
3872 Selector Sel,
3873 ArrayRef<SourceLocation> SelectorLocs,
3875 SourceLocation LBracLoc,
3876 MultiExprArg Args,
3877 SourceLocation RBracLoc) {
3878 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3879 /*SuperLoc=*/SourceLocation(),
3880 Sel, Method, LBracLoc,
3881 SelectorLocs, RBracLoc, Args);
3882 }
3883
3884 /// Build a new Objective-C instance/class message to 'super'.
3886 Selector Sel,
3887 ArrayRef<SourceLocation> SelectorLocs,
3888 QualType SuperType,
3890 SourceLocation LBracLoc,
3891 MultiExprArg Args,
3892 SourceLocation RBracLoc) {
3893 return Method->isInstanceMethod()
3894 ? SemaRef.ObjC().BuildInstanceMessage(
3895 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3896 SelectorLocs, RBracLoc, Args)
3897 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3898 Sel, Method, LBracLoc,
3899 SelectorLocs, RBracLoc, Args);
3900 }
3901
3902 /// Build a new Objective-C ivar reference expression.
3903 ///
3904 /// By default, performs semantic analysis to build the new expression.
3905 /// Subclasses may override this routine to provide different behavior.
3907 SourceLocation IvarLoc,
3908 bool IsArrow, bool IsFreeIvar) {
3909 CXXScopeSpec SS;
3910 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3912 BaseArg, BaseArg->getType(),
3913 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3914 /*FirstQualifierInScope=*/nullptr, NameInfo,
3915 /*TemplateArgs=*/nullptr,
3916 /*S=*/nullptr);
3917 if (IsFreeIvar && Result.isUsable())
3918 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3919 return Result;
3920 }
3921
3922 /// Build a new Objective-C property reference expression.
3923 ///
3924 /// By default, performs semantic analysis to build the new expression.
3925 /// Subclasses may override this routine to provide different behavior.
3928 SourceLocation PropertyLoc) {
3929 CXXScopeSpec SS;
3930 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3931 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3932 /*FIXME:*/PropertyLoc,
3933 /*IsArrow=*/false,
3934 SS, SourceLocation(),
3935 /*FirstQualifierInScope=*/nullptr,
3936 NameInfo,
3937 /*TemplateArgs=*/nullptr,
3938 /*S=*/nullptr);
3939 }
3940
3941 /// Build a new Objective-C property reference expression.
3942 ///
3943 /// By default, performs semantic analysis to build the new expression.
3944 /// Subclasses may override this routine to provide different behavior.
3946 ObjCMethodDecl *Getter,
3947 ObjCMethodDecl *Setter,
3948 SourceLocation PropertyLoc) {
3949 // Since these expressions can only be value-dependent, we do not
3950 // need to perform semantic analysis again.
3951 return Owned(
3952 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3954 PropertyLoc, Base));
3955 }
3956
3957 /// Build a new Objective-C "isa" 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 OpLoc, bool IsArrow) {
3963 CXXScopeSpec SS;
3964 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3965 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3966 OpLoc, IsArrow,
3967 SS, SourceLocation(),
3968 /*FirstQualifierInScope=*/nullptr,
3969 NameInfo,
3970 /*TemplateArgs=*/nullptr,
3971 /*S=*/nullptr);
3972 }
3973
3974 /// Build a new shuffle vector expression.
3975 ///
3976 /// By default, performs semantic analysis to build the new expression.
3977 /// Subclasses may override this routine to provide different behavior.
3979 MultiExprArg SubExprs,
3980 SourceLocation RParenLoc) {
3981 // Find the declaration for __builtin_shufflevector
3982 const IdentifierInfo &Name
3983 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3984 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3985 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3986 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3987
3988 // Build a reference to the __builtin_shufflevector builtin
3990 Expr *Callee = new (SemaRef.Context)
3991 DeclRefExpr(SemaRef.Context, Builtin, false,
3992 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3993 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3994 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3995 CK_BuiltinFnToFnPtr).get();
3996
3997 // Build the CallExpr
3998 ExprResult TheCall = CallExpr::Create(
3999 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
4000 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
4002
4003 // Type-check the __builtin_shufflevector expression.
4004 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
4005 }
4006
4007 /// Build a new convert vector expression.
4009 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4010 SourceLocation RParenLoc) {
4011 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4012 }
4013
4014 /// Build a new template argument pack expansion.
4015 ///
4016 /// By default, performs semantic analysis to build a new pack expansion
4017 /// for a template argument. Subclasses may override this routine to provide
4018 /// different behavior.
4020 SourceLocation EllipsisLoc,
4021 UnsignedOrNone NumExpansions) {
4022 switch (Pattern.getArgument().getKind()) {
4026 EllipsisLoc, NumExpansions);
4027 if (Result.isInvalid())
4028 return TemplateArgumentLoc();
4029
4031 /*IsCanonical=*/false),
4032 Result.get());
4033 }
4034
4036 return TemplateArgumentLoc(
4037 SemaRef.Context,
4039 NumExpansions),
4040 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4041 Pattern.getTemplateNameLoc(), EllipsisLoc);
4042
4050 llvm_unreachable("Pack expansion pattern has no parameter packs");
4051
4053 if (TypeSourceInfo *Expansion
4054 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4055 EllipsisLoc,
4056 NumExpansions))
4057 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4058 Expansion);
4059 break;
4060 }
4061
4062 return TemplateArgumentLoc();
4063 }
4064
4065 /// Build a new expression pack expansion.
4066 ///
4067 /// By default, performs semantic analysis to build a new pack expansion
4068 /// for an expression. Subclasses may override this routine to provide
4069 /// different behavior.
4071 UnsignedOrNone NumExpansions) {
4072 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4073 }
4074
4075 /// Build a new C++1z fold-expression.
4076 ///
4077 /// By default, performs semantic analysis in order to build a new fold
4078 /// expression.
4080 SourceLocation LParenLoc, Expr *LHS,
4081 BinaryOperatorKind Operator,
4082 SourceLocation EllipsisLoc, Expr *RHS,
4083 SourceLocation RParenLoc,
4084 UnsignedOrNone NumExpansions) {
4085 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4086 EllipsisLoc, RHS, RParenLoc,
4087 NumExpansions);
4088 }
4089
4091 LambdaScopeInfo *LSI) {
4092 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4093 if (Expr *Init = PVD->getInit())
4095 Init->containsUnexpandedParameterPack();
4096 else if (PVD->hasUninstantiatedDefaultArg())
4098 PVD->getUninstantiatedDefaultArg()
4099 ->containsUnexpandedParameterPack();
4100 }
4101 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4102 }
4103
4104 /// Build an empty C++1z fold-expression with the given operator.
4105 ///
4106 /// By default, produces the fallback value for the fold-expression, or
4107 /// produce an error if there is no fallback value.
4109 BinaryOperatorKind Operator) {
4110 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4111 }
4112
4113 /// Build a new atomic operation expression.
4114 ///
4115 /// By default, performs semantic analysis to build the new expression.
4116 /// Subclasses may override this routine to provide different behavior.
4119 SourceLocation RParenLoc) {
4120 // Use this for all of the locations, since we don't know the difference
4121 // between the call and the expr at this point.
4122 SourceRange Range{BuiltinLoc, RParenLoc};
4123 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4125 }
4126
4128 ArrayRef<Expr *> SubExprs, QualType Type) {
4129 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4130 }
4131
4133 SourceLocation BeginLoc,
4134 SourceLocation DirLoc,
4135 SourceLocation EndLoc,
4137 StmtResult StrBlock) {
4139 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4140 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4141 }
4142
4153
4155 SourceLocation BeginLoc,
4156 SourceLocation DirLoc,
4157 SourceLocation EndLoc,
4159 StmtResult Loop) {
4161 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4162 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4163 }
4164
4166 SourceLocation DirLoc,
4167 SourceLocation EndLoc,
4169 StmtResult StrBlock) {
4171 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4173 Clauses, StrBlock);
4174 }
4175
4185
4195
4197 SourceLocation DirLoc,
4198 SourceLocation EndLoc,
4200 StmtResult StrBlock) {
4204 Clauses, StrBlock);
4205 }
4206
4208 SourceLocation DirLoc,
4209 SourceLocation EndLoc,
4210 ArrayRef<OpenACCClause *> Clauses) {
4212 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4214 Clauses, {});
4215 }
4216
4226
4228 SourceLocation DirLoc,
4229 SourceLocation EndLoc,
4230 ArrayRef<OpenACCClause *> Clauses) {
4232 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4234 Clauses, {});
4235 }
4236
4238 SourceLocation DirLoc,
4239 SourceLocation EndLoc,
4240 ArrayRef<OpenACCClause *> Clauses) {
4242 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4244 Clauses, {});
4245 }
4246
4248 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4249 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4250 SourceLocation RParenLoc, SourceLocation EndLoc,
4251 ArrayRef<OpenACCClause *> Clauses) {
4253 Exprs.push_back(DevNumExpr);
4254 llvm::append_range(Exprs, QueueIdExprs);
4256 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4257 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4258 }
4259
4261 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4262 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4263 SourceLocation RParenLoc, SourceLocation EndLoc) {
4265 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4266 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4267 }
4268
4270 SourceLocation DirLoc,
4271 OpenACCAtomicKind AtKind,
4272 SourceLocation EndLoc,
4274 StmtResult AssociatedStmt) {
4276 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4277 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4278 AssociatedStmt);
4279 }
4280
4284
4285private:
4286 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4287 QualType ObjectType,
4288 NamedDecl *FirstQualifierInScope);
4289
4290 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4291 QualType ObjectType,
4292 NamedDecl *FirstQualifierInScope) {
4293 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4294 return TSInfo;
4295
4296 TypeLocBuilder TLB;
4297 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4298 ObjectType, FirstQualifierInScope);
4299 if (T.isNull())
4300 return nullptr;
4301 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4302 }
4303
4304 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4305 DependentNameTypeLoc TL,
4306 bool DeducibleTSTContext,
4307 QualType ObjectType = QualType(),
4308 NamedDecl *UnqualLookup = nullptr);
4309
4311 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4313
4314 OpenACCClause *
4315 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4316 OpenACCDirectiveKind DirKind,
4317 const OpenACCClause *OldClause);
4318};
4319
4320template <typename Derived>
4322 if (!S)
4323 return S;
4324
4325 switch (S->getStmtClass()) {
4326 case Stmt::NoStmtClass: break;
4327
4328 // Transform individual statement nodes
4329 // Pass SDK into statements that can produce a value
4330#define STMT(Node, Parent) \
4331 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4332#define VALUESTMT(Node, Parent) \
4333 case Stmt::Node##Class: \
4334 return getDerived().Transform##Node(cast<Node>(S), SDK);
4335#define ABSTRACT_STMT(Node)
4336#define EXPR(Node, Parent)
4337#include "clang/AST/StmtNodes.inc"
4338
4339 // Transform expressions by calling TransformExpr.
4340#define STMT(Node, Parent)
4341#define ABSTRACT_STMT(Stmt)
4342#define EXPR(Node, Parent) case Stmt::Node##Class:
4343#include "clang/AST/StmtNodes.inc"
4344 {
4345 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4346
4348 E = getSema().ActOnStmtExprResult(E);
4349 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4350 }
4351 }
4352
4353 return S;
4354}
4355
4356template<typename Derived>
4358 if (!S)
4359 return S;
4360
4361 switch (S->getClauseKind()) {
4362 default: break;
4363 // Transform individual clause nodes
4364#define GEN_CLANG_CLAUSE_CLASS
4365#define CLAUSE_CLASS(Enum, Str, Class) \
4366 case Enum: \
4367 return getDerived().Transform##Class(cast<Class>(S));
4368#include "llvm/Frontend/OpenMP/OMP.inc"
4369 }
4370
4371 return S;
4372}
4373
4374
4375template<typename Derived>
4377 if (!E)
4378 return E;
4379
4380 switch (E->getStmtClass()) {
4381 case Stmt::NoStmtClass: break;
4382#define STMT(Node, Parent) case Stmt::Node##Class: break;
4383#define ABSTRACT_STMT(Stmt)
4384#define EXPR(Node, Parent) \
4385 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4386#include "clang/AST/StmtNodes.inc"
4387 }
4388
4389 return E;
4390}
4391
4392template<typename Derived>
4394 bool NotCopyInit) {
4395 // Initializers are instantiated like expressions, except that various outer
4396 // layers are stripped.
4397 if (!Init)
4398 return Init;
4399
4400 if (auto *FE = dyn_cast<FullExpr>(Init))
4401 Init = FE->getSubExpr();
4402
4403 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4404 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4405 Init = OVE->getSourceExpr();
4406 }
4407
4408 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4409 Init = MTE->getSubExpr();
4410
4411 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4412 Init = Binder->getSubExpr();
4413
4414 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4415 Init = ICE->getSubExprAsWritten();
4416
4417 if (CXXStdInitializerListExpr *ILE =
4418 dyn_cast<CXXStdInitializerListExpr>(Init))
4419 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4420
4421 // If this is copy-initialization, we only need to reconstruct
4422 // InitListExprs. Other forms of copy-initialization will be a no-op if
4423 // the initializer is already the right type.
4424 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4425 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4426 return getDerived().TransformExpr(Init);
4427
4428 // Revert value-initialization back to empty parens.
4429 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4430 SourceRange Parens = VIE->getSourceRange();
4431 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4432 Parens.getEnd());
4433 }
4434
4435 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4437 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4438 SourceLocation());
4439
4440 // Revert initialization by constructor back to a parenthesized or braced list
4441 // of expressions. Any other form of initializer can just be reused directly.
4442 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4443 return getDerived().TransformExpr(Init);
4444
4445 // If the initialization implicitly converted an initializer list to a
4446 // std::initializer_list object, unwrap the std::initializer_list too.
4447 if (Construct && Construct->isStdInitListInitialization())
4448 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4449
4450 // Enter a list-init context if this was list initialization.
4453 Construct->isListInitialization());
4454
4455 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4456 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4457 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4458 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4459 SmallVector<Expr*, 8> NewArgs;
4460 bool ArgChanged = false;
4461 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4462 /*IsCall*/true, NewArgs, &ArgChanged))
4463 return ExprError();
4464
4465 // If this was list initialization, revert to syntactic list form.
4466 if (Construct->isListInitialization())
4467 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4468 Construct->getEndLoc());
4469
4470 // Build a ParenListExpr to represent anything else.
4472 if (Parens.isInvalid()) {
4473 // This was a variable declaration's initialization for which no initializer
4474 // was specified.
4475 assert(NewArgs.empty() &&
4476 "no parens or braces but have direct init with arguments?");
4477 return ExprEmpty();
4478 }
4479 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4480 Parens.getEnd());
4481}
4482
4483template<typename Derived>
4485 unsigned NumInputs,
4486 bool IsCall,
4487 SmallVectorImpl<Expr *> &Outputs,
4488 bool *ArgChanged) {
4489 for (unsigned I = 0; I != NumInputs; ++I) {
4490 // If requested, drop call arguments that need to be dropped.
4491 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4492 if (ArgChanged)
4493 *ArgChanged = true;
4494
4495 break;
4496 }
4497
4498 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4499 Expr *Pattern = Expansion->getPattern();
4500
4502 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4503 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4504
4505 // Determine whether the set of unexpanded parameter packs can and should
4506 // be expanded.
4507 bool Expand = true;
4508 bool RetainExpansion = false;
4509 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4510 UnsignedOrNone NumExpansions = OrigNumExpansions;
4512 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4513 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4514 RetainExpansion, NumExpansions))
4515 return true;
4516
4517 if (!Expand) {
4518 // The transform has determined that we should perform a simple
4519 // transformation on the pack expansion, producing another pack
4520 // expansion.
4521 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4522 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4523 if (OutPattern.isInvalid())
4524 return true;
4525
4526 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4527 Expansion->getEllipsisLoc(),
4528 NumExpansions);
4529 if (Out.isInvalid())
4530 return true;
4531
4532 if (ArgChanged)
4533 *ArgChanged = true;
4534 Outputs.push_back(Out.get());
4535 continue;
4536 }
4537
4538 // Record right away that the argument was changed. This needs
4539 // to happen even if the array expands to nothing.
4540 if (ArgChanged) *ArgChanged = true;
4541
4542 // The transform has determined that we should perform an elementwise
4543 // expansion of the pattern. Do so.
4544 for (unsigned I = 0; I != *NumExpansions; ++I) {
4545 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4546 ExprResult Out = getDerived().TransformExpr(Pattern);
4547 if (Out.isInvalid())
4548 return true;
4549
4550 if (Out.get()->containsUnexpandedParameterPack()) {
4551 Out = getDerived().RebuildPackExpansion(
4552 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4553 if (Out.isInvalid())
4554 return true;
4555 }
4556
4557 Outputs.push_back(Out.get());
4558 }
4559
4560 // If we're supposed to retain a pack expansion, do so by temporarily
4561 // forgetting the partially-substituted parameter pack.
4562 if (RetainExpansion) {
4563 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4564
4565 ExprResult Out = getDerived().TransformExpr(Pattern);
4566 if (Out.isInvalid())
4567 return true;
4568
4569 Out = getDerived().RebuildPackExpansion(
4570 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4571 if (Out.isInvalid())
4572 return true;
4573
4574 Outputs.push_back(Out.get());
4575 }
4576
4577 continue;
4578 }
4579
4581 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4582 : getDerived().TransformExpr(Inputs[I]);
4583 if (Result.isInvalid())
4584 return true;
4585
4586 if (Result.get() != Inputs[I] && ArgChanged)
4587 *ArgChanged = true;
4588
4589 Outputs.push_back(Result.get());
4590 }
4591
4592 return false;
4593}
4594
4595template <typename Derived>
4598
4601 /*LambdaContextDecl=*/nullptr,
4603 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4604
4605 if (Var) {
4606 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4608
4609 if (!ConditionVar)
4610 return Sema::ConditionError();
4611
4612 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4613 }
4614
4615 if (Expr) {
4616 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4617
4618 if (CondExpr.isInvalid())
4619 return Sema::ConditionError();
4620
4621 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4622 /*MissingOK=*/true);
4623 }
4624
4625 return Sema::ConditionResult();
4626}
4627
4628template <typename Derived>
4630 NestedNameSpecifierLoc NNS, QualType ObjectType,
4631 NamedDecl *FirstQualifierInScope) {
4633
4634 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4635 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4636 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4637 Qualifiers.push_back(Qualifier);
4638 };
4639 insertNNS(NNS);
4640
4641 CXXScopeSpec SS;
4642 while (!Qualifiers.empty()) {
4643 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4645
4646 switch (QNNS.getKind()) {
4648 llvm_unreachable("unexpected null nested name specifier");
4649
4652 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4654 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4655 break;
4656 }
4657
4659 // There is no meaningful transformation that one could perform on the
4660 // global scope.
4661 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4662 break;
4663
4665 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4667 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4668 Q.getEndLoc());
4669 break;
4670 }
4671
4673 assert(SS.isEmpty());
4674 TypeLoc TL = Q.castAsTypeLoc();
4675
4676 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4677 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4678 if (QualifierLoc) {
4679 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4680 QualifierLoc, ObjectType, FirstQualifierInScope);
4681 if (!QualifierLoc)
4682 return NestedNameSpecifierLoc();
4683 ObjectType = QualType();
4684 FirstQualifierInScope = nullptr;
4685 }
4686 SS.Adopt(QualifierLoc);
4688 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4689 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4690 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4691 false, SS,
4692 FirstQualifierInScope, false))
4693 return NestedNameSpecifierLoc();
4694 return SS.getWithLocInContext(SemaRef.Context);
4695 }
4696
4697 QualType T = TL.getType();
4698 TypeLocBuilder TLB;
4700 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4701 FirstQualifierInScope);
4702 if (T.isNull())
4703 return NestedNameSpecifierLoc();
4704 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4705 }
4706
4707 if (T->isDependentType() || T->isRecordType() ||
4708 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4709 if (T->isEnumeralType())
4710 SemaRef.Diag(TL.getBeginLoc(),
4711 diag::warn_cxx98_compat_enum_nested_name_spec);
4712 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4713 break;
4714 }
4715 // If the nested-name-specifier is an invalid type def, don't emit an
4716 // error because a previous error should have already been emitted.
4718 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4719 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4720 << T << SS.getRange();
4721 }
4722 return NestedNameSpecifierLoc();
4723 }
4724 }
4725 }
4726
4727 // Don't rebuild the nested-name-specifier if we don't have to.
4728 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4730 return NNS;
4731
4732 // If we can re-use the source-location data from the original
4733 // nested-name-specifier, do so.
4734 if (SS.location_size() == NNS.getDataLength() &&
4735 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4737
4738 // Allocate new nested-name-specifier location information.
4739 return SS.getWithLocInContext(SemaRef.Context);
4740}
4741
4742template<typename Derived>
4746 DeclarationName Name = NameInfo.getName();
4747 if (!Name)
4748 return DeclarationNameInfo();
4749
4750 switch (Name.getNameKind()) {
4758 return NameInfo;
4759
4761 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4762 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4763 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4764 if (!NewTemplate)
4765 return DeclarationNameInfo();
4766
4767 DeclarationNameInfo NewNameInfo(NameInfo);
4768 NewNameInfo.setName(
4769 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4770 return NewNameInfo;
4771 }
4772
4776 TypeSourceInfo *NewTInfo;
4777 CanQualType NewCanTy;
4778 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4779 NewTInfo = getDerived().TransformType(OldTInfo);
4780 if (!NewTInfo)
4781 return DeclarationNameInfo();
4782 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4783 }
4784 else {
4785 NewTInfo = nullptr;
4786 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4787 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4788 if (NewT.isNull())
4789 return DeclarationNameInfo();
4790 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4791 }
4792
4793 DeclarationName NewName
4794 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4795 NewCanTy);
4796 DeclarationNameInfo NewNameInfo(NameInfo);
4797 NewNameInfo.setName(NewName);
4798 NewNameInfo.setNamedTypeInfo(NewTInfo);
4799 return NewNameInfo;
4800 }
4801 }
4802
4803 llvm_unreachable("Unknown name kind.");
4804}
4805
4806template <typename Derived>
4808 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4810 QualType ObjectType, bool AllowInjectedClassName) {
4811 if (const IdentifierInfo *II = IO.getIdentifier())
4812 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4813 ObjectType, AllowInjectedClassName);
4814 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4815 NameLoc, ObjectType,
4816 AllowInjectedClassName);
4817}
4818
4819template <typename Derived>
4821 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4822 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4823 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4825 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4826
4827 if (QualifierLoc) {
4828 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4829 QualifierLoc, ObjectType, FirstQualifierInScope);
4830 if (!QualifierLoc)
4831 return TemplateName();
4832 }
4833
4834 NestedNameSpecifierLoc UnderlyingQualifier;
4835 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4836 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4837 FirstQualifierInScope, AllowInjectedClassName);
4838 if (NewUnderlyingName.isNull())
4839 return TemplateName();
4840 assert(!UnderlyingQualifier && "unexpected qualifier");
4841
4842 if (!getDerived().AlwaysRebuild() &&
4843 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4844 NewUnderlyingName == UnderlyingName)
4845 return Name;
4846 CXXScopeSpec SS;
4847 SS.Adopt(QualifierLoc);
4848 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4849 NewUnderlyingName);
4850 }
4851
4853 if (QualifierLoc) {
4854 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4855 QualifierLoc, ObjectType, FirstQualifierInScope);
4856 if (!QualifierLoc)
4857 return TemplateName();
4858 // The qualifier-in-scope and object type only apply to the leftmost
4859 // entity.
4860 ObjectType = QualType();
4861 }
4862
4863 if (!getDerived().AlwaysRebuild() &&
4864 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4865 ObjectType.isNull())
4866 return Name;
4867
4868 CXXScopeSpec SS;
4869 SS.Adopt(QualifierLoc);
4870 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4871 NameLoc, ObjectType,
4872 AllowInjectedClassName);
4873 }
4874
4877 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4878
4879 NestedNameSpecifierLoc ReplacementQualifierLoc;
4880 TemplateName ReplacementName = S->getReplacement();
4881 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4883 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4884 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4885 }
4886
4887 TemplateName NewName = getDerived().TransformTemplateName(
4888 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4889 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4890 if (NewName.isNull())
4891 return TemplateName();
4892 Decl *AssociatedDecl =
4893 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4894 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4895 AssociatedDecl == S->getAssociatedDecl())
4896 return Name;
4897 return SemaRef.Context.getSubstTemplateTemplateParm(
4898 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4899 S->getFinal());
4900 }
4901
4902 assert(!Name.getAsDeducedTemplateName() &&
4903 "DeducedTemplateName should not escape partial ordering");
4904
4905 // FIXME: Preserve UsingTemplateName.
4906 if (auto *Template = Name.getAsTemplateDecl()) {
4907 assert(!QualifierLoc && "Unexpected qualifier");
4908 return TemplateName(cast_or_null<TemplateDecl>(
4909 getDerived().TransformDecl(NameLoc, Template)));
4910 }
4911
4914 assert(!QualifierLoc &&
4915 "Unexpected qualified SubstTemplateTemplateParmPack");
4916 return getDerived().RebuildTemplateName(
4917 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4918 SubstPack->getIndex(), SubstPack->getFinal());
4919 }
4920
4921 // These should be getting filtered out before they reach the AST.
4922 llvm_unreachable("overloaded function decl survived to here");
4923}
4924
4925template <typename Derived>
4927 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4928 TemplateName Name, SourceLocation NameLoc) {
4929 TemplateName TN = getDerived().TransformTemplateName(
4930 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
4931 if (TN.isNull())
4932 return TemplateArgument();
4933 return TemplateArgument(TN);
4934}
4935
4936template<typename Derived>
4938 const TemplateArgument &Arg,
4939 TemplateArgumentLoc &Output) {
4940 Output = getSema().getTrivialTemplateArgumentLoc(
4941 Arg, QualType(), getDerived().getBaseLocation());
4942}
4943
4944template <typename Derived>
4946 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4947 bool Uneval) {
4948 const TemplateArgument &Arg = Input.getArgument();
4949 switch (Arg.getKind()) {
4952 llvm_unreachable("Unexpected TemplateArgument");
4953
4958 // Transform a resolved template argument straight to a resolved template
4959 // argument. We get here when substituting into an already-substituted
4960 // template type argument during concept satisfaction checking.
4962 QualType NewT = getDerived().TransformType(T);
4963 if (NewT.isNull())
4964 return true;
4965
4967 ? Arg.getAsDecl()
4968 : nullptr;
4969 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4971 : nullptr;
4972 if (D && !NewD)
4973 return true;
4974
4975 if (NewT == T && D == NewD)
4976 Output = Input;
4977 else if (Arg.getKind() == TemplateArgument::Integral)
4978 Output = TemplateArgumentLoc(
4979 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4981 else if (Arg.getKind() == TemplateArgument::NullPtr)
4982 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4984 else if (Arg.getKind() == TemplateArgument::Declaration)
4985 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4988 Output = TemplateArgumentLoc(
4989 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4991 else
4992 llvm_unreachable("unexpected template argument kind");
4993
4994 return false;
4995 }
4996
4998 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4999 if (!DI)
5001
5002 DI = getDerived().TransformType(DI);
5003 if (!DI)
5004 return true;
5005
5006 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
5007 return false;
5008 }
5009
5011 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5012
5013 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5014 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5015 Input.getTemplateNameLoc());
5016 if (Out.isNull())
5017 return true;
5018 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5019 QualifierLoc, Input.getTemplateNameLoc());
5020 return false;
5021 }
5022
5024 llvm_unreachable("Caller should expand pack expansions");
5025
5027 // Template argument expressions are constant expressions.
5029 getSema(),
5032 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5034
5035 Expr *InputExpr = Input.getSourceExpression();
5036 if (!InputExpr)
5037 InputExpr = Input.getArgument().getAsExpr();
5038
5039 ExprResult E = getDerived().TransformExpr(InputExpr);
5040 E = SemaRef.ActOnConstantExpression(E);
5041 if (E.isInvalid())
5042 return true;
5043 Output = TemplateArgumentLoc(
5044 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5045 return false;
5046 }
5047 }
5048
5049 // Work around bogus GCC warning
5050 return true;
5051}
5052
5053/// Iterator adaptor that invents template argument location information
5054/// for each of the template arguments in its underlying iterator.
5055template<typename Derived, typename InputIterator>
5058 InputIterator Iter;
5059
5060public:
5063 typedef typename std::iterator_traits<InputIterator>::difference_type
5065 typedef std::input_iterator_tag iterator_category;
5066
5067 class pointer {
5069
5070 public:
5071 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5072
5073 const TemplateArgumentLoc *operator->() const { return &Arg; }
5074 };
5075
5077 InputIterator Iter)
5078 : Self(Self), Iter(Iter) { }
5079
5081 ++Iter;
5082 return *this;
5083 }
5084
5087 ++(*this);
5088 return Old;
5089 }
5090
5093 Self.InventTemplateArgumentLoc(*Iter, Result);
5094 return Result;
5095 }
5096
5097 pointer operator->() const { return pointer(**this); }
5098
5101 return X.Iter == Y.Iter;
5102 }
5103
5106 return X.Iter != Y.Iter;
5107 }
5108};
5109
5110template<typename Derived>
5111template<typename InputIterator>
5113 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5114 bool Uneval) {
5115 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5117 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5118 // Unpack argument packs, which we translate them into separate
5119 // arguments.
5120 // FIXME: We could do much better if we could guarantee that the
5121 // TemplateArgumentLocInfo for the pack expansion would be usable for
5122 // all of the template arguments in the argument pack.
5123 typedef TemplateArgumentLocInventIterator<Derived,
5125 PackLocIterator;
5126
5127 TemplateArgumentListInfo *PackOutput = &Outputs;
5129
5131 PackLocIterator(*this, In.getArgument().pack_begin()),
5132 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5133 Uneval))
5134 return true;
5135
5136 continue;
5137 }
5138
5139 if (In.getArgument().isPackExpansion()) {
5140 UnexpandedInfo Info;
5141 TemplateArgumentLoc Prepared;
5142 if (PreparePackForExpansion(In, Uneval, Prepared, Info))
5143 return true;
5144 if (!Info.Expand) {
5145 Outputs.addArgument(Prepared);
5146 continue;
5147 }
5148
5149 // The transform has determined that we should perform an elementwise
5150 // expansion of the pattern. Do so.
5151 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5153 ForgetSubst.emplace(getDerived());
5154 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5155 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5156
5158 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5159 return true;
5160
5161 if (Out.getArgument().containsUnexpandedParameterPack()) {
5162 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5163 Info.OrigNumExpansions);
5164 if (Out.getArgument().isNull())
5165 return true;
5166 }
5167
5168 Outputs.addArgument(Out);
5169 }
5170
5171 // If we're supposed to retain a pack expansion, do so by temporarily
5172 // forgetting the partially-substituted parameter pack.
5173 if (Info.RetainExpansion) {
5174 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5175
5177 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5178 return true;
5179
5180 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5181 Info.OrigNumExpansions);
5182 if (Out.getArgument().isNull())
5183 return true;
5184
5185 Outputs.addArgument(Out);
5186 }
5187
5188 continue;
5189 }
5190
5191 // The simple case:
5192 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5193 return true;
5194
5195 Outputs.addArgument(Out);
5196 }
5197
5198 return false;
5199}
5200
5201template <typename Derived>
5202template <typename InputIterator>
5204 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5205 bool Uneval) {
5206
5207 // [C++26][temp.constr.normal]
5208 // any non-dependent concept template argument
5209 // is substituted into the constraint-expression of C.
5210 auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) {
5211 return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter();
5212 };
5213
5214 for (; First != Last; ++First) {
5217
5218 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5219 typedef TemplateArgumentLocInventIterator<Derived,
5221 PackLocIterator;
5223 PackLocIterator(*this, In.getArgument().pack_begin()),
5224 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5225 Uneval))
5226 return true;
5227 continue;
5228 }
5229
5230 if (!isNonDependentConceptArgument(In.getArgument())) {
5231 Outputs.addArgument(In);
5232 continue;
5233 }
5234
5235 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5236 return true;
5237
5238 Outputs.addArgument(Out);
5239 }
5240
5241 return false;
5242}
5243
5244// FIXME: Find ways to reduce code duplication for pack expansions.
5245template <typename Derived>
5247 bool Uneval,
5249 UnexpandedInfo &Info) {
5250 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5251 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5252 TemplateArgumentLoc &Pattern) {
5253 assert(Arg.getArgument().isPackExpansion());
5254 // We have a pack expansion, for which we will be substituting into the
5255 // pattern.
5256 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5257 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5259 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5260 if (IsLateExpansionAttempt) {
5261 // Request expansion only when there is an opportunity to expand a pack
5262 // that required a substituion first.
5263 bool SawPackTypes =
5264 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5265 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5266 });
5267 if (!SawPackTypes) {
5268 Info.Expand = false;
5269 return false;
5270 }
5271 }
5272 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5273
5274 // Determine whether the set of unexpanded parameter packs can and
5275 // should be expanded.
5276 Info.Expand = true;
5277 Info.RetainExpansion = false;
5278 Info.NumExpansions = Info.OrigNumExpansions;
5279 return getDerived().TryExpandParameterPacks(
5280 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5281 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5282 Info.RetainExpansion, Info.NumExpansions);
5283 };
5284
5285 TemplateArgumentLoc Pattern;
5286 if (ComputeInfo(In, false, Info, Pattern))
5287 return true;
5288
5289 if (Info.Expand) {
5290 Out = Pattern;
5291 return false;
5292 }
5293
5294 // The transform has determined that we should perform a simple
5295 // transformation on the pack expansion, producing another pack
5296 // expansion.
5297 TemplateArgumentLoc OutPattern;
5298 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5299 std::in_place, getSema(), std::nullopt);
5300 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5301 return true;
5302
5303 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5304 Info.NumExpansions);
5305 if (Out.getArgument().isNull())
5306 return true;
5307 SubstIndex.reset();
5308
5309 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5310 return false;
5311
5312 // Some packs will learn their length after substitution, e.g.
5313 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5314 // value of `T`.
5315 //
5316 // We only expand after we know sizes of all packs, check if this is the case
5317 // or not. However, we avoid a full template substitution and only do
5318 // expanstions after this point.
5319
5320 // E.g. when substituting template arguments of tuple with {T -> int} in the
5321 // following example:
5322 // template <class T>
5323 // struct TupleWithInt {
5324 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5325 // };
5326 // TupleWithInt<int>::type y;
5327 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5328 // lenght and run `ComputeInfo()` to provide the necessary information to our
5329 // caller.
5330 //
5331 // Note that we may still have situations where builtin is not going to be
5332 // expanded. For example:
5333 // template <class T>
5334 // struct Foo {
5335 // template <class U> using tuple_with_t =
5336 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5337 // tuple_with_t<short>;
5338 // }
5339 // Because the substitution into `type` happens in dependent context, `type`
5340 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5341 // and the caller will not be able to expand it.
5342 ForgetSubstitutionRAII ForgetSubst(getDerived());
5343 if (ComputeInfo(Out, true, Info, OutPattern))
5344 return true;
5345 if (!Info.Expand)
5346 return false;
5347 Out = OutPattern;
5348 Info.ExpandUnderForgetSubstitions = true;
5349 return false;
5350}
5351
5352//===----------------------------------------------------------------------===//
5353// Type transformation
5354//===----------------------------------------------------------------------===//
5355
5356template<typename Derived>
5359 return T;
5360
5361 // Temporary workaround. All of these transformations should
5362 // eventually turn into transformations on TypeLocs.
5363 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5365
5366 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5367
5368 if (!NewDI)
5369 return QualType();
5370
5371 return NewDI->getType();
5372}
5373
5374template<typename Derived>
5376 // Refine the base location to the type's location.
5377 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5380 return DI;
5381
5382 TypeLocBuilder TLB;
5383
5384 TypeLoc TL = DI->getTypeLoc();
5385 TLB.reserve(TL.getFullDataSize());
5386
5387 QualType Result = getDerived().TransformType(TLB, TL);
5388 if (Result.isNull())
5389 return nullptr;
5390
5391 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5392}
5393
5394template<typename Derived>
5397 switch (T.getTypeLocClass()) {
5398#define ABSTRACT_TYPELOC(CLASS, PARENT)
5399#define TYPELOC(CLASS, PARENT) \
5400 case TypeLoc::CLASS: \
5401 return getDerived().Transform##CLASS##Type(TLB, \
5402 T.castAs<CLASS##TypeLoc>());
5403#include "clang/AST/TypeLocNodes.def"
5404 }
5405
5406 llvm_unreachable("unhandled type loc!");
5407}
5408
5409template<typename Derived>
5412 return TransformType(T);
5413
5415 return T;
5416 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5418 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5419 return NewDI ? NewDI->getType() : QualType();
5420}
5421
5422template<typename Derived>
5425 if (!isa<DependentNameType>(DI->getType()))
5426 return TransformType(DI);
5427
5428 // Refine the base location to the type's location.
5429 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5432 return DI;
5433
5434 TypeLocBuilder TLB;
5435
5436 TypeLoc TL = DI->getTypeLoc();
5437 TLB.reserve(TL.getFullDataSize());
5438
5439 auto QTL = TL.getAs<QualifiedTypeLoc>();
5440 if (QTL)
5441 TL = QTL.getUnqualifiedLoc();
5442
5443 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5444
5445 QualType Result = getDerived().TransformDependentNameType(
5446 TLB, DNTL, /*DeducedTSTContext*/true);
5447 if (Result.isNull())
5448 return nullptr;
5449
5450 if (QTL) {
5451 Result = getDerived().RebuildQualifiedType(Result, QTL);
5452 if (Result.isNull())
5453 return nullptr;
5455 }
5456
5457 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5458}
5459
5460template<typename Derived>
5465 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5466 auto SuppressObjCLifetime =
5467 T.getType().getLocalQualifiers().hasObjCLifetime();
5468 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5469 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5470 SuppressObjCLifetime);
5471 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5472 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5473 TLB, STTP, SuppressObjCLifetime);
5474 } else {
5475 Result = getDerived().TransformType(TLB, UnqualTL);
5476 }
5477
5478 if (Result.isNull())
5479 return QualType();
5480
5481 Result = getDerived().RebuildQualifiedType(Result, T);
5482
5483 if (Result.isNull())
5484 return QualType();
5485
5486 // RebuildQualifiedType might have updated the type, but not in a way
5487 // that invalidates the TypeLoc. (There's no location information for
5488 // qualifiers.)
5490
5491 return Result;
5492}
5493
5494template <typename Derived>
5496 QualifiedTypeLoc TL) {
5497
5498 SourceLocation Loc = TL.getBeginLoc();
5499 Qualifiers Quals = TL.getType().getLocalQualifiers();
5500
5501 if ((T.getAddressSpace() != LangAS::Default &&
5502 Quals.getAddressSpace() != LangAS::Default) &&
5503 T.getAddressSpace() != Quals.getAddressSpace()) {
5504 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5505 << TL.getType() << T;
5506 return QualType();
5507 }
5508
5509 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5510 if (LocalPointerAuth.isPresent()) {
5511 if (T.getPointerAuth().isPresent()) {
5512 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5513 return QualType();
5514 }
5515 if (!T->isDependentType()) {
5516 if (!T->isSignableType(SemaRef.getASTContext())) {
5517 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5518 return QualType();
5519 }
5520 }
5521 }
5522 // C++ [dcl.fct]p7:
5523 // [When] adding cv-qualifications on top of the function type [...] the
5524 // cv-qualifiers are ignored.
5525 if (T->isFunctionType()) {
5526 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5527 Quals.getAddressSpace());
5528 return T;
5529 }
5530
5531 // C++ [dcl.ref]p1:
5532 // when the cv-qualifiers are introduced through the use of a typedef-name
5533 // or decltype-specifier [...] the cv-qualifiers are ignored.
5534 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5535 // applied to a reference type.
5536 if (T->isReferenceType()) {
5537 // The only qualifier that applies to a reference type is restrict.
5538 if (!Quals.hasRestrict())
5539 return T;
5541 }
5542
5543 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5544 // resulting type.
5545 if (Quals.hasObjCLifetime()) {
5546 if (!T->isObjCLifetimeType() && !T->isDependentType())
5547 Quals.removeObjCLifetime();
5548 else if (T.getObjCLifetime()) {
5549 // Objective-C ARC:
5550 // A lifetime qualifier applied to a substituted template parameter
5551 // overrides the lifetime qualifier from the template argument.
5552 const AutoType *AutoTy;
5553 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5554 // 'auto' types behave the same way as template parameters.
5555 QualType Deduced = AutoTy->getDeducedType();
5556 Qualifiers Qs = Deduced.getQualifiers();
5557 Qs.removeObjCLifetime();
5558 Deduced =
5559 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5560 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5561 AutoTy->isDependentType(),
5562 /*isPack=*/false,
5563 AutoTy->getTypeConstraintConcept(),
5564 AutoTy->getTypeConstraintArguments());
5565 } else {
5566 // Otherwise, complain about the addition of a qualifier to an
5567 // already-qualified type.
5568 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5569 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5570 Quals.removeObjCLifetime();
5571 }
5572 }
5573 }
5574
5575 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5576}
5577
5578template <typename Derived>
5579QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5580 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5581 NamedDecl *FirstQualifierInScope) {
5582 assert(!getDerived().AlreadyTransformed(TL.getType()));
5583
5584 switch (TL.getTypeLocClass()) {
5585 case TypeLoc::TemplateSpecialization:
5586 return getDerived().TransformTemplateSpecializationType(
5587 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5588 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5589 case TypeLoc::DependentName:
5590 return getDerived().TransformDependentNameType(
5591 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5592 ObjectType, FirstQualifierInScope);
5593 default:
5594 // Any dependent canonical type can appear here, through type alias
5595 // templates.
5596 return getDerived().TransformType(TLB, TL);
5597 }
5598}
5599
5600template <class TyLoc> static inline
5602 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5603 NewT.setNameLoc(T.getNameLoc());
5604 return T.getType();
5605}
5606
5607template<typename Derived>
5608QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5609 BuiltinTypeLoc T) {
5610 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5611 NewT.setBuiltinLoc(T.getBuiltinLoc());
5612 if (T.needsExtraLocalData())
5613 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5614 return T.getType();
5615}
5616
5617template<typename Derived>
5619 ComplexTypeLoc T) {
5620 // FIXME: recurse?
5621 return TransformTypeSpecType(TLB, T);
5622}
5623
5624template <typename Derived>
5626 AdjustedTypeLoc TL) {
5627 // Adjustments applied during transformation are handled elsewhere.
5628 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5629}
5630
5631template<typename Derived>
5633 DecayedTypeLoc TL) {
5634 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5635 if (OriginalType.isNull())
5636 return QualType();
5637
5638 QualType Result = TL.getType();
5639 if (getDerived().AlwaysRebuild() ||
5640 OriginalType != TL.getOriginalLoc().getType())
5641 Result = SemaRef.Context.getDecayedType(OriginalType);
5642 TLB.push<DecayedTypeLoc>(Result);
5643 // Nothing to set for DecayedTypeLoc.
5644 return Result;
5645}
5646
5647template <typename Derived>
5651 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5652 if (OriginalType.isNull())
5653 return QualType();
5654
5655 QualType Result = TL.getType();
5656 if (getDerived().AlwaysRebuild() ||
5657 OriginalType != TL.getElementLoc().getType())
5658 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5659 TLB.push<ArrayParameterTypeLoc>(Result);
5660 // Nothing to set for ArrayParameterTypeLoc.
5661 return Result;
5662}
5663
5664template<typename Derived>
5666 PointerTypeLoc TL) {
5667 QualType PointeeType
5668 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5669 if (PointeeType.isNull())
5670 return QualType();
5671
5672 QualType Result = TL.getType();
5673 if (PointeeType->getAs<ObjCObjectType>()) {
5674 // A dependent pointer type 'T *' has is being transformed such
5675 // that an Objective-C class type is being replaced for 'T'. The
5676 // resulting pointer type is an ObjCObjectPointerType, not a
5677 // PointerType.
5678 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5679
5681 NewT.setStarLoc(TL.getStarLoc());
5682 return Result;
5683 }
5684
5685 if (getDerived().AlwaysRebuild() ||
5686 PointeeType != TL.getPointeeLoc().getType()) {
5687 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5688 if (Result.isNull())
5689 return QualType();
5690 }
5691
5692 // Objective-C ARC can add lifetime qualifiers to the type that we're
5693 // pointing to.
5694 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5695
5696 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5697 NewT.setSigilLoc(TL.getSigilLoc());
5698 return Result;
5699}
5700
5701template<typename Derived>
5705 QualType PointeeType
5706 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5707 if (PointeeType.isNull())
5708 return QualType();
5709
5710 QualType Result = TL.getType();
5711 if (getDerived().AlwaysRebuild() ||
5712 PointeeType != TL.getPointeeLoc().getType()) {
5713 Result = getDerived().RebuildBlockPointerType(PointeeType,
5714 TL.getSigilLoc());
5715 if (Result.isNull())
5716 return QualType();
5717 }
5718
5720 NewT.setSigilLoc(TL.getSigilLoc());
5721 return Result;
5722}
5723
5724/// Transforms a reference type. Note that somewhat paradoxically we
5725/// don't care whether the type itself is an l-value type or an r-value
5726/// type; we only care if the type was *written* as an l-value type
5727/// or an r-value type.
5728template<typename Derived>
5731 ReferenceTypeLoc TL) {
5732 const ReferenceType *T = TL.getTypePtr();
5733
5734 // Note that this works with the pointee-as-written.
5735 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5736 if (PointeeType.isNull())
5737 return QualType();
5738
5739 QualType Result = TL.getType();
5740 if (getDerived().AlwaysRebuild() ||
5741 PointeeType != T->getPointeeTypeAsWritten()) {
5742 Result = getDerived().RebuildReferenceType(PointeeType,
5743 T->isSpelledAsLValue(),
5744 TL.getSigilLoc());
5745 if (Result.isNull())
5746 return QualType();
5747 }
5748
5749 // Objective-C ARC can add lifetime qualifiers to the type that we're
5750 // referring to.
5753
5754 // r-value references can be rebuilt as l-value references.
5755 ReferenceTypeLoc NewTL;
5757 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5758 else
5759 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5760 NewTL.setSigilLoc(TL.getSigilLoc());
5761
5762 return Result;
5763}
5764
5765template<typename Derived>
5769 return TransformReferenceType(TLB, TL);
5770}
5771
5772template<typename Derived>
5773QualType
5774TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5775 RValueReferenceTypeLoc TL) {
5776 return TransformReferenceType(TLB, TL);
5777}
5778
5779template<typename Derived>
5783 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5784 if (PointeeType.isNull())
5785 return QualType();
5786
5787 const MemberPointerType *T = TL.getTypePtr();
5788
5789 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5790 NestedNameSpecifierLoc NewQualifierLoc =
5791 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5792 if (!NewQualifierLoc)
5793 return QualType();
5794
5795 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5796 if (OldCls) {
5797 NewCls = cast_or_null<CXXRecordDecl>(
5798 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5799 if (!NewCls)
5800 return QualType();
5801 }
5802
5803 QualType Result = TL.getType();
5804 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5805 NewQualifierLoc.getNestedNameSpecifier() !=
5806 OldQualifierLoc.getNestedNameSpecifier() ||
5807 NewCls != OldCls) {
5808 CXXScopeSpec SS;
5809 SS.Adopt(NewQualifierLoc);
5810 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5811 TL.getStarLoc());
5812 if (Result.isNull())
5813 return QualType();
5814 }
5815
5816 // If we had to adjust the pointee type when building a member pointer, make
5817 // sure to push TypeLoc info for it.
5818 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5819 if (MPT && PointeeType != MPT->getPointeeType()) {
5820 assert(isa<AdjustedType>(MPT->getPointeeType()));
5821 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5822 }
5823
5825 NewTL.setSigilLoc(TL.getSigilLoc());
5826 NewTL.setQualifierLoc(NewQualifierLoc);
5827
5828 return Result;
5829}
5830
5831template<typename Derived>
5835 const ConstantArrayType *T = TL.getTypePtr();
5836 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5837 if (ElementType.isNull())
5838 return QualType();
5839
5840 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5841 Expr *OldSize = TL.getSizeExpr();
5842 if (!OldSize)
5843 OldSize = const_cast<Expr*>(T->getSizeExpr());
5844 Expr *NewSize = nullptr;
5845 if (OldSize) {
5848 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5849 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5850 }
5851
5852 QualType Result = TL.getType();
5853 if (getDerived().AlwaysRebuild() ||
5854 ElementType != T->getElementType() ||
5855 (T->getSizeExpr() && NewSize != OldSize)) {
5856 Result = getDerived().RebuildConstantArrayType(ElementType,
5857 T->getSizeModifier(),
5858 T->getSize(), NewSize,
5859 T->getIndexTypeCVRQualifiers(),
5860 TL.getBracketsRange());
5861 if (Result.isNull())
5862 return QualType();
5863 }
5864
5865 // We might have either a ConstantArrayType or a VariableArrayType now:
5866 // a ConstantArrayType is allowed to have an element type which is a
5867 // VariableArrayType if the type is dependent. Fortunately, all array
5868 // types have the same location layout.
5869 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5870 NewTL.setLBracketLoc(TL.getLBracketLoc());
5871 NewTL.setRBracketLoc(TL.getRBracketLoc());
5872 NewTL.setSizeExpr(NewSize);
5873
5874 return Result;
5875}
5876
5877template<typename Derived>
5879 TypeLocBuilder &TLB,
5881 const IncompleteArrayType *T = TL.getTypePtr();
5882 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5883 if (ElementType.isNull())
5884 return QualType();
5885
5886 QualType Result = TL.getType();
5887 if (getDerived().AlwaysRebuild() ||
5888 ElementType != T->getElementType()) {
5889 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5890 T->getSizeModifier(),
5891 T->getIndexTypeCVRQualifiers(),
5892 TL.getBracketsRange());
5893 if (Result.isNull())
5894 return QualType();
5895 }
5896
5898 NewTL.setLBracketLoc(TL.getLBracketLoc());
5899 NewTL.setRBracketLoc(TL.getRBracketLoc());
5900 NewTL.setSizeExpr(nullptr);
5901
5902 return Result;
5903}
5904
5905template<typename Derived>
5909 const VariableArrayType *T = TL.getTypePtr();
5910 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5911 if (ElementType.isNull())
5912 return QualType();
5913
5914 ExprResult SizeResult;
5915 {
5918 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5919 }
5920 if (SizeResult.isInvalid())
5921 return QualType();
5922 SizeResult =
5923 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5924 if (SizeResult.isInvalid())
5925 return QualType();
5926
5927 Expr *Size = SizeResult.get();
5928
5929 QualType Result = TL.getType();
5930 if (getDerived().AlwaysRebuild() ||
5931 ElementType != T->getElementType() ||
5932 Size != T->getSizeExpr()) {
5933 Result = getDerived().RebuildVariableArrayType(ElementType,
5934 T->getSizeModifier(),
5935 Size,
5936 T->getIndexTypeCVRQualifiers(),
5937 TL.getBracketsRange());
5938 if (Result.isNull())
5939 return QualType();
5940 }
5941
5942 // We might have constant size array now, but fortunately it has the same
5943 // location layout.
5944 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5945 NewTL.setLBracketLoc(TL.getLBracketLoc());
5946 NewTL.setRBracketLoc(TL.getRBracketLoc());
5947 NewTL.setSizeExpr(Size);
5948
5949 return Result;
5950}
5951
5952template<typename Derived>
5956 const DependentSizedArrayType *T = TL.getTypePtr();
5957 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5958 if (ElementType.isNull())
5959 return QualType();
5960
5961 // Array bounds are constant expressions.
5964
5965 // If we have a VLA then it won't be a constant.
5966 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5967
5968 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5969 Expr *origSize = TL.getSizeExpr();
5970 if (!origSize) origSize = T->getSizeExpr();
5971
5972 ExprResult sizeResult
5973 = getDerived().TransformExpr(origSize);
5974 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5975 if (sizeResult.isInvalid())
5976 return QualType();
5977
5978 Expr *size = sizeResult.get();
5979
5980 QualType Result = TL.getType();
5981 if (getDerived().AlwaysRebuild() ||
5982 ElementType != T->getElementType() ||
5983 size != origSize) {
5984 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5985 T->getSizeModifier(),
5986 size,
5987 T->getIndexTypeCVRQualifiers(),
5988 TL.getBracketsRange());
5989 if (Result.isNull())
5990 return QualType();
5991 }
5992
5993 // We might have any sort of array type now, but fortunately they
5994 // all have the same location layout.
5995 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5996 NewTL.setLBracketLoc(TL.getLBracketLoc());
5997 NewTL.setRBracketLoc(TL.getRBracketLoc());
5998 NewTL.setSizeExpr(size);
5999
6000 return Result;
6001}
6002
6003template <typename Derived>
6006 const DependentVectorType *T = TL.getTypePtr();
6007 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6008 if (ElementType.isNull())
6009 return QualType();
6010
6013
6014 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6015 Size = SemaRef.ActOnConstantExpression(Size);
6016 if (Size.isInvalid())
6017 return QualType();
6018
6019 QualType Result = TL.getType();
6020 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6021 Size.get() != T->getSizeExpr()) {
6022 Result = getDerived().RebuildDependentVectorType(
6023 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
6024 if (Result.isNull())
6025 return QualType();
6026 }
6027
6028 // Result might be dependent or not.
6031 TLB.push<DependentVectorTypeLoc>(Result);
6032 NewTL.setNameLoc(TL.getNameLoc());
6033 } else {
6034 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6035 NewTL.setNameLoc(TL.getNameLoc());
6036 }
6037
6038 return Result;
6039}
6040
6041template<typename Derived>
6043 TypeLocBuilder &TLB,
6045 const DependentSizedExtVectorType *T = TL.getTypePtr();
6046
6047 // FIXME: ext vector locs should be nested
6048 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6049 if (ElementType.isNull())
6050 return QualType();
6051
6052 // Vector sizes are constant expressions.
6055
6056 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6057 Size = SemaRef.ActOnConstantExpression(Size);
6058 if (Size.isInvalid())
6059 return QualType();
6060
6061 QualType Result = TL.getType();
6062 if (getDerived().AlwaysRebuild() ||
6063 ElementType != T->getElementType() ||
6064 Size.get() != T->getSizeExpr()) {
6065 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6066 Size.get(),
6067 T->getAttributeLoc());
6068 if (Result.isNull())
6069 return QualType();
6070 }
6071
6072 // Result might be dependent or not.
6076 NewTL.setNameLoc(TL.getNameLoc());
6077 } else {
6078 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6079 NewTL.setNameLoc(TL.getNameLoc());
6080 }
6081
6082 return Result;
6083}
6084
6085template <typename Derived>
6089 const ConstantMatrixType *T = TL.getTypePtr();
6090 QualType ElementType = getDerived().TransformType(T->getElementType());
6091 if (ElementType.isNull())
6092 return QualType();
6093
6094 QualType Result = TL.getType();
6095 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6096 Result = getDerived().RebuildConstantMatrixType(
6097 ElementType, T->getNumRows(), T->getNumColumns());
6098 if (Result.isNull())
6099 return QualType();
6100 }
6101
6103 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6104 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6105 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6106 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6107
6108 return Result;
6109}
6110
6111template <typename Derived>
6114 const DependentSizedMatrixType *T = TL.getTypePtr();
6115
6116 QualType ElementType = getDerived().TransformType(T->getElementType());
6117 if (ElementType.isNull()) {
6118 return QualType();
6119 }
6120
6121 // Matrix dimensions are constant expressions.
6124
6125 Expr *origRows = TL.getAttrRowOperand();
6126 if (!origRows)
6127 origRows = T->getRowExpr();
6128 Expr *origColumns = TL.getAttrColumnOperand();
6129 if (!origColumns)
6130 origColumns = T->getColumnExpr();
6131
6132 ExprResult rowResult = getDerived().TransformExpr(origRows);
6133 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6134 if (rowResult.isInvalid())
6135 return QualType();
6136
6137 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6138 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6139 if (columnResult.isInvalid())
6140 return QualType();
6141
6142 Expr *rows = rowResult.get();
6143 Expr *columns = columnResult.get();
6144
6145 QualType Result = TL.getType();
6146 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6147 rows != origRows || columns != origColumns) {
6148 Result = getDerived().RebuildDependentSizedMatrixType(
6149 ElementType, rows, columns, T->getAttributeLoc());
6150
6151 if (Result.isNull())
6152 return QualType();
6153 }
6154
6155 // We might have any sort of matrix type now, but fortunately they
6156 // all have the same location layout.
6157 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6158 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6159 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6160 NewTL.setAttrRowOperand(rows);
6161 NewTL.setAttrColumnOperand(columns);
6162 return Result;
6163}
6164
6165template <typename Derived>
6168 const DependentAddressSpaceType *T = TL.getTypePtr();
6169
6170 QualType pointeeType =
6171 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6172
6173 if (pointeeType.isNull())
6174 return QualType();
6175
6176 // Address spaces are constant expressions.
6179
6180 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6181 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6182 if (AddrSpace.isInvalid())
6183 return QualType();
6184
6185 QualType Result = TL.getType();
6186 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6187 AddrSpace.get() != T->getAddrSpaceExpr()) {
6188 Result = getDerived().RebuildDependentAddressSpaceType(
6189 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6190 if (Result.isNull())
6191 return QualType();
6192 }
6193
6194 // Result might be dependent or not.
6198
6199 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6200 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6201 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6202
6203 } else {
6204 TLB.TypeWasModifiedSafely(Result);
6205 }
6206
6207 return Result;
6208}
6209
6210template <typename Derived>
6212 VectorTypeLoc TL) {
6213 const VectorType *T = TL.getTypePtr();
6214 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6215 if (ElementType.isNull())
6216 return QualType();
6217
6218 QualType Result = TL.getType();
6219 if (getDerived().AlwaysRebuild() ||
6220 ElementType != T->getElementType()) {
6221 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6222 T->getVectorKind());
6223 if (Result.isNull())
6224 return QualType();
6225 }
6226
6227 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6228 NewTL.setNameLoc(TL.getNameLoc());
6229
6230 return Result;
6231}
6232
6233template<typename Derived>
6235 ExtVectorTypeLoc TL) {
6236 const VectorType *T = TL.getTypePtr();
6237 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6238 if (ElementType.isNull())
6239 return QualType();
6240
6241 QualType Result = TL.getType();
6242 if (getDerived().AlwaysRebuild() ||
6243 ElementType != T->getElementType()) {
6244 Result = getDerived().RebuildExtVectorType(ElementType,
6245 T->getNumElements(),
6246 /*FIXME*/ SourceLocation());
6247 if (Result.isNull())
6248 return QualType();
6249 }
6250
6251 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6252 NewTL.setNameLoc(TL.getNameLoc());
6253
6254 return Result;
6255}
6256
6257template <typename Derived>
6259 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6260 bool ExpectParameterPack) {
6261 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6262 TypeSourceInfo *NewDI = nullptr;
6263
6264 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6265 // If we're substituting into a pack expansion type and we know the
6266 // length we want to expand to, just substitute for the pattern.
6267 TypeLoc OldTL = OldDI->getTypeLoc();
6268 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6269
6270 TypeLocBuilder TLB;
6271 TypeLoc NewTL = OldDI->getTypeLoc();
6272 TLB.reserve(NewTL.getFullDataSize());
6273
6274 QualType Result = getDerived().TransformType(TLB,
6275 OldExpansionTL.getPatternLoc());
6276 if (Result.isNull())
6277 return nullptr;
6278
6280 OldExpansionTL.getPatternLoc().getSourceRange(),
6281 OldExpansionTL.getEllipsisLoc(),
6282 NumExpansions);
6283 if (Result.isNull())
6284 return nullptr;
6285
6286 PackExpansionTypeLoc NewExpansionTL
6287 = TLB.push<PackExpansionTypeLoc>(Result);
6288 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6289 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6290 } else
6291 NewDI = getDerived().TransformType(OldDI);
6292 if (!NewDI)
6293 return nullptr;
6294
6295 if (NewDI == OldDI && indexAdjustment == 0)
6296 return OldParm;
6297
6298 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6299 OldParm->getDeclContext(),
6300 OldParm->getInnerLocStart(),
6301 OldParm->getLocation(),
6302 OldParm->getIdentifier(),
6303 NewDI->getType(),
6304 NewDI,
6305 OldParm->getStorageClass(),
6306 /* DefArg */ nullptr);
6307 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6308 OldParm->getFunctionScopeIndex() + indexAdjustment);
6309 getDerived().transformedLocalDecl(OldParm, {newParm});
6310 return newParm;
6311}
6312
6313template <typename Derived>
6316 const QualType *ParamTypes,
6317 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6318 SmallVectorImpl<QualType> &OutParamTypes,
6321 unsigned *LastParamTransformed) {
6322 int indexAdjustment = 0;
6323
6324 unsigned NumParams = Params.size();
6325 for (unsigned i = 0; i != NumParams; ++i) {
6326 if (LastParamTransformed)
6327 *LastParamTransformed = i;
6328 if (ParmVarDecl *OldParm = Params[i]) {
6329 assert(OldParm->getFunctionScopeIndex() == i);
6330
6331 UnsignedOrNone NumExpansions = std::nullopt;
6332 ParmVarDecl *NewParm = nullptr;
6333 if (OldParm->isParameterPack()) {
6334 // We have a function parameter pack that may need to be expanded.
6336
6337 // Find the parameter packs that could be expanded.
6338 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6340 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6341 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6342
6343 // Determine whether we should expand the parameter packs.
6344 bool ShouldExpand = false;
6345 bool RetainExpansion = false;
6346 UnsignedOrNone OrigNumExpansions = std::nullopt;
6347 if (Unexpanded.size() > 0) {
6348 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6349 NumExpansions = OrigNumExpansions;
6351 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6352 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6353 ShouldExpand, RetainExpansion, NumExpansions)) {
6354 return true;
6355 }
6356 } else {
6357#ifndef NDEBUG
6358 const AutoType *AT =
6359 Pattern.getType().getTypePtr()->getContainedAutoType();
6360 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6361 "Could not find parameter packs or undeduced auto type!");
6362#endif
6363 }
6364
6365 if (ShouldExpand) {
6366 // Expand the function parameter pack into multiple, separate
6367 // parameters.
6368 getDerived().ExpandingFunctionParameterPack(OldParm);
6369 for (unsigned I = 0; I != *NumExpansions; ++I) {
6370 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6371 ParmVarDecl *NewParm
6372 = getDerived().TransformFunctionTypeParam(OldParm,
6373 indexAdjustment++,
6374 OrigNumExpansions,
6375 /*ExpectParameterPack=*/false);
6376 if (!NewParm)
6377 return true;
6378
6379 if (ParamInfos)
6380 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6381 OutParamTypes.push_back(NewParm->getType());
6382 if (PVars)
6383 PVars->push_back(NewParm);
6384 }
6385
6386 // If we're supposed to retain a pack expansion, do so by temporarily
6387 // forgetting the partially-substituted parameter pack.
6388 if (RetainExpansion) {
6389 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6390 ParmVarDecl *NewParm
6391 = getDerived().TransformFunctionTypeParam(OldParm,
6392 indexAdjustment++,
6393 OrigNumExpansions,
6394 /*ExpectParameterPack=*/false);
6395 if (!NewParm)
6396 return true;
6397
6398 if (ParamInfos)
6399 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6400 OutParamTypes.push_back(NewParm->getType());
6401 if (PVars)
6402 PVars->push_back(NewParm);
6403 }
6404
6405 // The next parameter should have the same adjustment as the
6406 // last thing we pushed, but we post-incremented indexAdjustment
6407 // on every push. Also, if we push nothing, the adjustment should
6408 // go down by one.
6409 indexAdjustment--;
6410
6411 // We're done with the pack expansion.
6412 continue;
6413 }
6414
6415 // We'll substitute the parameter now without expanding the pack
6416 // expansion.
6417 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6418 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6419 indexAdjustment,
6420 NumExpansions,
6421 /*ExpectParameterPack=*/true);
6422 assert(NewParm->isParameterPack() &&
6423 "Parameter pack no longer a parameter pack after "
6424 "transformation.");
6425 } else {
6426 NewParm = getDerived().TransformFunctionTypeParam(
6427 OldParm, indexAdjustment, std::nullopt,
6428 /*ExpectParameterPack=*/false);
6429 }
6430
6431 if (!NewParm)
6432 return true;
6433
6434 if (ParamInfos)
6435 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6436 OutParamTypes.push_back(NewParm->getType());
6437 if (PVars)
6438 PVars->push_back(NewParm);
6439 continue;
6440 }
6441
6442 // Deal with the possibility that we don't have a parameter
6443 // declaration for this parameter.
6444 assert(ParamTypes);
6445 QualType OldType = ParamTypes[i];
6446 bool IsPackExpansion = false;
6447 UnsignedOrNone NumExpansions = std::nullopt;
6448 QualType NewType;
6449 if (const PackExpansionType *Expansion
6450 = dyn_cast<PackExpansionType>(OldType)) {
6451 // We have a function parameter pack that may need to be expanded.
6452 QualType Pattern = Expansion->getPattern();
6454 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6455
6456 // Determine whether we should expand the parameter packs.
6457 bool ShouldExpand = false;
6458 bool RetainExpansion = false;
6460 Loc, SourceRange(), Unexpanded,
6461 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6462 RetainExpansion, NumExpansions)) {
6463 return true;
6464 }
6465
6466 if (ShouldExpand) {
6467 // Expand the function parameter pack into multiple, separate
6468 // parameters.
6469 for (unsigned I = 0; I != *NumExpansions; ++I) {
6470 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6471 QualType NewType = getDerived().TransformType(Pattern);
6472 if (NewType.isNull())
6473 return true;
6474
6475 if (NewType->containsUnexpandedParameterPack()) {
6476 NewType = getSema().getASTContext().getPackExpansionType(
6477 NewType, std::nullopt);
6478
6479 if (NewType.isNull())
6480 return true;
6481 }
6482
6483 if (ParamInfos)
6484 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6485 OutParamTypes.push_back(NewType);
6486 if (PVars)
6487 PVars->push_back(nullptr);
6488 }
6489
6490 // We're done with the pack expansion.
6491 continue;
6492 }
6493
6494 // If we're supposed to retain a pack expansion, do so by temporarily
6495 // forgetting the partially-substituted parameter pack.
6496 if (RetainExpansion) {
6497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6498 QualType NewType = getDerived().TransformType(Pattern);
6499 if (NewType.isNull())
6500 return true;
6501
6502 if (ParamInfos)
6503 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6504 OutParamTypes.push_back(NewType);
6505 if (PVars)
6506 PVars->push_back(nullptr);
6507 }
6508
6509 // We'll substitute the parameter now without expanding the pack
6510 // expansion.
6511 OldType = Expansion->getPattern();
6512 IsPackExpansion = true;
6513 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6514 NewType = getDerived().TransformType(OldType);
6515 } else {
6516 NewType = getDerived().TransformType(OldType);
6517 }
6518
6519 if (NewType.isNull())
6520 return true;
6521
6522 if (IsPackExpansion)
6523 NewType = getSema().Context.getPackExpansionType(NewType,
6524 NumExpansions);
6525
6526 if (ParamInfos)
6527 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6528 OutParamTypes.push_back(NewType);
6529 if (PVars)
6530 PVars->push_back(nullptr);
6531 }
6532
6533#ifndef NDEBUG
6534 if (PVars) {
6535 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6536 if (ParmVarDecl *parm = (*PVars)[i])
6537 assert(parm->getFunctionScopeIndex() == i);
6538 }
6539#endif
6540
6541 return false;
6542}
6543
6544template<typename Derived>
6548 SmallVector<QualType, 4> ExceptionStorage;
6549 return getDerived().TransformFunctionProtoType(
6550 TLB, TL, nullptr, Qualifiers(),
6551 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6552 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6553 ExceptionStorage, Changed);
6554 });
6555}
6556
6557template<typename Derived> template<typename Fn>
6559 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6560 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6561
6562 // Transform the parameters and return type.
6563 //
6564 // We are required to instantiate the params and return type in source order.
6565 // When the function has a trailing return type, we instantiate the
6566 // parameters before the return type, since the return type can then refer
6567 // to the parameters themselves (via decltype, sizeof, etc.).
6568 //
6569 SmallVector<QualType, 4> ParamTypes;
6571 Sema::ExtParameterInfoBuilder ExtParamInfos;
6572 const FunctionProtoType *T = TL.getTypePtr();
6573
6574 QualType ResultType;
6575
6576 if (T->hasTrailingReturn()) {
6578 TL.getBeginLoc(), TL.getParams(),
6580 T->getExtParameterInfosOrNull(),
6581 ParamTypes, &ParamDecls, ExtParamInfos))
6582 return QualType();
6583
6584 {
6585 // C++11 [expr.prim.general]p3:
6586 // If a declaration declares a member function or member function
6587 // template of a class X, the expression this is a prvalue of type
6588 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6589 // and the end of the function-definition, member-declarator, or
6590 // declarator.
6591 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6592 Sema::CXXThisScopeRAII ThisScope(
6593 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6594
6595 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6596 if (ResultType.isNull())
6597 return QualType();
6598 }
6599 }
6600 else {
6601 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6602 if (ResultType.isNull())
6603 return QualType();
6604
6606 TL.getBeginLoc(), TL.getParams(),
6608 T->getExtParameterInfosOrNull(),
6609 ParamTypes, &ParamDecls, ExtParamInfos))
6610 return QualType();
6611 }
6612
6613 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6614
6615 bool EPIChanged = false;
6616 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6617 return QualType();
6618
6619 // Handle extended parameter information.
6620 if (auto NewExtParamInfos =
6621 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6622 if (!EPI.ExtParameterInfos ||
6624 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6625 EPIChanged = true;
6626 }
6627 EPI.ExtParameterInfos = NewExtParamInfos;
6628 } else if (EPI.ExtParameterInfos) {
6629 EPIChanged = true;
6630 EPI.ExtParameterInfos = nullptr;
6631 }
6632
6633 // Transform any function effects with unevaluated conditions.
6634 // Hold this set in a local for the rest of this function, since EPI
6635 // may need to hold a FunctionEffectsRef pointing into it.
6636 std::optional<FunctionEffectSet> NewFX;
6637 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6638 NewFX.emplace();
6641
6642 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6643 FunctionEffectWithCondition NewEC = PrevEC;
6644 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6645 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6646 if (NewExpr.isInvalid())
6647 return QualType();
6648 std::optional<FunctionEffectMode> Mode =
6649 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6650 if (!Mode)
6651 return QualType();
6652
6653 // The condition expression has been transformed, and re-evaluated.
6654 // It may or may not have become constant.
6655 switch (*Mode) {
6657 NewEC.Cond = {};
6658 break;
6660 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6661 NewEC.Cond = {};
6662 break;
6664 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6665 break;
6667 llvm_unreachable(
6668 "FunctionEffectMode::None shouldn't be possible here");
6669 }
6670 }
6671 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6672 TL.getBeginLoc())) {
6674 NewFX->insert(NewEC, Errs);
6675 assert(Errs.empty());
6676 }
6677 }
6678 EPI.FunctionEffects = *NewFX;
6679 EPIChanged = true;
6680 }
6681
6682 QualType Result = TL.getType();
6683 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6684 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6685 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6686 if (Result.isNull())
6687 return QualType();
6688 }
6689
6692 NewTL.setLParenLoc(TL.getLParenLoc());
6693 NewTL.setRParenLoc(TL.getRParenLoc());
6696 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6697 NewTL.setParam(i, ParamDecls[i]);
6698
6699 return Result;
6700}
6701
6702template<typename Derived>
6705 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6706 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6707
6708 // Instantiate a dynamic noexcept expression, if any.
6709 if (isComputedNoexcept(ESI.Type)) {
6710 // Update this scrope because ContextDecl in Sema will be used in
6711 // TransformExpr.
6712 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6713 Sema::CXXThisScopeRAII ThisScope(
6714 SemaRef, Method ? Method->getParent() : nullptr,
6715 Method ? Method->getMethodQualifiers() : Qualifiers{},
6716 Method != nullptr);
6719 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6720 if (NoexceptExpr.isInvalid())
6721 return true;
6722
6724 NoexceptExpr =
6725 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6726 if (NoexceptExpr.isInvalid())
6727 return true;
6728
6729 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6730 Changed = true;
6731 ESI.NoexceptExpr = NoexceptExpr.get();
6732 ESI.Type = EST;
6733 }
6734
6735 if (ESI.Type != EST_Dynamic)
6736 return false;
6737
6738 // Instantiate a dynamic exception specification's type.
6739 for (QualType T : ESI.Exceptions) {
6740 if (const PackExpansionType *PackExpansion =
6741 T->getAs<PackExpansionType>()) {
6742 Changed = true;
6743
6744 // We have a pack expansion. Instantiate it.
6746 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6747 Unexpanded);
6748 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6749
6750 // Determine whether the set of unexpanded parameter packs can and
6751 // should
6752 // be expanded.
6753 bool Expand = false;
6754 bool RetainExpansion = false;
6755 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6756 // FIXME: Track the location of the ellipsis (and track source location
6757 // information for the types in the exception specification in general).
6759 Loc, SourceRange(), Unexpanded,
6760 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6761 NumExpansions))
6762 return true;
6763
6764 if (!Expand) {
6765 // We can't expand this pack expansion into separate arguments yet;
6766 // just substitute into the pattern and create a new pack expansion
6767 // type.
6768 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6769 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6770 if (U.isNull())
6771 return true;
6772
6773 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6774 Exceptions.push_back(U);
6775 continue;
6776 }
6777
6778 // Substitute into the pack expansion pattern for each slice of the
6779 // pack.
6780 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6781 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6782
6783 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6784 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6785 return true;
6786
6787 Exceptions.push_back(U);
6788 }
6789 } else {
6790 QualType U = getDerived().TransformType(T);
6791 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6792 return true;
6793 if (T != U)
6794 Changed = true;
6795
6796 Exceptions.push_back(U);
6797 }
6798 }
6799
6800 ESI.Exceptions = Exceptions;
6801 if (ESI.Exceptions.empty())
6802 ESI.Type = EST_DynamicNone;
6803 return false;
6804}
6805
6806template<typename Derived>
6808 TypeLocBuilder &TLB,
6810 const FunctionNoProtoType *T = TL.getTypePtr();
6811 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6812 if (ResultType.isNull())
6813 return QualType();
6814
6815 QualType Result = TL.getType();
6816 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6817 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6818
6821 NewTL.setLParenLoc(TL.getLParenLoc());
6822 NewTL.setRParenLoc(TL.getRParenLoc());
6824
6825 return Result;
6826}
6827
6828template <typename Derived>
6829QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6830 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6831
6832 const UnresolvedUsingType *T = TL.getTypePtr();
6833 bool Changed = false;
6834
6835 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6836 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6837 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6838 if (!QualifierLoc)
6839 return QualType();
6840 Changed |= QualifierLoc != OldQualifierLoc;
6841 }
6842
6843 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6844 if (!D)
6845 return QualType();
6846 Changed |= D != T->getDecl();
6847
6848 QualType Result = TL.getType();
6849 if (getDerived().AlwaysRebuild() || Changed) {
6850 Result = getDerived().RebuildUnresolvedUsingType(
6851 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6852 D);
6853 if (Result.isNull())
6854 return QualType();
6855 }
6856
6858 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6859 QualifierLoc, TL.getNameLoc());
6860 else
6861 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6862 QualifierLoc, TL.getNameLoc());
6863 return Result;
6864}
6865
6866template <typename Derived>
6868 UsingTypeLoc TL) {
6869 const UsingType *T = TL.getTypePtr();
6870 bool Changed = false;
6871
6872 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6873 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6874 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6875 if (!QualifierLoc)
6876 return QualType();
6877 Changed |= QualifierLoc != OldQualifierLoc;
6878 }
6879
6880 auto *D = cast_or_null<UsingShadowDecl>(
6881 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6882 if (!D)
6883 return QualType();
6884 Changed |= D != T->getDecl();
6885
6886 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6887 if (UnderlyingType.isNull())
6888 return QualType();
6889 Changed |= UnderlyingType != T->desugar();
6890
6891 QualType Result = TL.getType();
6892 if (getDerived().AlwaysRebuild() || Changed) {
6893 Result = getDerived().RebuildUsingType(
6894 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6895 UnderlyingType);
6896 if (Result.isNull())
6897 return QualType();
6898 }
6899 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6900 TL.getNameLoc());
6901 return Result;
6902}
6903
6904template<typename Derived>
6906 TypedefTypeLoc TL) {
6907 const TypedefType *T = TL.getTypePtr();
6908 bool Changed = false;
6909
6910 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6911 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6912 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6913 if (!QualifierLoc)
6914 return QualType();
6915 Changed |= QualifierLoc != OldQualifierLoc;
6916 }
6917
6918 auto *Typedef = cast_or_null<TypedefNameDecl>(
6919 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6920 if (!Typedef)
6921 return QualType();
6922 Changed |= Typedef != T->getDecl();
6923
6924 // FIXME: Transform the UnderlyingType if different from decl.
6925
6926 QualType Result = TL.getType();
6927 if (getDerived().AlwaysRebuild() || Changed) {
6928 Result = getDerived().RebuildTypedefType(
6929 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6930 if (Result.isNull())
6931 return QualType();
6932 }
6933
6934 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6935 QualifierLoc, TL.getNameLoc());
6936 return Result;
6937}
6938
6939template<typename Derived>
6941 TypeOfExprTypeLoc TL) {
6942 // typeof expressions are not potentially evaluated contexts
6946
6947 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6948 if (E.isInvalid())
6949 return QualType();
6950
6951 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6952 if (E.isInvalid())
6953 return QualType();
6954
6955 QualType Result = TL.getType();
6957 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6958 Result =
6959 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6960 if (Result.isNull())
6961 return QualType();
6962 }
6963
6964 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6965 NewTL.setTypeofLoc(TL.getTypeofLoc());
6966 NewTL.setLParenLoc(TL.getLParenLoc());
6967 NewTL.setRParenLoc(TL.getRParenLoc());
6968
6969 return Result;
6970}
6971
6972template<typename Derived>
6974 TypeOfTypeLoc TL) {
6975 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6976 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6977 if (!New_Under_TI)
6978 return QualType();
6979
6980 QualType Result = TL.getType();
6981 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6982 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6983 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6984 if (Result.isNull())
6985 return QualType();
6986 }
6987
6988 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6989 NewTL.setTypeofLoc(TL.getTypeofLoc());
6990 NewTL.setLParenLoc(TL.getLParenLoc());
6991 NewTL.setRParenLoc(TL.getRParenLoc());
6992 NewTL.setUnmodifiedTInfo(New_Under_TI);
6993
6994 return Result;
6995}
6996
6997template<typename Derived>
6999 DecltypeTypeLoc TL) {
7000 const DecltypeType *T = TL.getTypePtr();
7001
7002 // decltype expressions are not potentially evaluated contexts
7006
7007 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
7008 if (E.isInvalid())
7009 return QualType();
7010
7011 E = getSema().ActOnDecltypeExpression(E.get());
7012 if (E.isInvalid())
7013 return QualType();
7014
7015 QualType Result = TL.getType();
7016 if (getDerived().AlwaysRebuild() ||
7017 E.get() != T->getUnderlyingExpr()) {
7018 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
7019 if (Result.isNull())
7020 return QualType();
7021 }
7022 else E.get();
7023
7024 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
7025 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
7026 NewTL.setRParenLoc(TL.getRParenLoc());
7027 return Result;
7028}
7029
7030template <typename Derived>
7034 // Transform the index
7035 ExprResult IndexExpr;
7036 {
7037 EnterExpressionEvaluationContext ConstantContext(
7039
7040 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
7041 if (IndexExpr.isInvalid())
7042 return QualType();
7043 }
7044 QualType Pattern = TL.getPattern();
7045
7046 const PackIndexingType *PIT = TL.getTypePtr();
7047 SmallVector<QualType, 5> SubtitutedTypes;
7048 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
7049
7050 bool NotYetExpanded = Types.empty();
7051 bool FullySubstituted = true;
7052
7053 if (Types.empty() && !PIT->expandsToEmptyPack())
7054 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7055
7056 for (QualType T : Types) {
7057 if (!T->containsUnexpandedParameterPack()) {
7058 QualType Transformed = getDerived().TransformType(T);
7059 if (Transformed.isNull())
7060 return QualType();
7061 SubtitutedTypes.push_back(Transformed);
7062 continue;
7063 }
7064
7066 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7067 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7068 // Determine whether the set of unexpanded parameter packs can and should
7069 // be expanded.
7070 bool ShouldExpand = true;
7071 bool RetainExpansion = false;
7072 UnsignedOrNone NumExpansions = std::nullopt;
7073 if (getDerived().TryExpandParameterPacks(
7074 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7075 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7076 RetainExpansion, NumExpansions))
7077 return QualType();
7078 if (!ShouldExpand) {
7079 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7080 // FIXME: should we keep TypeLoc for individual expansions in
7081 // PackIndexingTypeLoc?
7082 TypeSourceInfo *TI =
7083 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7084 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7085 if (Pack.isNull())
7086 return QualType();
7087 if (NotYetExpanded) {
7088 FullySubstituted = false;
7089 QualType Out = getDerived().RebuildPackIndexingType(
7090 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7091 FullySubstituted);
7092 if (Out.isNull())
7093 return QualType();
7094
7096 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7097 return Out;
7098 }
7099 SubtitutedTypes.push_back(Pack);
7100 continue;
7101 }
7102 for (unsigned I = 0; I != *NumExpansions; ++I) {
7103 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7104 QualType Out = getDerived().TransformType(T);
7105 if (Out.isNull())
7106 return QualType();
7107 SubtitutedTypes.push_back(Out);
7108 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7109 }
7110 // If we're supposed to retain a pack expansion, do so by temporarily
7111 // forgetting the partially-substituted parameter pack.
7112 if (RetainExpansion) {
7113 FullySubstituted = false;
7114 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7115 QualType Out = getDerived().TransformType(T);
7116 if (Out.isNull())
7117 return QualType();
7118 SubtitutedTypes.push_back(Out);
7119 }
7120 }
7121
7122 // A pack indexing type can appear in a larger pack expansion,
7123 // e.g. `Pack...[pack_of_indexes]...`
7124 // so we need to temporarily disable substitution of pack elements
7125 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7126 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7127
7128 QualType Out = getDerived().RebuildPackIndexingType(
7129 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7130 FullySubstituted, SubtitutedTypes);
7131 if (Out.isNull())
7132 return Out;
7133
7135 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7136 return Out;
7137}
7138
7139template<typename Derived>
7141 TypeLocBuilder &TLB,
7143 QualType Result = TL.getType();
7144 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7145 if (Result->isDependentType()) {
7146 const UnaryTransformType *T = TL.getTypePtr();
7147
7148 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7149 if (!NewBaseTSI)
7150 return QualType();
7151 QualType NewBase = NewBaseTSI->getType();
7152
7153 Result = getDerived().RebuildUnaryTransformType(NewBase,
7154 T->getUTTKind(),
7155 TL.getKWLoc());
7156 if (Result.isNull())
7157 return QualType();
7158 }
7159
7161 NewTL.setKWLoc(TL.getKWLoc());
7162 NewTL.setParensRange(TL.getParensRange());
7163 NewTL.setUnderlyingTInfo(NewBaseTSI);
7164 return Result;
7165}
7166
7167template<typename Derived>
7170 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7171
7172 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7173 TemplateName TemplateName = getDerived().TransformTemplateName(
7174 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7175 TL.getTemplateNameLoc());
7176 if (TemplateName.isNull())
7177 return QualType();
7178
7179 QualType OldDeduced = T->getDeducedType();
7180 QualType NewDeduced;
7181 if (!OldDeduced.isNull()) {
7182 NewDeduced = getDerived().TransformType(OldDeduced);
7183 if (NewDeduced.isNull())
7184 return QualType();
7185 }
7186
7187 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7188 T->getKeyword(), TemplateName, NewDeduced);
7189 if (Result.isNull())
7190 return QualType();
7191
7192 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7193 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7194 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7195 NewTL.setQualifierLoc(QualifierLoc);
7196 return Result;
7197}
7198
7199template <typename Derived>
7201 TagTypeLoc TL) {
7202 const TagType *T = TL.getTypePtr();
7203
7204 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7205 if (QualifierLoc) {
7206 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7207 if (!QualifierLoc)
7208 return QualType();
7209 }
7210
7211 auto *TD = cast_or_null<TagDecl>(
7212 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7213 if (!TD)
7214 return QualType();
7215
7216 QualType Result = TL.getType();
7217 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7218 TD != T->getDecl()) {
7219 if (T->isCanonicalUnqualified())
7220 Result = getDerived().RebuildCanonicalTagType(TD);
7221 else
7222 Result = getDerived().RebuildTagType(
7223 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7224 if (Result.isNull())
7225 return QualType();
7226 }
7227
7228 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7230 NewTL.setQualifierLoc(QualifierLoc);
7231 NewTL.setNameLoc(TL.getNameLoc());
7232
7233 return Result;
7234}
7235
7236template <typename Derived>
7238 EnumTypeLoc TL) {
7239 return getDerived().TransformTagType(TLB, TL);
7240}
7241
7242template <typename Derived>
7243QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7244 RecordTypeLoc TL) {
7245 return getDerived().TransformTagType(TLB, TL);
7246}
7247
7248template<typename Derived>
7250 TypeLocBuilder &TLB,
7252 return getDerived().TransformTagType(TLB, TL);
7253}
7254
7255template<typename Derived>
7257 TypeLocBuilder &TLB,
7259 return getDerived().TransformTemplateTypeParmType(
7260 TLB, TL,
7261 /*SuppressObjCLifetime=*/false);
7262}
7263
7264template <typename Derived>
7266 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7267 return TransformTypeSpecType(TLB, TL);
7268}
7269
7270template<typename Derived>
7271QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7272 TypeLocBuilder &TLB,
7273 SubstTemplateTypeParmTypeLoc TL) {
7274 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7275
7276 Decl *NewReplaced =
7277 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7278
7279 // Substitute into the replacement type, which itself might involve something
7280 // that needs to be transformed. This only tends to occur with default
7281 // template arguments of template template parameters.
7282 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7283 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7284 if (Replacement.isNull())
7285 return QualType();
7286
7287 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7288 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7289 T->getFinal());
7290
7291 // Propagate type-source information.
7292 SubstTemplateTypeParmTypeLoc NewTL
7293 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7294 NewTL.setNameLoc(TL.getNameLoc());
7295 return Result;
7296
7297}
7298template <typename Derived>
7301 return TransformTypeSpecType(TLB, TL);
7302}
7303
7304template<typename Derived>
7306 TypeLocBuilder &TLB,
7308 return getDerived().TransformSubstTemplateTypeParmPackType(
7309 TLB, TL, /*SuppressObjCLifetime=*/false);
7310}
7311
7312template <typename Derived>
7315 return TransformTypeSpecType(TLB, TL);
7316}
7317
7318template<typename Derived>
7319QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7320 AtomicTypeLoc TL) {
7321 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7322 if (ValueType.isNull())
7323 return QualType();
7324
7325 QualType Result = TL.getType();
7326 if (getDerived().AlwaysRebuild() ||
7327 ValueType != TL.getValueLoc().getType()) {
7328 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7329 if (Result.isNull())
7330 return QualType();
7331 }
7332
7333 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7334 NewTL.setKWLoc(TL.getKWLoc());
7335 NewTL.setLParenLoc(TL.getLParenLoc());
7336 NewTL.setRParenLoc(TL.getRParenLoc());
7337
7338 return Result;
7339}
7340
7341template <typename Derived>
7343 PipeTypeLoc TL) {
7344 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7345 if (ValueType.isNull())
7346 return QualType();
7347
7348 QualType Result = TL.getType();
7349 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7350 const PipeType *PT = Result->castAs<PipeType>();
7351 bool isReadPipe = PT->isReadOnly();
7352 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7353 if (Result.isNull())
7354 return QualType();
7355 }
7356
7357 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7358 NewTL.setKWLoc(TL.getKWLoc());
7359
7360 return Result;
7361}
7362
7363template <typename Derived>
7365 BitIntTypeLoc TL) {
7366 const BitIntType *EIT = TL.getTypePtr();
7367 QualType Result = TL.getType();
7368
7369 if (getDerived().AlwaysRebuild()) {
7370 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7371 EIT->getNumBits(), TL.getNameLoc());
7372 if (Result.isNull())
7373 return QualType();
7374 }
7375
7376 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7377 NewTL.setNameLoc(TL.getNameLoc());
7378 return Result;
7379}
7380
7381template <typename Derived>
7384 const DependentBitIntType *EIT = TL.getTypePtr();
7385
7388 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7389 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7390
7391 if (BitsExpr.isInvalid())
7392 return QualType();
7393
7394 QualType Result = TL.getType();
7395
7396 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7397 Result = getDerived().RebuildDependentBitIntType(
7398 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7399
7400 if (Result.isNull())
7401 return QualType();
7402 }
7403
7406 NewTL.setNameLoc(TL.getNameLoc());
7407 } else {
7408 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7409 NewTL.setNameLoc(TL.getNameLoc());
7410 }
7411 return Result;
7412}
7413
7414template <typename Derived>
7417 llvm_unreachable("This type does not need to be transformed.");
7418}
7419
7420 /// Simple iterator that traverses the template arguments in a
7421 /// container that provides a \c getArgLoc() member function.
7422 ///
7423 /// This iterator is intended to be used with the iterator form of
7424 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7425 template<typename ArgLocContainer>
7427 ArgLocContainer *Container;
7428 unsigned Index;
7429
7430 public:
7433 typedef int difference_type;
7434 typedef std::input_iterator_tag iterator_category;
7435
7436 class pointer {
7438
7439 public:
7440 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7441
7443 return &Arg;
7444 }
7445 };
7446
7447
7449
7450 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7451 unsigned Index)
7452 : Container(&Container), Index(Index) { }
7453
7455 ++Index;
7456 return *this;
7457 }
7458
7461 ++(*this);
7462 return Old;
7463 }
7464
7466 return Container->getArgLoc(Index);
7467 }
7468
7470 return pointer(Container->getArgLoc(Index));
7471 }
7472
7475 return X.Container == Y.Container && X.Index == Y.Index;
7476 }
7477
7480 return !(X == Y);
7481 }
7482 };
7483
7484template<typename Derived>
7485QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7486 AutoTypeLoc TL) {
7487 const AutoType *T = TL.getTypePtr();
7488 QualType OldDeduced = T->getDeducedType();
7489 QualType NewDeduced;
7490 if (!OldDeduced.isNull()) {
7491 NewDeduced = getDerived().TransformType(OldDeduced);
7492 if (NewDeduced.isNull())
7493 return QualType();
7494 }
7495
7496 ConceptDecl *NewCD = nullptr;
7497 TemplateArgumentListInfo NewTemplateArgs;
7498 NestedNameSpecifierLoc NewNestedNameSpec;
7499 if (T->isConstrained()) {
7500 assert(TL.getConceptReference());
7501 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7502 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7503
7504 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7505 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7507 if (getDerived().TransformTemplateArguments(
7508 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7509 NewTemplateArgs))
7510 return QualType();
7511
7512 if (TL.getNestedNameSpecifierLoc()) {
7513 NewNestedNameSpec
7514 = getDerived().TransformNestedNameSpecifierLoc(
7515 TL.getNestedNameSpecifierLoc());
7516 if (!NewNestedNameSpec)
7517 return QualType();
7518 }
7519 }
7520
7521 QualType Result = TL.getType();
7522 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7523 T->isDependentType() || T->isConstrained()) {
7524 // FIXME: Maybe don't rebuild if all template arguments are the same.
7526 NewArgList.reserve(NewTemplateArgs.size());
7527 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7528 NewArgList.push_back(ArgLoc.getArgument());
7529 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7530 NewArgList);
7531 if (Result.isNull())
7532 return QualType();
7533 }
7534
7535 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7536 NewTL.setNameLoc(TL.getNameLoc());
7537 NewTL.setRParenLoc(TL.getRParenLoc());
7538 NewTL.setConceptReference(nullptr);
7539
7540 if (T->isConstrained()) {
7542 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7543 TL.getConceptNameLoc(),
7544 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7545 auto *CR = ConceptReference::Create(
7546 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7547 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7548 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7549 NewTL.setConceptReference(CR);
7550 }
7551
7552 return Result;
7553}
7554
7555template <typename Derived>
7558 return getDerived().TransformTemplateSpecializationType(
7559 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7560 /*AllowInjectedClassName=*/false);
7561}
7562
7563template <typename Derived>
7566 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7567 const TemplateSpecializationType *T = TL.getTypePtr();
7568
7569 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7570 TemplateName Template = getDerived().TransformTemplateName(
7571 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7572 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7573 AllowInjectedClassName);
7574 if (Template.isNull())
7575 return QualType();
7576
7577 TemplateArgumentListInfo NewTemplateArgs;
7578 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7579 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7581 ArgIterator;
7582 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7583 ArgIterator(TL, TL.getNumArgs()),
7584 NewTemplateArgs))
7585 return QualType();
7586
7587 // This needs to be rebuilt if either the arguments changed, or if the
7588 // original template changed. If the template changed, and even if the
7589 // arguments didn't change, these arguments might not correspond to their
7590 // respective parameters, therefore needing conversions.
7591 QualType Result = getDerived().RebuildTemplateSpecializationType(
7592 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7593 NewTemplateArgs);
7594
7595 if (!Result.isNull()) {
7597 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7598 TL.getTemplateNameLoc(), NewTemplateArgs);
7599 }
7600
7601 return Result;
7602}
7603
7604template <typename Derived>
7606 AttributedTypeLoc TL) {
7607 const AttributedType *oldType = TL.getTypePtr();
7608 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7609 if (modifiedType.isNull())
7610 return QualType();
7611
7612 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7613 const Attr *oldAttr = TL.getAttr();
7614 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7615 if (oldAttr && !newAttr)
7616 return QualType();
7617
7618 QualType result = TL.getType();
7619
7620 // FIXME: dependent operand expressions?
7621 if (getDerived().AlwaysRebuild() ||
7622 modifiedType != oldType->getModifiedType()) {
7623 // If the equivalent type is equal to the modified type, we don't want to
7624 // transform it as well because:
7625 //
7626 // 1. The transformation would yield the same result and is therefore
7627 // superfluous, and
7628 //
7629 // 2. Transforming the same type twice can cause problems, e.g. if it
7630 // is a FunctionProtoType, we may end up instantiating the function
7631 // parameters twice, which causes an assertion since the parameters
7632 // are already bound to their counterparts in the template for this
7633 // instantiation.
7634 //
7635 QualType equivalentType = modifiedType;
7636 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7637 TypeLocBuilder AuxiliaryTLB;
7638 AuxiliaryTLB.reserve(TL.getFullDataSize());
7639 equivalentType =
7640 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7641 if (equivalentType.isNull())
7642 return QualType();
7643 }
7644
7645 // Check whether we can add nullability; it is only represented as
7646 // type sugar, and therefore cannot be diagnosed in any other way.
7647 if (auto nullability = oldType->getImmediateNullability()) {
7648 if (!modifiedType->canHaveNullability()) {
7649 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7650 : TL.getModifiedLoc().getBeginLoc()),
7651 diag::err_nullability_nonpointer)
7652 << DiagNullabilityKind(*nullability, false) << modifiedType;
7653 return QualType();
7654 }
7655 }
7656
7657 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7658 modifiedType,
7659 equivalentType,
7660 TL.getAttr());
7661 }
7662
7663 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7664 newTL.setAttr(newAttr);
7665 return result;
7666}
7667
7668template <typename Derived>
7671 const CountAttributedType *OldTy = TL.getTypePtr();
7672 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7673 if (InnerTy.isNull())
7674 return QualType();
7675
7676 Expr *OldCount = TL.getCountExpr();
7677 Expr *NewCount = nullptr;
7678 if (OldCount) {
7679 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7680 if (CountResult.isInvalid())
7681 return QualType();
7682 NewCount = CountResult.get();
7683 }
7684
7685 QualType Result = TL.getType();
7686 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7687 OldCount != NewCount) {
7688 // Currently, CountAttributedType can only wrap incomplete array types.
7690 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7691 }
7692
7693 TLB.push<CountAttributedTypeLoc>(Result);
7694 return Result;
7695}
7696
7697template <typename Derived>
7700 // The BTFTagAttributedType is available for C only.
7701 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7702}
7703
7704template <typename Derived>
7707
7708 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7709
7710 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7711 if (WrappedTy.isNull())
7712 return QualType();
7713
7714 QualType ContainedTy = QualType();
7715 QualType OldContainedTy = oldType->getContainedType();
7716 if (!OldContainedTy.isNull()) {
7717 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7718 if (!oldContainedTSI)
7719 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7720 OldContainedTy, SourceLocation());
7721 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7722 if (!ContainedTSI)
7723 return QualType();
7724 ContainedTy = ContainedTSI->getType();
7725 }
7726
7727 QualType Result = TL.getType();
7728 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7729 ContainedTy != oldType->getContainedType()) {
7731 WrappedTy, ContainedTy, oldType->getAttrs());
7732 }
7733
7735 return Result;
7736}
7737
7738template <typename Derived>
7741 // No transformations needed.
7742 return TL.getType();
7743}
7744
7745template<typename Derived>
7748 ParenTypeLoc TL) {
7749 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7750 if (Inner.isNull())
7751 return QualType();
7752
7753 QualType Result = TL.getType();
7754 if (getDerived().AlwaysRebuild() ||
7755 Inner != TL.getInnerLoc().getType()) {
7756 Result = getDerived().RebuildParenType(Inner);
7757 if (Result.isNull())
7758 return QualType();
7759 }
7760
7761 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7762 NewTL.setLParenLoc(TL.getLParenLoc());
7763 NewTL.setRParenLoc(TL.getRParenLoc());
7764 return Result;
7765}
7766
7767template <typename Derived>
7771 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7772 if (Inner.isNull())
7773 return QualType();
7774
7775 QualType Result = TL.getType();
7776 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7777 Result =
7778 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7779 if (Result.isNull())
7780 return QualType();
7781 }
7782
7784 NewTL.setExpansionLoc(TL.getExpansionLoc());
7785 return Result;
7786}
7787
7788template<typename Derived>
7789QualType TreeTransform<Derived>::TransformDependentNameType(
7791 return TransformDependentNameType(TLB, TL, false);
7792}
7793
7794template <typename Derived>
7795QualType TreeTransform<Derived>::TransformDependentNameType(
7796 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7797 QualType ObjectType, NamedDecl *UnqualLookup) {
7798 const DependentNameType *T = TL.getTypePtr();
7799
7800 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7801 if (QualifierLoc) {
7802 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7803 QualifierLoc, ObjectType, UnqualLookup);
7804 if (!QualifierLoc)
7805 return QualType();
7806 } else {
7807 assert((ObjectType.isNull() && !UnqualLookup) &&
7808 "must be transformed by TransformNestedNameSpecifierLoc");
7809 }
7810
7812 = getDerived().RebuildDependentNameType(T->getKeyword(),
7813 TL.getElaboratedKeywordLoc(),
7814 QualifierLoc,
7815 T->getIdentifier(),
7816 TL.getNameLoc(),
7817 DeducedTSTContext);
7818 if (Result.isNull())
7819 return QualType();
7820
7821 if (isa<TagType>(Result)) {
7822 auto NewTL = TLB.push<TagTypeLoc>(Result);
7823 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7824 NewTL.setQualifierLoc(QualifierLoc);
7825 NewTL.setNameLoc(TL.getNameLoc());
7827 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7828 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7829 NewTL.setTemplateNameLoc(TL.getNameLoc());
7830 NewTL.setQualifierLoc(QualifierLoc);
7831 } else if (isa<TypedefType>(Result)) {
7832 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7833 QualifierLoc, TL.getNameLoc());
7834 } else if (isa<UnresolvedUsingType>(Result)) {
7835 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7836 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7837 } else {
7838 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7839 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7840 NewTL.setQualifierLoc(QualifierLoc);
7841 NewTL.setNameLoc(TL.getNameLoc());
7842 }
7843 return Result;
7844}
7845
7846template<typename Derived>
7849 QualType Pattern
7850 = getDerived().TransformType(TLB, TL.getPatternLoc());
7851 if (Pattern.isNull())
7852 return QualType();
7853
7854 QualType Result = TL.getType();
7855 if (getDerived().AlwaysRebuild() ||
7856 Pattern != TL.getPatternLoc().getType()) {
7857 Result = getDerived().RebuildPackExpansionType(Pattern,
7858 TL.getPatternLoc().getSourceRange(),
7859 TL.getEllipsisLoc(),
7860 TL.getTypePtr()->getNumExpansions());
7861 if (Result.isNull())
7862 return QualType();
7863 }
7864
7866 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7867 return Result;
7868}
7869
7870template<typename Derived>
7874 // ObjCInterfaceType is never dependent.
7875 TLB.pushFullCopy(TL);
7876 return TL.getType();
7877}
7878
7879template<typename Derived>
7883 const ObjCTypeParamType *T = TL.getTypePtr();
7884 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7885 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7886 if (!OTP)
7887 return QualType();
7888
7889 QualType Result = TL.getType();
7890 if (getDerived().AlwaysRebuild() ||
7891 OTP != T->getDecl()) {
7892 Result = getDerived().RebuildObjCTypeParamType(
7893 OTP, TL.getProtocolLAngleLoc(),
7894 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7895 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7896 if (Result.isNull())
7897 return QualType();
7898 }
7899
7901 if (TL.getNumProtocols()) {
7902 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7903 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7904 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7905 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7906 }
7907 return Result;
7908}
7909
7910template<typename Derived>
7913 ObjCObjectTypeLoc TL) {
7914 // Transform base type.
7915 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7916 if (BaseType.isNull())
7917 return QualType();
7918
7919 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7920
7921 // Transform type arguments.
7922 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7923 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7924 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7925 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7926 QualType TypeArg = TypeArgInfo->getType();
7927 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7928 AnyChanged = true;
7929
7930 // We have a pack expansion. Instantiate it.
7931 const auto *PackExpansion = PackExpansionLoc.getType()
7932 ->castAs<PackExpansionType>();
7934 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7935 Unexpanded);
7936 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7937
7938 // Determine whether the set of unexpanded parameter packs can
7939 // and should be expanded.
7940 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7941 bool Expand = false;
7942 bool RetainExpansion = false;
7943 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7944 if (getDerived().TryExpandParameterPacks(
7945 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7946 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
7947 RetainExpansion, NumExpansions))
7948 return QualType();
7949
7950 if (!Expand) {
7951 // We can't expand this pack expansion into separate arguments yet;
7952 // just substitute into the pattern and create a new pack expansion
7953 // type.
7954 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7955
7956 TypeLocBuilder TypeArgBuilder;
7957 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7958 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7959 PatternLoc);
7960 if (NewPatternType.isNull())
7961 return QualType();
7962
7963 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7964 NewPatternType, NumExpansions);
7965 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7966 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7967 NewTypeArgInfos.push_back(
7968 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7969 continue;
7970 }
7971
7972 // Substitute into the pack expansion pattern for each slice of the
7973 // pack.
7974 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7975 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
7976
7977 TypeLocBuilder TypeArgBuilder;
7978 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7979
7980 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7981 PatternLoc);
7982 if (NewTypeArg.isNull())
7983 return QualType();
7984
7985 NewTypeArgInfos.push_back(
7986 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7987 }
7988
7989 continue;
7990 }
7991
7992 TypeLocBuilder TypeArgBuilder;
7993 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7994 QualType NewTypeArg =
7995 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7996 if (NewTypeArg.isNull())
7997 return QualType();
7998
7999 // If nothing changed, just keep the old TypeSourceInfo.
8000 if (NewTypeArg == TypeArg) {
8001 NewTypeArgInfos.push_back(TypeArgInfo);
8002 continue;
8003 }
8004
8005 NewTypeArgInfos.push_back(
8006 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8007 AnyChanged = true;
8008 }
8009
8010 QualType Result = TL.getType();
8011 if (getDerived().AlwaysRebuild() || AnyChanged) {
8012 // Rebuild the type.
8013 Result = getDerived().RebuildObjCObjectType(
8014 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8015 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8016 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8017 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8018
8019 if (Result.isNull())
8020 return QualType();
8021 }
8022
8023 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8024 NewT.setHasBaseTypeAsWritten(true);
8025 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8026 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8027 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8028 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8029 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8030 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8031 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8032 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8033 return Result;
8034}
8035
8036template<typename Derived>
8040 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8041 if (PointeeType.isNull())
8042 return QualType();
8043
8044 QualType Result = TL.getType();
8045 if (getDerived().AlwaysRebuild() ||
8046 PointeeType != TL.getPointeeLoc().getType()) {
8047 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8048 TL.getStarLoc());
8049 if (Result.isNull())
8050 return QualType();
8051 }
8052
8054 NewT.setStarLoc(TL.getStarLoc());
8055 return Result;
8056}
8057
8058//===----------------------------------------------------------------------===//
8059// Statement transformation
8060//===----------------------------------------------------------------------===//
8061template<typename Derived>
8064 return S;
8065}
8066
8067template<typename Derived>
8070 return getDerived().TransformCompoundStmt(S, false);
8071}
8072
8073template<typename Derived>
8076 bool IsStmtExpr) {
8077 Sema::CompoundScopeRAII CompoundScope(getSema());
8078 Sema::FPFeaturesStateRAII FPSave(getSema());
8079 if (S->hasStoredFPFeatures())
8080 getSema().resetFPOptions(
8081 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8082
8083 const Stmt *ExprResult = S->getStmtExprResult();
8084 bool SubStmtInvalid = false;
8085 bool SubStmtChanged = false;
8086 SmallVector<Stmt*, 8> Statements;
8087 for (auto *B : S->body()) {
8088 StmtResult Result = getDerived().TransformStmt(
8089 B, IsStmtExpr && B == ExprResult ? StmtDiscardKind::StmtExprResult
8090 : StmtDiscardKind::Discarded);
8091
8092 if (Result.isInvalid()) {
8093 // Immediately fail if this was a DeclStmt, since it's very
8094 // likely that this will cause problems for future statements.
8095 if (isa<DeclStmt>(B))
8096 return StmtError();
8097
8098 // Otherwise, just keep processing substatements and fail later.
8099 SubStmtInvalid = true;
8100 continue;
8101 }
8102
8103 SubStmtChanged = SubStmtChanged || Result.get() != B;
8104 Statements.push_back(Result.getAs<Stmt>());
8105 }
8106
8107 if (SubStmtInvalid)
8108 return StmtError();
8109
8110 if (!getDerived().AlwaysRebuild() &&
8111 !SubStmtChanged)
8112 return S;
8113
8114 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8115 Statements,
8116 S->getRBracLoc(),
8117 IsStmtExpr);
8118}
8119
8120template<typename Derived>
8123 ExprResult LHS, RHS;
8124 {
8127
8128 // Transform the left-hand case value.
8129 LHS = getDerived().TransformExpr(S->getLHS());
8130 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8131 if (LHS.isInvalid())
8132 return StmtError();
8133
8134 // Transform the right-hand case value (for the GNU case-range extension).
8135 RHS = getDerived().TransformExpr(S->getRHS());
8136 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8137 if (RHS.isInvalid())
8138 return StmtError();
8139 }
8140
8141 // Build the case statement.
8142 // Case statements are always rebuilt so that they will attached to their
8143 // transformed switch statement.
8144 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8145 LHS.get(),
8146 S->getEllipsisLoc(),
8147 RHS.get(),
8148 S->getColonLoc());
8149 if (Case.isInvalid())
8150 return StmtError();
8151
8152 // Transform the statement following the case
8153 StmtResult SubStmt =
8154 getDerived().TransformStmt(S->getSubStmt());
8155 if (SubStmt.isInvalid())
8156 return StmtError();
8157
8158 // Attach the body to the case statement
8159 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8160}
8161
8162template <typename Derived>
8164 // Transform the statement following the default case
8165 StmtResult SubStmt =
8166 getDerived().TransformStmt(S->getSubStmt());
8167 if (SubStmt.isInvalid())
8168 return StmtError();
8169
8170 // Default statements are always rebuilt
8171 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8172 SubStmt.get());
8173}
8174
8175template<typename Derived>
8178 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8179 if (SubStmt.isInvalid())
8180 return StmtError();
8181
8182 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8183 S->getDecl());
8184 if (!LD)
8185 return StmtError();
8186
8187 // If we're transforming "in-place" (we're not creating new local
8188 // declarations), assume we're replacing the old label statement
8189 // and clear out the reference to it.
8190 if (LD == S->getDecl())
8191 S->getDecl()->setStmt(nullptr);
8192
8193 // FIXME: Pass the real colon location in.
8194 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8196 SubStmt.get());
8197}
8198
8199template <typename Derived>
8201 if (!R)
8202 return R;
8203
8204 switch (R->getKind()) {
8205// Transform attributes by calling TransformXXXAttr.
8206#define ATTR(X) \
8207 case attr::X: \
8208 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8209#include "clang/Basic/AttrList.inc"
8210 }
8211 return R;
8212}
8213
8214template <typename Derived>
8216 const Stmt *InstS,
8217 const Attr *R) {
8218 if (!R)
8219 return R;
8220
8221 switch (R->getKind()) {
8222// Transform attributes by calling TransformStmtXXXAttr.
8223#define ATTR(X) \
8224 case attr::X: \
8225 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8226#include "clang/Basic/AttrList.inc"
8227 }
8228 return TransformAttr(R);
8229}
8230
8231template <typename Derived>
8234 StmtDiscardKind SDK) {
8235 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8236 if (SubStmt.isInvalid())
8237 return StmtError();
8238
8239 bool AttrsChanged = false;
8241
8242 // Visit attributes and keep track if any are transformed.
8243 for (const auto *I : S->getAttrs()) {
8244 const Attr *R =
8245 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8246 AttrsChanged |= (I != R);
8247 if (R)
8248 Attrs.push_back(R);
8249 }
8250
8251 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8252 return S;
8253
8254 // If transforming the attributes failed for all of the attributes in the
8255 // statement, don't make an AttributedStmt without attributes.
8256 if (Attrs.empty())
8257 return SubStmt;
8258
8259 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8260 SubStmt.get());
8261}
8262
8263template<typename Derived>
8266 // Transform the initialization statement
8267 StmtResult Init = getDerived().TransformStmt(S->getInit());
8268 if (Init.isInvalid())
8269 return StmtError();
8270
8272 if (!S->isConsteval()) {
8273 // Transform the condition
8274 Cond = getDerived().TransformCondition(
8275 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8276 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8278 if (Cond.isInvalid())
8279 return StmtError();
8280 }
8281
8282 // If this is a constexpr if, determine which arm we should instantiate.
8283 std::optional<bool> ConstexprConditionValue;
8284 if (S->isConstexpr())
8285 ConstexprConditionValue = Cond.getKnownValue();
8286
8287 // Transform the "then" branch.
8288 StmtResult Then;
8289 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8293 S->isNonNegatedConsteval());
8294
8295 Then = getDerived().TransformStmt(S->getThen());
8296 if (Then.isInvalid())
8297 return StmtError();
8298 } else {
8299 // Discarded branch is replaced with empty CompoundStmt so we can keep
8300 // proper source location for start and end of original branch, so
8301 // subsequent transformations like CoverageMapping work properly
8302 Then = new (getSema().Context)
8303 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8304 }
8305
8306 // Transform the "else" branch.
8307 StmtResult Else;
8308 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8312 S->isNegatedConsteval());
8313
8314 Else = getDerived().TransformStmt(S->getElse());
8315 if (Else.isInvalid())
8316 return StmtError();
8317 } else if (S->getElse() && ConstexprConditionValue &&
8318 *ConstexprConditionValue) {
8319 // Same thing here as with <then> branch, we are discarding it, we can't
8320 // replace it with NULL nor NullStmt as we need to keep for source location
8321 // range, for CoverageMapping
8322 Else = new (getSema().Context)
8323 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8324 }
8325
8326 if (!getDerived().AlwaysRebuild() &&
8327 Init.get() == S->getInit() &&
8328 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8329 Then.get() == S->getThen() &&
8330 Else.get() == S->getElse())
8331 return S;
8332
8333 return getDerived().RebuildIfStmt(
8334 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8335 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8336}
8337
8338template<typename Derived>
8341 // Transform the initialization statement
8342 StmtResult Init = getDerived().TransformStmt(S->getInit());
8343 if (Init.isInvalid())
8344 return StmtError();
8345
8346 // Transform the condition.
8347 Sema::ConditionResult Cond = getDerived().TransformCondition(
8348 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8350 if (Cond.isInvalid())
8351 return StmtError();
8352
8353 // Rebuild the switch statement.
8355 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8356 Init.get(), Cond, S->getRParenLoc());
8357 if (Switch.isInvalid())
8358 return StmtError();
8359
8360 // Transform the body of the switch statement.
8361 StmtResult Body = getDerived().TransformStmt(S->getBody());
8362 if (Body.isInvalid())
8363 return StmtError();
8364
8365 // Complete the switch statement.
8366 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8367 Body.get());
8368}
8369
8370template<typename Derived>
8373 // Transform the condition
8374 Sema::ConditionResult Cond = getDerived().TransformCondition(
8375 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8377 if (Cond.isInvalid())
8378 return StmtError();
8379
8380 // OpenACC Restricts a while-loop inside of certain construct/clause
8381 // combinations, so diagnose that here in OpenACC mode.
8383 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8384
8385 // Transform the body
8386 StmtResult Body = getDerived().TransformStmt(S->getBody());
8387 if (Body.isInvalid())
8388 return StmtError();
8389
8390 if (!getDerived().AlwaysRebuild() &&
8391 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8392 Body.get() == S->getBody())
8393 return Owned(S);
8394
8395 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8396 Cond, S->getRParenLoc(), Body.get());
8397}
8398
8399template<typename Derived>
8402 // OpenACC Restricts a do-loop inside of certain construct/clause
8403 // combinations, so diagnose that here in OpenACC mode.
8405 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8406
8407 // Transform the body
8408 StmtResult Body = getDerived().TransformStmt(S->getBody());
8409 if (Body.isInvalid())
8410 return StmtError();
8411
8412 // Transform the condition
8413 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8414 if (Cond.isInvalid())
8415 return StmtError();
8416
8417 if (!getDerived().AlwaysRebuild() &&
8418 Cond.get() == S->getCond() &&
8419 Body.get() == S->getBody())
8420 return S;
8421
8422 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8423 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8424 S->getRParenLoc());
8425}
8426
8427template<typename Derived>
8430 if (getSema().getLangOpts().OpenMP)
8431 getSema().OpenMP().startOpenMPLoop();
8432
8433 // Transform the initialization statement
8434 StmtResult Init = getDerived().TransformStmt(S->getInit());
8435 if (Init.isInvalid())
8436 return StmtError();
8437
8438 // In OpenMP loop region loop control variable must be captured and be
8439 // private. Perform analysis of first part (if any).
8440 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8441 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8442 Init.get());
8443
8444 // Transform the condition
8445 Sema::ConditionResult Cond = getDerived().TransformCondition(
8446 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8448 if (Cond.isInvalid())
8449 return StmtError();
8450
8451 // Transform the increment
8452 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8453 if (Inc.isInvalid())
8454 return StmtError();
8455
8456 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8457 if (S->getInc() && !FullInc.get())
8458 return StmtError();
8459
8460 // OpenACC Restricts a for-loop inside of certain construct/clause
8461 // combinations, so diagnose that here in OpenACC mode.
8463 SemaRef.OpenACC().ActOnForStmtBegin(
8464 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8465 Cond.get().second, S->getInc(), Inc.get());
8466
8467 // Transform the body
8468 StmtResult Body = getDerived().TransformStmt(S->getBody());
8469 if (Body.isInvalid())
8470 return StmtError();
8471
8472 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8473
8474 if (!getDerived().AlwaysRebuild() &&
8475 Init.get() == S->getInit() &&
8476 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8477 Inc.get() == S->getInc() &&
8478 Body.get() == S->getBody())
8479 return S;
8480
8481 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8482 Init.get(), Cond, FullInc,
8483 S->getRParenLoc(), Body.get());
8484}
8485
8486template<typename Derived>
8489 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8490 S->getLabel());
8491 if (!LD)
8492 return StmtError();
8493
8494 // Goto statements must always be rebuilt, to resolve the label.
8495 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8496 cast<LabelDecl>(LD));
8497}
8498
8499template<typename Derived>
8502 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8503 if (Target.isInvalid())
8504 return StmtError();
8505 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8506
8507 if (!getDerived().AlwaysRebuild() &&
8508 Target.get() == S->getTarget())
8509 return S;
8510
8511 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8512 Target.get());
8513}
8514
8515template<typename Derived>
8518 if (!S->hasLabelTarget())
8519 return S;
8520
8521 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8522 S->getLabelDecl());
8523 if (!LD)
8524 return StmtError();
8525
8526 return new (SemaRef.Context)
8527 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8528}
8529
8530template<typename Derived>
8533 if (!S->hasLabelTarget())
8534 return S;
8535
8536 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8537 S->getLabelDecl());
8538 if (!LD)
8539 return StmtError();
8540
8541 return new (SemaRef.Context)
8542 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8543}
8544
8545template<typename Derived>
8548 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8549 /*NotCopyInit*/false);
8550 if (Result.isInvalid())
8551 return StmtError();
8552
8553 // FIXME: We always rebuild the return statement because there is no way
8554 // to tell whether the return type of the function has changed.
8555 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8556}
8557
8558template<typename Derived>
8561 bool DeclChanged = false;
8563 LambdaScopeInfo *LSI = getSema().getCurLambda();
8564 for (auto *D : S->decls()) {
8565 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8566 if (!Transformed)
8567 return StmtError();
8568
8569 if (Transformed != D)
8570 DeclChanged = true;
8571
8572 if (LSI) {
8573 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8574 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8575 LSI->ContainsUnexpandedParameterPack |=
8576 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8577 } else {
8578 LSI->ContainsUnexpandedParameterPack |=
8579 getSema()
8580 .getASTContext()
8581 .getTypeDeclType(TD)
8582 ->containsUnexpandedParameterPack();
8583 }
8584 }
8585 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8586 LSI->ContainsUnexpandedParameterPack |=
8587 VD->getType()->containsUnexpandedParameterPack();
8588 }
8589
8590 Decls.push_back(Transformed);
8591 }
8592
8593 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8594 return S;
8595
8596 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8597}
8598
8599template<typename Derived>
8602
8603 SmallVector<Expr*, 8> Constraints;
8606
8607 SmallVector<Expr*, 8> Clobbers;
8608
8609 bool ExprsChanged = false;
8610
8611 auto RebuildString = [&](Expr *E) {
8612 ExprResult Result = getDerived().TransformExpr(E);
8613 if (!Result.isUsable())
8614 return Result;
8615 if (Result.get() != E) {
8616 ExprsChanged = true;
8617 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8618 }
8619 return Result;
8620 };
8621
8622 // Go through the outputs.
8623 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8624 Names.push_back(S->getOutputIdentifier(I));
8625
8626 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8627 if (Result.isInvalid())
8628 return StmtError();
8629
8630 Constraints.push_back(Result.get());
8631
8632 // Transform the output expr.
8633 Expr *OutputExpr = S->getOutputExpr(I);
8634 Result = getDerived().TransformExpr(OutputExpr);
8635 if (Result.isInvalid())
8636 return StmtError();
8637
8638 ExprsChanged |= Result.get() != OutputExpr;
8639
8640 Exprs.push_back(Result.get());
8641 }
8642
8643 // Go through the inputs.
8644 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8645 Names.push_back(S->getInputIdentifier(I));
8646
8647 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8648 if (Result.isInvalid())
8649 return StmtError();
8650
8651 Constraints.push_back(Result.get());
8652
8653 // Transform the input expr.
8654 Expr *InputExpr = S->getInputExpr(I);
8655 Result = getDerived().TransformExpr(InputExpr);
8656 if (Result.isInvalid())
8657 return StmtError();
8658
8659 ExprsChanged |= Result.get() != InputExpr;
8660
8661 Exprs.push_back(Result.get());
8662 }
8663
8664 // Go through the Labels.
8665 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8666 Names.push_back(S->getLabelIdentifier(I));
8667
8668 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8669 if (Result.isInvalid())
8670 return StmtError();
8671 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8672 Exprs.push_back(Result.get());
8673 }
8674
8675 // Go through the clobbers.
8676 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8677 ExprResult Result = RebuildString(S->getClobberExpr(I));
8678 if (Result.isInvalid())
8679 return StmtError();
8680 Clobbers.push_back(Result.get());
8681 }
8682
8683 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8684 if (AsmString.isInvalid())
8685 return StmtError();
8686
8687 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8688 return S;
8689
8690 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8691 S->isVolatile(), S->getNumOutputs(),
8692 S->getNumInputs(), Names.data(),
8693 Constraints, Exprs, AsmString.get(),
8694 Clobbers, S->getNumLabels(),
8695 S->getRParenLoc());
8696}
8697
8698template<typename Derived>
8701 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8702
8703 bool HadError = false, HadChange = false;
8704
8705 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8706 SmallVector<Expr*, 8> TransformedExprs;
8707 TransformedExprs.reserve(SrcExprs.size());
8708 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8709 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8710 if (!Result.isUsable()) {
8711 HadError = true;
8712 } else {
8713 HadChange |= (Result.get() != SrcExprs[i]);
8714 TransformedExprs.push_back(Result.get());
8715 }
8716 }
8717
8718 if (HadError) return StmtError();
8719 if (!HadChange && !getDerived().AlwaysRebuild())
8720 return Owned(S);
8721
8722 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8723 AsmToks, S->getAsmString(),
8724 S->getNumOutputs(), S->getNumInputs(),
8725 S->getAllConstraints(), S->getClobbers(),
8726 TransformedExprs, S->getEndLoc());
8727}
8728
8729// C++ Coroutines
8730template<typename Derived>
8733 auto *ScopeInfo = SemaRef.getCurFunction();
8734 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8735 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8736 ScopeInfo->NeedsCoroutineSuspends &&
8737 ScopeInfo->CoroutineSuspends.first == nullptr &&
8738 ScopeInfo->CoroutineSuspends.second == nullptr &&
8739 "expected clean scope info");
8740
8741 // Set that we have (possibly-invalid) suspend points before we do anything
8742 // that may fail.
8743 ScopeInfo->setNeedsCoroutineSuspends(false);
8744
8745 // We re-build the coroutine promise object (and the coroutine parameters its
8746 // type and constructor depend on) based on the types used in our current
8747 // function. We must do so, and set it on the current FunctionScopeInfo,
8748 // before attempting to transform the other parts of the coroutine body
8749 // statement, such as the implicit suspend statements (because those
8750 // statements reference the FunctionScopeInfo::CoroutinePromise).
8751 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8752 return StmtError();
8753 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8754 if (!Promise)
8755 return StmtError();
8756 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8757 ScopeInfo->CoroutinePromise = Promise;
8758
8759 // Transform the implicit coroutine statements constructed using dependent
8760 // types during the previous parse: initial and final suspensions, the return
8761 // object, and others. We also transform the coroutine function's body.
8762 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8763 if (InitSuspend.isInvalid())
8764 return StmtError();
8765 StmtResult FinalSuspend =
8766 getDerived().TransformStmt(S->getFinalSuspendStmt());
8767 if (FinalSuspend.isInvalid() ||
8768 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8769 return StmtError();
8770 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8771 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8772
8773 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8774 if (BodyRes.isInvalid())
8775 return StmtError();
8776
8777 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8778 if (Builder.isInvalid())
8779 return StmtError();
8780
8781 Expr *ReturnObject = S->getReturnValueInit();
8782 assert(ReturnObject && "the return object is expected to be valid");
8783 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8784 /*NoCopyInit*/ false);
8785 if (Res.isInvalid())
8786 return StmtError();
8787 Builder.ReturnValue = Res.get();
8788
8789 // If during the previous parse the coroutine still had a dependent promise
8790 // statement, we may need to build some implicit coroutine statements
8791 // (such as exception and fallthrough handlers) for the first time.
8792 if (S->hasDependentPromiseType()) {
8793 // We can only build these statements, however, if the current promise type
8794 // is not dependent.
8795 if (!Promise->getType()->isDependentType()) {
8796 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8797 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8798 "these nodes should not have been built yet");
8799 if (!Builder.buildDependentStatements())
8800 return StmtError();
8801 }
8802 } else {
8803 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8804 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8805 if (Res.isInvalid())
8806 return StmtError();
8807 Builder.OnFallthrough = Res.get();
8808 }
8809
8810 if (auto *OnException = S->getExceptionHandler()) {
8811 StmtResult Res = getDerived().TransformStmt(OnException);
8812 if (Res.isInvalid())
8813 return StmtError();
8814 Builder.OnException = Res.get();
8815 }
8816
8817 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8818 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8819 if (Res.isInvalid())
8820 return StmtError();
8821 Builder.ReturnStmtOnAllocFailure = Res.get();
8822 }
8823
8824 // Transform any additional statements we may have already built
8825 assert(S->getAllocate() && S->getDeallocate() &&
8826 "allocation and deallocation calls must already be built");
8827 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8828 if (AllocRes.isInvalid())
8829 return StmtError();
8830 Builder.Allocate = AllocRes.get();
8831
8832 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8833 if (DeallocRes.isInvalid())
8834 return StmtError();
8835 Builder.Deallocate = DeallocRes.get();
8836
8837 if (auto *ResultDecl = S->getResultDecl()) {
8838 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8839 if (Res.isInvalid())
8840 return StmtError();
8841 Builder.ResultDecl = Res.get();
8842 }
8843
8844 if (auto *ReturnStmt = S->getReturnStmt()) {
8845 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8846 if (Res.isInvalid())
8847 return StmtError();
8848 Builder.ReturnStmt = Res.get();
8849 }
8850 }
8851
8852 return getDerived().RebuildCoroutineBodyStmt(Builder);
8853}
8854
8855template<typename Derived>
8858 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8859 /*NotCopyInit*/false);
8860 if (Result.isInvalid())
8861 return StmtError();
8862
8863 // Always rebuild; we don't know if this needs to be injected into a new
8864 // context or if the promise type has changed.
8865 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8866 S->isImplicit());
8867}
8868
8869template <typename Derived>
8871 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8872 /*NotCopyInit*/ false);
8873 if (Operand.isInvalid())
8874 return ExprError();
8875
8876 // Rebuild the common-expr from the operand rather than transforming it
8877 // separately.
8878
8879 // FIXME: getCurScope() should not be used during template instantiation.
8880 // We should pick up the set of unqualified lookup results for operator
8881 // co_await during the initial parse.
8882 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8883 getSema().getCurScope(), E->getKeywordLoc());
8884
8885 // Always rebuild; we don't know if this needs to be injected into a new
8886 // context or if the promise type has changed.
8887 return getDerived().RebuildCoawaitExpr(
8888 E->getKeywordLoc(), Operand.get(),
8889 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8890}
8891
8892template <typename Derived>
8895 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8896 /*NotCopyInit*/ false);
8897 if (OperandResult.isInvalid())
8898 return ExprError();
8899
8900 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8901 E->getOperatorCoawaitLookup());
8902
8903 if (LookupResult.isInvalid())
8904 return ExprError();
8905
8906 // Always rebuild; we don't know if this needs to be injected into a new
8907 // context or if the promise type has changed.
8908 return getDerived().RebuildDependentCoawaitExpr(
8909 E->getKeywordLoc(), OperandResult.get(),
8911}
8912
8913template<typename Derived>
8916 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8917 /*NotCopyInit*/false);
8918 if (Result.isInvalid())
8919 return ExprError();
8920
8921 // Always rebuild; we don't know if this needs to be injected into a new
8922 // context or if the promise type has changed.
8923 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8924}
8925
8926// Objective-C Statements.
8927
8928template<typename Derived>
8931 // Transform the body of the @try.
8932 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8933 if (TryBody.isInvalid())
8934 return StmtError();
8935
8936 // Transform the @catch statements (if present).
8937 bool AnyCatchChanged = false;
8938 SmallVector<Stmt*, 8> CatchStmts;
8939 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8940 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8941 if (Catch.isInvalid())
8942 return StmtError();
8943 if (Catch.get() != S->getCatchStmt(I))
8944 AnyCatchChanged = true;
8945 CatchStmts.push_back(Catch.get());
8946 }
8947
8948 // Transform the @finally statement (if present).
8949 StmtResult Finally;
8950 if (S->getFinallyStmt()) {
8951 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8952 if (Finally.isInvalid())
8953 return StmtError();
8954 }
8955
8956 // If nothing changed, just retain this statement.
8957 if (!getDerived().AlwaysRebuild() &&
8958 TryBody.get() == S->getTryBody() &&
8959 !AnyCatchChanged &&
8960 Finally.get() == S->getFinallyStmt())
8961 return S;
8962
8963 // Build a new statement.
8964 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8965 CatchStmts, Finally.get());
8966}
8967
8968template<typename Derived>
8971 // Transform the @catch parameter, if there is one.
8972 VarDecl *Var = nullptr;
8973 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8974 TypeSourceInfo *TSInfo = nullptr;
8975 if (FromVar->getTypeSourceInfo()) {
8976 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8977 if (!TSInfo)
8978 return StmtError();
8979 }
8980
8981 QualType T;
8982 if (TSInfo)
8983 T = TSInfo->getType();
8984 else {
8985 T = getDerived().TransformType(FromVar->getType());
8986 if (T.isNull())
8987 return StmtError();
8988 }
8989
8990 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8991 if (!Var)
8992 return StmtError();
8993 }
8994
8995 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8996 if (Body.isInvalid())
8997 return StmtError();
8998
8999 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9000 S->getRParenLoc(),
9001 Var, Body.get());
9002}
9003
9004template<typename Derived>
9007 // Transform the body.
9008 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9009 if (Body.isInvalid())
9010 return StmtError();
9011
9012 // If nothing changed, just retain this statement.
9013 if (!getDerived().AlwaysRebuild() &&
9014 Body.get() == S->getFinallyBody())
9015 return S;
9016
9017 // Build a new statement.
9018 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9019 Body.get());
9020}
9021
9022template<typename Derived>
9026 if (S->getThrowExpr()) {
9027 Operand = getDerived().TransformExpr(S->getThrowExpr());
9028 if (Operand.isInvalid())
9029 return StmtError();
9030 }
9031
9032 if (!getDerived().AlwaysRebuild() &&
9033 Operand.get() == S->getThrowExpr())
9034 return S;
9035
9036 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9037}
9038
9039template<typename Derived>
9043 // Transform the object we are locking.
9044 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9045 if (Object.isInvalid())
9046 return StmtError();
9047 Object =
9048 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9049 Object.get());
9050 if (Object.isInvalid())
9051 return StmtError();
9052
9053 // Transform the body.
9054 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9055 if (Body.isInvalid())
9056 return StmtError();
9057
9058 // If nothing change, just retain the current statement.
9059 if (!getDerived().AlwaysRebuild() &&
9060 Object.get() == S->getSynchExpr() &&
9061 Body.get() == S->getSynchBody())
9062 return S;
9063
9064 // Build a new statement.
9065 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9066 Object.get(), Body.get());
9067}
9068
9069template<typename Derived>
9073 // Transform the body.
9074 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9075 if (Body.isInvalid())
9076 return StmtError();
9077
9078 // If nothing changed, just retain this statement.
9079 if (!getDerived().AlwaysRebuild() &&
9080 Body.get() == S->getSubStmt())
9081 return S;
9082
9083 // Build a new statement.
9084 return getDerived().RebuildObjCAutoreleasePoolStmt(
9085 S->getAtLoc(), Body.get());
9086}
9087
9088template<typename Derived>
9092 // Transform the element statement.
9093 StmtResult Element = getDerived().TransformStmt(
9094 S->getElement(), StmtDiscardKind::NotDiscarded);
9095 if (Element.isInvalid())
9096 return StmtError();
9097
9098 // Transform the collection expression.
9099 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9100 if (Collection.isInvalid())
9101 return StmtError();
9102
9103 // Transform the body.
9104 StmtResult Body = getDerived().TransformStmt(S->getBody());
9105 if (Body.isInvalid())
9106 return StmtError();
9107
9108 // If nothing changed, just retain this statement.
9109 if (!getDerived().AlwaysRebuild() &&
9110 Element.get() == S->getElement() &&
9111 Collection.get() == S->getCollection() &&
9112 Body.get() == S->getBody())
9113 return S;
9114
9115 // Build a new statement.
9116 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9117 Element.get(),
9118 Collection.get(),
9119 S->getRParenLoc(),
9120 Body.get());
9121}
9122
9123template <typename Derived>
9125 // Transform the exception declaration, if any.
9126 VarDecl *Var = nullptr;
9127 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9128 TypeSourceInfo *T =
9129 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9130 if (!T)
9131 return StmtError();
9132
9133 Var = getDerived().RebuildExceptionDecl(
9134 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9135 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9136 if (!Var || Var->isInvalidDecl())
9137 return StmtError();
9138 }
9139
9140 // Transform the actual exception handler.
9141 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9142 if (Handler.isInvalid())
9143 return StmtError();
9144
9145 if (!getDerived().AlwaysRebuild() && !Var &&
9146 Handler.get() == S->getHandlerBlock())
9147 return S;
9148
9149 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9150}
9151
9152template <typename Derived>
9154 // Transform the try block itself.
9155 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9156 if (TryBlock.isInvalid())
9157 return StmtError();
9158
9159 // Transform the handlers.
9160 bool HandlerChanged = false;
9161 SmallVector<Stmt *, 8> Handlers;
9162 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9163 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9164 if (Handler.isInvalid())
9165 return StmtError();
9166
9167 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9168 Handlers.push_back(Handler.getAs<Stmt>());
9169 }
9170
9171 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9172
9173 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9174 !HandlerChanged)
9175 return S;
9176
9177 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9178 Handlers);
9179}
9180
9181template<typename Derived>
9184 EnterExpressionEvaluationContext ForRangeInitContext(
9186 /*LambdaContextDecl=*/nullptr,
9188 getSema().getLangOpts().CPlusPlus23);
9189
9190 // P2718R0 - Lifetime extension in range-based for loops.
9191 if (getSema().getLangOpts().CPlusPlus23) {
9192 auto &LastRecord = getSema().currentEvaluationContext();
9193 LastRecord.InLifetimeExtendingContext = true;
9194 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9195 }
9197 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9198 if (Init.isInvalid())
9199 return StmtError();
9200
9201 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9202 if (Range.isInvalid())
9203 return StmtError();
9204
9205 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9206 assert(getSema().getLangOpts().CPlusPlus23 ||
9207 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9208 auto ForRangeLifetimeExtendTemps =
9209 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9210
9211 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9212 if (Begin.isInvalid())
9213 return StmtError();
9214 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9215 if (End.isInvalid())
9216 return StmtError();
9217
9218 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9219 if (Cond.isInvalid())
9220 return StmtError();
9221 if (Cond.get())
9222 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9223 if (Cond.isInvalid())
9224 return StmtError();
9225 if (Cond.get())
9226 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9227
9228 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9229 if (Inc.isInvalid())
9230 return StmtError();
9231 if (Inc.get())
9232 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9233
9234 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9235 if (LoopVar.isInvalid())
9236 return StmtError();
9237
9238 StmtResult NewStmt = S;
9239 if (getDerived().AlwaysRebuild() ||
9240 Init.get() != S->getInit() ||
9241 Range.get() != S->getRangeStmt() ||
9242 Begin.get() != S->getBeginStmt() ||
9243 End.get() != S->getEndStmt() ||
9244 Cond.get() != S->getCond() ||
9245 Inc.get() != S->getInc() ||
9246 LoopVar.get() != S->getLoopVarStmt()) {
9247 NewStmt = getDerived().RebuildCXXForRangeStmt(
9248 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9249 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9250 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9251 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9252 // Might not have attached any initializer to the loop variable.
9253 getSema().ActOnInitializerError(
9254 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9255 return StmtError();
9256 }
9257 }
9258
9259 // OpenACC Restricts a while-loop inside of certain construct/clause
9260 // combinations, so diagnose that here in OpenACC mode.
9262 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9263
9264 StmtResult Body = getDerived().TransformStmt(S->getBody());
9265 if (Body.isInvalid())
9266 return StmtError();
9267
9268 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9269
9270 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9271 // it now so we have a new statement to attach the body to.
9272 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9273 NewStmt = getDerived().RebuildCXXForRangeStmt(
9274 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9275 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9276 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9277 if (NewStmt.isInvalid())
9278 return StmtError();
9279 }
9280
9281 if (NewStmt.get() == S)
9282 return S;
9283
9284 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9285}
9286
9287template<typename Derived>
9291 // Transform the nested-name-specifier, if any.
9292 NestedNameSpecifierLoc QualifierLoc;
9293 if (S->getQualifierLoc()) {
9294 QualifierLoc
9295 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9296 if (!QualifierLoc)
9297 return StmtError();
9298 }
9299
9300 // Transform the declaration name.
9301 DeclarationNameInfo NameInfo = S->getNameInfo();
9302 if (NameInfo.getName()) {
9303 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9304 if (!NameInfo.getName())
9305 return StmtError();
9306 }
9307
9308 // Check whether anything changed.
9309 if (!getDerived().AlwaysRebuild() &&
9310 QualifierLoc == S->getQualifierLoc() &&
9311 NameInfo.getName() == S->getNameInfo().getName())
9312 return S;
9313
9314 // Determine whether this name exists, if we can.
9315 CXXScopeSpec SS;
9316 SS.Adopt(QualifierLoc);
9317 bool Dependent = false;
9318 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9320 if (S->isIfExists())
9321 break;
9322
9323 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9324
9326 if (S->isIfNotExists())
9327 break;
9328
9329 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9330
9332 Dependent = true;
9333 break;
9334
9336 return StmtError();
9337 }
9338
9339 // We need to continue with the instantiation, so do so now.
9340 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9341 if (SubStmt.isInvalid())
9342 return StmtError();
9343
9344 // If we have resolved the name, just transform to the substatement.
9345 if (!Dependent)
9346 return SubStmt;
9347
9348 // The name is still dependent, so build a dependent expression again.
9349 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9350 S->isIfExists(),
9351 QualifierLoc,
9352 NameInfo,
9353 SubStmt.get());
9354}
9355
9356template<typename Derived>
9359 NestedNameSpecifierLoc QualifierLoc;
9360 if (E->getQualifierLoc()) {
9361 QualifierLoc
9362 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9363 if (!QualifierLoc)
9364 return ExprError();
9365 }
9366
9367 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9368 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9369 if (!PD)
9370 return ExprError();
9371
9372 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9373 if (Base.isInvalid())
9374 return ExprError();
9375
9376 return new (SemaRef.getASTContext())
9377 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9379 QualifierLoc, E->getMemberLoc());
9380}
9381
9382template <typename Derived>
9385 auto BaseRes = getDerived().TransformExpr(E->getBase());
9386 if (BaseRes.isInvalid())
9387 return ExprError();
9388 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9389 if (IdxRes.isInvalid())
9390 return ExprError();
9391
9392 if (!getDerived().AlwaysRebuild() &&
9393 BaseRes.get() == E->getBase() &&
9394 IdxRes.get() == E->getIdx())
9395 return E;
9396
9397 return getDerived().RebuildArraySubscriptExpr(
9398 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9399}
9400
9401template <typename Derived>
9403 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9404 if (TryBlock.isInvalid())
9405 return StmtError();
9406
9407 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9408 if (Handler.isInvalid())
9409 return StmtError();
9410
9411 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9412 Handler.get() == S->getHandler())
9413 return S;
9414
9415 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9416 TryBlock.get(), Handler.get());
9417}
9418
9419template <typename Derived>
9421 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9422 if (Block.isInvalid())
9423 return StmtError();
9424
9425 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9426}
9427
9428template <typename Derived>
9430 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9431 if (FilterExpr.isInvalid())
9432 return StmtError();
9433
9434 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9435 if (Block.isInvalid())
9436 return StmtError();
9437
9438 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9439 Block.get());
9440}
9441
9442template <typename Derived>
9444 if (isa<SEHFinallyStmt>(Handler))
9445 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9446 else
9447 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9448}
9449
9450template<typename Derived>
9453 return S;
9454}
9455
9456//===----------------------------------------------------------------------===//
9457// OpenMP directive transformation
9458//===----------------------------------------------------------------------===//
9459
9460template <typename Derived>
9461StmtResult
9462TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9463 // OMPCanonicalLoops are eliminated during transformation, since they will be
9464 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9465 // after transformation.
9466 return getDerived().TransformStmt(L->getLoopStmt());
9467}
9468
9469template <typename Derived>
9472
9473 // Transform the clauses
9475 ArrayRef<OMPClause *> Clauses = D->clauses();
9476 TClauses.reserve(Clauses.size());
9477 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9478 I != E; ++I) {
9479 if (*I) {
9480 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9481 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9482 getDerived().getSema().OpenMP().EndOpenMPClause();
9483 if (Clause)
9484 TClauses.push_back(Clause);
9485 } else {
9486 TClauses.push_back(nullptr);
9487 }
9488 }
9489 StmtResult AssociatedStmt;
9490 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9491 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9492 D->getDirectiveKind(),
9493 /*CurScope=*/nullptr);
9494 StmtResult Body;
9495 {
9496 Sema::CompoundScopeRAII CompoundScope(getSema());
9497 Stmt *CS;
9498 if (D->getDirectiveKind() == OMPD_atomic ||
9499 D->getDirectiveKind() == OMPD_critical ||
9500 D->getDirectiveKind() == OMPD_section ||
9501 D->getDirectiveKind() == OMPD_master)
9502 CS = D->getAssociatedStmt();
9503 else
9504 CS = D->getRawStmt();
9505 Body = getDerived().TransformStmt(CS);
9506 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9507 getSema().getLangOpts().OpenMPIRBuilder)
9508 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9509 }
9510 AssociatedStmt =
9511 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9512 if (AssociatedStmt.isInvalid()) {
9513 return StmtError();
9514 }
9515 }
9516 if (TClauses.size() != Clauses.size()) {
9517 return StmtError();
9518 }
9519
9520 // Transform directive name for 'omp critical' directive.
9521 DeclarationNameInfo DirName;
9522 if (D->getDirectiveKind() == OMPD_critical) {
9523 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9524 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9525 }
9526 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9527 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9528 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9529 } else if (D->getDirectiveKind() == OMPD_cancel) {
9530 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9531 }
9532
9533 return getDerived().RebuildOMPExecutableDirective(
9534 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9535 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9536}
9537
9538/// This is mostly the same as above, but allows 'informational' class
9539/// directives when rebuilding the stmt. It still takes an
9540/// OMPExecutableDirective-type argument because we're reusing that as the
9541/// superclass for the 'assume' directive at present, instead of defining a
9542/// mostly-identical OMPInformationalDirective parent class.
9543template <typename Derived>
9546
9547 // Transform the clauses
9549 ArrayRef<OMPClause *> Clauses = D->clauses();
9550 TClauses.reserve(Clauses.size());
9551 for (OMPClause *C : Clauses) {
9552 if (C) {
9553 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9554 OMPClause *Clause = getDerived().TransformOMPClause(C);
9555 getDerived().getSema().OpenMP().EndOpenMPClause();
9556 if (Clause)
9557 TClauses.push_back(Clause);
9558 } else {
9559 TClauses.push_back(nullptr);
9560 }
9561 }
9562 StmtResult AssociatedStmt;
9563 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9564 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9565 D->getDirectiveKind(),
9566 /*CurScope=*/nullptr);
9567 StmtResult Body;
9568 {
9569 Sema::CompoundScopeRAII CompoundScope(getSema());
9570 assert(D->getDirectiveKind() == OMPD_assume &&
9571 "Unexpected informational directive");
9572 Stmt *CS = D->getAssociatedStmt();
9573 Body = getDerived().TransformStmt(CS);
9574 }
9575 AssociatedStmt =
9576 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9577 if (AssociatedStmt.isInvalid())
9578 return StmtError();
9579 }
9580 if (TClauses.size() != Clauses.size())
9581 return StmtError();
9582
9583 DeclarationNameInfo DirName;
9584
9585 return getDerived().RebuildOMPInformationalDirective(
9586 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9587 D->getBeginLoc(), D->getEndLoc());
9588}
9589
9590template <typename Derived>
9593 // TODO: Fix This
9594 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9595 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9596 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9597 return StmtError();
9598}
9599
9600template <typename Derived>
9601StmtResult
9602TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9603 DeclarationNameInfo DirName;
9604 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9605 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9606 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9607 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9608 return Res;
9609}
9610
9611template <typename Derived>
9614 DeclarationNameInfo DirName;
9615 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9616 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9617 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9618 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9619 return Res;
9620}
9621
9622template <typename Derived>
9625 DeclarationNameInfo DirName;
9626 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9627 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9628 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9629 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9630 return Res;
9631}
9632
9633template <typename Derived>
9636 DeclarationNameInfo DirName;
9637 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9638 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9640 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9641 return Res;
9642}
9643
9644template <typename Derived>
9647 DeclarationNameInfo DirName;
9648 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9649 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9651 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9652 return Res;
9653}
9654
9655template <typename Derived>
9658 DeclarationNameInfo DirName;
9659 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9660 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9661 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9662 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9663 return Res;
9664}
9665
9666template <typename Derived>
9668 OMPInterchangeDirective *D) {
9669 DeclarationNameInfo DirName;
9670 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9671 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9672 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9673 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9674 return Res;
9675}
9676
9677template <typename Derived>
9680 DeclarationNameInfo DirName;
9681 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9682 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9683 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9684 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9685 return Res;
9686}
9687
9688template <typename Derived>
9691 DeclarationNameInfo DirName;
9692 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9693 OMPD_for, DirName, nullptr, D->getBeginLoc());
9694 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9695 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9696 return Res;
9697}
9698
9699template <typename Derived>
9702 DeclarationNameInfo DirName;
9703 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9704 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9705 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9706 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9707 return Res;
9708}
9709
9710template <typename Derived>
9713 DeclarationNameInfo DirName;
9714 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9715 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9716 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9717 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9718 return Res;
9719}
9720
9721template <typename Derived>
9724 DeclarationNameInfo DirName;
9725 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9726 OMPD_section, DirName, nullptr, D->getBeginLoc());
9727 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9728 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9729 return Res;
9730}
9731
9732template <typename Derived>
9735 DeclarationNameInfo DirName;
9736 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9737 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9738 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9739 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9740 return Res;
9741}
9742
9743template <typename Derived>
9746 DeclarationNameInfo DirName;
9747 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9748 OMPD_single, DirName, nullptr, D->getBeginLoc());
9749 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9750 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9751 return Res;
9752}
9753
9754template <typename Derived>
9757 DeclarationNameInfo DirName;
9758 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9759 OMPD_master, DirName, nullptr, D->getBeginLoc());
9760 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9761 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9762 return Res;
9763}
9764
9765template <typename Derived>
9768 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9769 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9770 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9771 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9772 return Res;
9773}
9774
9775template <typename Derived>
9777 OMPParallelForDirective *D) {
9778 DeclarationNameInfo DirName;
9779 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9780 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9781 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9782 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9783 return Res;
9784}
9785
9786template <typename Derived>
9788 OMPParallelForSimdDirective *D) {
9789 DeclarationNameInfo DirName;
9790 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9791 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9792 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9793 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9794 return Res;
9795}
9796
9797template <typename Derived>
9799 OMPParallelMasterDirective *D) {
9800 DeclarationNameInfo DirName;
9801 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9802 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9803 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9804 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9805 return Res;
9806}
9807
9808template <typename Derived>
9810 OMPParallelMaskedDirective *D) {
9811 DeclarationNameInfo DirName;
9812 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9813 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9814 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9815 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9816 return Res;
9817}
9818
9819template <typename Derived>
9821 OMPParallelSectionsDirective *D) {
9822 DeclarationNameInfo DirName;
9823 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9824 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9825 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9826 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9827 return Res;
9828}
9829
9830template <typename Derived>
9833 DeclarationNameInfo DirName;
9834 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9835 OMPD_task, DirName, nullptr, D->getBeginLoc());
9836 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9837 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9838 return Res;
9839}
9840
9841template <typename Derived>
9843 OMPTaskyieldDirective *D) {
9844 DeclarationNameInfo DirName;
9845 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9846 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9847 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9848 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9849 return Res;
9850}
9851
9852template <typename Derived>
9855 DeclarationNameInfo DirName;
9856 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9857 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9858 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9859 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9860 return Res;
9861}
9862
9863template <typename Derived>
9866 DeclarationNameInfo DirName;
9867 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9868 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9869 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9870 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9871 return Res;
9872}
9873
9874template <typename Derived>
9877 DeclarationNameInfo DirName;
9878 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9879 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9880 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9881 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9882 return Res;
9883}
9884
9885template <typename Derived>
9888 DeclarationNameInfo DirName;
9889 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9890 OMPD_error, DirName, nullptr, D->getBeginLoc());
9891 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9892 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9893 return Res;
9894}
9895
9896template <typename Derived>
9898 OMPTaskgroupDirective *D) {
9899 DeclarationNameInfo DirName;
9900 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9901 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9902 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9903 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9904 return Res;
9905}
9906
9907template <typename Derived>
9910 DeclarationNameInfo DirName;
9911 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9912 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9913 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9914 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9915 return Res;
9916}
9917
9918template <typename Derived>
9921 DeclarationNameInfo DirName;
9922 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9923 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9924 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9925 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9926 return Res;
9927}
9928
9929template <typename Derived>
9932 DeclarationNameInfo DirName;
9933 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9934 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9935 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9936 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9937 return Res;
9938}
9939
9940template <typename Derived>
9943 DeclarationNameInfo DirName;
9944 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9945 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9946 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9947 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9948 return Res;
9949}
9950
9951template <typename Derived>
9954 DeclarationNameInfo DirName;
9955 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9956 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9957 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9958 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9959 return Res;
9960}
9961
9962template <typename Derived>
9965 DeclarationNameInfo DirName;
9966 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9967 OMPD_target, DirName, nullptr, D->getBeginLoc());
9968 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9969 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9970 return Res;
9971}
9972
9973template <typename Derived>
9975 OMPTargetDataDirective *D) {
9976 DeclarationNameInfo DirName;
9977 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9978 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9979 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9980 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9981 return Res;
9982}
9983
9984template <typename Derived>
9986 OMPTargetEnterDataDirective *D) {
9987 DeclarationNameInfo DirName;
9988 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9989 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9990 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9991 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9992 return Res;
9993}
9994
9995template <typename Derived>
9997 OMPTargetExitDataDirective *D) {
9998 DeclarationNameInfo DirName;
9999 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10000 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
10001 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10002 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10003 return Res;
10004}
10005
10006template <typename Derived>
10008 OMPTargetParallelDirective *D) {
10009 DeclarationNameInfo DirName;
10010 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10011 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10012 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10013 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10014 return Res;
10015}
10016
10017template <typename Derived>
10019 OMPTargetParallelForDirective *D) {
10020 DeclarationNameInfo DirName;
10021 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10022 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10023 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10024 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10025 return Res;
10026}
10027
10028template <typename Derived>
10030 OMPTargetUpdateDirective *D) {
10031 DeclarationNameInfo DirName;
10032 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10033 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10034 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10035 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10036 return Res;
10037}
10038
10039template <typename Derived>
10042 DeclarationNameInfo DirName;
10043 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10044 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10045 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10046 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10047 return Res;
10048}
10049
10050template <typename Derived>
10052 OMPCancellationPointDirective *D) {
10053 DeclarationNameInfo DirName;
10054 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10055 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10056 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10057 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10058 return Res;
10059}
10060
10061template <typename Derived>
10064 DeclarationNameInfo DirName;
10065 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10066 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10067 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10068 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10069 return Res;
10070}
10071
10072template <typename Derived>
10075 DeclarationNameInfo DirName;
10076 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10077 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10078 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10079 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10080 return Res;
10081}
10082
10083template <typename Derived>
10085 OMPTaskLoopSimdDirective *D) {
10086 DeclarationNameInfo DirName;
10087 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10088 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10089 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10090 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10091 return Res;
10092}
10093
10094template <typename Derived>
10096 OMPMasterTaskLoopDirective *D) {
10097 DeclarationNameInfo DirName;
10098 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10099 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10100 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10101 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10102 return Res;
10103}
10104
10105template <typename Derived>
10107 OMPMaskedTaskLoopDirective *D) {
10108 DeclarationNameInfo DirName;
10109 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10110 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10111 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10112 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10113 return Res;
10114}
10115
10116template <typename Derived>
10118 OMPMasterTaskLoopSimdDirective *D) {
10119 DeclarationNameInfo DirName;
10120 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10121 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10122 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10123 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10124 return Res;
10125}
10126
10127template <typename Derived>
10129 OMPMaskedTaskLoopSimdDirective *D) {
10130 DeclarationNameInfo DirName;
10131 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10132 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10133 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10134 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10135 return Res;
10136}
10137
10138template <typename Derived>
10140 OMPParallelMasterTaskLoopDirective *D) {
10141 DeclarationNameInfo DirName;
10142 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10143 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10144 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10145 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10146 return Res;
10147}
10148
10149template <typename Derived>
10151 OMPParallelMaskedTaskLoopDirective *D) {
10152 DeclarationNameInfo DirName;
10153 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10154 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10155 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10156 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10157 return Res;
10158}
10159
10160template <typename Derived>
10163 OMPParallelMasterTaskLoopSimdDirective *D) {
10164 DeclarationNameInfo DirName;
10165 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10166 OMPD_parallel_master_taskloop_simd, 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 OMPParallelMaskedTaskLoopSimdDirective *D) {
10176 DeclarationNameInfo DirName;
10177 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10178 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10179 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10180 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10181 return Res;
10182}
10183
10184template <typename Derived>
10186 OMPDistributeDirective *D) {
10187 DeclarationNameInfo DirName;
10188 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10189 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10190 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10191 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10192 return Res;
10193}
10194
10195template <typename Derived>
10197 OMPDistributeParallelForDirective *D) {
10198 DeclarationNameInfo DirName;
10199 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10200 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10201 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10202 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10203 return Res;
10204}
10205
10206template <typename Derived>
10209 OMPDistributeParallelForSimdDirective *D) {
10210 DeclarationNameInfo DirName;
10211 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10212 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10213 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10214 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10215 return Res;
10216}
10217
10218template <typename Derived>
10220 OMPDistributeSimdDirective *D) {
10221 DeclarationNameInfo DirName;
10222 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10223 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10224 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10225 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10226 return Res;
10227}
10228
10229template <typename Derived>
10231 OMPTargetParallelForSimdDirective *D) {
10232 DeclarationNameInfo DirName;
10233 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10234 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10235 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10236 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10237 return Res;
10238}
10239
10240template <typename Derived>
10242 OMPTargetSimdDirective *D) {
10243 DeclarationNameInfo DirName;
10244 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10245 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10246 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10247 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10248 return Res;
10249}
10250
10251template <typename Derived>
10253 OMPTeamsDistributeDirective *D) {
10254 DeclarationNameInfo DirName;
10255 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10256 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10257 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10258 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10259 return Res;
10260}
10261
10262template <typename Derived>
10264 OMPTeamsDistributeSimdDirective *D) {
10265 DeclarationNameInfo DirName;
10266 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10267 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10269 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10270 return Res;
10271}
10272
10273template <typename Derived>
10275 OMPTeamsDistributeParallelForSimdDirective *D) {
10276 DeclarationNameInfo DirName;
10277 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10278 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10279 D->getBeginLoc());
10280 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10281 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10282 return Res;
10283}
10284
10285template <typename Derived>
10287 OMPTeamsDistributeParallelForDirective *D) {
10288 DeclarationNameInfo DirName;
10289 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10290 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10291 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10292 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10293 return Res;
10294}
10295
10296template <typename Derived>
10298 OMPTargetTeamsDirective *D) {
10299 DeclarationNameInfo DirName;
10300 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10301 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10302 auto Res = getDerived().TransformOMPExecutableDirective(D);
10303 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10304 return Res;
10305}
10306
10307template <typename Derived>
10309 OMPTargetTeamsDistributeDirective *D) {
10310 DeclarationNameInfo DirName;
10311 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10312 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10313 auto Res = getDerived().TransformOMPExecutableDirective(D);
10314 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10315 return Res;
10316}
10317
10318template <typename Derived>
10321 OMPTargetTeamsDistributeParallelForDirective *D) {
10322 DeclarationNameInfo DirName;
10323 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10324 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10325 D->getBeginLoc());
10326 auto Res = getDerived().TransformOMPExecutableDirective(D);
10327 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10328 return Res;
10329}
10330
10331template <typename Derived>
10334 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10335 DeclarationNameInfo DirName;
10336 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10337 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10338 D->getBeginLoc());
10339 auto Res = getDerived().TransformOMPExecutableDirective(D);
10340 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10341 return Res;
10342}
10343
10344template <typename Derived>
10347 OMPTargetTeamsDistributeSimdDirective *D) {
10348 DeclarationNameInfo DirName;
10349 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10350 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10351 auto Res = getDerived().TransformOMPExecutableDirective(D);
10352 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10353 return Res;
10354}
10355
10356template <typename Derived>
10359 DeclarationNameInfo DirName;
10360 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10361 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10363 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10364 return Res;
10365}
10366
10367template <typename Derived>
10370 DeclarationNameInfo DirName;
10371 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10372 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10373 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10374 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10375 return Res;
10376}
10377
10378template <typename Derived>
10381 DeclarationNameInfo DirName;
10382 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10383 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10384 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10385 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10386 return Res;
10387}
10388
10389template <typename Derived>
10391 OMPGenericLoopDirective *D) {
10392 DeclarationNameInfo DirName;
10393 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10394 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10395 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10396 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10397 return Res;
10398}
10399
10400template <typename Derived>
10402 OMPTeamsGenericLoopDirective *D) {
10403 DeclarationNameInfo DirName;
10404 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10405 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10406 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10407 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10408 return Res;
10409}
10410
10411template <typename Derived>
10413 OMPTargetTeamsGenericLoopDirective *D) {
10414 DeclarationNameInfo DirName;
10415 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10416 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10417 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10418 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10419 return Res;
10420}
10421
10422template <typename Derived>
10424 OMPParallelGenericLoopDirective *D) {
10425 DeclarationNameInfo DirName;
10426 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10427 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10428 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10429 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10430 return Res;
10431}
10432
10433template <typename Derived>
10436 OMPTargetParallelGenericLoopDirective *D) {
10437 DeclarationNameInfo DirName;
10438 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10439 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10440 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10441 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10442 return Res;
10443}
10444
10445//===----------------------------------------------------------------------===//
10446// OpenMP clause transformation
10447//===----------------------------------------------------------------------===//
10448template <typename Derived>
10450 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10451 if (Cond.isInvalid())
10452 return nullptr;
10453 return getDerived().RebuildOMPIfClause(
10454 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10455 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10456}
10457
10458template <typename Derived>
10460 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10461 if (Cond.isInvalid())
10462 return nullptr;
10463 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10464 C->getLParenLoc(), C->getEndLoc());
10465}
10466
10467template <typename Derived>
10468OMPClause *
10470 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10471 if (NumThreads.isInvalid())
10472 return nullptr;
10473 return getDerived().RebuildOMPNumThreadsClause(
10474 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10475 C->getModifierLoc(), C->getEndLoc());
10476}
10477
10478template <typename Derived>
10479OMPClause *
10481 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10482 if (E.isInvalid())
10483 return nullptr;
10484 return getDerived().RebuildOMPSafelenClause(
10485 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10486}
10487
10488template <typename Derived>
10489OMPClause *
10491 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10492 if (E.isInvalid())
10493 return nullptr;
10494 return getDerived().RebuildOMPAllocatorClause(
10495 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10496}
10497
10498template <typename Derived>
10499OMPClause *
10501 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10502 if (E.isInvalid())
10503 return nullptr;
10504 return getDerived().RebuildOMPSimdlenClause(
10505 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10506}
10507
10508template <typename Derived>
10510 SmallVector<Expr *, 4> TransformedSizes;
10511 TransformedSizes.reserve(C->getNumSizes());
10512 bool Changed = false;
10513 for (Expr *E : C->getSizesRefs()) {
10514 if (!E) {
10515 TransformedSizes.push_back(nullptr);
10516 continue;
10517 }
10518
10519 ExprResult T = getDerived().TransformExpr(E);
10520 if (T.isInvalid())
10521 return nullptr;
10522 if (E != T.get())
10523 Changed = true;
10524 TransformedSizes.push_back(T.get());
10525 }
10526
10527 if (!Changed && !getDerived().AlwaysRebuild())
10528 return C;
10529 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10530 C->getLParenLoc(), C->getEndLoc());
10531}
10532
10533template <typename Derived>
10534OMPClause *
10536 SmallVector<Expr *> TransformedArgs;
10537 TransformedArgs.reserve(C->getNumLoops());
10538 bool Changed = false;
10539 for (Expr *E : C->getArgsRefs()) {
10540 if (!E) {
10541 TransformedArgs.push_back(nullptr);
10542 continue;
10543 }
10544
10545 ExprResult T = getDerived().TransformExpr(E);
10546 if (T.isInvalid())
10547 return nullptr;
10548 if (E != T.get())
10549 Changed = true;
10550 TransformedArgs.push_back(T.get());
10551 }
10552
10553 if (!Changed && !getDerived().AlwaysRebuild())
10554 return C;
10555 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10556 C->getLParenLoc(), C->getEndLoc());
10557}
10558
10559template <typename Derived>
10561 if (!getDerived().AlwaysRebuild())
10562 return C;
10563 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10564}
10565
10566template <typename Derived>
10567OMPClause *
10569 ExprResult T = getDerived().TransformExpr(C->getFactor());
10570 if (T.isInvalid())
10571 return nullptr;
10572 Expr *Factor = T.get();
10573 bool Changed = Factor != C->getFactor();
10574
10575 if (!Changed && !getDerived().AlwaysRebuild())
10576 return C;
10577 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10578 C->getEndLoc());
10579}
10580
10581template <typename Derived>
10582OMPClause *
10584 ExprResult F = getDerived().TransformExpr(C->getFirst());
10585 if (F.isInvalid())
10586 return nullptr;
10587
10588 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10589 if (Cn.isInvalid())
10590 return nullptr;
10591
10592 Expr *First = F.get();
10593 Expr *Count = Cn.get();
10594
10595 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10596
10597 // If no changes and AlwaysRebuild() is false, return the original clause
10598 if (!Changed && !getDerived().AlwaysRebuild())
10599 return C;
10600
10601 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10602 C->getLParenLoc(), C->getFirstLoc(),
10603 C->getCountLoc(), C->getEndLoc());
10604}
10605
10606template <typename Derived>
10607OMPClause *
10609 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10610 if (E.isInvalid())
10611 return nullptr;
10612 return getDerived().RebuildOMPCollapseClause(
10613 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10614}
10615
10616template <typename Derived>
10617OMPClause *
10619 return getDerived().RebuildOMPDefaultClause(
10620 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10621 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10622 C->getEndLoc());
10623}
10624
10625template <typename Derived>
10626OMPClause *
10628 return getDerived().RebuildOMPProcBindClause(
10629 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10630 C->getLParenLoc(), C->getEndLoc());
10631}
10632
10633template <typename Derived>
10634OMPClause *
10636 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10637 if (E.isInvalid())
10638 return nullptr;
10639 return getDerived().RebuildOMPScheduleClause(
10640 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10641 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10642 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10643 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10644}
10645
10646template <typename Derived>
10647OMPClause *
10649 ExprResult E;
10650 if (auto *Num = C->getNumForLoops()) {
10651 E = getDerived().TransformExpr(Num);
10652 if (E.isInvalid())
10653 return nullptr;
10654 }
10655 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10656 C->getLParenLoc(), E.get());
10657}
10658
10659template <typename Derived>
10660OMPClause *
10662 ExprResult E;
10663 if (Expr *Evt = C->getEventHandler()) {
10664 E = getDerived().TransformExpr(Evt);
10665 if (E.isInvalid())
10666 return nullptr;
10667 }
10668 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10669 C->getLParenLoc(), C->getEndLoc());
10670}
10671
10672template <typename Derived>
10673OMPClause *
10676 if (auto *Condition = C->getCondition()) {
10677 Cond = getDerived().TransformExpr(Condition);
10678 if (Cond.isInvalid())
10679 return nullptr;
10680 }
10681 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
10682 C->getLParenLoc(), C->getEndLoc());
10683}
10684
10685template <typename Derived>
10686OMPClause *
10688 // No need to rebuild this clause, no template-dependent parameters.
10689 return C;
10690}
10691
10692template <typename Derived>
10693OMPClause *
10695 // No need to rebuild this clause, no template-dependent parameters.
10696 return C;
10697}
10698
10699template <typename Derived>
10701 // No need to rebuild this clause, no template-dependent parameters.
10702 return C;
10703}
10704
10705template <typename Derived>
10707 // No need to rebuild this clause, no template-dependent parameters.
10708 return C;
10709}
10710
10711template <typename Derived>
10712OMPClause *
10714 // No need to rebuild this clause, no template-dependent parameters.
10715 return C;
10716}
10717
10718template <typename Derived>
10719OMPClause *
10721 // No need to rebuild this clause, no template-dependent parameters.
10722 return C;
10723}
10724
10725template <typename Derived>
10726OMPClause *
10728 // No need to rebuild this clause, no template-dependent parameters.
10729 return C;
10730}
10731
10732template <typename Derived>
10734 // No need to rebuild this clause, no template-dependent parameters.
10735 return C;
10736}
10737
10738template <typename Derived>
10739OMPClause *
10741 return C;
10742}
10743
10744template <typename Derived>
10746 ExprResult E = getDerived().TransformExpr(C->getExpr());
10747 if (E.isInvalid())
10748 return nullptr;
10749 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10750 C->getLParenLoc(), C->getEndLoc());
10751}
10752
10753template <typename Derived>
10754OMPClause *
10756 return C;
10757}
10758
10759template <typename Derived>
10760OMPClause *
10762 return C;
10763}
10764template <typename Derived>
10767 return C;
10768}
10769template <typename Derived>
10772 return C;
10773}
10774template <typename Derived>
10777 return C;
10778}
10779
10780template <typename Derived>
10781OMPClause *
10783 // No need to rebuild this clause, no template-dependent parameters.
10784 return C;
10785}
10786
10787template <typename Derived>
10788OMPClause *
10790 // No need to rebuild this clause, no template-dependent parameters.
10791 return C;
10792}
10793
10794template <typename Derived>
10795OMPClause *
10797 // No need to rebuild this clause, no template-dependent parameters.
10798 return C;
10799}
10800
10801template <typename Derived>
10802OMPClause *
10804 // No need to rebuild this clause, no template-dependent parameters.
10805 return C;
10806}
10807
10808template <typename Derived>
10809OMPClause *
10811 // No need to rebuild this clause, no template-dependent parameters.
10812 return C;
10813}
10814
10815template <typename Derived>
10817 // No need to rebuild this clause, no template-dependent parameters.
10818 return C;
10819}
10820
10821template <typename Derived>
10822OMPClause *
10824 // No need to rebuild this clause, no template-dependent parameters.
10825 return C;
10826}
10827
10828template <typename Derived>
10830 // No need to rebuild this clause, no template-dependent parameters.
10831 return C;
10832}
10833
10834template <typename Derived>
10835OMPClause *
10837 // No need to rebuild this clause, no template-dependent parameters.
10838 return C;
10839}
10840
10841template <typename Derived>
10843 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10844 if (IVR.isInvalid())
10845 return nullptr;
10846
10847 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10848 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10849 for (Expr *E : llvm::drop_begin(C->varlist())) {
10850 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10851 if (ER.isInvalid())
10852 return nullptr;
10853 InteropInfo.PreferTypes.push_back(ER.get());
10854 }
10855 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10856 C->getBeginLoc(), C->getLParenLoc(),
10857 C->getVarLoc(), C->getEndLoc());
10858}
10859
10860template <typename Derived>
10862 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10863 if (ER.isInvalid())
10864 return nullptr;
10865 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10866 C->getLParenLoc(), C->getVarLoc(),
10867 C->getEndLoc());
10868}
10869
10870template <typename Derived>
10871OMPClause *
10873 ExprResult ER;
10874 if (Expr *IV = C->getInteropVar()) {
10875 ER = getDerived().TransformExpr(IV);
10876 if (ER.isInvalid())
10877 return nullptr;
10878 }
10879 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10880 C->getLParenLoc(), C->getVarLoc(),
10881 C->getEndLoc());
10882}
10883
10884template <typename Derived>
10885OMPClause *
10887 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10888 if (Cond.isInvalid())
10889 return nullptr;
10890 return getDerived().RebuildOMPNovariantsClause(
10891 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10892}
10893
10894template <typename Derived>
10895OMPClause *
10897 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10898 if (Cond.isInvalid())
10899 return nullptr;
10900 return getDerived().RebuildOMPNocontextClause(
10901 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10902}
10903
10904template <typename Derived>
10905OMPClause *
10907 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10908 if (ThreadID.isInvalid())
10909 return nullptr;
10910 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10911 C->getLParenLoc(), C->getEndLoc());
10912}
10913
10914template <typename Derived>
10916 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10917 if (E.isInvalid())
10918 return nullptr;
10919 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10920 C->getLParenLoc(), C->getEndLoc());
10921}
10922
10923template <typename Derived>
10926 llvm_unreachable("unified_address clause cannot appear in dependent context");
10927}
10928
10929template <typename Derived>
10932 llvm_unreachable(
10933 "unified_shared_memory clause cannot appear in dependent context");
10934}
10935
10936template <typename Derived>
10939 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10940}
10941
10942template <typename Derived>
10945 llvm_unreachable(
10946 "dynamic_allocators clause cannot appear in dependent context");
10947}
10948
10949template <typename Derived>
10952 llvm_unreachable(
10953 "atomic_default_mem_order clause cannot appear in dependent context");
10954}
10955
10956template <typename Derived>
10957OMPClause *
10959 llvm_unreachable("self_maps clause cannot appear in dependent context");
10960}
10961
10962template <typename Derived>
10964 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10965 C->getBeginLoc(), C->getLParenLoc(),
10966 C->getEndLoc());
10967}
10968
10969template <typename Derived>
10970OMPClause *
10972 return getDerived().RebuildOMPSeverityClause(
10973 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10974 C->getLParenLoc(), C->getEndLoc());
10975}
10976
10977template <typename Derived>
10978OMPClause *
10980 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10981 if (E.isInvalid())
10982 return nullptr;
10983 return getDerived().RebuildOMPMessageClause(
10984 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10985}
10986
10987template <typename Derived>
10988OMPClause *
10991 Vars.reserve(C->varlist_size());
10992 for (auto *VE : C->varlist()) {
10993 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10994 if (EVar.isInvalid())
10995 return nullptr;
10996 Vars.push_back(EVar.get());
10997 }
10998 return getDerived().RebuildOMPPrivateClause(
10999 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11000}
11001
11002template <typename Derived>
11006 Vars.reserve(C->varlist_size());
11007 for (auto *VE : C->varlist()) {
11008 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11009 if (EVar.isInvalid())
11010 return nullptr;
11011 Vars.push_back(EVar.get());
11012 }
11013 return getDerived().RebuildOMPFirstprivateClause(
11014 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11015}
11016
11017template <typename Derived>
11018OMPClause *
11021 Vars.reserve(C->varlist_size());
11022 for (auto *VE : C->varlist()) {
11023 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11024 if (EVar.isInvalid())
11025 return nullptr;
11026 Vars.push_back(EVar.get());
11027 }
11028 return getDerived().RebuildOMPLastprivateClause(
11029 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11030 C->getLParenLoc(), C->getEndLoc());
11031}
11032
11033template <typename Derived>
11034OMPClause *
11037 Vars.reserve(C->varlist_size());
11038 for (auto *VE : C->varlist()) {
11039 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11040 if (EVar.isInvalid())
11041 return nullptr;
11042 Vars.push_back(EVar.get());
11043 }
11044 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11045 C->getLParenLoc(), C->getEndLoc());
11046}
11047
11048template <typename Derived>
11049OMPClause *
11052 Vars.reserve(C->varlist_size());
11053 for (auto *VE : C->varlist()) {
11054 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11055 if (EVar.isInvalid())
11056 return nullptr;
11057 Vars.push_back(EVar.get());
11058 }
11059 CXXScopeSpec ReductionIdScopeSpec;
11060 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11061
11062 DeclarationNameInfo NameInfo = C->getNameInfo();
11063 if (NameInfo.getName()) {
11064 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11065 if (!NameInfo.getName())
11066 return nullptr;
11067 }
11068 // Build a list of all UDR decls with the same names ranged by the Scopes.
11069 // The Scope boundary is a duplication of the previous decl.
11070 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11071 for (auto *E : C->reduction_ops()) {
11072 // Transform all the decls.
11073 if (E) {
11074 auto *ULE = cast<UnresolvedLookupExpr>(E);
11075 UnresolvedSet<8> Decls;
11076 for (auto *D : ULE->decls()) {
11077 NamedDecl *InstD =
11078 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11079 Decls.addDecl(InstD, InstD->getAccess());
11080 }
11081 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11082 SemaRef.Context, /*NamingClass=*/nullptr,
11083 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11084 /*ADL=*/true, Decls.begin(), Decls.end(),
11085 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11086 } else
11087 UnresolvedReductions.push_back(nullptr);
11088 }
11089 return getDerived().RebuildOMPReductionClause(
11090 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11091 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11092 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11093}
11094
11095template <typename Derived>
11099 Vars.reserve(C->varlist_size());
11100 for (auto *VE : C->varlist()) {
11101 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11102 if (EVar.isInvalid())
11103 return nullptr;
11104 Vars.push_back(EVar.get());
11105 }
11106 CXXScopeSpec ReductionIdScopeSpec;
11107 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11108
11109 DeclarationNameInfo NameInfo = C->getNameInfo();
11110 if (NameInfo.getName()) {
11111 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11112 if (!NameInfo.getName())
11113 return nullptr;
11114 }
11115 // Build a list of all UDR decls with the same names ranged by the Scopes.
11116 // The Scope boundary is a duplication of the previous decl.
11117 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11118 for (auto *E : C->reduction_ops()) {
11119 // Transform all the decls.
11120 if (E) {
11121 auto *ULE = cast<UnresolvedLookupExpr>(E);
11122 UnresolvedSet<8> Decls;
11123 for (auto *D : ULE->decls()) {
11124 NamedDecl *InstD =
11125 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11126 Decls.addDecl(InstD, InstD->getAccess());
11127 }
11128 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11129 SemaRef.Context, /*NamingClass=*/nullptr,
11130 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11131 /*ADL=*/true, Decls.begin(), Decls.end(),
11132 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11133 } else
11134 UnresolvedReductions.push_back(nullptr);
11135 }
11136 return getDerived().RebuildOMPTaskReductionClause(
11137 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11138 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11139}
11140
11141template <typename Derived>
11142OMPClause *
11145 Vars.reserve(C->varlist_size());
11146 for (auto *VE : C->varlist()) {
11147 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11148 if (EVar.isInvalid())
11149 return nullptr;
11150 Vars.push_back(EVar.get());
11151 }
11152 CXXScopeSpec ReductionIdScopeSpec;
11153 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11154
11155 DeclarationNameInfo NameInfo = C->getNameInfo();
11156 if (NameInfo.getName()) {
11157 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11158 if (!NameInfo.getName())
11159 return nullptr;
11160 }
11161 // Build a list of all UDR decls with the same names ranged by the Scopes.
11162 // The Scope boundary is a duplication of the previous decl.
11163 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11164 for (auto *E : C->reduction_ops()) {
11165 // Transform all the decls.
11166 if (E) {
11167 auto *ULE = cast<UnresolvedLookupExpr>(E);
11168 UnresolvedSet<8> Decls;
11169 for (auto *D : ULE->decls()) {
11170 NamedDecl *InstD =
11171 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11172 Decls.addDecl(InstD, InstD->getAccess());
11173 }
11174 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11175 SemaRef.Context, /*NamingClass=*/nullptr,
11176 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11177 /*ADL=*/true, Decls.begin(), Decls.end(),
11178 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11179 } else
11180 UnresolvedReductions.push_back(nullptr);
11181 }
11182 return getDerived().RebuildOMPInReductionClause(
11183 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11184 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11185}
11186
11187template <typename Derived>
11188OMPClause *
11191 Vars.reserve(C->varlist_size());
11192 for (auto *VE : C->varlist()) {
11193 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11194 if (EVar.isInvalid())
11195 return nullptr;
11196 Vars.push_back(EVar.get());
11197 }
11198 ExprResult Step = getDerived().TransformExpr(C->getStep());
11199 if (Step.isInvalid())
11200 return nullptr;
11201 return getDerived().RebuildOMPLinearClause(
11202 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11203 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11204 C->getEndLoc());
11205}
11206
11207template <typename Derived>
11208OMPClause *
11211 Vars.reserve(C->varlist_size());
11212 for (auto *VE : C->varlist()) {
11213 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11214 if (EVar.isInvalid())
11215 return nullptr;
11216 Vars.push_back(EVar.get());
11217 }
11218 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11219 if (Alignment.isInvalid())
11220 return nullptr;
11221 return getDerived().RebuildOMPAlignedClause(
11222 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11223 C->getColonLoc(), C->getEndLoc());
11224}
11225
11226template <typename Derived>
11227OMPClause *
11230 Vars.reserve(C->varlist_size());
11231 for (auto *VE : C->varlist()) {
11232 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11233 if (EVar.isInvalid())
11234 return nullptr;
11235 Vars.push_back(EVar.get());
11236 }
11237 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11238 C->getLParenLoc(), C->getEndLoc());
11239}
11240
11241template <typename Derived>
11242OMPClause *
11245 Vars.reserve(C->varlist_size());
11246 for (auto *VE : C->varlist()) {
11247 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11248 if (EVar.isInvalid())
11249 return nullptr;
11250 Vars.push_back(EVar.get());
11251 }
11252 return getDerived().RebuildOMPCopyprivateClause(
11253 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11254}
11255
11256template <typename Derived>
11259 Vars.reserve(C->varlist_size());
11260 for (auto *VE : C->varlist()) {
11261 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11262 if (EVar.isInvalid())
11263 return nullptr;
11264 Vars.push_back(EVar.get());
11265 }
11266 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11267 C->getLParenLoc(), C->getEndLoc());
11268}
11269
11270template <typename Derived>
11271OMPClause *
11273 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11274 if (E.isInvalid())
11275 return nullptr;
11276 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11277 C->getLParenLoc(), C->getEndLoc());
11278}
11279
11280template <typename Derived>
11281OMPClause *
11284 Expr *DepModifier = C->getModifier();
11285 if (DepModifier) {
11286 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11287 if (DepModRes.isInvalid())
11288 return nullptr;
11289 DepModifier = DepModRes.get();
11290 }
11291 Vars.reserve(C->varlist_size());
11292 for (auto *VE : C->varlist()) {
11293 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11294 if (EVar.isInvalid())
11295 return nullptr;
11296 Vars.push_back(EVar.get());
11297 }
11298 return getDerived().RebuildOMPDependClause(
11299 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11300 C->getOmpAllMemoryLoc()},
11301 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11302}
11303
11304template <typename Derived>
11305OMPClause *
11307 ExprResult E = getDerived().TransformExpr(C->getDevice());
11308 if (E.isInvalid())
11309 return nullptr;
11310 return getDerived().RebuildOMPDeviceClause(
11311 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11312 C->getModifierLoc(), C->getEndLoc());
11313}
11314
11315template <typename Derived, class T>
11318 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11319 DeclarationNameInfo &MapperIdInfo,
11320 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11321 // Transform expressions in the list.
11322 Vars.reserve(C->varlist_size());
11323 for (auto *VE : C->varlist()) {
11324 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11325 if (EVar.isInvalid())
11326 return true;
11327 Vars.push_back(EVar.get());
11328 }
11329 // Transform mapper scope specifier and identifier.
11330 NestedNameSpecifierLoc QualifierLoc;
11331 if (C->getMapperQualifierLoc()) {
11332 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11333 C->getMapperQualifierLoc());
11334 if (!QualifierLoc)
11335 return true;
11336 }
11337 MapperIdScopeSpec.Adopt(QualifierLoc);
11338 MapperIdInfo = C->getMapperIdInfo();
11339 if (MapperIdInfo.getName()) {
11340 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11341 if (!MapperIdInfo.getName())
11342 return true;
11343 }
11344 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11345 // the previous user-defined mapper lookup in dependent environment.
11346 for (auto *E : C->mapperlists()) {
11347 // Transform all the decls.
11348 if (E) {
11349 auto *ULE = cast<UnresolvedLookupExpr>(E);
11350 UnresolvedSet<8> Decls;
11351 for (auto *D : ULE->decls()) {
11352 NamedDecl *InstD =
11353 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11354 Decls.addDecl(InstD, InstD->getAccess());
11355 }
11356 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11357 TT.getSema().Context, /*NamingClass=*/nullptr,
11358 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11359 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11360 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11361 } else {
11362 UnresolvedMappers.push_back(nullptr);
11363 }
11364 }
11365 return false;
11366}
11367
11368template <typename Derived>
11369OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11370 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11372 Expr *IteratorModifier = C->getIteratorModifier();
11373 if (IteratorModifier) {
11374 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11375 if (MapModRes.isInvalid())
11376 return nullptr;
11377 IteratorModifier = MapModRes.get();
11378 }
11379 CXXScopeSpec MapperIdScopeSpec;
11380 DeclarationNameInfo MapperIdInfo;
11381 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11383 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11384 return nullptr;
11385 return getDerived().RebuildOMPMapClause(
11386 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11387 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11388 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11389}
11390
11391template <typename Derived>
11392OMPClause *
11394 Expr *Allocator = C->getAllocator();
11395 if (Allocator) {
11396 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11397 if (AllocatorRes.isInvalid())
11398 return nullptr;
11399 Allocator = AllocatorRes.get();
11400 }
11401 Expr *Alignment = C->getAlignment();
11402 if (Alignment) {
11403 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11404 if (AlignmentRes.isInvalid())
11405 return nullptr;
11406 Alignment = AlignmentRes.get();
11407 }
11409 Vars.reserve(C->varlist_size());
11410 for (auto *VE : C->varlist()) {
11411 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11412 if (EVar.isInvalid())
11413 return nullptr;
11414 Vars.push_back(EVar.get());
11415 }
11416 return getDerived().RebuildOMPAllocateClause(
11417 Allocator, Alignment, C->getFirstAllocateModifier(),
11418 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11419 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11420 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11421}
11422
11423template <typename Derived>
11424OMPClause *
11427 Vars.reserve(C->varlist_size());
11428 for (auto *VE : C->varlist()) {
11429 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11430 if (EVar.isInvalid())
11431 return nullptr;
11432 Vars.push_back(EVar.get());
11433 }
11434 return getDerived().RebuildOMPNumTeamsClause(
11435 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11436}
11437
11438template <typename Derived>
11439OMPClause *
11442 Vars.reserve(C->varlist_size());
11443 for (auto *VE : C->varlist()) {
11444 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11445 if (EVar.isInvalid())
11446 return nullptr;
11447 Vars.push_back(EVar.get());
11448 }
11449 return getDerived().RebuildOMPThreadLimitClause(
11450 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11451}
11452
11453template <typename Derived>
11454OMPClause *
11456 ExprResult E = getDerived().TransformExpr(C->getPriority());
11457 if (E.isInvalid())
11458 return nullptr;
11459 return getDerived().RebuildOMPPriorityClause(
11460 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11461}
11462
11463template <typename Derived>
11464OMPClause *
11466 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11467 if (E.isInvalid())
11468 return nullptr;
11469 return getDerived().RebuildOMPGrainsizeClause(
11470 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11471 C->getModifierLoc(), C->getEndLoc());
11472}
11473
11474template <typename Derived>
11475OMPClause *
11477 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11478 if (E.isInvalid())
11479 return nullptr;
11480 return getDerived().RebuildOMPNumTasksClause(
11481 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11482 C->getModifierLoc(), C->getEndLoc());
11483}
11484
11485template <typename Derived>
11487 ExprResult E = getDerived().TransformExpr(C->getHint());
11488 if (E.isInvalid())
11489 return nullptr;
11490 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11491 C->getLParenLoc(), C->getEndLoc());
11492}
11493
11494template <typename Derived>
11497 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11498 if (E.isInvalid())
11499 return nullptr;
11500 return getDerived().RebuildOMPDistScheduleClause(
11501 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11502 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11503}
11504
11505template <typename Derived>
11506OMPClause *
11508 // Rebuild Defaultmap Clause since we need to invoke the checking of
11509 // defaultmap(none:variable-category) after template initialization.
11510 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11511 C->getDefaultmapKind(),
11512 C->getBeginLoc(),
11513 C->getLParenLoc(),
11514 C->getDefaultmapModifierLoc(),
11515 C->getDefaultmapKindLoc(),
11516 C->getEndLoc());
11517}
11518
11519template <typename Derived>
11521 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11523 CXXScopeSpec MapperIdScopeSpec;
11524 DeclarationNameInfo MapperIdInfo;
11525 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11527 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11528 return nullptr;
11529 return getDerived().RebuildOMPToClause(
11530 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11531 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11532}
11533
11534template <typename Derived>
11536 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11538 CXXScopeSpec MapperIdScopeSpec;
11539 DeclarationNameInfo MapperIdInfo;
11540 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11542 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11543 return nullptr;
11544 return getDerived().RebuildOMPFromClause(
11545 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11546 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11547}
11548
11549template <typename Derived>
11553 Vars.reserve(C->varlist_size());
11554 for (auto *VE : C->varlist()) {
11555 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11556 if (EVar.isInvalid())
11557 return nullptr;
11558 Vars.push_back(EVar.get());
11559 }
11560 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11561 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11562}
11563
11564template <typename Derived>
11568 Vars.reserve(C->varlist_size());
11569 for (auto *VE : C->varlist()) {
11570 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11571 if (EVar.isInvalid())
11572 return nullptr;
11573 Vars.push_back(EVar.get());
11574 }
11575 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11576 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11577}
11578
11579template <typename Derived>
11580OMPClause *
11583 Vars.reserve(C->varlist_size());
11584 for (auto *VE : C->varlist()) {
11585 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11586 if (EVar.isInvalid())
11587 return nullptr;
11588 Vars.push_back(EVar.get());
11589 }
11590 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11591 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11592}
11593
11594template <typename Derived>
11598 Vars.reserve(C->varlist_size());
11599 for (auto *VE : C->varlist()) {
11600 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11601 if (EVar.isInvalid())
11602 return nullptr;
11603 Vars.push_back(EVar.get());
11604 }
11605 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11606 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11607}
11608
11609template <typename Derived>
11610OMPClause *
11613 Vars.reserve(C->varlist_size());
11614 for (auto *VE : C->varlist()) {
11615 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11616 if (EVar.isInvalid())
11617 return nullptr;
11618 Vars.push_back(EVar.get());
11619 }
11620 return getDerived().RebuildOMPNontemporalClause(
11621 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11622}
11623
11624template <typename Derived>
11625OMPClause *
11628 Vars.reserve(C->varlist_size());
11629 for (auto *VE : C->varlist()) {
11630 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11631 if (EVar.isInvalid())
11632 return nullptr;
11633 Vars.push_back(EVar.get());
11634 }
11635 return getDerived().RebuildOMPInclusiveClause(
11636 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11637}
11638
11639template <typename Derived>
11640OMPClause *
11643 Vars.reserve(C->varlist_size());
11644 for (auto *VE : C->varlist()) {
11645 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11646 if (EVar.isInvalid())
11647 return nullptr;
11648 Vars.push_back(EVar.get());
11649 }
11650 return getDerived().RebuildOMPExclusiveClause(
11651 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11652}
11653
11654template <typename Derived>
11658 Data.reserve(C->getNumberOfAllocators());
11659 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11660 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11661 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11662 if (Allocator.isInvalid())
11663 continue;
11664 ExprResult AllocatorTraits;
11665 if (Expr *AT = D.AllocatorTraits) {
11666 AllocatorTraits = getDerived().TransformExpr(AT);
11667 if (AllocatorTraits.isInvalid())
11668 continue;
11669 }
11670 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11671 NewD.Allocator = Allocator.get();
11672 NewD.AllocatorTraits = AllocatorTraits.get();
11673 NewD.LParenLoc = D.LParenLoc;
11674 NewD.RParenLoc = D.RParenLoc;
11675 }
11676 return getDerived().RebuildOMPUsesAllocatorsClause(
11677 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11678}
11679
11680template <typename Derived>
11681OMPClause *
11683 SmallVector<Expr *, 4> Locators;
11684 Locators.reserve(C->varlist_size());
11685 ExprResult ModifierRes;
11686 if (Expr *Modifier = C->getModifier()) {
11687 ModifierRes = getDerived().TransformExpr(Modifier);
11688 if (ModifierRes.isInvalid())
11689 return nullptr;
11690 }
11691 for (Expr *E : C->varlist()) {
11692 ExprResult Locator = getDerived().TransformExpr(E);
11693 if (Locator.isInvalid())
11694 continue;
11695 Locators.push_back(Locator.get());
11696 }
11697 return getDerived().RebuildOMPAffinityClause(
11698 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11699 ModifierRes.get(), Locators);
11700}
11701
11702template <typename Derived>
11704 return getDerived().RebuildOMPOrderClause(
11705 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11706 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11707}
11708
11709template <typename Derived>
11711 return getDerived().RebuildOMPBindClause(
11712 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11713 C->getLParenLoc(), C->getEndLoc());
11714}
11715
11716template <typename Derived>
11719 ExprResult Size = getDerived().TransformExpr(C->getSize());
11720 if (Size.isInvalid())
11721 return nullptr;
11722 return getDerived().RebuildOMPXDynCGroupMemClause(
11723 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11724}
11725
11726template <typename Derived>
11727OMPClause *
11730 Vars.reserve(C->varlist_size());
11731 for (auto *VE : C->varlist()) {
11732 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11733 if (EVar.isInvalid())
11734 return nullptr;
11735 Vars.push_back(EVar.get());
11736 }
11737 return getDerived().RebuildOMPDoacrossClause(
11738 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11739 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11740}
11741
11742template <typename Derived>
11743OMPClause *
11746 for (auto *A : C->getAttrs())
11747 NewAttrs.push_back(getDerived().TransformAttr(A));
11748 return getDerived().RebuildOMPXAttributeClause(
11749 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11750}
11751
11752template <typename Derived>
11754 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11755}
11756
11757//===----------------------------------------------------------------------===//
11758// OpenACC transformation
11759//===----------------------------------------------------------------------===//
11760namespace {
11761template <typename Derived>
11762class OpenACCClauseTransform final
11763 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11764 TreeTransform<Derived> &Self;
11765 ArrayRef<const OpenACCClause *> ExistingClauses;
11766 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11767 OpenACCClause *NewClause = nullptr;
11768
11769 ExprResult VisitVar(Expr *VarRef) {
11770 ExprResult Res = Self.TransformExpr(VarRef);
11771
11772 if (!Res.isUsable())
11773 return Res;
11774
11775 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11776 ParsedClause.getClauseKind(),
11777 Res.get());
11778
11779 return Res;
11780 }
11781
11782 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11783 llvm::SmallVector<Expr *> InstantiatedVarList;
11784 for (Expr *CurVar : VarList) {
11785 ExprResult VarRef = VisitVar(CurVar);
11786
11787 if (VarRef.isUsable())
11788 InstantiatedVarList.push_back(VarRef.get());
11789 }
11790
11791 return InstantiatedVarList;
11792 }
11793
11794public:
11795 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11796 ArrayRef<const OpenACCClause *> ExistingClauses,
11797 SemaOpenACC::OpenACCParsedClause &PC)
11798 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11799
11800 OpenACCClause *CreatedClause() const { return NewClause; }
11801
11802#define VISIT_CLAUSE(CLAUSE_NAME) \
11803 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11804#include "clang/Basic/OpenACCClauses.def"
11805};
11806
11807template <typename Derived>
11808void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11809 const OpenACCDefaultClause &C) {
11810 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11811
11812 NewClause = OpenACCDefaultClause::Create(
11813 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11814 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11815 ParsedClause.getEndLoc());
11816}
11817
11818template <typename Derived>
11819void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11820 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11821 assert(Cond && "If constructed with invalid Condition");
11822 Sema::ConditionResult Res = Self.TransformCondition(
11823 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11824
11825 if (Res.isInvalid() || !Res.get().second)
11826 return;
11827
11828 ParsedClause.setConditionDetails(Res.get().second);
11829
11830 NewClause = OpenACCIfClause::Create(
11831 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11832 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11833 ParsedClause.getEndLoc());
11834}
11835
11836template <typename Derived>
11837void OpenACCClauseTransform<Derived>::VisitSelfClause(
11838 const OpenACCSelfClause &C) {
11839
11840 // If this is an 'update' 'self' clause, this is actually a var list instead.
11841 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11842 llvm::SmallVector<Expr *> InstantiatedVarList;
11843 for (Expr *CurVar : C.getVarList()) {
11844 ExprResult Res = Self.TransformExpr(CurVar);
11845
11846 if (!Res.isUsable())
11847 continue;
11848
11849 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11850 ParsedClause.getClauseKind(),
11851 Res.get());
11852
11853 if (Res.isUsable())
11854 InstantiatedVarList.push_back(Res.get());
11855 }
11856
11857 ParsedClause.setVarListDetails(InstantiatedVarList,
11859
11860 NewClause = OpenACCSelfClause::Create(
11861 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11862 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11863 ParsedClause.getEndLoc());
11864 } else {
11865
11866 if (C.hasConditionExpr()) {
11867 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11869 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11871
11872 if (Res.isInvalid() || !Res.get().second)
11873 return;
11874
11875 ParsedClause.setConditionDetails(Res.get().second);
11876 }
11877
11878 NewClause = OpenACCSelfClause::Create(
11879 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11880 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11881 ParsedClause.getEndLoc());
11882 }
11883}
11884
11885template <typename Derived>
11886void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11887 const OpenACCNumGangsClause &C) {
11888 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11889
11890 for (Expr *CurIntExpr : C.getIntExprs()) {
11891 ExprResult Res = Self.TransformExpr(CurIntExpr);
11892
11893 if (!Res.isUsable())
11894 return;
11895
11896 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11897 C.getClauseKind(),
11898 C.getBeginLoc(), Res.get());
11899 if (!Res.isUsable())
11900 return;
11901
11902 InstantiatedIntExprs.push_back(Res.get());
11903 }
11904
11905 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11907 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11908 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11909 ParsedClause.getEndLoc());
11910}
11911
11912template <typename Derived>
11913void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11914 const OpenACCPrivateClause &C) {
11915 llvm::SmallVector<Expr *> InstantiatedVarList;
11917
11918 for (const auto [RefExpr, InitRecipe] :
11919 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11920 ExprResult VarRef = VisitVar(RefExpr);
11921
11922 if (VarRef.isUsable()) {
11923 InstantiatedVarList.push_back(VarRef.get());
11924
11925 // We only have to create a new one if it is dependent, and Sema won't
11926 // make one of these unless the type is non-dependent.
11927 if (InitRecipe.isSet())
11928 InitRecipes.push_back(InitRecipe);
11929 else
11930 InitRecipes.push_back(
11931 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
11932 }
11933 }
11934 ParsedClause.setVarListDetails(InstantiatedVarList,
11936
11937 NewClause = OpenACCPrivateClause::Create(
11938 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11939 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11940 ParsedClause.getEndLoc());
11941}
11942
11943template <typename Derived>
11944void OpenACCClauseTransform<Derived>::VisitHostClause(
11945 const OpenACCHostClause &C) {
11946 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11948
11949 NewClause = OpenACCHostClause::Create(
11950 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11951 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11952 ParsedClause.getEndLoc());
11953}
11954
11955template <typename Derived>
11956void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11957 const OpenACCDeviceClause &C) {
11958 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11960
11961 NewClause = OpenACCDeviceClause::Create(
11962 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11963 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11964 ParsedClause.getEndLoc());
11965}
11966
11967template <typename Derived>
11968void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11970 llvm::SmallVector<Expr *> InstantiatedVarList;
11972
11973 for (const auto [RefExpr, InitRecipe] :
11974 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11975 ExprResult VarRef = VisitVar(RefExpr);
11976
11977 if (VarRef.isUsable()) {
11978 InstantiatedVarList.push_back(VarRef.get());
11979
11980 // We only have to create a new one if it is dependent, and Sema won't
11981 // make one of these unless the type is non-dependent.
11982 if (InitRecipe.isSet())
11983 InitRecipes.push_back(InitRecipe);
11984 else
11985 InitRecipes.push_back(
11986 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
11987 VarRef.get()));
11988 }
11989 }
11990 ParsedClause.setVarListDetails(InstantiatedVarList,
11992
11994 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11995 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11996 ParsedClause.getEndLoc());
11997}
11998
11999template <typename Derived>
12000void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12001 const OpenACCNoCreateClause &C) {
12002 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12004
12006 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12007 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12008 ParsedClause.getEndLoc());
12009}
12010
12011template <typename Derived>
12012void OpenACCClauseTransform<Derived>::VisitPresentClause(
12013 const OpenACCPresentClause &C) {
12014 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12016
12017 NewClause = OpenACCPresentClause::Create(
12018 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12019 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12020 ParsedClause.getEndLoc());
12021}
12022
12023template <typename Derived>
12024void OpenACCClauseTransform<Derived>::VisitCopyClause(
12025 const OpenACCCopyClause &C) {
12026 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12027 C.getModifierList());
12028
12029 NewClause = OpenACCCopyClause::Create(
12030 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12031 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12032 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12033 ParsedClause.getEndLoc());
12034}
12035
12036template <typename Derived>
12037void OpenACCClauseTransform<Derived>::VisitLinkClause(
12038 const OpenACCLinkClause &C) {
12039 llvm_unreachable("link clause not valid unless a decl transform");
12040}
12041
12042template <typename Derived>
12043void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12045 llvm_unreachable("device_resident clause not valid unless a decl transform");
12046}
12047template <typename Derived>
12048void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12049 const OpenACCNoHostClause &C) {
12050 llvm_unreachable("nohost clause not valid unless a decl transform");
12051}
12052template <typename Derived>
12053void OpenACCClauseTransform<Derived>::VisitBindClause(
12054 const OpenACCBindClause &C) {
12055 llvm_unreachable("bind clause not valid unless a decl transform");
12056}
12057
12058template <typename Derived>
12059void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12060 const OpenACCCopyInClause &C) {
12061 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12062 C.getModifierList());
12063
12064 NewClause = OpenACCCopyInClause::Create(
12065 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12066 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12067 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12068 ParsedClause.getEndLoc());
12069}
12070
12071template <typename Derived>
12072void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12073 const OpenACCCopyOutClause &C) {
12074 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12075 C.getModifierList());
12076
12077 NewClause = OpenACCCopyOutClause::Create(
12078 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12079 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12080 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12081 ParsedClause.getEndLoc());
12082}
12083
12084template <typename Derived>
12085void OpenACCClauseTransform<Derived>::VisitCreateClause(
12086 const OpenACCCreateClause &C) {
12087 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12088 C.getModifierList());
12089
12090 NewClause = OpenACCCreateClause::Create(
12091 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12092 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12093 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12094 ParsedClause.getEndLoc());
12095}
12096template <typename Derived>
12097void OpenACCClauseTransform<Derived>::VisitAttachClause(
12098 const OpenACCAttachClause &C) {
12099 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12100
12101 // Ensure each var is a pointer type.
12102 llvm::erase_if(VarList, [&](Expr *E) {
12103 return Self.getSema().OpenACC().CheckVarIsPointerType(
12105 });
12106
12107 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12108 NewClause = OpenACCAttachClause::Create(
12109 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12110 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12111 ParsedClause.getEndLoc());
12112}
12113
12114template <typename Derived>
12115void OpenACCClauseTransform<Derived>::VisitDetachClause(
12116 const OpenACCDetachClause &C) {
12117 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12118
12119 // Ensure each var is a pointer type.
12120 llvm::erase_if(VarList, [&](Expr *E) {
12121 return Self.getSema().OpenACC().CheckVarIsPointerType(
12123 });
12124
12125 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12126 NewClause = OpenACCDetachClause::Create(
12127 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12128 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12129 ParsedClause.getEndLoc());
12130}
12131
12132template <typename Derived>
12133void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12134 const OpenACCDeleteClause &C) {
12135 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12137 NewClause = OpenACCDeleteClause::Create(
12138 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12139 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12140 ParsedClause.getEndLoc());
12141}
12142
12143template <typename Derived>
12144void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12145 const OpenACCUseDeviceClause &C) {
12146 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12149 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12150 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12151 ParsedClause.getEndLoc());
12152}
12153
12154template <typename Derived>
12155void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12156 const OpenACCDevicePtrClause &C) {
12157 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12158
12159 // Ensure each var is a pointer type.
12160 llvm::erase_if(VarList, [&](Expr *E) {
12161 return Self.getSema().OpenACC().CheckVarIsPointerType(
12163 });
12164
12165 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12167 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12168 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12169 ParsedClause.getEndLoc());
12170}
12171
12172template <typename Derived>
12173void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12174 const OpenACCNumWorkersClause &C) {
12175 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12176 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12177
12178 ExprResult Res = Self.TransformExpr(IntExpr);
12179 if (!Res.isUsable())
12180 return;
12181
12182 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12183 C.getClauseKind(),
12184 C.getBeginLoc(), Res.get());
12185 if (!Res.isUsable())
12186 return;
12187
12188 ParsedClause.setIntExprDetails(Res.get());
12190 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12191 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12192 ParsedClause.getEndLoc());
12193}
12194
12195template <typename Derived>
12196void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12197 const OpenACCDeviceNumClause &C) {
12198 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12199 assert(IntExpr && "device_num clause constructed with invalid int expr");
12200
12201 ExprResult Res = Self.TransformExpr(IntExpr);
12202 if (!Res.isUsable())
12203 return;
12204
12205 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12206 C.getClauseKind(),
12207 C.getBeginLoc(), Res.get());
12208 if (!Res.isUsable())
12209 return;
12210
12211 ParsedClause.setIntExprDetails(Res.get());
12213 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12214 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12215 ParsedClause.getEndLoc());
12216}
12217
12218template <typename Derived>
12219void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12221 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12222 assert(IntExpr && "default_async clause constructed with invalid int expr");
12223
12224 ExprResult Res = Self.TransformExpr(IntExpr);
12225 if (!Res.isUsable())
12226 return;
12227
12228 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12229 C.getClauseKind(),
12230 C.getBeginLoc(), Res.get());
12231 if (!Res.isUsable())
12232 return;
12233
12234 ParsedClause.setIntExprDetails(Res.get());
12236 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12237 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12238 ParsedClause.getEndLoc());
12239}
12240
12241template <typename Derived>
12242void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12244 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12245 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12246
12247 ExprResult Res = Self.TransformExpr(IntExpr);
12248 if (!Res.isUsable())
12249 return;
12250
12251 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12252 C.getClauseKind(),
12253 C.getBeginLoc(), Res.get());
12254 if (!Res.isUsable())
12255 return;
12256
12257 ParsedClause.setIntExprDetails(Res.get());
12259 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12260 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12261 ParsedClause.getEndLoc());
12262}
12263
12264template <typename Derived>
12265void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12266 const OpenACCAsyncClause &C) {
12267 if (C.hasIntExpr()) {
12268 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12269 if (!Res.isUsable())
12270 return;
12271
12272 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12273 C.getClauseKind(),
12274 C.getBeginLoc(), Res.get());
12275 if (!Res.isUsable())
12276 return;
12277 ParsedClause.setIntExprDetails(Res.get());
12278 }
12279
12280 NewClause = OpenACCAsyncClause::Create(
12281 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12282 ParsedClause.getLParenLoc(),
12283 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12284 : nullptr,
12285 ParsedClause.getEndLoc());
12286}
12287
12288template <typename Derived>
12289void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12290 const OpenACCWorkerClause &C) {
12291 if (C.hasIntExpr()) {
12292 // restrictions on this expression are all "does it exist in certain
12293 // situations" that are not possible to be dependent, so the only check we
12294 // have is that it transforms, and is an int expression.
12295 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12296 if (!Res.isUsable())
12297 return;
12298
12299 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12300 C.getClauseKind(),
12301 C.getBeginLoc(), Res.get());
12302 if (!Res.isUsable())
12303 return;
12304 ParsedClause.setIntExprDetails(Res.get());
12305 }
12306
12307 NewClause = OpenACCWorkerClause::Create(
12308 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12309 ParsedClause.getLParenLoc(),
12310 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12311 : nullptr,
12312 ParsedClause.getEndLoc());
12313}
12314
12315template <typename Derived>
12316void OpenACCClauseTransform<Derived>::VisitVectorClause(
12317 const OpenACCVectorClause &C) {
12318 if (C.hasIntExpr()) {
12319 // restrictions on this expression are all "does it exist in certain
12320 // situations" that are not possible to be dependent, so the only check we
12321 // have is that it transforms, and is an int expression.
12322 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12323 if (!Res.isUsable())
12324 return;
12325
12326 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12327 C.getClauseKind(),
12328 C.getBeginLoc(), Res.get());
12329 if (!Res.isUsable())
12330 return;
12331 ParsedClause.setIntExprDetails(Res.get());
12332 }
12333
12334 NewClause = OpenACCVectorClause::Create(
12335 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12336 ParsedClause.getLParenLoc(),
12337 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12338 : nullptr,
12339 ParsedClause.getEndLoc());
12340}
12341
12342template <typename Derived>
12343void OpenACCClauseTransform<Derived>::VisitWaitClause(
12344 const OpenACCWaitClause &C) {
12345 if (C.hasExprs()) {
12346 Expr *DevNumExpr = nullptr;
12347 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12348
12349 // Instantiate devnum expr if it exists.
12350 if (C.getDevNumExpr()) {
12351 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12352 if (!Res.isUsable())
12353 return;
12354 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12355 C.getClauseKind(),
12356 C.getBeginLoc(), Res.get());
12357 if (!Res.isUsable())
12358 return;
12359
12360 DevNumExpr = Res.get();
12361 }
12362
12363 // Instantiate queue ids.
12364 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12365 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12366 if (!Res.isUsable())
12367 return;
12368 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12369 C.getClauseKind(),
12370 C.getBeginLoc(), Res.get());
12371 if (!Res.isUsable())
12372 return;
12373
12374 InstantiatedQueueIdExprs.push_back(Res.get());
12375 }
12376
12377 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12378 std::move(InstantiatedQueueIdExprs));
12379 }
12380
12381 NewClause = OpenACCWaitClause::Create(
12382 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12383 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12384 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12385 ParsedClause.getEndLoc());
12386}
12387
12388template <typename Derived>
12389void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12390 const OpenACCDeviceTypeClause &C) {
12391 // Nothing to transform here, just create a new version of 'C'.
12393 Self.getSema().getASTContext(), C.getClauseKind(),
12394 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12395 C.getArchitectures(), ParsedClause.getEndLoc());
12396}
12397
12398template <typename Derived>
12399void OpenACCClauseTransform<Derived>::VisitAutoClause(
12400 const OpenACCAutoClause &C) {
12401 // Nothing to do, so just create a new node.
12402 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12403 ParsedClause.getBeginLoc(),
12404 ParsedClause.getEndLoc());
12405}
12406
12407template <typename Derived>
12408void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12409 const OpenACCIndependentClause &C) {
12410 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12411 ParsedClause.getBeginLoc(),
12412 ParsedClause.getEndLoc());
12413}
12414
12415template <typename Derived>
12416void OpenACCClauseTransform<Derived>::VisitSeqClause(
12417 const OpenACCSeqClause &C) {
12418 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12419 ParsedClause.getBeginLoc(),
12420 ParsedClause.getEndLoc());
12421}
12422template <typename Derived>
12423void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12424 const OpenACCFinalizeClause &C) {
12425 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12426 ParsedClause.getBeginLoc(),
12427 ParsedClause.getEndLoc());
12428}
12429
12430template <typename Derived>
12431void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12432 const OpenACCIfPresentClause &C) {
12433 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12434 ParsedClause.getBeginLoc(),
12435 ParsedClause.getEndLoc());
12436}
12437
12438template <typename Derived>
12439void OpenACCClauseTransform<Derived>::VisitReductionClause(
12440 const OpenACCReductionClause &C) {
12441 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12442 SmallVector<Expr *> ValidVars;
12444
12445 for (const auto [Var, OrigRecipe] :
12446 llvm::zip(TransformedVars, C.getRecipes())) {
12447 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12448 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12449 if (Res.isUsable()) {
12450 ValidVars.push_back(Res.get());
12451
12452 if (OrigRecipe.isSet())
12453 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
12454 else
12455 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12456 C.getReductionOp(), Res.get()));
12457 }
12458 }
12459
12460 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12461 ExistingClauses, ParsedClause.getDirectiveKind(),
12462 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12463 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12464}
12465
12466template <typename Derived>
12467void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12468 const OpenACCCollapseClause &C) {
12469 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12470 assert(LoopCount && "collapse clause constructed with invalid loop count");
12471
12472 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12473
12474 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12475 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12476 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12477
12478 NewLoopCount =
12479 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12480
12481 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12483 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12484 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12485 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12486}
12487
12488template <typename Derived>
12489void OpenACCClauseTransform<Derived>::VisitTileClause(
12490 const OpenACCTileClause &C) {
12491
12492 llvm::SmallVector<Expr *> TransformedExprs;
12493
12494 for (Expr *E : C.getSizeExprs()) {
12495 ExprResult NewSizeExpr = Self.TransformExpr(E);
12496
12497 if (!NewSizeExpr.isUsable())
12498 return;
12499
12500 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12501 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12502 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12503
12504 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12505
12506 if (!NewSizeExpr.isUsable())
12507 return;
12508 TransformedExprs.push_back(NewSizeExpr.get());
12509 }
12510
12511 ParsedClause.setIntExprDetails(TransformedExprs);
12512 NewClause = OpenACCTileClause::Create(
12513 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12514 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12515 ParsedClause.getEndLoc());
12516}
12517template <typename Derived>
12518void OpenACCClauseTransform<Derived>::VisitGangClause(
12519 const OpenACCGangClause &C) {
12520 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12521 llvm::SmallVector<Expr *> TransformedIntExprs;
12522
12523 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12524 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12525 if (!ER.isUsable())
12526 continue;
12527
12528 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12529 ParsedClause.getDirectiveKind(),
12530 C.getExpr(I).first, ER.get());
12531 if (!ER.isUsable())
12532 continue;
12533 TransformedGangKinds.push_back(C.getExpr(I).first);
12534 TransformedIntExprs.push_back(ER.get());
12535 }
12536
12537 NewClause = Self.getSema().OpenACC().CheckGangClause(
12538 ParsedClause.getDirectiveKind(), ExistingClauses,
12539 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12540 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12541}
12542} // namespace
12543template <typename Derived>
12544OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12545 ArrayRef<const OpenACCClause *> ExistingClauses,
12546 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12547
12549 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12550 ParsedClause.setEndLoc(OldClause->getEndLoc());
12551
12552 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12553 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12554
12555 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12556 ParsedClause};
12557 Transform.Visit(OldClause);
12558
12559 return Transform.CreatedClause();
12560}
12561
12562template <typename Derived>
12564TreeTransform<Derived>::TransformOpenACCClauseList(
12566 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12567 for (const auto *Clause : OldClauses) {
12568 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12569 TransformedClauses, DirKind, Clause))
12570 TransformedClauses.push_back(TransformedClause);
12571 }
12572 return TransformedClauses;
12573}
12574
12575template <typename Derived>
12578 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12579
12580 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12581 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12582 C->clauses());
12583
12584 if (getSema().OpenACC().ActOnStartStmtDirective(
12585 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12586 return StmtError();
12587
12588 // Transform Structured Block.
12589 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12590 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12591 C->clauses(), TransformedClauses);
12592 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12593 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12594 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12595
12596 return getDerived().RebuildOpenACCComputeConstruct(
12597 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12598 C->getEndLoc(), TransformedClauses, StrBlock);
12599}
12600
12601template <typename Derived>
12604
12605 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12606
12607 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12608 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12609 C->clauses());
12610
12611 if (getSema().OpenACC().ActOnStartStmtDirective(
12612 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12613 return StmtError();
12614
12615 // Transform Loop.
12616 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12617 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12618 C->clauses(), TransformedClauses);
12619 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12620 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12621 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12622
12623 return getDerived().RebuildOpenACCLoopConstruct(
12624 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12625 TransformedClauses, Loop);
12626}
12627
12628template <typename Derived>
12630 OpenACCCombinedConstruct *C) {
12631 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12632
12633 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12634 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12635 C->clauses());
12636
12637 if (getSema().OpenACC().ActOnStartStmtDirective(
12638 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12639 return StmtError();
12640
12641 // Transform Loop.
12642 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12643 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12644 C->clauses(), TransformedClauses);
12645 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12646 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12647 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12648
12649 return getDerived().RebuildOpenACCCombinedConstruct(
12650 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12651 C->getEndLoc(), TransformedClauses, Loop);
12652}
12653
12654template <typename Derived>
12657 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12658
12659 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12660 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12661 C->clauses());
12662 if (getSema().OpenACC().ActOnStartStmtDirective(
12663 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12664 return StmtError();
12665
12666 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12667 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12668 C->clauses(), TransformedClauses);
12669 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12670 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12671 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12672
12673 return getDerived().RebuildOpenACCDataConstruct(
12674 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12675 TransformedClauses, StrBlock);
12676}
12677
12678template <typename Derived>
12680 OpenACCEnterDataConstruct *C) {
12681 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12682
12683 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12684 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12685 C->clauses());
12686 if (getSema().OpenACC().ActOnStartStmtDirective(
12687 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12688 return StmtError();
12689
12690 return getDerived().RebuildOpenACCEnterDataConstruct(
12691 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12692 TransformedClauses);
12693}
12694
12695template <typename Derived>
12697 OpenACCExitDataConstruct *C) {
12698 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12699
12700 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12701 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12702 C->clauses());
12703 if (getSema().OpenACC().ActOnStartStmtDirective(
12704 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12705 return StmtError();
12706
12707 return getDerived().RebuildOpenACCExitDataConstruct(
12708 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12709 TransformedClauses);
12710}
12711
12712template <typename Derived>
12714 OpenACCHostDataConstruct *C) {
12715 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12716
12717 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12718 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12719 C->clauses());
12720 if (getSema().OpenACC().ActOnStartStmtDirective(
12721 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12722 return StmtError();
12723
12724 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12725 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12726 C->clauses(), TransformedClauses);
12727 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12728 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12729 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12730
12731 return getDerived().RebuildOpenACCHostDataConstruct(
12732 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12733 TransformedClauses, StrBlock);
12734}
12735
12736template <typename Derived>
12739 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12740
12741 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12742 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12743 C->clauses());
12744 if (getSema().OpenACC().ActOnStartStmtDirective(
12745 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12746 return StmtError();
12747
12748 return getDerived().RebuildOpenACCInitConstruct(
12749 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12750 TransformedClauses);
12751}
12752
12753template <typename Derived>
12755 OpenACCShutdownConstruct *C) {
12756 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12757
12758 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12759 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12760 C->clauses());
12761 if (getSema().OpenACC().ActOnStartStmtDirective(
12762 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12763 return StmtError();
12764
12765 return getDerived().RebuildOpenACCShutdownConstruct(
12766 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12767 TransformedClauses);
12768}
12769template <typename Derived>
12772 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12773
12774 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12775 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12776 C->clauses());
12777 if (getSema().OpenACC().ActOnStartStmtDirective(
12778 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12779 return StmtError();
12780
12781 return getDerived().RebuildOpenACCSetConstruct(
12782 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12783 TransformedClauses);
12784}
12785
12786template <typename Derived>
12788 OpenACCUpdateConstruct *C) {
12789 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12790
12791 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12792 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12793 C->clauses());
12794 if (getSema().OpenACC().ActOnStartStmtDirective(
12795 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12796 return StmtError();
12797
12798 return getDerived().RebuildOpenACCUpdateConstruct(
12799 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12800 TransformedClauses);
12801}
12802
12803template <typename Derived>
12806 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12807
12808 ExprResult DevNumExpr;
12809 if (C->hasDevNumExpr()) {
12810 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12811
12812 if (DevNumExpr.isUsable())
12813 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12815 C->getBeginLoc(), DevNumExpr.get());
12816 }
12817
12818 llvm::SmallVector<Expr *> QueueIdExprs;
12819
12820 for (Expr *QE : C->getQueueIdExprs()) {
12821 assert(QE && "Null queue id expr?");
12822 ExprResult NewEQ = getDerived().TransformExpr(QE);
12823
12824 if (!NewEQ.isUsable())
12825 break;
12826 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12828 C->getBeginLoc(), NewEQ.get());
12829 if (NewEQ.isUsable())
12830 QueueIdExprs.push_back(NewEQ.get());
12831 }
12832
12833 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12834 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12835 C->clauses());
12836
12837 if (getSema().OpenACC().ActOnStartStmtDirective(
12838 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12839 return StmtError();
12840
12841 return getDerived().RebuildOpenACCWaitConstruct(
12842 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12843 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12844 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12845}
12846template <typename Derived>
12848 OpenACCCacheConstruct *C) {
12849 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12850
12851 llvm::SmallVector<Expr *> TransformedVarList;
12852 for (Expr *Var : C->getVarList()) {
12853 assert(Var && "Null var listexpr?");
12854
12855 ExprResult NewVar = getDerived().TransformExpr(Var);
12856
12857 if (!NewVar.isUsable())
12858 break;
12859
12860 NewVar = getSema().OpenACC().ActOnVar(
12861 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
12862 if (!NewVar.isUsable())
12863 break;
12864
12865 TransformedVarList.push_back(NewVar.get());
12866 }
12867
12868 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12869 C->getBeginLoc(), {}))
12870 return StmtError();
12871
12872 return getDerived().RebuildOpenACCCacheConstruct(
12873 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12874 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
12875 C->getEndLoc());
12876}
12877
12878template <typename Derived>
12880 OpenACCAtomicConstruct *C) {
12881 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12882
12883 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12884 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12885 C->clauses());
12886
12887 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12888 C->getBeginLoc(), {}))
12889 return StmtError();
12890
12891 // Transform Associated Stmt.
12892 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12893 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
12894
12895 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
12896 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
12897 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
12898 AssocStmt);
12899
12900 return getDerived().RebuildOpenACCAtomicConstruct(
12901 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
12902 C->getEndLoc(), TransformedClauses, AssocStmt);
12903}
12904
12905template <typename Derived>
12908 if (getDerived().AlwaysRebuild())
12909 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12910 // Nothing can ever change, so there is never anything to transform.
12911 return E;
12912}
12913
12914//===----------------------------------------------------------------------===//
12915// Expression transformation
12916//===----------------------------------------------------------------------===//
12917template<typename Derived>
12920 return TransformExpr(E->getSubExpr());
12921}
12922
12923template <typename Derived>
12926 if (!E->isTypeDependent())
12927 return E;
12928
12929 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12930
12931 if (!NewT)
12932 return ExprError();
12933
12934 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12935 return E;
12936
12937 return getDerived().RebuildSYCLUniqueStableNameExpr(
12938 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12939}
12940
12941template<typename Derived>
12944 if (!E->isTypeDependent())
12945 return E;
12946
12947 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12948 E->getIdentKind());
12949}
12950
12951template<typename Derived>
12954 NestedNameSpecifierLoc QualifierLoc;
12955 if (E->getQualifierLoc()) {
12956 QualifierLoc
12957 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12958 if (!QualifierLoc)
12959 return ExprError();
12960 }
12961
12962 ValueDecl *ND
12963 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12964 E->getDecl()));
12965 if (!ND || ND->isInvalidDecl())
12966 return ExprError();
12967
12968 NamedDecl *Found = ND;
12969 if (E->getFoundDecl() != E->getDecl()) {
12970 Found = cast_or_null<NamedDecl>(
12971 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12972 if (!Found)
12973 return ExprError();
12974 }
12975
12976 DeclarationNameInfo NameInfo = E->getNameInfo();
12977 if (NameInfo.getName()) {
12978 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12979 if (!NameInfo.getName())
12980 return ExprError();
12981 }
12982
12983 if (!getDerived().AlwaysRebuild() &&
12984 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12985 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12986 Found == E->getFoundDecl() &&
12987 NameInfo.getName() == E->getDecl()->getDeclName() &&
12988 !E->hasExplicitTemplateArgs()) {
12989
12990 // Mark it referenced in the new context regardless.
12991 // FIXME: this is a bit instantiation-specific.
12992 SemaRef.MarkDeclRefReferenced(E);
12993
12994 return E;
12995 }
12996
12997 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12998 if (E->hasExplicitTemplateArgs()) {
12999 TemplateArgs = &TransArgs;
13000 TransArgs.setLAngleLoc(E->getLAngleLoc());
13001 TransArgs.setRAngleLoc(E->getRAngleLoc());
13002 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13003 E->getNumTemplateArgs(),
13004 TransArgs))
13005 return ExprError();
13006 }
13007
13008 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13009 Found, TemplateArgs);
13010}
13011
13012template<typename Derived>
13015 return E;
13016}
13017
13018template <typename Derived>
13020 FixedPointLiteral *E) {
13021 return E;
13022}
13023
13024template<typename Derived>
13027 return E;
13028}
13029
13030template<typename Derived>
13033 return E;
13034}
13035
13036template<typename Derived>
13039 return E;
13040}
13041
13042template<typename Derived>
13045 return E;
13046}
13047
13048template<typename Derived>
13051 return getDerived().TransformCallExpr(E);
13052}
13053
13054template<typename Derived>
13057 ExprResult ControllingExpr;
13058 TypeSourceInfo *ControllingType = nullptr;
13059 if (E->isExprPredicate())
13060 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13061 else
13062 ControllingType = getDerived().TransformType(E->getControllingType());
13063
13064 if (ControllingExpr.isInvalid() && !ControllingType)
13065 return ExprError();
13066
13067 SmallVector<Expr *, 4> AssocExprs;
13069 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13070 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13071 if (TSI) {
13072 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13073 if (!AssocType)
13074 return ExprError();
13075 AssocTypes.push_back(AssocType);
13076 } else {
13077 AssocTypes.push_back(nullptr);
13078 }
13079
13080 ExprResult AssocExpr =
13081 getDerived().TransformExpr(Assoc.getAssociationExpr());
13082 if (AssocExpr.isInvalid())
13083 return ExprError();
13084 AssocExprs.push_back(AssocExpr.get());
13085 }
13086
13087 if (!ControllingType)
13088 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13089 E->getDefaultLoc(),
13090 E->getRParenLoc(),
13091 ControllingExpr.get(),
13092 AssocTypes,
13093 AssocExprs);
13094 return getDerived().RebuildGenericSelectionExpr(
13095 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13096 ControllingType, AssocTypes, AssocExprs);
13097}
13098
13099template<typename Derived>
13102 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13103 if (SubExpr.isInvalid())
13104 return ExprError();
13105
13106 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13107 return E;
13108
13109 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13110 E->getRParen());
13111}
13112
13113/// The operand of a unary address-of operator has special rules: it's
13114/// allowed to refer to a non-static member of a class even if there's no 'this'
13115/// object available.
13116template<typename Derived>
13119 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13120 return getDerived().TransformDependentScopeDeclRefExpr(
13121 DRE, /*IsAddressOfOperand=*/true, nullptr);
13122 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13123 return getDerived().TransformUnresolvedLookupExpr(
13124 ULE, /*IsAddressOfOperand=*/true);
13125 else
13126 return getDerived().TransformExpr(E);
13127}
13128
13129template<typename Derived>
13132 ExprResult SubExpr;
13133 if (E->getOpcode() == UO_AddrOf)
13134 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13135 else
13136 SubExpr = TransformExpr(E->getSubExpr());
13137 if (SubExpr.isInvalid())
13138 return ExprError();
13139
13140 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13141 return E;
13142
13143 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13144 E->getOpcode(),
13145 SubExpr.get());
13146}
13147
13148template<typename Derived>
13150TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13151 // Transform the type.
13152 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13153 if (!Type)
13154 return ExprError();
13155
13156 // Transform all of the components into components similar to what the
13157 // parser uses.
13158 // FIXME: It would be slightly more efficient in the non-dependent case to
13159 // just map FieldDecls, rather than requiring the rebuilder to look for
13160 // the fields again. However, __builtin_offsetof is rare enough in
13161 // template code that we don't care.
13162 bool ExprChanged = false;
13163 typedef Sema::OffsetOfComponent Component;
13164 SmallVector<Component, 4> Components;
13165 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13166 const OffsetOfNode &ON = E->getComponent(I);
13167 Component Comp;
13168 Comp.isBrackets = true;
13169 Comp.LocStart = ON.getSourceRange().getBegin();
13170 Comp.LocEnd = ON.getSourceRange().getEnd();
13171 switch (ON.getKind()) {
13172 case OffsetOfNode::Array: {
13173 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13174 ExprResult Index = getDerived().TransformExpr(FromIndex);
13175 if (Index.isInvalid())
13176 return ExprError();
13177
13178 ExprChanged = ExprChanged || Index.get() != FromIndex;
13179 Comp.isBrackets = true;
13180 Comp.U.E = Index.get();
13181 break;
13182 }
13183
13186 Comp.isBrackets = false;
13187 Comp.U.IdentInfo = ON.getFieldName();
13188 if (!Comp.U.IdentInfo)
13189 continue;
13190
13191 break;
13192
13193 case OffsetOfNode::Base:
13194 // Will be recomputed during the rebuild.
13195 continue;
13196 }
13197
13198 Components.push_back(Comp);
13199 }
13200
13201 // If nothing changed, retain the existing expression.
13202 if (!getDerived().AlwaysRebuild() &&
13203 Type == E->getTypeSourceInfo() &&
13204 !ExprChanged)
13205 return E;
13206
13207 // Build a new offsetof expression.
13208 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
13209 Components, E->getRParenLoc());
13210}
13211
13212template<typename Derived>
13215 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13216 "opaque value expression requires transformation");
13217 return E;
13218}
13219
13220template <typename Derived>
13223 bool Changed = false;
13224 for (Expr *C : E->subExpressions()) {
13225 ExprResult NewC = getDerived().TransformExpr(C);
13226 if (NewC.isInvalid())
13227 return ExprError();
13228 Children.push_back(NewC.get());
13229
13230 Changed |= NewC.get() != C;
13231 }
13232 if (!getDerived().AlwaysRebuild() && !Changed)
13233 return E;
13234 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13235 Children, E->getType());
13236}
13237
13238template<typename Derived>
13241 // Rebuild the syntactic form. The original syntactic form has
13242 // opaque-value expressions in it, so strip those away and rebuild
13243 // the result. This is a really awful way of doing this, but the
13244 // better solution (rebuilding the semantic expressions and
13245 // rebinding OVEs as necessary) doesn't work; we'd need
13246 // TreeTransform to not strip away implicit conversions.
13247 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13248 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13249 if (result.isInvalid()) return ExprError();
13250
13251 // If that gives us a pseudo-object result back, the pseudo-object
13252 // expression must have been an lvalue-to-rvalue conversion which we
13253 // should reapply.
13254 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13255 result = SemaRef.PseudoObject().checkRValue(result.get());
13256
13257 return result;
13258}
13259
13260template<typename Derived>
13264 if (E->isArgumentType()) {
13265 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13266
13267 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13268 if (!NewT)
13269 return ExprError();
13270
13271 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13272 return E;
13273
13274 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13275 E->getKind(),
13276 E->getSourceRange());
13277 }
13278
13279 // C++0x [expr.sizeof]p1:
13280 // The operand is either an expression, which is an unevaluated operand
13281 // [...]
13285
13286 // Try to recover if we have something like sizeof(T::X) where X is a type.
13287 // Notably, there must be *exactly* one set of parens if X is a type.
13288 TypeSourceInfo *RecoveryTSI = nullptr;
13289 ExprResult SubExpr;
13290 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13291 if (auto *DRE =
13292 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13293 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13294 PE, DRE, false, &RecoveryTSI);
13295 else
13296 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13297
13298 if (RecoveryTSI) {
13299 return getDerived().RebuildUnaryExprOrTypeTrait(
13300 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13301 } else if (SubExpr.isInvalid())
13302 return ExprError();
13303
13304 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13305 return E;
13306
13307 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13308 E->getOperatorLoc(),
13309 E->getKind(),
13310 E->getSourceRange());
13311}
13312
13313template<typename Derived>
13316 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13317 if (LHS.isInvalid())
13318 return ExprError();
13319
13320 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13321 if (RHS.isInvalid())
13322 return ExprError();
13323
13324
13325 if (!getDerived().AlwaysRebuild() &&
13326 LHS.get() == E->getLHS() &&
13327 RHS.get() == E->getRHS())
13328 return E;
13329
13330 return getDerived().RebuildArraySubscriptExpr(
13331 LHS.get(),
13332 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13333}
13334
13335template <typename Derived>
13338 ExprResult Base = getDerived().TransformExpr(E->getBase());
13339 if (Base.isInvalid())
13340 return ExprError();
13341
13342 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13343 if (RowIdx.isInvalid())
13344 return ExprError();
13345
13346 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13347 if (ColumnIdx.isInvalid())
13348 return ExprError();
13349
13350 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13351 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13352 return E;
13353
13354 return getDerived().RebuildMatrixSubscriptExpr(
13355 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13356}
13357
13358template <typename Derived>
13361 ExprResult Base = getDerived().TransformExpr(E->getBase());
13362 if (Base.isInvalid())
13363 return ExprError();
13364
13365 ExprResult LowerBound;
13366 if (E->getLowerBound()) {
13367 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13368 if (LowerBound.isInvalid())
13369 return ExprError();
13370 }
13371
13372 ExprResult Length;
13373 if (E->getLength()) {
13374 Length = getDerived().TransformExpr(E->getLength());
13375 if (Length.isInvalid())
13376 return ExprError();
13377 }
13378
13379 ExprResult Stride;
13380 if (E->isOMPArraySection()) {
13381 if (Expr *Str = E->getStride()) {
13382 Stride = getDerived().TransformExpr(Str);
13383 if (Stride.isInvalid())
13384 return ExprError();
13385 }
13386 }
13387
13388 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13389 LowerBound.get() == E->getLowerBound() &&
13390 Length.get() == E->getLength() &&
13391 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13392 return E;
13393
13394 return getDerived().RebuildArraySectionExpr(
13395 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13396 LowerBound.get(), E->getColonLocFirst(),
13397 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13398 Length.get(), Stride.get(), E->getRBracketLoc());
13399}
13400
13401template <typename Derived>
13404 ExprResult Base = getDerived().TransformExpr(E->getBase());
13405 if (Base.isInvalid())
13406 return ExprError();
13407
13409 bool ErrorFound = false;
13410 for (Expr *Dim : E->getDimensions()) {
13411 ExprResult DimRes = getDerived().TransformExpr(Dim);
13412 if (DimRes.isInvalid()) {
13413 ErrorFound = true;
13414 continue;
13415 }
13416 Dims.push_back(DimRes.get());
13417 }
13418
13419 if (ErrorFound)
13420 return ExprError();
13421 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13422 E->getRParenLoc(), Dims,
13423 E->getBracketsRanges());
13424}
13425
13426template <typename Derived>
13429 unsigned NumIterators = E->numOfIterators();
13431
13432 bool ErrorFound = false;
13433 bool NeedToRebuild = getDerived().AlwaysRebuild();
13434 for (unsigned I = 0; I < NumIterators; ++I) {
13435 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13436 Data[I].DeclIdent = D->getIdentifier();
13437 Data[I].DeclIdentLoc = D->getLocation();
13438 if (D->getLocation() == D->getBeginLoc()) {
13439 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13440 "Implicit type must be int.");
13441 } else {
13442 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13443 QualType DeclTy = getDerived().TransformType(D->getType());
13444 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13445 }
13446 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13447 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13448 ExprResult End = getDerived().TransformExpr(Range.End);
13449 ExprResult Step = getDerived().TransformExpr(Range.Step);
13450 ErrorFound = ErrorFound ||
13451 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13452 !Data[I].Type.get().isNull())) ||
13453 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13454 if (ErrorFound)
13455 continue;
13456 Data[I].Range.Begin = Begin.get();
13457 Data[I].Range.End = End.get();
13458 Data[I].Range.Step = Step.get();
13459 Data[I].AssignLoc = E->getAssignLoc(I);
13460 Data[I].ColonLoc = E->getColonLoc(I);
13461 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13462 NeedToRebuild =
13463 NeedToRebuild ||
13464 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13465 D->getType().getTypePtrOrNull()) ||
13466 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13467 Range.Step != Data[I].Range.Step;
13468 }
13469 if (ErrorFound)
13470 return ExprError();
13471 if (!NeedToRebuild)
13472 return E;
13473
13474 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13475 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13476 if (!Res.isUsable())
13477 return Res;
13478 auto *IE = cast<OMPIteratorExpr>(Res.get());
13479 for (unsigned I = 0; I < NumIterators; ++I)
13480 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13481 IE->getIteratorDecl(I));
13482 return Res;
13483}
13484
13485template<typename Derived>
13488 // Transform the callee.
13489 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13490 if (Callee.isInvalid())
13491 return ExprError();
13492
13493 // Transform arguments.
13494 bool ArgChanged = false;
13496 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13497 &ArgChanged))
13498 return ExprError();
13499
13500 if (!getDerived().AlwaysRebuild() &&
13501 Callee.get() == E->getCallee() &&
13502 !ArgChanged)
13503 return SemaRef.MaybeBindToTemporary(E);
13504
13505 // FIXME: Wrong source location information for the '('.
13506 SourceLocation FakeLParenLoc
13507 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13508
13509 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13510 if (E->hasStoredFPFeatures()) {
13511 FPOptionsOverride NewOverrides = E->getFPFeatures();
13512 getSema().CurFPFeatures =
13513 NewOverrides.applyOverrides(getSema().getLangOpts());
13514 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13515 }
13516
13517 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13518 Args,
13519 E->getRParenLoc());
13520}
13521
13522template<typename Derived>
13525 ExprResult Base = getDerived().TransformExpr(E->getBase());
13526 if (Base.isInvalid())
13527 return ExprError();
13528
13529 NestedNameSpecifierLoc QualifierLoc;
13530 if (E->hasQualifier()) {
13531 QualifierLoc
13532 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13533
13534 if (!QualifierLoc)
13535 return ExprError();
13536 }
13537 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13538
13540 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13541 E->getMemberDecl()));
13542 if (!Member)
13543 return ExprError();
13544
13545 NamedDecl *FoundDecl = E->getFoundDecl();
13546 if (FoundDecl == E->getMemberDecl()) {
13547 FoundDecl = Member;
13548 } else {
13549 FoundDecl = cast_or_null<NamedDecl>(
13550 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13551 if (!FoundDecl)
13552 return ExprError();
13553 }
13554
13555 if (!getDerived().AlwaysRebuild() &&
13556 Base.get() == E->getBase() &&
13557 QualifierLoc == E->getQualifierLoc() &&
13558 Member == E->getMemberDecl() &&
13559 FoundDecl == E->getFoundDecl() &&
13560 !E->hasExplicitTemplateArgs()) {
13561
13562 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13563 // for Openmp where the field need to be privatizized in the case.
13564 if (!(isa<CXXThisExpr>(E->getBase()) &&
13565 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13567 // Mark it referenced in the new context regardless.
13568 // FIXME: this is a bit instantiation-specific.
13569 SemaRef.MarkMemberReferenced(E);
13570 return E;
13571 }
13572 }
13573
13574 TemplateArgumentListInfo TransArgs;
13575 if (E->hasExplicitTemplateArgs()) {
13576 TransArgs.setLAngleLoc(E->getLAngleLoc());
13577 TransArgs.setRAngleLoc(E->getRAngleLoc());
13578 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13579 E->getNumTemplateArgs(),
13580 TransArgs))
13581 return ExprError();
13582 }
13583
13584 // FIXME: Bogus source location for the operator
13585 SourceLocation FakeOperatorLoc =
13586 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13587
13588 // FIXME: to do this check properly, we will need to preserve the
13589 // first-qualifier-in-scope here, just in case we had a dependent
13590 // base (and therefore couldn't do the check) and a
13591 // nested-name-qualifier (and therefore could do the lookup).
13592 NamedDecl *FirstQualifierInScope = nullptr;
13593 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13594 if (MemberNameInfo.getName()) {
13595 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13596 if (!MemberNameInfo.getName())
13597 return ExprError();
13598 }
13599
13600 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13601 E->isArrow(),
13602 QualifierLoc,
13603 TemplateKWLoc,
13604 MemberNameInfo,
13605 Member,
13606 FoundDecl,
13607 (E->hasExplicitTemplateArgs()
13608 ? &TransArgs : nullptr),
13609 FirstQualifierInScope);
13610}
13611
13612template<typename Derived>
13615 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13616 if (LHS.isInvalid())
13617 return ExprError();
13618
13619 ExprResult RHS =
13620 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13621 if (RHS.isInvalid())
13622 return ExprError();
13623
13624 if (!getDerived().AlwaysRebuild() &&
13625 LHS.get() == E->getLHS() &&
13626 RHS.get() == E->getRHS())
13627 return E;
13628
13629 if (E->isCompoundAssignmentOp())
13630 // FPFeatures has already been established from trailing storage
13631 return getDerived().RebuildBinaryOperator(
13632 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13633 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13634 FPOptionsOverride NewOverrides(E->getFPFeatures());
13635 getSema().CurFPFeatures =
13636 NewOverrides.applyOverrides(getSema().getLangOpts());
13637 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13638 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13639 LHS.get(), RHS.get());
13640}
13641
13642template <typename Derived>
13645 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13646
13647 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13648 if (LHS.isInvalid())
13649 return ExprError();
13650
13651 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13652 if (RHS.isInvalid())
13653 return ExprError();
13654
13655 // Extract the already-resolved callee declarations so that we can restrict
13656 // ourselves to using them as the unqualified lookup results when rebuilding.
13657 UnresolvedSet<2> UnqualLookups;
13658 bool ChangedAnyLookups = false;
13659 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13660 const_cast<Expr *>(Decomp.InnerBinOp)};
13661 for (Expr *PossibleBinOp : PossibleBinOps) {
13662 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13663 if (!Op)
13664 continue;
13665 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13666 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13667 continue;
13668
13669 // Transform the callee in case we built a call to a local extern
13670 // declaration.
13671 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13672 E->getOperatorLoc(), Callee->getFoundDecl()));
13673 if (!Found)
13674 return ExprError();
13675 if (Found != Callee->getFoundDecl())
13676 ChangedAnyLookups = true;
13677 UnqualLookups.addDecl(Found);
13678 }
13679
13680 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13681 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13682 // Mark all functions used in the rewrite as referenced. Note that when
13683 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13684 // function calls, and/or there might be a user-defined conversion sequence
13685 // applied to the operands of the <.
13686 // FIXME: this is a bit instantiation-specific.
13687 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13688 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13689 return E;
13690 }
13691
13692 return getDerived().RebuildCXXRewrittenBinaryOperator(
13693 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13694}
13695
13696template<typename Derived>
13700 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13701 FPOptionsOverride NewOverrides(E->getFPFeatures());
13702 getSema().CurFPFeatures =
13703 NewOverrides.applyOverrides(getSema().getLangOpts());
13704 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13705 return getDerived().TransformBinaryOperator(E);
13706}
13707
13708template<typename Derived>
13711 // Just rebuild the common and RHS expressions and see whether we
13712 // get any changes.
13713
13714 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13715 if (commonExpr.isInvalid())
13716 return ExprError();
13717
13718 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13719 if (rhs.isInvalid())
13720 return ExprError();
13721
13722 if (!getDerived().AlwaysRebuild() &&
13723 commonExpr.get() == e->getCommon() &&
13724 rhs.get() == e->getFalseExpr())
13725 return e;
13726
13727 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13728 e->getQuestionLoc(),
13729 nullptr,
13730 e->getColonLoc(),
13731 rhs.get());
13732}
13733
13734template<typename Derived>
13737 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13738 if (Cond.isInvalid())
13739 return ExprError();
13740
13741 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13742 if (LHS.isInvalid())
13743 return ExprError();
13744
13745 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13746 if (RHS.isInvalid())
13747 return ExprError();
13748
13749 if (!getDerived().AlwaysRebuild() &&
13750 Cond.get() == E->getCond() &&
13751 LHS.get() == E->getLHS() &&
13752 RHS.get() == E->getRHS())
13753 return E;
13754
13755 return getDerived().RebuildConditionalOperator(Cond.get(),
13756 E->getQuestionLoc(),
13757 LHS.get(),
13758 E->getColonLoc(),
13759 RHS.get());
13760}
13761
13762template<typename Derived>
13765 // Implicit casts are eliminated during transformation, since they
13766 // will be recomputed by semantic analysis after transformation.
13767 return getDerived().TransformExpr(E->getSubExprAsWritten());
13768}
13769
13770template<typename Derived>
13773 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13774 if (!Type)
13775 return ExprError();
13776
13777 ExprResult SubExpr
13778 = getDerived().TransformExpr(E->getSubExprAsWritten());
13779 if (SubExpr.isInvalid())
13780 return ExprError();
13781
13782 if (!getDerived().AlwaysRebuild() &&
13783 Type == E->getTypeInfoAsWritten() &&
13784 SubExpr.get() == E->getSubExpr())
13785 return E;
13786
13787 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13788 Type,
13789 E->getRParenLoc(),
13790 SubExpr.get());
13791}
13792
13793template<typename Derived>
13796 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13797 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13798 if (!NewT)
13799 return ExprError();
13800
13801 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13802 if (Init.isInvalid())
13803 return ExprError();
13804
13805 if (!getDerived().AlwaysRebuild() &&
13806 OldT == NewT &&
13807 Init.get() == E->getInitializer())
13808 return SemaRef.MaybeBindToTemporary(E);
13809
13810 // Note: the expression type doesn't necessarily match the
13811 // type-as-written, but that's okay, because it should always be
13812 // derivable from the initializer.
13813
13814 return getDerived().RebuildCompoundLiteralExpr(
13815 E->getLParenLoc(), NewT,
13816 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13817}
13818
13819template<typename Derived>
13822 ExprResult Base = getDerived().TransformExpr(E->getBase());
13823 if (Base.isInvalid())
13824 return ExprError();
13825
13826 if (!getDerived().AlwaysRebuild() &&
13827 Base.get() == E->getBase())
13828 return E;
13829
13830 // FIXME: Bad source location
13831 SourceLocation FakeOperatorLoc =
13832 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13833 return getDerived().RebuildExtVectorElementExpr(
13834 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13835 E->getAccessor());
13836}
13837
13838template<typename Derived>
13841 if (InitListExpr *Syntactic = E->getSyntacticForm())
13842 E = Syntactic;
13843
13844 bool InitChanged = false;
13845
13848
13850 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13851 Inits, &InitChanged))
13852 return ExprError();
13853
13854 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13855 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13856 // in some cases. We can't reuse it in general, because the syntactic and
13857 // semantic forms are linked, and we can't know that semantic form will
13858 // match even if the syntactic form does.
13859 }
13860
13861 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13862 E->getRBraceLoc());
13863}
13864
13865template<typename Derived>
13868 Designation Desig;
13869
13870 // transform the initializer value
13871 ExprResult Init = getDerived().TransformExpr(E->getInit());
13872 if (Init.isInvalid())
13873 return ExprError();
13874
13875 // transform the designators.
13876 SmallVector<Expr*, 4> ArrayExprs;
13877 bool ExprChanged = false;
13878 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13879 if (D.isFieldDesignator()) {
13880 if (D.getFieldDecl()) {
13881 FieldDecl *Field = cast_or_null<FieldDecl>(
13882 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13883 if (Field != D.getFieldDecl())
13884 // Rebuild the expression when the transformed FieldDecl is
13885 // different to the already assigned FieldDecl.
13886 ExprChanged = true;
13887 if (Field->isAnonymousStructOrUnion())
13888 continue;
13889 } else {
13890 // Ensure that the designator expression is rebuilt when there isn't
13891 // a resolved FieldDecl in the designator as we don't want to assign
13892 // a FieldDecl to a pattern designator that will be instantiated again.
13893 ExprChanged = true;
13894 }
13895 Desig.AddDesignator(Designator::CreateFieldDesignator(
13896 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13897 continue;
13898 }
13899
13900 if (D.isArrayDesignator()) {
13901 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13902 if (Index.isInvalid())
13903 return ExprError();
13904
13905 Desig.AddDesignator(
13906 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13907
13908 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
13909 ArrayExprs.push_back(Index.get());
13910 continue;
13911 }
13912
13913 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13914 ExprResult Start
13915 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13916 if (Start.isInvalid())
13917 return ExprError();
13918
13919 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13920 if (End.isInvalid())
13921 return ExprError();
13922
13923 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13924 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13925
13926 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13927 End.get() != E->getArrayRangeEnd(D);
13928
13929 ArrayExprs.push_back(Start.get());
13930 ArrayExprs.push_back(End.get());
13931 }
13932
13933 if (!getDerived().AlwaysRebuild() &&
13934 Init.get() == E->getInit() &&
13935 !ExprChanged)
13936 return E;
13937
13938 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13939 E->getEqualOrColonLoc(),
13940 E->usesGNUSyntax(), Init.get());
13941}
13942
13943// Seems that if TransformInitListExpr() only works on the syntactic form of an
13944// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13945template<typename Derived>
13949 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13950 "initializer");
13951 return ExprError();
13952}
13953
13954template<typename Derived>
13957 NoInitExpr *E) {
13958 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13959 return ExprError();
13960}
13961
13962template<typename Derived>
13965 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13966 return ExprError();
13967}
13968
13969template<typename Derived>
13972 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13973 return ExprError();
13974}
13975
13976template<typename Derived>
13980 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13981
13982 // FIXME: Will we ever have proper type location here? Will we actually
13983 // need to transform the type?
13984 QualType T = getDerived().TransformType(E->getType());
13985 if (T.isNull())
13986 return ExprError();
13987
13988 if (!getDerived().AlwaysRebuild() &&
13989 T == E->getType())
13990 return E;
13991
13992 return getDerived().RebuildImplicitValueInitExpr(T);
13993}
13994
13995template<typename Derived>
13998 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13999 if (!TInfo)
14000 return ExprError();
14001
14002 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14003 if (SubExpr.isInvalid())
14004 return ExprError();
14005
14006 if (!getDerived().AlwaysRebuild() &&
14007 TInfo == E->getWrittenTypeInfo() &&
14008 SubExpr.get() == E->getSubExpr())
14009 return E;
14010
14011 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14012 TInfo, E->getRParenLoc());
14013}
14014
14015template<typename Derived>
14018 bool ArgumentChanged = false;
14020 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14021 &ArgumentChanged))
14022 return ExprError();
14023
14024 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14025 Inits,
14026 E->getRParenLoc());
14027}
14028
14029/// Transform an address-of-label expression.
14030///
14031/// By default, the transformation of an address-of-label expression always
14032/// rebuilds the expression, so that the label identifier can be resolved to
14033/// the corresponding label statement by semantic analysis.
14034template<typename Derived>
14037 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14038 E->getLabel());
14039 if (!LD)
14040 return ExprError();
14041
14042 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14043 cast<LabelDecl>(LD));
14044}
14045
14046template<typename Derived>
14049 SemaRef.ActOnStartStmtExpr();
14050 StmtResult SubStmt
14051 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14052 if (SubStmt.isInvalid()) {
14053 SemaRef.ActOnStmtExprError();
14054 return ExprError();
14055 }
14056
14057 unsigned OldDepth = E->getTemplateDepth();
14058 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14059
14060 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14061 SubStmt.get() == E->getSubStmt()) {
14062 // Calling this an 'error' is unintuitive, but it does the right thing.
14063 SemaRef.ActOnStmtExprError();
14064 return SemaRef.MaybeBindToTemporary(E);
14065 }
14066
14067 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14068 E->getRParenLoc(), NewDepth);
14069}
14070
14071template<typename Derived>
14074 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14075 if (Cond.isInvalid())
14076 return ExprError();
14077
14078 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14079 if (LHS.isInvalid())
14080 return ExprError();
14081
14082 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14083 if (RHS.isInvalid())
14084 return ExprError();
14085
14086 if (!getDerived().AlwaysRebuild() &&
14087 Cond.get() == E->getCond() &&
14088 LHS.get() == E->getLHS() &&
14089 RHS.get() == E->getRHS())
14090 return E;
14091
14092 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14093 Cond.get(), LHS.get(), RHS.get(),
14094 E->getRParenLoc());
14095}
14096
14097template<typename Derived>
14100 return E;
14101}
14102
14103template<typename Derived>
14106 switch (E->getOperator()) {
14107 case OO_New:
14108 case OO_Delete:
14109 case OO_Array_New:
14110 case OO_Array_Delete:
14111 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14112
14113 case OO_Subscript:
14114 case OO_Call: {
14115 // This is a call to an object's operator().
14116 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14117
14118 // Transform the object itself.
14119 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14120 if (Object.isInvalid())
14121 return ExprError();
14122
14123 // FIXME: Poor location information. Also, if the location for the end of
14124 // the token is within a macro expansion, getLocForEndOfToken() will return
14125 // an invalid source location. If that happens and we have an otherwise
14126 // valid end location, use the valid one instead of the invalid one.
14127 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14128 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14129 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14130 FakeLParenLoc = EndLoc;
14131
14132 // Transform the call arguments.
14134 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14135 Args))
14136 return ExprError();
14137
14138 if (E->getOperator() == OO_Subscript)
14139 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14140 Args, E->getEndLoc());
14141
14142 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14143 E->getEndLoc());
14144 }
14145
14146#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14147 case OO_##Name: \
14148 break;
14149
14150#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14151#include "clang/Basic/OperatorKinds.def"
14152
14153 case OO_Conditional:
14154 llvm_unreachable("conditional operator is not actually overloadable");
14155
14156 case OO_None:
14158 llvm_unreachable("not an overloaded operator?");
14159 }
14160
14162 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14163 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14164 else
14165 First = getDerived().TransformExpr(E->getArg(0));
14166 if (First.isInvalid())
14167 return ExprError();
14168
14169 ExprResult Second;
14170 if (E->getNumArgs() == 2) {
14171 Second =
14172 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14173 if (Second.isInvalid())
14174 return ExprError();
14175 }
14176
14177 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14178 FPOptionsOverride NewOverrides(E->getFPFeatures());
14179 getSema().CurFPFeatures =
14180 NewOverrides.applyOverrides(getSema().getLangOpts());
14181 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14182
14183 Expr *Callee = E->getCallee();
14184 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14185 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14187 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14188 return ExprError();
14189
14190 return getDerived().RebuildCXXOperatorCallExpr(
14191 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14192 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14193 }
14194
14195 UnresolvedSet<1> Functions;
14196 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14197 Callee = ICE->getSubExprAsWritten();
14198 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14199 ValueDecl *VD = cast_or_null<ValueDecl>(
14200 getDerived().TransformDecl(DR->getLocation(), DR));
14201 if (!VD)
14202 return ExprError();
14203
14204 if (!isa<CXXMethodDecl>(VD))
14205 Functions.addDecl(VD);
14206
14207 return getDerived().RebuildCXXOperatorCallExpr(
14208 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14209 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14210}
14211
14212template<typename Derived>
14215 return getDerived().TransformCallExpr(E);
14216}
14217
14218template <typename Derived>
14220 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14221 getSema().CurContext != E->getParentContext();
14222
14223 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14224 return E;
14225
14226 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14227 E->getBeginLoc(), E->getEndLoc(),
14228 getSema().CurContext);
14229}
14230
14231template <typename Derived>
14233 return E;
14234}
14235
14236template<typename Derived>
14239 // Transform the callee.
14240 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14241 if (Callee.isInvalid())
14242 return ExprError();
14243
14244 // Transform exec config.
14245 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14246 if (EC.isInvalid())
14247 return ExprError();
14248
14249 // Transform arguments.
14250 bool ArgChanged = false;
14252 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14253 &ArgChanged))
14254 return ExprError();
14255
14256 if (!getDerived().AlwaysRebuild() &&
14257 Callee.get() == E->getCallee() &&
14258 !ArgChanged)
14259 return SemaRef.MaybeBindToTemporary(E);
14260
14261 // FIXME: Wrong source location information for the '('.
14262 SourceLocation FakeLParenLoc
14263 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14264 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14265 Args,
14266 E->getRParenLoc(), EC.get());
14267}
14268
14269template<typename Derived>
14272 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14273 if (!Type)
14274 return ExprError();
14275
14276 ExprResult SubExpr
14277 = getDerived().TransformExpr(E->getSubExprAsWritten());
14278 if (SubExpr.isInvalid())
14279 return ExprError();
14280
14281 if (!getDerived().AlwaysRebuild() &&
14282 Type == E->getTypeInfoAsWritten() &&
14283 SubExpr.get() == E->getSubExpr())
14284 return E;
14285 return getDerived().RebuildCXXNamedCastExpr(
14288 // FIXME. this should be '(' location
14289 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14290}
14291
14292template<typename Derived>
14295 TypeSourceInfo *TSI =
14296 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14297 if (!TSI)
14298 return ExprError();
14299
14300 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14301 if (Sub.isInvalid())
14302 return ExprError();
14303
14304 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14305 Sub.get(), BCE->getEndLoc());
14306}
14307
14308template<typename Derived>
14310TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14311 return getDerived().TransformCXXNamedCastExpr(E);
14312}
14313
14314template<typename Derived>
14317 return getDerived().TransformCXXNamedCastExpr(E);
14318}
14319
14320template<typename Derived>
14324 return getDerived().TransformCXXNamedCastExpr(E);
14325}
14326
14327template<typename Derived>
14330 return getDerived().TransformCXXNamedCastExpr(E);
14331}
14332
14333template<typename Derived>
14336 return getDerived().TransformCXXNamedCastExpr(E);
14337}
14338
14339template<typename Derived>
14344 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14345 if (!Type)
14346 return ExprError();
14347
14348 ExprResult SubExpr
14349 = getDerived().TransformExpr(E->getSubExprAsWritten());
14350 if (SubExpr.isInvalid())
14351 return ExprError();
14352
14353 if (!getDerived().AlwaysRebuild() &&
14354 Type == E->getTypeInfoAsWritten() &&
14355 SubExpr.get() == E->getSubExpr())
14356 return E;
14357
14358 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14359 E->getLParenLoc(),
14360 SubExpr.get(),
14361 E->getRParenLoc(),
14362 E->isListInitialization());
14363}
14364
14365template<typename Derived>
14368 if (E->isTypeOperand()) {
14369 TypeSourceInfo *TInfo
14370 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14371 if (!TInfo)
14372 return ExprError();
14373
14374 if (!getDerived().AlwaysRebuild() &&
14375 TInfo == E->getTypeOperandSourceInfo())
14376 return E;
14377
14378 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14379 TInfo, E->getEndLoc());
14380 }
14381
14382 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14383 // type. We must not unilaterally enter unevaluated context here, as then
14384 // semantic processing can re-transform an already transformed operand.
14385 Expr *Op = E->getExprOperand();
14387 if (E->isGLValue())
14388 if (auto *RD = Op->getType()->getAsCXXRecordDecl();
14389 RD && RD->isPolymorphic())
14390 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14391
14394
14395 ExprResult SubExpr = getDerived().TransformExpr(Op);
14396 if (SubExpr.isInvalid())
14397 return ExprError();
14398
14399 if (!getDerived().AlwaysRebuild() &&
14400 SubExpr.get() == E->getExprOperand())
14401 return E;
14402
14403 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14404 SubExpr.get(), E->getEndLoc());
14405}
14406
14407template<typename Derived>
14410 if (E->isTypeOperand()) {
14411 TypeSourceInfo *TInfo
14412 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14413 if (!TInfo)
14414 return ExprError();
14415
14416 if (!getDerived().AlwaysRebuild() &&
14417 TInfo == E->getTypeOperandSourceInfo())
14418 return E;
14419
14420 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14421 TInfo, E->getEndLoc());
14422 }
14423
14426
14427 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14428 if (SubExpr.isInvalid())
14429 return ExprError();
14430
14431 if (!getDerived().AlwaysRebuild() &&
14432 SubExpr.get() == E->getExprOperand())
14433 return E;
14434
14435 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14436 SubExpr.get(), E->getEndLoc());
14437}
14438
14439template<typename Derived>
14442 return E;
14443}
14444
14445template<typename Derived>
14449 return E;
14450}
14451
14452template<typename Derived>
14455
14456 // In lambdas, the qualifiers of the type depends of where in
14457 // the call operator `this` appear, and we do not have a good way to
14458 // rebuild this information, so we transform the type.
14459 //
14460 // In other contexts, the type of `this` may be overrided
14461 // for type deduction, so we need to recompute it.
14462 //
14463 // Always recompute the type if we're in the body of a lambda, and
14464 // 'this' is dependent on a lambda's explicit object parameter; we
14465 // also need to always rebuild the expression in this case to clear
14466 // the flag.
14467 QualType T = [&]() {
14468 auto &S = getSema();
14469 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14470 return S.getCurrentThisType();
14471 if (S.getCurLambda())
14472 return getDerived().TransformType(E->getType());
14473 return S.getCurrentThisType();
14474 }();
14475
14476 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14477 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14478 // Mark it referenced in the new context regardless.
14479 // FIXME: this is a bit instantiation-specific.
14480 getSema().MarkThisReferenced(E);
14481 return E;
14482 }
14483
14484 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14485}
14486
14487template<typename Derived>
14490 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14491 if (SubExpr.isInvalid())
14492 return ExprError();
14493
14494 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14495
14496 if (!getDerived().AlwaysRebuild() &&
14497 SubExpr.get() == E->getSubExpr())
14498 return E;
14499
14500 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14501 E->isThrownVariableInScope());
14502}
14503
14504template<typename Derived>
14507 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14508 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14509 if (!Param)
14510 return ExprError();
14511
14512 ExprResult InitRes;
14513 if (E->hasRewrittenInit()) {
14514 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14515 if (InitRes.isInvalid())
14516 return ExprError();
14517 }
14518
14519 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14520 E->getUsedContext() == SemaRef.CurContext &&
14521 InitRes.get() == E->getRewrittenExpr())
14522 return E;
14523
14524 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14525 InitRes.get());
14526}
14527
14528template<typename Derived>
14531 FieldDecl *Field = cast_or_null<FieldDecl>(
14532 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14533 if (!Field)
14534 return ExprError();
14535
14536 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14537 E->getUsedContext() == SemaRef.CurContext)
14538 return E;
14539
14540 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14541}
14542
14543template<typename Derived>
14547 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14548 if (!T)
14549 return ExprError();
14550
14551 if (!getDerived().AlwaysRebuild() &&
14552 T == E->getTypeSourceInfo())
14553 return E;
14554
14555 return getDerived().RebuildCXXScalarValueInitExpr(T,
14556 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14557 E->getRParenLoc());
14558}
14559
14560template<typename Derived>
14563 // Transform the type that we're allocating
14564 TypeSourceInfo *AllocTypeInfo =
14565 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14566 if (!AllocTypeInfo)
14567 return ExprError();
14568
14569 // Transform the size of the array we're allocating (if any).
14570 std::optional<Expr *> ArraySize;
14571 if (E->isArray()) {
14572 ExprResult NewArraySize;
14573 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14574 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14575 if (NewArraySize.isInvalid())
14576 return ExprError();
14577 }
14578 ArraySize = NewArraySize.get();
14579 }
14580
14581 // Transform the placement arguments (if any).
14582 bool ArgumentChanged = false;
14583 SmallVector<Expr*, 8> PlacementArgs;
14584 if (getDerived().TransformExprs(E->getPlacementArgs(),
14585 E->getNumPlacementArgs(), true,
14586 PlacementArgs, &ArgumentChanged))
14587 return ExprError();
14588
14589 // Transform the initializer (if any).
14590 Expr *OldInit = E->getInitializer();
14591 ExprResult NewInit;
14592 if (OldInit)
14593 NewInit = getDerived().TransformInitializer(OldInit, true);
14594 if (NewInit.isInvalid())
14595 return ExprError();
14596
14597 // Transform new operator and delete operator.
14598 FunctionDecl *OperatorNew = nullptr;
14599 if (E->getOperatorNew()) {
14600 OperatorNew = cast_or_null<FunctionDecl>(
14601 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14602 if (!OperatorNew)
14603 return ExprError();
14604 }
14605
14606 FunctionDecl *OperatorDelete = nullptr;
14607 if (E->getOperatorDelete()) {
14608 OperatorDelete = cast_or_null<FunctionDecl>(
14609 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14610 if (!OperatorDelete)
14611 return ExprError();
14612 }
14613
14614 if (!getDerived().AlwaysRebuild() &&
14615 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14616 ArraySize == E->getArraySize() &&
14617 NewInit.get() == OldInit &&
14618 OperatorNew == E->getOperatorNew() &&
14619 OperatorDelete == E->getOperatorDelete() &&
14620 !ArgumentChanged) {
14621 // Mark any declarations we need as referenced.
14622 // FIXME: instantiation-specific.
14623 if (OperatorNew)
14624 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14625 if (OperatorDelete)
14626 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14627
14628 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14629 QualType ElementType
14630 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14631 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
14633 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
14634 }
14635 }
14636
14637 return E;
14638 }
14639
14640 QualType AllocType = AllocTypeInfo->getType();
14641 if (!ArraySize) {
14642 // If no array size was specified, but the new expression was
14643 // instantiated with an array type (e.g., "new T" where T is
14644 // instantiated with "int[4]"), extract the outer bound from the
14645 // array type as our array size. We do this with constant and
14646 // dependently-sized array types.
14647 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14648 if (!ArrayT) {
14649 // Do nothing
14650 } else if (const ConstantArrayType *ConsArrayT
14651 = dyn_cast<ConstantArrayType>(ArrayT)) {
14652 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14653 SemaRef.Context.getSizeType(),
14654 /*FIXME:*/ E->getBeginLoc());
14655 AllocType = ConsArrayT->getElementType();
14656 } else if (const DependentSizedArrayType *DepArrayT
14657 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14658 if (DepArrayT->getSizeExpr()) {
14659 ArraySize = DepArrayT->getSizeExpr();
14660 AllocType = DepArrayT->getElementType();
14661 }
14662 }
14663 }
14664
14665 return getDerived().RebuildCXXNewExpr(
14666 E->getBeginLoc(), E->isGlobalNew(),
14667 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14668 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14669 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14670}
14671
14672template<typename Derived>
14675 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14676 if (Operand.isInvalid())
14677 return ExprError();
14678
14679 // Transform the delete operator, if known.
14680 FunctionDecl *OperatorDelete = nullptr;
14681 if (E->getOperatorDelete()) {
14682 OperatorDelete = cast_or_null<FunctionDecl>(
14683 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14684 if (!OperatorDelete)
14685 return ExprError();
14686 }
14687
14688 if (!getDerived().AlwaysRebuild() &&
14689 Operand.get() == E->getArgument() &&
14690 OperatorDelete == E->getOperatorDelete()) {
14691 // Mark any declarations we need as referenced.
14692 // FIXME: instantiation-specific.
14693 if (OperatorDelete)
14694 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14695
14696 if (!E->getArgument()->isTypeDependent()) {
14697 QualType Destroyed = SemaRef.Context.getBaseElementType(
14698 E->getDestroyedType());
14699 if (auto *Record = Destroyed->getAsCXXRecordDecl())
14700 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
14701 SemaRef.LookupDestructor(Record));
14702 }
14703
14704 return E;
14705 }
14706
14707 return getDerived().RebuildCXXDeleteExpr(
14708 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14709}
14710
14711template<typename Derived>
14715 ExprResult Base = getDerived().TransformExpr(E->getBase());
14716 if (Base.isInvalid())
14717 return ExprError();
14718
14719 ParsedType ObjectTypePtr;
14720 bool MayBePseudoDestructor = false;
14721 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14722 E->getOperatorLoc(),
14723 E->isArrow()? tok::arrow : tok::period,
14724 ObjectTypePtr,
14725 MayBePseudoDestructor);
14726 if (Base.isInvalid())
14727 return ExprError();
14728
14729 QualType ObjectType = ObjectTypePtr.get();
14730 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14731 if (QualifierLoc) {
14732 QualifierLoc
14733 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14734 if (!QualifierLoc)
14735 return ExprError();
14736 }
14737 CXXScopeSpec SS;
14738 SS.Adopt(QualifierLoc);
14739
14741 if (E->getDestroyedTypeInfo()) {
14742 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
14743 E->getDestroyedTypeInfo(), ObjectType,
14744 /*FirstQualifierInScope=*/nullptr);
14745 if (!DestroyedTypeInfo)
14746 return ExprError();
14747 Destroyed = DestroyedTypeInfo;
14748 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14749 // We aren't likely to be able to resolve the identifier down to a type
14750 // now anyway, so just retain the identifier.
14751 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14752 E->getDestroyedTypeLoc());
14753 } else {
14754 // Look for a destructor known with the given name.
14755 ParsedType T = SemaRef.getDestructorName(
14756 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14757 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14758 if (!T)
14759 return ExprError();
14760
14761 Destroyed
14763 E->getDestroyedTypeLoc());
14764 }
14765
14766 TypeSourceInfo *ScopeTypeInfo = nullptr;
14767 if (E->getScopeTypeInfo()) {
14768 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14769 E->getScopeTypeInfo(), ObjectType, nullptr);
14770 if (!ScopeTypeInfo)
14771 return ExprError();
14772 }
14773
14774 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14775 E->getOperatorLoc(),
14776 E->isArrow(),
14777 SS,
14778 ScopeTypeInfo,
14779 E->getColonColonLoc(),
14780 E->getTildeLoc(),
14781 Destroyed);
14782}
14783
14784template <typename Derived>
14786 bool RequiresADL,
14787 LookupResult &R) {
14788 // Transform all the decls.
14789 bool AllEmptyPacks = true;
14790 for (auto *OldD : Old->decls()) {
14791 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14792 if (!InstD) {
14793 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14794 // This can happen because of dependent hiding.
14795 if (isa<UsingShadowDecl>(OldD))
14796 continue;
14797 else {
14798 R.clear();
14799 return true;
14800 }
14801 }
14802
14803 // Expand using pack declarations.
14804 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14805 ArrayRef<NamedDecl*> Decls = SingleDecl;
14806 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14807 Decls = UPD->expansions();
14808
14809 // Expand using declarations.
14810 for (auto *D : Decls) {
14811 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14812 for (auto *SD : UD->shadows())
14813 R.addDecl(SD);
14814 } else {
14815 R.addDecl(D);
14816 }
14817 }
14818
14819 AllEmptyPacks &= Decls.empty();
14820 }
14821
14822 // C++ [temp.res]/8.4.2:
14823 // The program is ill-formed, no diagnostic required, if [...] lookup for
14824 // a name in the template definition found a using-declaration, but the
14825 // lookup in the corresponding scope in the instantiation odoes not find
14826 // any declarations because the using-declaration was a pack expansion and
14827 // the corresponding pack is empty
14828 if (AllEmptyPacks && !RequiresADL) {
14829 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14830 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14831 return true;
14832 }
14833
14834 // Resolve a kind, but don't do any further analysis. If it's
14835 // ambiguous, the callee needs to deal with it.
14836 R.resolveKind();
14837
14838 if (Old->hasTemplateKeyword() && !R.empty()) {
14840 getSema().FilterAcceptableTemplateNames(R,
14841 /*AllowFunctionTemplates=*/true,
14842 /*AllowDependent=*/true);
14843 if (R.empty()) {
14844 // If a 'template' keyword was used, a lookup that finds only non-template
14845 // names is an error.
14846 getSema().Diag(R.getNameLoc(),
14847 diag::err_template_kw_refers_to_non_template)
14849 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14850 getSema().Diag(FoundDecl->getLocation(),
14851 diag::note_template_kw_refers_to_non_template)
14852 << R.getLookupName();
14853 return true;
14854 }
14855 }
14856
14857 return false;
14858}
14859
14860template <typename Derived>
14865
14866template <typename Derived>
14869 bool IsAddressOfOperand) {
14870 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14872
14873 // Transform the declaration set.
14874 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14875 return ExprError();
14876
14877 // Rebuild the nested-name qualifier, if present.
14878 CXXScopeSpec SS;
14879 if (Old->getQualifierLoc()) {
14880 NestedNameSpecifierLoc QualifierLoc
14881 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14882 if (!QualifierLoc)
14883 return ExprError();
14884
14885 SS.Adopt(QualifierLoc);
14886 }
14887
14888 if (Old->getNamingClass()) {
14889 CXXRecordDecl *NamingClass
14890 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14891 Old->getNameLoc(),
14892 Old->getNamingClass()));
14893 if (!NamingClass) {
14894 R.clear();
14895 return ExprError();
14896 }
14897
14898 R.setNamingClass(NamingClass);
14899 }
14900
14901 // Rebuild the template arguments, if any.
14902 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14903 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14904 if (Old->hasExplicitTemplateArgs() &&
14905 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14906 Old->getNumTemplateArgs(),
14907 TransArgs)) {
14908 R.clear();
14909 return ExprError();
14910 }
14911
14912 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14913 // a non-static data member is named in an unevaluated operand, or when
14914 // a member is named in a dependent class scope function template explicit
14915 // specialization that is neither declared static nor with an explicit object
14916 // parameter.
14917 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14918 return SemaRef.BuildPossibleImplicitMemberExpr(
14919 SS, TemplateKWLoc, R,
14920 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14921 /*S=*/nullptr);
14922
14923 // If we have neither explicit template arguments, nor the template keyword,
14924 // it's a normal declaration name or member reference.
14925 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14926 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14927
14928 // If we have template arguments, then rebuild the template-id expression.
14929 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14930 Old->requiresADL(), &TransArgs);
14931}
14932
14933template<typename Derived>
14936 bool ArgChanged = false;
14938 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14939 TypeSourceInfo *From = E->getArg(I);
14940 TypeLoc FromTL = From->getTypeLoc();
14941 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14942 TypeLocBuilder TLB;
14943 TLB.reserve(FromTL.getFullDataSize());
14944 QualType To = getDerived().TransformType(TLB, FromTL);
14945 if (To.isNull())
14946 return ExprError();
14947
14948 if (To == From->getType())
14949 Args.push_back(From);
14950 else {
14951 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14952 ArgChanged = true;
14953 }
14954 continue;
14955 }
14956
14957 ArgChanged = true;
14958
14959 // We have a pack expansion. Instantiate it.
14960 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14961 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14963 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14964
14965 // Determine whether the set of unexpanded parameter packs can and should
14966 // be expanded.
14967 bool Expand = true;
14968 bool RetainExpansion = false;
14969 UnsignedOrNone OrigNumExpansions =
14970 ExpansionTL.getTypePtr()->getNumExpansions();
14971 UnsignedOrNone NumExpansions = OrigNumExpansions;
14972 if (getDerived().TryExpandParameterPacks(
14973 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
14974 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
14975 RetainExpansion, NumExpansions))
14976 return ExprError();
14977
14978 if (!Expand) {
14979 // The transform has determined that we should perform a simple
14980 // transformation on the pack expansion, producing another pack
14981 // expansion.
14982 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
14983
14984 TypeLocBuilder TLB;
14985 TLB.reserve(From->getTypeLoc().getFullDataSize());
14986
14987 QualType To = getDerived().TransformType(TLB, PatternTL);
14988 if (To.isNull())
14989 return ExprError();
14990
14991 To = getDerived().RebuildPackExpansionType(To,
14992 PatternTL.getSourceRange(),
14993 ExpansionTL.getEllipsisLoc(),
14994 NumExpansions);
14995 if (To.isNull())
14996 return ExprError();
14997
14998 PackExpansionTypeLoc ToExpansionTL
14999 = TLB.push<PackExpansionTypeLoc>(To);
15000 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15001 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15002 continue;
15003 }
15004
15005 // Expand the pack expansion by substituting for each argument in the
15006 // pack(s).
15007 for (unsigned I = 0; I != *NumExpansions; ++I) {
15008 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15009 TypeLocBuilder TLB;
15010 TLB.reserve(PatternTL.getFullDataSize());
15011 QualType To = getDerived().TransformType(TLB, PatternTL);
15012 if (To.isNull())
15013 return ExprError();
15014
15015 if (To->containsUnexpandedParameterPack()) {
15016 To = getDerived().RebuildPackExpansionType(To,
15017 PatternTL.getSourceRange(),
15018 ExpansionTL.getEllipsisLoc(),
15019 NumExpansions);
15020 if (To.isNull())
15021 return ExprError();
15022
15023 PackExpansionTypeLoc ToExpansionTL
15024 = TLB.push<PackExpansionTypeLoc>(To);
15025 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15026 }
15027
15028 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15029 }
15030
15031 if (!RetainExpansion)
15032 continue;
15033
15034 // If we're supposed to retain a pack expansion, do so by temporarily
15035 // forgetting the partially-substituted parameter pack.
15036 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15037
15038 TypeLocBuilder TLB;
15039 TLB.reserve(From->getTypeLoc().getFullDataSize());
15040
15041 QualType To = getDerived().TransformType(TLB, PatternTL);
15042 if (To.isNull())
15043 return ExprError();
15044
15045 To = getDerived().RebuildPackExpansionType(To,
15046 PatternTL.getSourceRange(),
15047 ExpansionTL.getEllipsisLoc(),
15048 NumExpansions);
15049 if (To.isNull())
15050 return ExprError();
15051
15052 PackExpansionTypeLoc ToExpansionTL
15053 = TLB.push<PackExpansionTypeLoc>(To);
15054 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15055 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15056 }
15057
15058 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15059 return E;
15060
15061 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15062 E->getEndLoc());
15063}
15064
15065template<typename Derived>
15069 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15070 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15071 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15072 Old->NumTemplateArgs, TransArgs))
15073 return ExprError();
15074
15075 return getDerived().RebuildConceptSpecializationExpr(
15076 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15077 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15078 &TransArgs);
15079}
15080
15081template<typename Derived>
15084 SmallVector<ParmVarDecl*, 4> TransParams;
15085 SmallVector<QualType, 4> TransParamTypes;
15086 Sema::ExtParameterInfoBuilder ExtParamInfos;
15087
15088 // C++2a [expr.prim.req]p2
15089 // Expressions appearing within a requirement-body are unevaluated operands.
15093
15095 getSema().Context, getSema().CurContext,
15096 E->getBody()->getBeginLoc());
15097
15098 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15099
15100 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15101 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15102 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15103
15104 for (ParmVarDecl *Param : TransParams)
15105 if (Param)
15106 Param->setDeclContext(Body);
15107
15108 // On failure to transform, TransformRequiresTypeParams returns an expression
15109 // in the event that the transformation of the type params failed in some way.
15110 // It is expected that this will result in a 'not satisfied' Requires clause
15111 // when instantiating.
15112 if (!TypeParamResult.isUnset())
15113 return TypeParamResult;
15114
15116 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15117 TransReqs))
15118 return ExprError();
15119
15120 for (concepts::Requirement *Req : TransReqs) {
15121 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15122 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15123 ER->getReturnTypeRequirement()
15124 .getTypeConstraintTemplateParameterList()->getParam(0)
15125 ->setDeclContext(Body);
15126 }
15127 }
15128 }
15129
15130 return getDerived().RebuildRequiresExpr(
15131 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15132 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15133}
15134
15135template<typename Derived>
15139 for (concepts::Requirement *Req : Reqs) {
15140 concepts::Requirement *TransReq = nullptr;
15141 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15142 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15143 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15144 TransReq = getDerived().TransformExprRequirement(ExprReq);
15145 else
15146 TransReq = getDerived().TransformNestedRequirement(
15148 if (!TransReq)
15149 return true;
15150 Transformed.push_back(TransReq);
15151 }
15152 return false;
15153}
15154
15155template<typename Derived>
15159 if (Req->isSubstitutionFailure()) {
15160 if (getDerived().AlwaysRebuild())
15161 return getDerived().RebuildTypeRequirement(
15163 return Req;
15164 }
15165 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15166 if (!TransType)
15167 return nullptr;
15168 return getDerived().RebuildTypeRequirement(TransType);
15169}
15170
15171template<typename Derived>
15174 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15175 if (Req->isExprSubstitutionFailure())
15176 TransExpr = Req->getExprSubstitutionDiagnostic();
15177 else {
15178 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15179 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15180 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15181 if (TransExprRes.isInvalid())
15182 return nullptr;
15183 TransExpr = TransExprRes.get();
15184 }
15185
15186 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15187 const auto &RetReq = Req->getReturnTypeRequirement();
15188 if (RetReq.isEmpty())
15189 TransRetReq.emplace();
15190 else if (RetReq.isSubstitutionFailure())
15191 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15192 else if (RetReq.isTypeConstraint()) {
15193 TemplateParameterList *OrigTPL =
15194 RetReq.getTypeConstraintTemplateParameterList();
15196 getDerived().TransformTemplateParameterList(OrigTPL);
15197 if (!TPL)
15198 return nullptr;
15199 TransRetReq.emplace(TPL);
15200 }
15201 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15202 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15203 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15204 Req->getNoexceptLoc(),
15205 std::move(*TransRetReq));
15206 return getDerived().RebuildExprRequirement(
15208 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15209}
15210
15211template<typename Derived>
15215 if (Req->hasInvalidConstraint()) {
15216 if (getDerived().AlwaysRebuild())
15217 return getDerived().RebuildNestedRequirement(
15219 return Req;
15220 }
15221 ExprResult TransConstraint =
15222 getDerived().TransformExpr(Req->getConstraintExpr());
15223 if (TransConstraint.isInvalid())
15224 return nullptr;
15225 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15226}
15227
15228template<typename Derived>
15231 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15232 if (!T)
15233 return ExprError();
15234
15235 if (!getDerived().AlwaysRebuild() &&
15237 return E;
15238
15239 ExprResult SubExpr;
15240 {
15243 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15244 if (SubExpr.isInvalid())
15245 return ExprError();
15246 }
15247
15248 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15249 SubExpr.get(), E->getEndLoc());
15250}
15251
15252template<typename Derived>
15255 ExprResult SubExpr;
15256 {
15259 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15260 if (SubExpr.isInvalid())
15261 return ExprError();
15262
15263 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15264 return E;
15265 }
15266
15267 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15268 SubExpr.get(), E->getEndLoc());
15269}
15270
15271template <typename Derived>
15273 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15274 TypeSourceInfo **RecoveryTSI) {
15275 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15276 DRE, AddrTaken, RecoveryTSI);
15277
15278 // Propagate both errors and recovered types, which return ExprEmpty.
15279 if (!NewDRE.isUsable())
15280 return NewDRE;
15281
15282 // We got an expr, wrap it up in parens.
15283 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15284 return PE;
15285 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15286 PE->getRParen());
15287}
15288
15289template <typename Derived>
15295
15296template <typename Derived>
15298 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15299 TypeSourceInfo **RecoveryTSI) {
15300 assert(E->getQualifierLoc());
15301 NestedNameSpecifierLoc QualifierLoc =
15302 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15303 if (!QualifierLoc)
15304 return ExprError();
15305 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15306
15307 // TODO: If this is a conversion-function-id, verify that the
15308 // destination type name (if present) resolves the same way after
15309 // instantiation as it did in the local scope.
15310
15311 DeclarationNameInfo NameInfo =
15312 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15313 if (!NameInfo.getName())
15314 return ExprError();
15315
15316 if (!E->hasExplicitTemplateArgs()) {
15317 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15318 // Note: it is sufficient to compare the Name component of NameInfo:
15319 // if name has not changed, DNLoc has not changed either.
15320 NameInfo.getName() == E->getDeclName())
15321 return E;
15322
15323 return getDerived().RebuildDependentScopeDeclRefExpr(
15324 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15325 IsAddressOfOperand, RecoveryTSI);
15326 }
15327
15328 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15329 if (getDerived().TransformTemplateArguments(
15330 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15331 return ExprError();
15332
15333 return getDerived().RebuildDependentScopeDeclRefExpr(
15334 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15335 RecoveryTSI);
15336}
15337
15338template<typename Derived>
15341 // CXXConstructExprs other than for list-initialization and
15342 // CXXTemporaryObjectExpr are always implicit, so when we have
15343 // a 1-argument construction we just transform that argument.
15344 if (getDerived().AllowSkippingCXXConstructExpr() &&
15345 ((E->getNumArgs() == 1 ||
15346 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15347 (!getDerived().DropCallArgument(E->getArg(0))) &&
15348 !E->isListInitialization()))
15349 return getDerived().TransformInitializer(E->getArg(0),
15350 /*DirectInit*/ false);
15351
15352 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15353
15354 QualType T = getDerived().TransformType(E->getType());
15355 if (T.isNull())
15356 return ExprError();
15357
15358 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15359 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15360 if (!Constructor)
15361 return ExprError();
15362
15363 bool ArgumentChanged = false;
15365 {
15368 E->isListInitialization());
15369 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15370 &ArgumentChanged))
15371 return ExprError();
15372 }
15373
15374 if (!getDerived().AlwaysRebuild() &&
15375 T == E->getType() &&
15376 Constructor == E->getConstructor() &&
15377 !ArgumentChanged) {
15378 // Mark the constructor as referenced.
15379 // FIXME: Instantiation-specific
15380 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15381 return E;
15382 }
15383
15384 return getDerived().RebuildCXXConstructExpr(
15385 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15386 E->hadMultipleCandidates(), E->isListInitialization(),
15387 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15388 E->getConstructionKind(), E->getParenOrBraceRange());
15389}
15390
15391template<typename Derived>
15394 QualType T = getDerived().TransformType(E->getType());
15395 if (T.isNull())
15396 return ExprError();
15397
15398 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15399 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15400 if (!Constructor)
15401 return ExprError();
15402
15403 if (!getDerived().AlwaysRebuild() &&
15404 T == E->getType() &&
15405 Constructor == E->getConstructor()) {
15406 // Mark the constructor as referenced.
15407 // FIXME: Instantiation-specific
15408 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15409 return E;
15410 }
15411
15412 return getDerived().RebuildCXXInheritedCtorInitExpr(
15413 T, E->getLocation(), Constructor,
15414 E->constructsVBase(), E->inheritedFromVBase());
15415}
15416
15417/// Transform a C++ temporary-binding expression.
15418///
15419/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15420/// transform the subexpression and return that.
15421template<typename Derived>
15424 if (auto *Dtor = E->getTemporary()->getDestructor())
15425 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15426 const_cast<CXXDestructorDecl *>(Dtor));
15427 return getDerived().TransformExpr(E->getSubExpr());
15428}
15429
15430/// Transform a C++ expression that contains cleanups that should
15431/// be run after the expression is evaluated.
15432///
15433/// Since ExprWithCleanups nodes are implicitly generated, we
15434/// just transform the subexpression and return that.
15435template<typename Derived>
15438 return getDerived().TransformExpr(E->getSubExpr());
15439}
15440
15441template<typename Derived>
15445 TypeSourceInfo *T =
15446 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15447 if (!T)
15448 return ExprError();
15449
15450 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15451 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15452 if (!Constructor)
15453 return ExprError();
15454
15455 bool ArgumentChanged = false;
15457 Args.reserve(E->getNumArgs());
15458 {
15461 E->isListInitialization());
15462 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15463 &ArgumentChanged))
15464 return ExprError();
15465
15466 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15467 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15468 if (Res.isInvalid())
15469 return ExprError();
15470 Args = {Res.get()};
15471 }
15472 }
15473
15474 if (!getDerived().AlwaysRebuild() &&
15475 T == E->getTypeSourceInfo() &&
15476 Constructor == E->getConstructor() &&
15477 !ArgumentChanged) {
15478 // FIXME: Instantiation-specific
15479 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15480 return SemaRef.MaybeBindToTemporary(E);
15481 }
15482
15483 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15484 return getDerived().RebuildCXXTemporaryObjectExpr(
15485 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15486}
15487
15488template<typename Derived>
15491 // Transform any init-capture expressions before entering the scope of the
15492 // lambda body, because they are not semantically within that scope.
15493 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15494 struct TransformedInitCapture {
15495 // The location of the ... if the result is retaining a pack expansion.
15496 SourceLocation EllipsisLoc;
15497 // Zero or more expansions of the init-capture.
15498 SmallVector<InitCaptureInfoTy, 4> Expansions;
15499 };
15501 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15502 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15503 CEnd = E->capture_end();
15504 C != CEnd; ++C) {
15505 if (!E->isInitCapture(C))
15506 continue;
15507
15508 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15509 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15510
15511 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15512 UnsignedOrNone NumExpansions) {
15513 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15514 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15515
15516 if (NewExprInitResult.isInvalid()) {
15517 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15518 return;
15519 }
15520 Expr *NewExprInit = NewExprInitResult.get();
15521
15522 QualType NewInitCaptureType =
15523 getSema().buildLambdaInitCaptureInitialization(
15524 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15525 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15526 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15528 NewExprInit);
15529 Result.Expansions.push_back(
15530 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15531 };
15532
15533 // If this is an init-capture pack, consider expanding the pack now.
15534 if (OldVD->isParameterPack()) {
15535 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15536 ->getTypeLoc()
15539 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15540
15541 // Determine whether the set of unexpanded parameter packs can and should
15542 // be expanded.
15543 bool Expand = true;
15544 bool RetainExpansion = false;
15545 UnsignedOrNone OrigNumExpansions =
15546 ExpansionTL.getTypePtr()->getNumExpansions();
15547 UnsignedOrNone NumExpansions = OrigNumExpansions;
15548 if (getDerived().TryExpandParameterPacks(
15549 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
15550 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15551 RetainExpansion, NumExpansions))
15552 return ExprError();
15553 assert(!RetainExpansion && "Should not need to retain expansion after a "
15554 "capture since it cannot be extended");
15555 if (Expand) {
15556 for (unsigned I = 0; I != *NumExpansions; ++I) {
15557 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15558 SubstInitCapture(SourceLocation(), std::nullopt);
15559 }
15560 } else {
15561 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15562 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15563 }
15564 } else {
15565 SubstInitCapture(SourceLocation(), std::nullopt);
15566 }
15567 }
15568
15569 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15570 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15571
15572 // Create the local class that will describe the lambda.
15573
15574 // FIXME: DependencyKind below is wrong when substituting inside a templated
15575 // context that isn't a DeclContext (such as a variable template), or when
15576 // substituting an unevaluated lambda inside of a function's parameter's type
15577 // - as parameter types are not instantiated from within a function's DC. We
15578 // use evaluation contexts to distinguish the function parameter case.
15581 DeclContext *DC = getSema().CurContext;
15582 // A RequiresExprBodyDecl is not interesting for dependencies.
15583 // For the following case,
15584 //
15585 // template <typename>
15586 // concept C = requires { [] {}; };
15587 //
15588 // template <class F>
15589 // struct Widget;
15590 //
15591 // template <C F>
15592 // struct Widget<F> {};
15593 //
15594 // While we are substituting Widget<F>, the parent of DC would be
15595 // the template specialization itself. Thus, the lambda expression
15596 // will be deemed as dependent even if there are no dependent template
15597 // arguments.
15598 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15599 while (DC->isRequiresExprBody())
15600 DC = DC->getParent();
15601 if ((getSema().isUnevaluatedContext() ||
15602 getSema().isConstantEvaluatedContext()) &&
15603 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15604 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15605
15606 CXXRecordDecl *OldClass = E->getLambdaClass();
15607 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15608 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15609 E->getCaptureDefault());
15610 getDerived().transformedLocalDecl(OldClass, {Class});
15611
15612 CXXMethodDecl *NewCallOperator =
15613 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15614
15615 // Enter the scope of the lambda.
15616 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15617 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15618 E->hasExplicitParameters(), E->isMutable());
15619
15620 // Introduce the context of the call operator.
15621 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15622 /*NewThisContext*/false);
15623
15624 bool Invalid = false;
15625
15626 // Transform captures.
15627 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15628 CEnd = E->capture_end();
15629 C != CEnd; ++C) {
15630 // When we hit the first implicit capture, tell Sema that we've finished
15631 // the list of explicit captures.
15632 if (C->isImplicit())
15633 break;
15634
15635 // Capturing 'this' is trivial.
15636 if (C->capturesThis()) {
15637 // If this is a lambda that is part of a default member initialiser
15638 // and which we're instantiating outside the class that 'this' is
15639 // supposed to refer to, adjust the type of 'this' accordingly.
15640 //
15641 // Otherwise, leave the type of 'this' as-is.
15642 Sema::CXXThisScopeRAII ThisScope(
15643 getSema(),
15644 dyn_cast_if_present<CXXRecordDecl>(
15645 getSema().getFunctionLevelDeclContext()),
15646 Qualifiers());
15647 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15648 /*BuildAndDiagnose*/ true, nullptr,
15649 C->getCaptureKind() == LCK_StarThis);
15650 continue;
15651 }
15652 // Captured expression will be recaptured during captured variables
15653 // rebuilding.
15654 if (C->capturesVLAType())
15655 continue;
15656
15657 // Rebuild init-captures, including the implied field declaration.
15658 if (E->isInitCapture(C)) {
15659 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15660
15661 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15663
15664 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15665 ExprResult Init = Info.first;
15666 QualType InitQualType = Info.second;
15667 if (Init.isInvalid() || InitQualType.isNull()) {
15668 Invalid = true;
15669 break;
15670 }
15671 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15672 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15673 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15674 getSema().CurContext);
15675 if (!NewVD) {
15676 Invalid = true;
15677 break;
15678 }
15679 NewVDs.push_back(NewVD);
15680 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15681 // Cases we want to tackle:
15682 // ([C(Pack)] {}, ...)
15683 // But rule out cases e.g.
15684 // [...C = Pack()] {}
15685 if (NewC.EllipsisLoc.isInvalid())
15686 LSI->ContainsUnexpandedParameterPack |=
15687 Init.get()->containsUnexpandedParameterPack();
15688 }
15689
15690 if (Invalid)
15691 break;
15692
15693 getDerived().transformedLocalDecl(OldVD, NewVDs);
15694 continue;
15695 }
15696
15697 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15698
15699 // Determine the capture kind for Sema.
15701 : C->getCaptureKind() == LCK_ByCopy
15704 SourceLocation EllipsisLoc;
15705 if (C->isPackExpansion()) {
15706 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15707 bool ShouldExpand = false;
15708 bool RetainExpansion = false;
15709 UnsignedOrNone NumExpansions = std::nullopt;
15710 if (getDerived().TryExpandParameterPacks(
15711 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
15712 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
15713 RetainExpansion, NumExpansions)) {
15714 Invalid = true;
15715 continue;
15716 }
15717
15718 if (ShouldExpand) {
15719 // The transform has determined that we should perform an expansion;
15720 // transform and capture each of the arguments.
15721 // expansion of the pattern. Do so.
15722 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
15723 for (unsigned I = 0; I != *NumExpansions; ++I) {
15724 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15725 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
15726 getDerived().TransformDecl(C->getLocation(), Pack));
15727 if (!CapturedVar) {
15728 Invalid = true;
15729 continue;
15730 }
15731
15732 // Capture the transformed variable.
15733 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15734 }
15735
15736 // FIXME: Retain a pack expansion if RetainExpansion is true.
15737
15738 continue;
15739 }
15740
15741 EllipsisLoc = C->getEllipsisLoc();
15742 }
15743
15744 // Transform the captured variable.
15745 auto *CapturedVar = cast_or_null<ValueDecl>(
15746 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15747 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15748 Invalid = true;
15749 continue;
15750 }
15751
15752 // This is not an init-capture; however it contains an unexpanded pack e.g.
15753 // ([Pack] {}(), ...)
15754 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15755 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15756
15757 // Capture the transformed variable.
15758 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15759 EllipsisLoc);
15760 }
15761 getSema().finishLambdaExplicitCaptures(LSI);
15762
15763 // Transform the template parameters, and add them to the current
15764 // instantiation scope. The null case is handled correctly.
15765 auto TPL = getDerived().TransformTemplateParameterList(
15766 E->getTemplateParameterList());
15767 LSI->GLTemplateParameterList = TPL;
15768 if (TPL) {
15769 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15770 TPL);
15771 LSI->ContainsUnexpandedParameterPack |=
15772 TPL->containsUnexpandedParameterPack();
15773 }
15774
15775 TypeLocBuilder NewCallOpTLBuilder;
15776 TypeLoc OldCallOpTypeLoc =
15777 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15778 QualType NewCallOpType =
15779 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15780 if (NewCallOpType.isNull())
15781 return ExprError();
15782 LSI->ContainsUnexpandedParameterPack |=
15783 NewCallOpType->containsUnexpandedParameterPack();
15784 TypeSourceInfo *NewCallOpTSI =
15785 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15786
15787 // The type may be an AttributedType or some other kind of sugar;
15788 // get the actual underlying FunctionProtoType.
15789 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15790 assert(FPTL && "Not a FunctionProtoType?");
15791
15792 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
15793 if (!TRC.ArgPackSubstIndex)
15795
15796 getSema().CompleteLambdaCallOperator(
15797 NewCallOperator, E->getCallOperator()->getLocation(),
15798 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
15799 E->getCallOperator()->getConstexprKind(),
15800 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15801 E->hasExplicitResultType());
15802
15803 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15804 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15805
15806 {
15807 // Number the lambda for linkage purposes if necessary.
15808 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15809
15810 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15811 if (getDerived().ReplacingOriginal()) {
15812 Numbering = OldClass->getLambdaNumbering();
15813 }
15814
15815 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15816 }
15817
15818 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15819 // evaluation context even if we're not transforming the function body.
15820 getSema().PushExpressionEvaluationContextForFunction(
15822 E->getCallOperator());
15823
15826 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15827 getSema().pushCodeSynthesisContext(C);
15828
15829 // Instantiate the body of the lambda expression.
15830 StmtResult Body =
15831 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15832
15833 getSema().popCodeSynthesisContext();
15834
15835 // ActOnLambda* will pop the function scope for us.
15836 FuncScopeCleanup.disable();
15837
15838 if (Body.isInvalid()) {
15839 SavedContext.pop();
15840 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15841 /*IsInstantiation=*/true);
15842 return ExprError();
15843 }
15844
15845 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15846 /*IsInstantiation=*/true,
15847 /*RetainFunctionScopeInfo=*/true);
15848 SavedContext.pop();
15849
15850 // Recompute the dependency of the lambda so that we can defer the lambda call
15851 // construction until after we have all the necessary template arguments. For
15852 // example, given
15853 //
15854 // template <class> struct S {
15855 // template <class U>
15856 // using Type = decltype([](U){}(42.0));
15857 // };
15858 // void foo() {
15859 // using T = S<int>::Type<float>;
15860 // ^~~~~~
15861 // }
15862 //
15863 // We would end up here from instantiating S<int> when ensuring its
15864 // completeness. That would transform the lambda call expression regardless of
15865 // the absence of the corresponding argument for U.
15866 //
15867 // Going ahead with unsubstituted type U makes things worse: we would soon
15868 // compare the argument type (which is float) against the parameter U
15869 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15870 // error suggesting unmatched types 'U' and 'float'!
15871 //
15872 // That said, everything will be fine if we defer that semantic checking.
15873 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15874 // dependent. Since the CallExpr's dependency boils down to the lambda's
15875 // dependency in this case, we can harness that by recomputing the dependency
15876 // from the instantiation arguments.
15877 //
15878 // FIXME: Creating the type of a lambda requires us to have a dependency
15879 // value, which happens before its substitution. We update its dependency
15880 // *after* the substitution in case we can't decide the dependency
15881 // so early, e.g. because we want to see if any of the *substituted*
15882 // parameters are dependent.
15883 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15884 Class->setLambdaDependencyKind(DependencyKind);
15885
15886 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15887 Body.get()->getEndLoc(), LSI);
15888}
15889
15890template<typename Derived>
15895
15896template<typename Derived>
15899 // Transform captures.
15901 CEnd = E->capture_end();
15902 C != CEnd; ++C) {
15903 // When we hit the first implicit capture, tell Sema that we've finished
15904 // the list of explicit captures.
15905 if (!C->isImplicit())
15906 continue;
15907
15908 // Capturing 'this' is trivial.
15909 if (C->capturesThis()) {
15910 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15911 /*BuildAndDiagnose*/ true, nullptr,
15912 C->getCaptureKind() == LCK_StarThis);
15913 continue;
15914 }
15915 // Captured expression will be recaptured during captured variables
15916 // rebuilding.
15917 if (C->capturesVLAType())
15918 continue;
15919
15920 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15921 assert(!E->isInitCapture(C) && "implicit init-capture?");
15922
15923 // Transform the captured variable.
15924 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15925 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15926 if (!CapturedVar || CapturedVar->isInvalidDecl())
15927 return StmtError();
15928
15929 // Capture the transformed variable.
15930 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15931 }
15932
15933 return S;
15934}
15935
15936template<typename Derived>
15940 TypeSourceInfo *T =
15941 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15942 if (!T)
15943 return ExprError();
15944
15945 bool ArgumentChanged = false;
15947 Args.reserve(E->getNumArgs());
15948 {
15952 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15953 &ArgumentChanged))
15954 return ExprError();
15955 }
15956
15957 if (!getDerived().AlwaysRebuild() &&
15958 T == E->getTypeSourceInfo() &&
15959 !ArgumentChanged)
15960 return E;
15961
15962 // FIXME: we're faking the locations of the commas
15963 return getDerived().RebuildCXXUnresolvedConstructExpr(
15964 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15965}
15966
15967template<typename Derived>
15971 // Transform the base of the expression.
15972 ExprResult Base((Expr*) nullptr);
15973 Expr *OldBase;
15974 QualType BaseType;
15975 QualType ObjectType;
15976 if (!E->isImplicitAccess()) {
15977 OldBase = E->getBase();
15978 Base = getDerived().TransformExpr(OldBase);
15979 if (Base.isInvalid())
15980 return ExprError();
15981
15982 // Start the member reference and compute the object's type.
15983 ParsedType ObjectTy;
15984 bool MayBePseudoDestructor = false;
15985 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15986 E->getOperatorLoc(),
15987 E->isArrow()? tok::arrow : tok::period,
15988 ObjectTy,
15989 MayBePseudoDestructor);
15990 if (Base.isInvalid())
15991 return ExprError();
15992
15993 ObjectType = ObjectTy.get();
15994 BaseType = ((Expr*) Base.get())->getType();
15995 } else {
15996 OldBase = nullptr;
15997 BaseType = getDerived().TransformType(E->getBaseType());
15998 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15999 }
16000
16001 // Transform the first part of the nested-name-specifier that qualifies
16002 // the member name.
16003 NamedDecl *FirstQualifierInScope
16004 = getDerived().TransformFirstQualifierInScope(
16005 E->getFirstQualifierFoundInScope(),
16006 E->getQualifierLoc().getBeginLoc());
16007
16008 NestedNameSpecifierLoc QualifierLoc;
16009 if (E->getQualifier()) {
16010 QualifierLoc
16011 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16012 ObjectType,
16013 FirstQualifierInScope);
16014 if (!QualifierLoc)
16015 return ExprError();
16016 }
16017
16018 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16019
16020 // TODO: If this is a conversion-function-id, verify that the
16021 // destination type name (if present) resolves the same way after
16022 // instantiation as it did in the local scope.
16023
16024 DeclarationNameInfo NameInfo
16025 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16026 if (!NameInfo.getName())
16027 return ExprError();
16028
16029 if (!E->hasExplicitTemplateArgs()) {
16030 // This is a reference to a member without an explicitly-specified
16031 // template argument list. Optimize for this common case.
16032 if (!getDerived().AlwaysRebuild() &&
16033 Base.get() == OldBase &&
16034 BaseType == E->getBaseType() &&
16035 QualifierLoc == E->getQualifierLoc() &&
16036 NameInfo.getName() == E->getMember() &&
16037 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16038 return E;
16039
16040 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16041 BaseType,
16042 E->isArrow(),
16043 E->getOperatorLoc(),
16044 QualifierLoc,
16045 TemplateKWLoc,
16046 FirstQualifierInScope,
16047 NameInfo,
16048 /*TemplateArgs*/nullptr);
16049 }
16050
16051 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16052 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16053 E->getNumTemplateArgs(),
16054 TransArgs))
16055 return ExprError();
16056
16057 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16058 BaseType,
16059 E->isArrow(),
16060 E->getOperatorLoc(),
16061 QualifierLoc,
16062 TemplateKWLoc,
16063 FirstQualifierInScope,
16064 NameInfo,
16065 &TransArgs);
16066}
16067
16068template <typename Derived>
16070 UnresolvedMemberExpr *Old) {
16071 // Transform the base of the expression.
16072 ExprResult Base((Expr *)nullptr);
16073 QualType BaseType;
16074 if (!Old->isImplicitAccess()) {
16075 Base = getDerived().TransformExpr(Old->getBase());
16076 if (Base.isInvalid())
16077 return ExprError();
16078 Base =
16079 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16080 if (Base.isInvalid())
16081 return ExprError();
16082 BaseType = Base.get()->getType();
16083 } else {
16084 BaseType = getDerived().TransformType(Old->getBaseType());
16085 }
16086
16087 NestedNameSpecifierLoc QualifierLoc;
16088 if (Old->getQualifierLoc()) {
16089 QualifierLoc =
16090 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16091 if (!QualifierLoc)
16092 return ExprError();
16093 }
16094
16095 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16096
16097 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16098
16099 // Transform the declaration set.
16100 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16101 return ExprError();
16102
16103 // Determine the naming class.
16104 if (Old->getNamingClass()) {
16105 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16106 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16107 if (!NamingClass)
16108 return ExprError();
16109
16110 R.setNamingClass(NamingClass);
16111 }
16112
16113 TemplateArgumentListInfo TransArgs;
16114 if (Old->hasExplicitTemplateArgs()) {
16115 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16116 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16117 if (getDerived().TransformTemplateArguments(
16118 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16119 return ExprError();
16120 }
16121
16122 // FIXME: to do this check properly, we will need to preserve the
16123 // first-qualifier-in-scope here, just in case we had a dependent
16124 // base (and therefore couldn't do the check) and a
16125 // nested-name-qualifier (and therefore could do the lookup).
16126 NamedDecl *FirstQualifierInScope = nullptr;
16127
16128 return getDerived().RebuildUnresolvedMemberExpr(
16129 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16130 TemplateKWLoc, FirstQualifierInScope, R,
16131 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16132}
16133
16134template<typename Derived>
16139 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16140 if (SubExpr.isInvalid())
16141 return ExprError();
16142
16143 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16144 return E;
16145
16146 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16147}
16148
16149template<typename Derived>
16152 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16153 if (Pattern.isInvalid())
16154 return ExprError();
16155
16156 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16157 return E;
16158
16159 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16160 E->getNumExpansions());
16161}
16162
16163template <typename Derived>
16165 ArrayRef<TemplateArgument> PackArgs) {
16167 for (const TemplateArgument &Arg : PackArgs) {
16168 if (!Arg.isPackExpansion()) {
16169 Result = *Result + 1;
16170 continue;
16171 }
16172
16173 TemplateArgumentLoc ArgLoc;
16174 InventTemplateArgumentLoc(Arg, ArgLoc);
16175
16176 // Find the pattern of the pack expansion.
16177 SourceLocation Ellipsis;
16178 UnsignedOrNone OrigNumExpansions = std::nullopt;
16179 TemplateArgumentLoc Pattern =
16180 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16181 OrigNumExpansions);
16182
16183 // Substitute under the pack expansion. Do not expand the pack (yet).
16184 TemplateArgumentLoc OutPattern;
16185 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16186 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16187 /*Uneval*/ true))
16188 return 1u;
16189
16190 // See if we can determine the number of arguments from the result.
16191 UnsignedOrNone NumExpansions =
16192 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16193 if (!NumExpansions) {
16194 // No: we must be in an alias template expansion, and we're going to
16195 // need to actually expand the packs.
16196 Result = std::nullopt;
16197 break;
16198 }
16199
16200 Result = *Result + *NumExpansions;
16201 }
16202 return Result;
16203}
16204
16205template<typename Derived>
16208 // If E is not value-dependent, then nothing will change when we transform it.
16209 // Note: This is an instantiation-centric view.
16210 if (!E->isValueDependent())
16211 return E;
16212
16215
16217 TemplateArgument ArgStorage;
16218
16219 // Find the argument list to transform.
16220 if (E->isPartiallySubstituted()) {
16221 PackArgs = E->getPartialArguments();
16222 } else if (E->isValueDependent()) {
16223 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16224 bool ShouldExpand = false;
16225 bool RetainExpansion = false;
16226 UnsignedOrNone NumExpansions = std::nullopt;
16227 if (getDerived().TryExpandParameterPacks(
16228 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16229 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16230 RetainExpansion, NumExpansions))
16231 return ExprError();
16232
16233 // If we need to expand the pack, build a template argument from it and
16234 // expand that.
16235 if (ShouldExpand) {
16236 auto *Pack = E->getPack();
16237 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16238 ArgStorage = getSema().Context.getPackExpansionType(
16239 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16240 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16241 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16242 } else {
16243 auto *VD = cast<ValueDecl>(Pack);
16244 ExprResult DRE = getSema().BuildDeclRefExpr(
16245 VD, VD->getType().getNonLValueExprType(getSema().Context),
16246 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16247 E->getPackLoc());
16248 if (DRE.isInvalid())
16249 return ExprError();
16250 ArgStorage = TemplateArgument(
16251 new (getSema().Context)
16252 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16253 /*IsCanonical=*/false);
16254 }
16255 PackArgs = ArgStorage;
16256 }
16257 }
16258
16259 // If we're not expanding the pack, just transform the decl.
16260 if (!PackArgs.size()) {
16261 auto *Pack = cast_or_null<NamedDecl>(
16262 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16263 if (!Pack)
16264 return ExprError();
16265 return getDerived().RebuildSizeOfPackExpr(
16266 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16267 std::nullopt, {});
16268 }
16269
16270 // Try to compute the result without performing a partial substitution.
16272 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16273
16274 // Common case: we could determine the number of expansions without
16275 // substituting.
16276 if (Result)
16277 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16278 E->getPackLoc(),
16279 E->getRParenLoc(), *Result, {});
16280
16281 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16282 E->getPackLoc());
16283 {
16284 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16286 Derived, const TemplateArgument*> PackLocIterator;
16287 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16288 PackLocIterator(*this, PackArgs.end()),
16289 TransformedPackArgs, /*Uneval*/true))
16290 return ExprError();
16291 }
16292
16293 // Check whether we managed to fully-expand the pack.
16294 // FIXME: Is it possible for us to do so and not hit the early exit path?
16296 bool PartialSubstitution = false;
16297 for (auto &Loc : TransformedPackArgs.arguments()) {
16298 Args.push_back(Loc.getArgument());
16299 if (Loc.getArgument().isPackExpansion())
16300 PartialSubstitution = true;
16301 }
16302
16303 if (PartialSubstitution)
16304 return getDerived().RebuildSizeOfPackExpr(
16305 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16306 std::nullopt, Args);
16307
16308 return getDerived().RebuildSizeOfPackExpr(
16309 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16310 /*Length=*/static_cast<unsigned>(Args.size()),
16311 /*PartialArgs=*/{});
16312}
16313
16314template <typename Derived>
16317 if (!E->isValueDependent())
16318 return E;
16319
16320 // Transform the index
16321 ExprResult IndexExpr;
16322 {
16323 EnterExpressionEvaluationContext ConstantContext(
16325 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16326 if (IndexExpr.isInvalid())
16327 return ExprError();
16328 }
16329
16330 SmallVector<Expr *, 5> ExpandedExprs;
16331 bool FullySubstituted = true;
16332 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16333 Expr *Pattern = E->getPackIdExpression();
16335 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16336 Unexpanded);
16337 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16338
16339 // Determine whether the set of unexpanded parameter packs can and should
16340 // be expanded.
16341 bool ShouldExpand = true;
16342 bool RetainExpansion = false;
16343 UnsignedOrNone OrigNumExpansions = std::nullopt,
16344 NumExpansions = std::nullopt;
16345 if (getDerived().TryExpandParameterPacks(
16346 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16347 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16348 RetainExpansion, NumExpansions))
16349 return true;
16350 if (!ShouldExpand) {
16351 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16352 ExprResult Pack = getDerived().TransformExpr(Pattern);
16353 if (Pack.isInvalid())
16354 return ExprError();
16355 return getDerived().RebuildPackIndexingExpr(
16356 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16357 {}, /*FullySubstituted=*/false);
16358 }
16359 for (unsigned I = 0; I != *NumExpansions; ++I) {
16360 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16361 ExprResult Out = getDerived().TransformExpr(Pattern);
16362 if (Out.isInvalid())
16363 return true;
16364 if (Out.get()->containsUnexpandedParameterPack()) {
16365 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16366 OrigNumExpansions);
16367 if (Out.isInvalid())
16368 return true;
16369 FullySubstituted = false;
16370 }
16371 ExpandedExprs.push_back(Out.get());
16372 }
16373 // If we're supposed to retain a pack expansion, do so by temporarily
16374 // forgetting the partially-substituted parameter pack.
16375 if (RetainExpansion) {
16376 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16377
16378 ExprResult Out = getDerived().TransformExpr(Pattern);
16379 if (Out.isInvalid())
16380 return true;
16381
16382 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16383 OrigNumExpansions);
16384 if (Out.isInvalid())
16385 return true;
16386 FullySubstituted = false;
16387 ExpandedExprs.push_back(Out.get());
16388 }
16389 } else if (!E->expandsToEmptyPack()) {
16390 if (getDerived().TransformExprs(E->getExpressions().data(),
16391 E->getExpressions().size(), false,
16392 ExpandedExprs))
16393 return ExprError();
16394 }
16395
16396 return getDerived().RebuildPackIndexingExpr(
16397 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16398 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16399}
16400
16401template <typename Derived>
16404 if (!getSema().ArgPackSubstIndex)
16405 // We aren't expanding the parameter pack, so just return ourselves.
16406 return E;
16407
16408 TemplateArgument Pack = E->getArgumentPack();
16410 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
16411 E->getAssociatedDecl(), E->getParameterPack(),
16412 E->getParameterPackLocation(), Arg, SemaRef.getPackIndex(Pack),
16413 E->getFinal());
16414}
16415
16416template <typename Derived>
16419 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16420 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
16421 if (Replacement.isInvalid())
16422 return true;
16423
16424 Decl *AssociatedDecl =
16425 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
16426 if (!AssociatedDecl)
16427 return true;
16428
16429 if (Replacement.get() == OrigReplacement &&
16430 AssociatedDecl == E->getAssociatedDecl())
16431 return E;
16432
16433 auto getParamAndType = [E](Decl *AssociatedDecl)
16434 -> std::tuple<NonTypeTemplateParmDecl *, QualType> {
16435 auto [PDecl, Arg] =
16436 getReplacedTemplateParameter(AssociatedDecl, E->getIndex());
16437 auto *Param = cast<NonTypeTemplateParmDecl>(PDecl);
16438 if (Arg.isNull())
16439 return {Param, Param->getType()};
16440 if (UnsignedOrNone PackIndex = E->getPackIndex())
16441 Arg = Arg.getPackAsArray()[*PackIndex];
16442 return {Param, Arg.getNonTypeTemplateArgumentType()};
16443 };
16444
16445 // If the replacement expression did not change, and the parameter type
16446 // did not change, we can skip the semantic action because it would
16447 // produce the same result anyway.
16448 if (auto [Param, ParamType] = getParamAndType(AssociatedDecl);
16449 !SemaRef.Context.hasSameType(
16450 ParamType, std::get<1>(getParamAndType(E->getAssociatedDecl()))) ||
16451 Replacement.get() != OrigReplacement) {
16452 // When transforming the replacement expression previously, all Sema
16453 // specific annotations, such as implicit casts, are discarded. Calling the
16454 // corresponding sema action is necessary to recover those. Otherwise,
16455 // equivalency of the result would be lost.
16456 TemplateArgument SugaredConverted, CanonicalConverted;
16457 Replacement = SemaRef.CheckTemplateArgument(
16458 Param, ParamType, Replacement.get(), SugaredConverted,
16459 CanonicalConverted,
16460 /*StrictCheck=*/false, Sema::CTAK_Specified);
16461 if (Replacement.isInvalid())
16462 return true;
16463 } else {
16464 // Otherwise, the same expression would have been produced.
16465 Replacement = E->getReplacement();
16466 }
16467
16468 return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
16469 Replacement.get()->getType(), Replacement.get()->getValueKind(),
16470 E->getNameLoc(), Replacement.get(), AssociatedDecl, E->getIndex(),
16471 E->getPackIndex(), E->isReferenceParameter(), E->getFinal());
16472}
16473
16474template<typename Derived>
16477 // Default behavior is to do nothing with this transformation.
16478 return E;
16479}
16480
16481template<typename Derived>
16485 return getDerived().TransformExpr(E->getSubExpr());
16486}
16487
16488template<typename Derived>
16491 UnresolvedLookupExpr *Callee = nullptr;
16492 if (Expr *OldCallee = E->getCallee()) {
16493 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16494 if (CalleeResult.isInvalid())
16495 return ExprError();
16496 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16497 }
16498
16499 Expr *Pattern = E->getPattern();
16500
16502 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16503 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16504
16505 // Determine whether the set of unexpanded parameter packs can and should
16506 // be expanded.
16507 bool Expand = true;
16508 bool RetainExpansion = false;
16509 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
16510 NumExpansions = OrigNumExpansions;
16511 if (getDerived().TryExpandParameterPacks(
16512 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16513 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16514 NumExpansions))
16515 return true;
16516
16517 if (!Expand) {
16518 // Do not expand any packs here, just transform and rebuild a fold
16519 // expression.
16520 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16521
16522 ExprResult LHS =
16523 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16524 if (LHS.isInvalid())
16525 return true;
16526
16527 ExprResult RHS =
16528 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16529 if (RHS.isInvalid())
16530 return true;
16531
16532 if (!getDerived().AlwaysRebuild() &&
16533 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16534 return E;
16535
16536 return getDerived().RebuildCXXFoldExpr(
16537 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16538 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16539 }
16540
16541 // Formally a fold expression expands to nested parenthesized expressions.
16542 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16543 // them.
16544 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
16545 SemaRef.Diag(E->getEllipsisLoc(),
16546 clang::diag::err_fold_expression_limit_exceeded)
16547 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16548 << E->getSourceRange();
16549 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16550 return ExprError();
16551 }
16552
16553 // The transform has determined that we should perform an elementwise
16554 // expansion of the pattern. Do so.
16555 ExprResult Result = getDerived().TransformExpr(E->getInit());
16556 if (Result.isInvalid())
16557 return true;
16558 bool LeftFold = E->isLeftFold();
16559
16560 // If we're retaining an expansion for a right fold, it is the innermost
16561 // component and takes the init (if any).
16562 if (!LeftFold && RetainExpansion) {
16563 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16564
16565 ExprResult Out = getDerived().TransformExpr(Pattern);
16566 if (Out.isInvalid())
16567 return true;
16568
16569 Result = getDerived().RebuildCXXFoldExpr(
16570 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16571 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16572 if (Result.isInvalid())
16573 return true;
16574 }
16575
16576 bool WarnedOnComparison = false;
16577 for (unsigned I = 0; I != *NumExpansions; ++I) {
16578 Sema::ArgPackSubstIndexRAII SubstIndex(
16579 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16580 ExprResult Out = getDerived().TransformExpr(Pattern);
16581 if (Out.isInvalid())
16582 return true;
16583
16584 if (Out.get()->containsUnexpandedParameterPack()) {
16585 // We still have a pack; retain a pack expansion for this slice.
16586 Result = getDerived().RebuildCXXFoldExpr(
16587 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16588 E->getOperator(), E->getEllipsisLoc(),
16589 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16590 OrigNumExpansions);
16591 } else if (Result.isUsable()) {
16592 // We've got down to a single element; build a binary operator.
16593 Expr *LHS = LeftFold ? Result.get() : Out.get();
16594 Expr *RHS = LeftFold ? Out.get() : Result.get();
16595 if (Callee) {
16596 UnresolvedSet<16> Functions;
16597 Functions.append(Callee->decls_begin(), Callee->decls_end());
16598 Result = getDerived().RebuildCXXOperatorCallExpr(
16599 BinaryOperator::getOverloadedOperator(E->getOperator()),
16600 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16601 Functions, LHS, RHS);
16602 } else {
16603 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16604 E->getOperator(), LHS, RHS,
16605 /*ForFoldExpresion=*/true);
16606 if (!WarnedOnComparison && Result.isUsable()) {
16607 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
16608 BO && BO->isComparisonOp()) {
16609 WarnedOnComparison = true;
16610 SemaRef.Diag(BO->getBeginLoc(),
16611 diag::warn_comparison_in_fold_expression)
16612 << BO->getOpcodeStr();
16613 }
16614 }
16615 }
16616 } else
16617 Result = Out;
16618
16619 if (Result.isInvalid())
16620 return true;
16621 }
16622
16623 // If we're retaining an expansion for a left fold, it is the outermost
16624 // component and takes the complete expansion so far as its init (if any).
16625 if (LeftFold && RetainExpansion) {
16626 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16627
16628 ExprResult Out = getDerived().TransformExpr(Pattern);
16629 if (Out.isInvalid())
16630 return true;
16631
16632 Result = getDerived().RebuildCXXFoldExpr(
16633 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16634 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16635 if (Result.isInvalid())
16636 return true;
16637 }
16638
16639 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16640 PE->setIsProducedByFoldExpansion();
16641
16642 // If we had no init and an empty pack, and we're not retaining an expansion,
16643 // then produce a fallback value or error.
16644 if (Result.isUnset())
16645 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16646 E->getOperator());
16647 return Result;
16648}
16649
16650template <typename Derived>
16653 SmallVector<Expr *, 4> TransformedInits;
16654 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16655
16656 QualType T = getDerived().TransformType(E->getType());
16657
16658 bool ArgChanged = false;
16659
16660 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
16661 TransformedInits, &ArgChanged))
16662 return ExprError();
16663
16664 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
16665 return E;
16666
16667 return getDerived().RebuildCXXParenListInitExpr(
16668 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
16669 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
16670}
16671
16672template<typename Derived>
16676 return getDerived().TransformExpr(E->getSubExpr());
16677}
16678
16679template<typename Derived>
16682 return SemaRef.MaybeBindToTemporary(E);
16683}
16684
16685template<typename Derived>
16688 return E;
16689}
16690
16691template<typename Derived>
16694 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16695 if (SubExpr.isInvalid())
16696 return ExprError();
16697
16698 if (!getDerived().AlwaysRebuild() &&
16699 SubExpr.get() == E->getSubExpr())
16700 return E;
16701
16702 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16703}
16704
16705template<typename Derived>
16708 // Transform each of the elements.
16709 SmallVector<Expr *, 8> Elements;
16710 bool ArgChanged = false;
16711 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16712 /*IsCall=*/false, Elements, &ArgChanged))
16713 return ExprError();
16714
16715 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16716 return SemaRef.MaybeBindToTemporary(E);
16717
16718 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16719 Elements.data(),
16720 Elements.size());
16721}
16722
16723template<typename Derived>
16727 // Transform each of the elements.
16729 bool ArgChanged = false;
16730 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16731 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16732
16733 if (OrigElement.isPackExpansion()) {
16734 // This key/value element is a pack expansion.
16736 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16737 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16738 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16739
16740 // Determine whether the set of unexpanded parameter packs can
16741 // and should be expanded.
16742 bool Expand = true;
16743 bool RetainExpansion = false;
16744 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
16745 UnsignedOrNone NumExpansions = OrigNumExpansions;
16746 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16747 OrigElement.Value->getEndLoc());
16748 if (getDerived().TryExpandParameterPacks(
16749 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
16750 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16751 NumExpansions))
16752 return ExprError();
16753
16754 if (!Expand) {
16755 // The transform has determined that we should perform a simple
16756 // transformation on the pack expansion, producing another pack
16757 // expansion.
16758 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16759 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16760 if (Key.isInvalid())
16761 return ExprError();
16762
16763 if (Key.get() != OrigElement.Key)
16764 ArgChanged = true;
16765
16766 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16767 if (Value.isInvalid())
16768 return ExprError();
16769
16770 if (Value.get() != OrigElement.Value)
16771 ArgChanged = true;
16772
16773 ObjCDictionaryElement Expansion = {
16774 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16775 };
16776 Elements.push_back(Expansion);
16777 continue;
16778 }
16779
16780 // Record right away that the argument was changed. This needs
16781 // to happen even if the array expands to nothing.
16782 ArgChanged = true;
16783
16784 // The transform has determined that we should perform an elementwise
16785 // expansion of the pattern. Do so.
16786 for (unsigned I = 0; I != *NumExpansions; ++I) {
16787 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16788 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16789 if (Key.isInvalid())
16790 return ExprError();
16791
16792 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16793 if (Value.isInvalid())
16794 return ExprError();
16795
16796 ObjCDictionaryElement Element = {
16797 Key.get(), Value.get(), SourceLocation(), NumExpansions
16798 };
16799
16800 // If any unexpanded parameter packs remain, we still have a
16801 // pack expansion.
16802 // FIXME: Can this really happen?
16803 if (Key.get()->containsUnexpandedParameterPack() ||
16804 Value.get()->containsUnexpandedParameterPack())
16805 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16806
16807 Elements.push_back(Element);
16808 }
16809
16810 // FIXME: Retain a pack expansion if RetainExpansion is true.
16811
16812 // We've finished with this pack expansion.
16813 continue;
16814 }
16815
16816 // Transform and check key.
16817 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16818 if (Key.isInvalid())
16819 return ExprError();
16820
16821 if (Key.get() != OrigElement.Key)
16822 ArgChanged = true;
16823
16824 // Transform and check value.
16826 = getDerived().TransformExpr(OrigElement.Value);
16827 if (Value.isInvalid())
16828 return ExprError();
16829
16830 if (Value.get() != OrigElement.Value)
16831 ArgChanged = true;
16832
16833 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16834 std::nullopt};
16835 Elements.push_back(Element);
16836 }
16837
16838 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16839 return SemaRef.MaybeBindToTemporary(E);
16840
16841 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16842 Elements);
16843}
16844
16845template<typename Derived>
16848 TypeSourceInfo *EncodedTypeInfo
16849 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16850 if (!EncodedTypeInfo)
16851 return ExprError();
16852
16853 if (!getDerived().AlwaysRebuild() &&
16854 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16855 return E;
16856
16857 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16858 EncodedTypeInfo,
16859 E->getRParenLoc());
16860}
16861
16862template<typename Derived>
16865 // This is a kind of implicit conversion, and it needs to get dropped
16866 // and recomputed for the same general reasons that ImplicitCastExprs
16867 // do, as well a more specific one: this expression is only valid when
16868 // it appears *immediately* as an argument expression.
16869 return getDerived().TransformExpr(E->getSubExpr());
16870}
16871
16872template<typename Derived>
16875 TypeSourceInfo *TSInfo
16876 = getDerived().TransformType(E->getTypeInfoAsWritten());
16877 if (!TSInfo)
16878 return ExprError();
16879
16880 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16881 if (Result.isInvalid())
16882 return ExprError();
16883
16884 if (!getDerived().AlwaysRebuild() &&
16885 TSInfo == E->getTypeInfoAsWritten() &&
16886 Result.get() == E->getSubExpr())
16887 return E;
16888
16889 return SemaRef.ObjC().BuildObjCBridgedCast(
16890 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16891 Result.get());
16892}
16893
16894template <typename Derived>
16897 return E;
16898}
16899
16900template<typename Derived>
16903 // Transform arguments.
16904 bool ArgChanged = false;
16906 Args.reserve(E->getNumArgs());
16907 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16908 &ArgChanged))
16909 return ExprError();
16910
16911 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16912 // Class message: transform the receiver type.
16913 TypeSourceInfo *ReceiverTypeInfo
16914 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16915 if (!ReceiverTypeInfo)
16916 return ExprError();
16917
16918 // If nothing changed, just retain the existing message send.
16919 if (!getDerived().AlwaysRebuild() &&
16920 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16921 return SemaRef.MaybeBindToTemporary(E);
16922
16923 // Build a new class message send.
16925 E->getSelectorLocs(SelLocs);
16926 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16927 E->getSelector(),
16928 SelLocs,
16929 E->getMethodDecl(),
16930 E->getLeftLoc(),
16931 Args,
16932 E->getRightLoc());
16933 }
16934 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16935 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16936 if (!E->getMethodDecl())
16937 return ExprError();
16938
16939 // Build a new class message send to 'super'.
16941 E->getSelectorLocs(SelLocs);
16942 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16943 E->getSelector(),
16944 SelLocs,
16945 E->getReceiverType(),
16946 E->getMethodDecl(),
16947 E->getLeftLoc(),
16948 Args,
16949 E->getRightLoc());
16950 }
16951
16952 // Instance message: transform the receiver
16953 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16954 "Only class and instance messages may be instantiated");
16955 ExprResult Receiver
16956 = getDerived().TransformExpr(E->getInstanceReceiver());
16957 if (Receiver.isInvalid())
16958 return ExprError();
16959
16960 // If nothing changed, just retain the existing message send.
16961 if (!getDerived().AlwaysRebuild() &&
16962 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16963 return SemaRef.MaybeBindToTemporary(E);
16964
16965 // Build a new instance message send.
16967 E->getSelectorLocs(SelLocs);
16968 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16969 E->getSelector(),
16970 SelLocs,
16971 E->getMethodDecl(),
16972 E->getLeftLoc(),
16973 Args,
16974 E->getRightLoc());
16975}
16976
16977template<typename Derived>
16980 return E;
16981}
16982
16983template<typename Derived>
16986 return E;
16987}
16988
16989template<typename Derived>
16992 // Transform the base expression.
16993 ExprResult Base = getDerived().TransformExpr(E->getBase());
16994 if (Base.isInvalid())
16995 return ExprError();
16996
16997 // We don't need to transform the ivar; it will never change.
16998
16999 // If nothing changed, just retain the existing expression.
17000 if (!getDerived().AlwaysRebuild() &&
17001 Base.get() == E->getBase())
17002 return E;
17003
17004 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17005 E->getLocation(),
17006 E->isArrow(), E->isFreeIvar());
17007}
17008
17009template<typename Derived>
17012 // 'super' and types never change. Property never changes. Just
17013 // retain the existing expression.
17014 if (!E->isObjectReceiver())
17015 return E;
17016
17017 // Transform the base expression.
17018 ExprResult Base = getDerived().TransformExpr(E->getBase());
17019 if (Base.isInvalid())
17020 return ExprError();
17021
17022 // We don't need to transform the property; it will never change.
17023
17024 // If nothing changed, just retain the existing expression.
17025 if (!getDerived().AlwaysRebuild() &&
17026 Base.get() == E->getBase())
17027 return E;
17028
17029 if (E->isExplicitProperty())
17030 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17031 E->getExplicitProperty(),
17032 E->getLocation());
17033
17034 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17035 SemaRef.Context.PseudoObjectTy,
17036 E->getImplicitPropertyGetter(),
17037 E->getImplicitPropertySetter(),
17038 E->getLocation());
17039}
17040
17041template<typename Derived>
17044 // Transform the base expression.
17045 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17046 if (Base.isInvalid())
17047 return ExprError();
17048
17049 // Transform the key expression.
17050 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17051 if (Key.isInvalid())
17052 return ExprError();
17053
17054 // If nothing changed, just retain the existing expression.
17055 if (!getDerived().AlwaysRebuild() &&
17056 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17057 return E;
17058
17059 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17060 Base.get(), Key.get(),
17061 E->getAtIndexMethodDecl(),
17062 E->setAtIndexMethodDecl());
17063}
17064
17065template<typename Derived>
17068 // Transform the base expression.
17069 ExprResult Base = getDerived().TransformExpr(E->getBase());
17070 if (Base.isInvalid())
17071 return ExprError();
17072
17073 // If nothing changed, just retain the existing expression.
17074 if (!getDerived().AlwaysRebuild() &&
17075 Base.get() == E->getBase())
17076 return E;
17077
17078 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17079 E->getOpLoc(),
17080 E->isArrow());
17081}
17082
17083template<typename Derived>
17086 bool ArgumentChanged = false;
17087 SmallVector<Expr*, 8> SubExprs;
17088 SubExprs.reserve(E->getNumSubExprs());
17089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17090 SubExprs, &ArgumentChanged))
17091 return ExprError();
17092
17093 if (!getDerived().AlwaysRebuild() &&
17094 !ArgumentChanged)
17095 return E;
17096
17097 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17098 SubExprs,
17099 E->getRParenLoc());
17100}
17101
17102template<typename Derived>
17105 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17106 if (SrcExpr.isInvalid())
17107 return ExprError();
17108
17109 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17110 if (!Type)
17111 return ExprError();
17112
17113 if (!getDerived().AlwaysRebuild() &&
17114 Type == E->getTypeSourceInfo() &&
17115 SrcExpr.get() == E->getSrcExpr())
17116 return E;
17117
17118 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17119 SrcExpr.get(), Type,
17120 E->getRParenLoc());
17121}
17122
17123template<typename Derived>
17126 BlockDecl *oldBlock = E->getBlockDecl();
17127
17128 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17129 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17130
17131 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17132 blockScope->TheDecl->setBlockMissingReturnType(
17133 oldBlock->blockMissingReturnType());
17134
17136 SmallVector<QualType, 4> paramTypes;
17137
17138 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17139
17140 // Parameter substitution.
17141 Sema::ExtParameterInfoBuilder extParamInfos;
17142 if (getDerived().TransformFunctionTypeParams(
17143 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17144 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17145 extParamInfos)) {
17146 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17147 return ExprError();
17148 }
17149
17150 QualType exprResultType =
17151 getDerived().TransformType(exprFunctionType->getReturnType());
17152
17153 auto epi = exprFunctionType->getExtProtoInfo();
17154 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17155
17157 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17158 blockScope->FunctionType = functionType;
17159
17160 // Set the parameters on the block decl.
17161 if (!params.empty())
17162 blockScope->TheDecl->setParams(params);
17163
17164 if (!oldBlock->blockMissingReturnType()) {
17165 blockScope->HasImplicitReturnType = false;
17166 blockScope->ReturnType = exprResultType;
17167 }
17168
17169 // Transform the body
17170 StmtResult body = getDerived().TransformStmt(E->getBody());
17171 if (body.isInvalid()) {
17172 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17173 return ExprError();
17174 }
17175
17176#ifndef NDEBUG
17177 // In builds with assertions, make sure that we captured everything we
17178 // captured before.
17179 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17180 for (const auto &I : oldBlock->captures()) {
17181 VarDecl *oldCapture = I.getVariable();
17182
17183 // Ignore parameter packs.
17184 if (oldCapture->isParameterPack())
17185 continue;
17186
17187 VarDecl *newCapture =
17188 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17189 oldCapture));
17190 assert(blockScope->CaptureMap.count(newCapture));
17191 }
17192
17193 // The this pointer may not be captured by the instantiated block, even when
17194 // it's captured by the original block, if the expression causing the
17195 // capture is in the discarded branch of a constexpr if statement.
17196 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17197 "this pointer isn't captured in the old block");
17198 }
17199#endif
17200
17201 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17202 /*Scope=*/nullptr);
17203}
17204
17205template<typename Derived>
17208 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17209 if (SrcExpr.isInvalid())
17210 return ExprError();
17211
17212 QualType Type = getDerived().TransformType(E->getType());
17213
17214 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17215 E->getRParenLoc());
17216}
17217
17218template<typename Derived>
17221 bool ArgumentChanged = false;
17222 SmallVector<Expr*, 8> SubExprs;
17223 SubExprs.reserve(E->getNumSubExprs());
17224 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17225 SubExprs, &ArgumentChanged))
17226 return ExprError();
17227
17228 if (!getDerived().AlwaysRebuild() &&
17229 !ArgumentChanged)
17230 return E;
17231
17232 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17233 E->getOp(), E->getRParenLoc());
17234}
17235
17236//===----------------------------------------------------------------------===//
17237// Type reconstruction
17238//===----------------------------------------------------------------------===//
17239
17240template<typename Derived>
17243 return SemaRef.BuildPointerType(PointeeType, Star,
17245}
17246
17247template<typename Derived>
17250 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17252}
17253
17254template<typename Derived>
17257 bool WrittenAsLValue,
17258 SourceLocation Sigil) {
17259 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17260 Sigil, getDerived().getBaseEntity());
17261}
17262
17263template <typename Derived>
17265 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17266 SourceLocation Sigil) {
17267 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17269}
17270
17271template<typename Derived>
17273 const ObjCTypeParamDecl *Decl,
17274 SourceLocation ProtocolLAngleLoc,
17276 ArrayRef<SourceLocation> ProtocolLocs,
17277 SourceLocation ProtocolRAngleLoc) {
17278 return SemaRef.ObjC().BuildObjCTypeParamType(
17279 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17280 /*FailOnError=*/true);
17281}
17282
17283template<typename Derived>
17285 QualType BaseType,
17286 SourceLocation Loc,
17287 SourceLocation TypeArgsLAngleLoc,
17289 SourceLocation TypeArgsRAngleLoc,
17290 SourceLocation ProtocolLAngleLoc,
17292 ArrayRef<SourceLocation> ProtocolLocs,
17293 SourceLocation ProtocolRAngleLoc) {
17294 return SemaRef.ObjC().BuildObjCObjectType(
17295 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17296 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17297 /*FailOnError=*/true,
17298 /*Rebuilding=*/true);
17299}
17300
17301template<typename Derived>
17303 QualType PointeeType,
17305 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17306}
17307
17308template <typename Derived>
17310 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17311 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17312 if (SizeExpr || !Size)
17313 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17314 IndexTypeQuals, BracketsRange,
17316
17317 QualType Types[] = {
17318 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17319 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17320 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17321 };
17322 QualType SizeType;
17323 for (const auto &T : Types)
17324 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17325 SizeType = T;
17326 break;
17327 }
17328
17329 // Note that we can return a VariableArrayType here in the case where
17330 // the element type was a dependent VariableArrayType.
17331 IntegerLiteral *ArraySize
17332 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17333 /*FIXME*/BracketsRange.getBegin());
17334 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17335 IndexTypeQuals, BracketsRange,
17337}
17338
17339template <typename Derived>
17341 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17342 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17343 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17344 IndexTypeQuals, BracketsRange);
17345}
17346
17347template <typename Derived>
17349 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17350 SourceRange BracketsRange) {
17351 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17352 IndexTypeQuals, BracketsRange);
17353}
17354
17355template <typename Derived>
17357 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17358 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17359 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17360 SizeExpr,
17361 IndexTypeQuals, BracketsRange);
17362}
17363
17364template <typename Derived>
17366 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17367 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17368 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17369 SizeExpr,
17370 IndexTypeQuals, BracketsRange);
17371}
17372
17373template <typename Derived>
17375 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17376 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17377 AttributeLoc);
17378}
17379
17380template <typename Derived>
17382 unsigned NumElements,
17383 VectorKind VecKind) {
17384 // FIXME: semantic checking!
17385 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17386}
17387
17388template <typename Derived>
17390 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17391 VectorKind VecKind) {
17392 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17393}
17394
17395template<typename Derived>
17397 unsigned NumElements,
17398 SourceLocation AttributeLoc) {
17399 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17400 NumElements, true);
17401 IntegerLiteral *VectorSize
17402 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17403 AttributeLoc);
17404 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17405}
17406
17407template<typename Derived>
17410 Expr *SizeExpr,
17411 SourceLocation AttributeLoc) {
17412 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17413}
17414
17415template <typename Derived>
17417 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17418 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17419 NumColumns);
17420}
17421
17422template <typename Derived>
17424 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17425 SourceLocation AttributeLoc) {
17426 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17427 AttributeLoc);
17428}
17429
17430template <typename Derived>
17434 return SemaRef.BuildFunctionType(T, ParamTypes,
17437 EPI);
17438}
17439
17440template<typename Derived>
17442 return SemaRef.Context.getFunctionNoProtoType(T);
17443}
17444
17445template <typename Derived>
17448 SourceLocation NameLoc, Decl *D) {
17449 assert(D && "no decl found");
17450 if (D->isInvalidDecl()) return QualType();
17451
17452 // FIXME: Doesn't account for ObjCInterfaceDecl!
17453 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17454 // A valid resolved using typename pack expansion decl can have multiple
17455 // UsingDecls, but they must each have exactly one type, and it must be
17456 // the same type in every case. But we must have at least one expansion!
17457 if (UPD->expansions().empty()) {
17458 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17459 << UPD->isCXXClassMember() << UPD;
17460 return QualType();
17461 }
17462
17463 // We might still have some unresolved types. Try to pick a resolved type
17464 // if we can. The final instantiation will check that the remaining
17465 // unresolved types instantiate to the type we pick.
17466 QualType FallbackT;
17467 QualType T;
17468 for (auto *E : UPD->expansions()) {
17469 QualType ThisT =
17470 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17471 if (ThisT.isNull())
17472 continue;
17473 if (ThisT->getAs<UnresolvedUsingType>())
17474 FallbackT = ThisT;
17475 else if (T.isNull())
17476 T = ThisT;
17477 else
17478 assert(getSema().Context.hasSameType(ThisT, T) &&
17479 "mismatched resolved types in using pack expansion");
17480 }
17481 return T.isNull() ? FallbackT : T;
17482 }
17483 if (auto *Using = dyn_cast<UsingDecl>(D)) {
17484 assert(Using->hasTypename() &&
17485 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17486
17487 // A valid resolved using typename decl points to exactly one type decl.
17488 assert(++Using->shadow_begin() == Using->shadow_end());
17489
17490 UsingShadowDecl *Shadow = *Using->shadow_begin();
17491 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
17492 return QualType();
17493 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
17494 }
17496 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17497 return SemaRef.Context.getUnresolvedUsingType(
17499}
17500
17501template <typename Derived>
17503 TypeOfKind Kind) {
17504 return SemaRef.BuildTypeofExprType(E, Kind);
17505}
17506
17507template<typename Derived>
17509 TypeOfKind Kind) {
17510 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17511}
17512
17513template <typename Derived>
17515 return SemaRef.BuildDecltypeType(E);
17516}
17517
17518template <typename Derived>
17520 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17521 SourceLocation EllipsisLoc, bool FullySubstituted,
17522 ArrayRef<QualType> Expansions) {
17523 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17524 FullySubstituted, Expansions);
17525}
17526
17527template<typename Derived>
17529 UnaryTransformType::UTTKind UKind,
17530 SourceLocation Loc) {
17531 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17532}
17533
17534template <typename Derived>
17537 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
17538 return SemaRef.CheckTemplateIdType(
17539 Keyword, Template, TemplateNameLoc, TemplateArgs,
17540 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
17541}
17542
17543template<typename Derived>
17545 SourceLocation KWLoc) {
17546 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17547}
17548
17549template<typename Derived>
17551 SourceLocation KWLoc,
17552 bool isReadPipe) {
17553 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17554 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17555}
17556
17557template <typename Derived>
17559 unsigned NumBits,
17560 SourceLocation Loc) {
17561 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17562 NumBits, true);
17563 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17564 SemaRef.Context.IntTy, Loc);
17565 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17566}
17567
17568template <typename Derived>
17570 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17571 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17572}
17573
17574template <typename Derived>
17576 bool TemplateKW,
17577 TemplateName Name) {
17578 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17579 Name);
17580}
17581
17582template <typename Derived>
17584 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
17585 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
17587 TemplateName.setIdentifier(&Name, NameLoc);
17589 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17590 TemplateName, ParsedType::make(ObjectType),
17591 /*EnteringContext=*/false, Template,
17592 AllowInjectedClassName);
17593 return Template.get();
17594}
17595
17596template<typename Derived>
17599 SourceLocation TemplateKWLoc,
17600 OverloadedOperatorKind Operator,
17601 SourceLocation NameLoc,
17602 QualType ObjectType,
17603 bool AllowInjectedClassName) {
17604 UnqualifiedId Name;
17605 // FIXME: Bogus location information.
17606 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17607 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17609 getSema().ActOnTemplateName(
17610 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17611 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17612 return Template.get();
17613}
17614
17615template <typename Derived>
17618 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17619 Expr *Second) {
17620 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17621
17622 if (First->getObjectKind() == OK_ObjCProperty) {
17625 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17626 Opc, First, Second);
17627 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
17628 if (Result.isInvalid())
17629 return ExprError();
17630 First = Result.get();
17631 }
17632
17633 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17634 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17635 if (Result.isInvalid())
17636 return ExprError();
17637 Second = Result.get();
17638 }
17639
17640 // Determine whether this should be a builtin operation.
17641 if (Op == OO_Subscript) {
17642 if (!First->getType()->isOverloadableType() &&
17643 !Second->getType()->isOverloadableType())
17644 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17645 OpLoc);
17646 } else if (Op == OO_Arrow) {
17647 // It is possible that the type refers to a RecoveryExpr created earlier
17648 // in the tree transformation.
17649 if (First->getType()->isDependentType())
17650 return ExprError();
17651 // -> is never a builtin operation.
17652 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17653 } else if (Second == nullptr || isPostIncDec) {
17654 if (!First->getType()->isOverloadableType() ||
17655 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17656 // The argument is not of overloadable type, or this is an expression
17657 // of the form &Class::member, so try to create a built-in unary
17658 // operation.
17660 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17661
17662 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17663 }
17664 } else {
17665 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17666 !First->getType()->isOverloadableType() &&
17667 !Second->getType()->isOverloadableType()) {
17668 // Neither of the arguments is type-dependent or has an overloadable
17669 // type, so try to create a built-in binary operation.
17672 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17673 if (Result.isInvalid())
17674 return ExprError();
17675
17676 return Result;
17677 }
17678 }
17679
17680 // Create the overloaded operator invocation for unary operators.
17681 if (!Second || isPostIncDec) {
17683 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17684 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17685 RequiresADL);
17686 }
17687
17688 // Create the overloaded operator invocation for binary operators.
17690 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17691 First, Second, RequiresADL);
17692 if (Result.isInvalid())
17693 return ExprError();
17694
17695 return Result;
17696}
17697
17698template<typename Derived>
17701 SourceLocation OperatorLoc,
17702 bool isArrow,
17703 CXXScopeSpec &SS,
17704 TypeSourceInfo *ScopeType,
17705 SourceLocation CCLoc,
17706 SourceLocation TildeLoc,
17707 PseudoDestructorTypeStorage Destroyed) {
17708 QualType CanonicalBaseType = Base->getType().getCanonicalType();
17709 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17710 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
17711 (isArrow && isa<PointerType>(CanonicalBaseType) &&
17712 !cast<PointerType>(CanonicalBaseType)
17713 ->getPointeeType()
17714 ->getAsCanonical<RecordType>())) {
17715 // This pseudo-destructor expression is still a pseudo-destructor.
17716 return SemaRef.BuildPseudoDestructorExpr(
17717 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17718 CCLoc, TildeLoc, Destroyed);
17719 }
17720
17721 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17722 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
17723 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17724 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17725 NameInfo.setNamedTypeInfo(DestroyedType);
17726
17727 // The scope type is now known to be a valid nested name specifier
17728 // component. Tack it on to the nested name specifier.
17729 if (ScopeType) {
17730 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
17731 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17732 diag::err_expected_class_or_namespace)
17733 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17734 return ExprError();
17735 }
17736 SS.clear();
17737 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
17738 }
17739
17740 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17741 return getSema().BuildMemberReferenceExpr(
17742 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
17743 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
17744 /*TemplateArgs*/ nullptr,
17745 /*S*/ nullptr);
17746}
17747
17748template<typename Derived>
17751 SourceLocation Loc = S->getBeginLoc();
17752 CapturedDecl *CD = S->getCapturedDecl();
17753 unsigned NumParams = CD->getNumParams();
17754 unsigned ContextParamPos = CD->getContextParamPosition();
17756 for (unsigned I = 0; I < NumParams; ++I) {
17757 if (I != ContextParamPos) {
17758 Params.push_back(
17759 std::make_pair(
17760 CD->getParam(I)->getName(),
17761 getDerived().TransformType(CD->getParam(I)->getType())));
17762 } else {
17763 Params.push_back(std::make_pair(StringRef(), QualType()));
17764 }
17765 }
17766 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17767 S->getCapturedRegionKind(), Params);
17768 StmtResult Body;
17769 {
17770 Sema::CompoundScopeRAII CompoundScope(getSema());
17771 Body = getDerived().TransformStmt(S->getCapturedStmt());
17772 }
17773
17774 if (Body.isInvalid()) {
17775 getSema().ActOnCapturedRegionError();
17776 return StmtError();
17777 }
17778
17779 return getSema().ActOnCapturedRegionEnd(Body.get());
17780}
17781
17782template <typename Derived>
17785 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
17786 // function definition or instantiation of a function template specialization
17787 // and will therefore never appear in a dependent context.
17788 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
17789 "context");
17790}
17791
17792template <typename Derived>
17794 // We can transform the base expression and allow argument resolution to fill
17795 // in the rest.
17796 return getDerived().TransformExpr(E->getArgLValue());
17797}
17798
17799} // end namespace clang
17800
17801#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.
#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.
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 'pragma omp metadirective' directive.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType IntTy
CanQualType PseudoObjectTy
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getPackExpansionType(QualType Pattern, UnsignedOrNone NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
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:4484
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:5955
Represents a loop initializing the elements of an array.
Definition Expr.h:5902
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1804
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7105
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
Wrapper for source info for arrays.
Definition TypeLoc.h:1748
void setLBracketLoc(SourceLocation Loc)
Definition TypeLoc.h:1754
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2998
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3036
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3038
Expr * getDimensionExpression() const
Definition ExprCXX.h:3048
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3044
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3035
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6619
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6814
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2644
Attr - This represents one attribute.
Definition Attr.h:44
attr::Kind getKind() const
Definition Attr.h:90
Represents an attribute applied to a statement.
Definition Stmt.h:2203
Stmt * getSubStmt()
Definition Stmt.h:2239
SourceLocation getAttrLoc() const
Definition Stmt.h:2234
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2235
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:4387
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2175
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4108
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2137
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8130
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4654
void setIsVariadic(bool value)
Definition Decl.h:4730
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6558
Wrapper for source info for block pointers.
Definition TypeLoc.h:1497
BreakStmt - This represents a break.
Definition Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5478
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5497
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5496
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:3903
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:234
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition ExprCXX.h:604
Represents binding an expression to a temporary.
Definition ExprCXX.h:1494
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:723
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
A C++ const_cast expression (C++ [expr.const.cast]).
Definition ExprCXX.h:566
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1730
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1692
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1642
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.cpp:581
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.cpp:575
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1631
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1689
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1271
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1039
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1378
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2628
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3872
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:481
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5034
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition ExprCXX.h:1833
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:375
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:406
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:413
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:409
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2357
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4311
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:768
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5143
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2747
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1854
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:526
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:286
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2198
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:73
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:206
SourceRange getRange() const
Definition DeclSpec.h:79
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:94
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:210
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:178
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:800
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1901
Represents the this expression in C++.
Definition ExprCXX.h:1155
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:848
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3746
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3790
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3801
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3784
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3795
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3804
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1069
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
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:1513
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4926
unsigned getNumParams() const
Definition Decl.h:4964
unsigned getContextParamPosition() const
Definition Decl.h:4993
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:4966
This captures a statement into a function.
Definition Stmt.h:3886
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1455
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:3990
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4081
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition Stmt.cpp:1470
CaseStmt - Represent a case statement.
Definition Stmt.h:1920
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:1975
Expr * getSubExpr()
Definition Expr.h:3660
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4782
Represents a 'co_await' expression.
Definition ExprCXX.h:5371
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1720
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1770
body_range body()
Definition Stmt.h:1783
SourceLocation getLBracLoc() const
Definition Stmt.h:1857
bool hasStoredFPFeatures() const
Definition Stmt.h:1767
Stmt * getStmtExprResult()
Definition Stmt.h:1842
SourceLocation getRBracLoc() const
Definition Stmt.h:1858
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:4325
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3760
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1082
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4373
ContinueStmt - This represents a continue.
Definition Stmt.h:3119
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4653
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition StmtCXX.h:473
Represents the body of a coroutine.
Definition StmtCXX.h:320
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3436
Represents a 'co_yield' expression.
Definition ExprCXX.h:5452
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h:1445
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:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2109
DeclContextLookupResult lookup_result
Definition DeclBase.h:2577
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.
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1270
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1611
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInvalidDecl() const
Definition DeclBase.h:588
SourceLocation getLocation() const
Definition DeclBase.h:439
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
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:1874
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2259
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2484
void setAttrOperandParensRange(SourceRange range)
Definition TypeLoc.h:1969
Represents an extended address space qualifier where the input address space value is dependent.
Definition TypeBase.h:4061
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5403
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2552
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3512
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3586
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3560
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3578
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3596
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3570
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3613
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3551
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3606
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3548
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4011
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2067
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4101
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4420
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2039
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4227
Represents a single C99 designator.
Definition Expr.h:5528
Represents a C99 designated initializer expression.
Definition Expr.h:5485
Designation - Represent a full designation, which is a sequence of designators.
Definition Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Designator.h:115
bool hasErrorOccurred() const
Definition Diagnostic.h:872
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2832
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition TypeBase.h:4974
Expr * getCondition() const
Definition TypeBase.h:4981
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:744
Represents a reference to emded data.
Definition Expr.h:5060
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:3884
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3663
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:451
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3077
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3209
QualType getType() const
Definition Expr.h:144
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:523
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:434
An expression trait intrinsic.
Definition ExprCXX.h:3071
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6498
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3160
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2888
Represents a function declaration or definition.
Definition Decl.h:2000
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2774
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5222
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:4867
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5521
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5507
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5088
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4832
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4843
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5254
param_type_iterator param_type_begin() const
Definition TypeBase.h:5698
unsigned getNumParams() const
Definition TypeLoc.h:1687
SourceLocation getLocalRangeEnd() const
Definition TypeLoc.h:1639
void setLocalRangeBegin(SourceLocation L)
Definition TypeLoc.h:1635
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1651
SourceRange getExceptionSpecRange() const
Definition TypeLoc.h:1667
void setParam(unsigned i, ParmVarDecl *VD)
Definition TypeLoc.h:1694
ArrayRef< ParmVarDecl * > getParams() const
Definition TypeLoc.h:1678
void setRParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1659
void setLocalRangeEnd(SourceLocation L)
Definition TypeLoc.h:1643
void setExceptionSpecRange(SourceRange R)
Definition TypeLoc.h:1673
TypeLoc getReturnLoc() const
Definition TypeLoc.h:1696
SourceLocation getLocalRangeBegin() const
Definition TypeLoc.h:1631
SourceLocation getLParenLoc() const
Definition TypeLoc.h:1647
SourceLocation getRParenLoc() const
Definition TypeLoc.h:1655
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4476
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3395
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4857
Represents a C11 generic selection.
Definition Expr.h:6112
AssociationTy< false > Association
Definition Expr.h:6343
GotoStmt - This represents a direct goto.
Definition Stmt.h:2969
Type source information for HLSL attributed resource type.
Definition TypeLoc.h:1085
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7283
One of these records is kept for each identifier that is lexed.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2259
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1731
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3787
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:5991
Represents a C array with an unspecified size.
Definition TypeBase.h:3909
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3008
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Describes an C or C++ initializer list.
Definition Expr.h:5233
InitListExpr * getSyntacticForm() const
Definition Expr.h:5406
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:971
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2146
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1970
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1363
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1358
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1367
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2035
Represents the results of name lookup.
Definition Lookup.h:147
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition Lookup.h:607
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition Lookup.h:475
bool empty() const
Return true if no decls were found.
Definition Lookup.h:362
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition Lookup.h:666
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition Lookup.h:576
DeclarationName getLookupName() const
Gets the name to look up.
Definition Lookup.h:265
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3614
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Definition StmtCXX.h:253
An instance of this class represents the declaration of a property member.
Definition DeclCXX.h:4344
A member reference to an MSPropertyDecl.
Definition ExprCXX.h:936
MS property subscript expression.
Definition ExprCXX.h:1007
void setExpansionLoc(SourceLocation Loc)
Definition TypeLoc.h:1354
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4922
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2799
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2096
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
Wrapper for source info for member pointers.
Definition TypeLoc.h:1515
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3653
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
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:487
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:5811
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1683
This represents the 'absent' clause in the 'pragma omp assume' directive.
This represents 'acq_rel' clause in the 'pragma omp atomic|flush' directives.
This represents 'acquire' clause in the 'pragma omp atomic|flush' directives.
This represents clause 'affinity' in the 'pragma omp task'-based directives.
This represents the 'align' clause in the 'pragma omp allocate' directive.
This represents clause 'aligned' in the 'pragma omp ...' directives.
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 represents 'at' clause in the 'pragma omp error' directive.
This represents 'atomic_default_mem_order' clause in the 'pragma omp requires' directive.
This represents 'bind' clause in the 'pragma omp ...' directives.
This represents 'capture' clause in the 'pragma omp atomic' directive.
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 'compare' clause in the 'pragma omp atomic' directive.
This represents the 'contains' clause in the 'pragma omp assume' directive.
This represents clause 'copyin' in the 'pragma omp ...' directives.
This represents clause 'copyprivate' in the 'pragma omp ...' directives.
This represents 'default' clause in the 'pragma omp ...' directive.
This represents 'defaultmap' clause in the 'pragma omp ...' directive.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
This represents implicit clause 'depobj' for the 'pragma omp depobj' directive.
This represents 'destroy' clause in the 'pragma omp depobj' directive or the 'pragma omp interop' dir...
This represents 'detach' clause in the 'pragma omp task' directive.
This represents 'device' clause in the 'pragma omp ...' directive.
This represents 'dist_schedule' clause in the 'pragma omp ...' directive.
This represents the 'doacross' clause for the 'pragma omp ordered' directive.
This represents 'dynamic_allocators' clause in the 'pragma omp requires' directive.
This represents clause 'exclusive' in the 'pragma omp scan' directive.
This represents 'fail' clause in the 'pragma omp atomic' directive.
This represents 'filter' clause in the 'pragma omp ...' directive.
This represents 'final' clause in the 'pragma omp ...' directive.
This represents clause 'firstprivate' in the 'pragma omp ...' directives.
This represents implicit clause 'flush' for the 'pragma omp flush' directive.
This represents clause 'from' in the 'pragma omp ...' directives.
Representation of the 'full' clause of the 'pragma omp unroll' directive.
This represents 'grainsize' clause in the 'pragma omp ...' directive.
This represents clause 'has_device_ptr' in the 'pragma omp ...' directives.
This represents 'hint' clause in the 'pragma omp ...' directive.
This represents the 'holds' clause in the 'pragma omp assume' directive.
This represents 'if' clause in the 'pragma omp ...' directive.
This represents clause 'in_reduction' in the 'pragma omp task' directives.
This represents clause 'inclusive' in the 'pragma omp scan' directive.
This represents the 'init' clause in 'pragma omp ...' directives.
This represents clause 'is_device_ptr' in the 'pragma omp ...' directives.
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition ExprOpenMP.h:151
This represents clause 'lastprivate' in the 'pragma omp ...' directives.
This represents clause 'linear' in the 'pragma omp ...' directives.
This class represents the 'looprange' clause in the 'pragma omp fuse' directive.
This represents clauses with a list of expressions that are mappable.
This represents 'mergeable' clause in the 'pragma omp ...' directive.
This represents the 'message' clause in the 'pragma omp error' and the 'pragma omp parallel' directiv...
This represents the 'no_openmp' clause in the 'pragma omp assume' directive.
This represents the 'no_openmp_constructs' clause in the.
This represents the 'no_openmp_routines' clause in the 'pragma omp assume' directive.
This represents the 'no_parallelism' clause in the 'pragma omp assume' directive.
This represents 'nocontext' clause in the 'pragma omp ...' directive.
This represents 'nogroup' clause in the 'pragma omp ...' directive.
This represents clause 'nontemporal' in the 'pragma omp ...' directives.
This represents 'novariants' clause in the 'pragma omp ...' directive.
This represents 'nowait' clause in the 'pragma omp ...' directive.
This represents 'num_tasks' clause in the 'pragma omp ...' directive.
This represents 'num_teams' clause in the 'pragma omp ...' directive.
This represents 'num_threads' clause in the 'pragma omp ...' directive.
This represents 'order' clause in the 'pragma omp ...' directive.
This represents 'ordered' 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 'priority' clause in the 'pragma omp ...' directive.
This represents clause 'private' in the 'pragma omp ...' directives.
This represents 'proc_bind' clause in the 'pragma omp ...' directive.
This represents 'read' clause in the 'pragma omp atomic' directive.
This represents clause 'reduction' in the 'pragma omp ...' directives.
This represents 'relaxed' clause in the 'pragma omp atomic' directives.
This represents 'release' clause in the 'pragma omp atomic|flush' directives.
This represents 'reverse_offload' clause in the 'pragma omp requires' directive.
This represents 'simd' clause in the 'pragma omp ...' directive.
This represents 'safelen' clause in the 'pragma omp ...' directive.
This represents 'schedule' clause in the 'pragma omp ...' directive.
This represents 'self_maps' clause in the 'pragma omp requires' directive.
This represents 'seq_cst' clause in the 'pragma omp atomic|flush' directives.
This represents the 'severity' clause in the 'pragma omp error' and the 'pragma omp parallel' directi...
This represents clause 'shared' in the 'pragma omp ...' directives.
This represents 'simdlen' clause in the 'pragma omp ...' directive.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
This represents clause 'task_reduction' in the 'pragma omp taskgroup' directives.
This represents 'thread_limit' clause in the 'pragma omp ...' directive.
This represents 'threads' clause in the 'pragma omp ...' directive.
This represents clause 'to' in the 'pragma omp ...' directives.
This represents 'unified_address' clause in the 'pragma omp requires' directive.
This represents 'unified_shared_memory' clause in the 'pragma omp requires' directive.
This represents 'untied' clause in the 'pragma omp ...' directive.
This represents 'update' clause in the 'pragma omp atomic' directive.
This represents the 'use' clause in 'pragma omp ...' directives.
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
This represents clause 'uses_allocators' in the 'pragma omp target'-based directives.
This represents 'weak' clause in the 'pragma omp atomic' directives.
This represents 'write' clause in the 'pragma omp atomic' directive.
This represents 'ompx_attribute' clause in a directive that might generate an outlined function.
This represents 'ompx_bare' clause in the 'pragma omp target teams ...' directive.
This represents 'ompx_dyn_cgroup_mem' clause in the 'pragma omp target ...' directive.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:192
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:1703
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:88
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:128
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1643
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:308
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:409
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:1582
Wrapper for source info for ObjC interfaces.
Definition TypeLoc.h:1274
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition ExprObjC.h:1498
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:548
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:940
@ SuperInstance
The receiver is the instance of the superclass object.
Definition ExprObjC.h:954
@ Instance
The receiver is an object instance.
Definition ExprObjC.h:948
@ SuperClass
The receiver is a superclass.
Definition ExprObjC.h:951
@ Class
The receiver is a class.
Definition ExprObjC.h:945
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Wraps an ObjCPointerType with source location information.
Definition TypeLoc.h:1557
void setStarLoc(SourceLocation Loc)
Definition TypeLoc.h:1563
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition TypeLoc.h:1229
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition ExprObjC.h:616
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:504
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:454
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:52
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition ExprObjC.h:839
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:578
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition TypeLoc.h:895
@ Array
An index into an array.
Definition Expr.h:2426
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2430
@ Field
A field.
Definition Expr.h:2428
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2433
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:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2090
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)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition ExprCXX.h:3130
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3282
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3264
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3243
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3256
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3252
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3326
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3229
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3332
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3240
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3272
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3279
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4365
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2604
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2600
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2616
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2287
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2182
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2207
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2211
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1382
Represents a parameter to a function.
Definition Decl.h:1790
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1850
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1823
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:2946
unsigned getFunctionScopeDepth() const
Definition Decl.h:1840
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2696
PipeType - OpenCL20.
Definition TypeBase.h:8096
bool isReadOnly() const
Definition TypeBase.h:8126
Pointer-authentication qualifiers.
Definition TypeBase.h:152
void setSigilLoc(SourceLocation Loc)
Definition TypeLoc.h:1461
TypeLoc getPointeeLoc() const
Definition TypeLoc.h:1465
SourceLocation getSigilLoc() const
Definition TypeLoc.h:1457
Wrapper for source info for pointers.
Definition TypeLoc.h:1484
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3328
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2005
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2696
const IdentifierInfo * getIdentifier() const
Definition ExprCXX.h:2716
SourceLocation getLocation() const
Definition ExprCXX.h:2720
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2712
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6690
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8278
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8318
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8372
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8310
Represents a template name as written in source code.
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition TypeLoc.h:300
The collection of all-type qualifiers we support.
Definition TypeBase.h:331
void removeObjCLifetime()
Definition TypeBase.h:551
bool hasRestrict() const
Definition TypeBase.h:477
static Qualifiers fromCVRMask(unsigned CVR)
Definition TypeBase.h:435
PointerAuthQualifier getPointerAuth() const
Definition TypeBase.h:603
bool hasObjCLifetime() const
Definition TypeBase.h:544
bool empty() const
Definition TypeBase.h:647
LangAS getAddressSpace() const
Definition TypeBase.h:571
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7389
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3573
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3589
Represents the body of a requires-expression.
Definition DeclCXX.h:2098
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition DeclCXX.cpp:2389
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:3160
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition Stmt.cpp:1323
Represents a __leave statement.
Definition Stmt.h:3847
SYCLKernelCallStmt represents the transformation that is applied to the body of a function declared w...
Definition StmtSYCL.h:37
Smart pointer class that efficiently represents Objective-C method names.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
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 * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' 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 * 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 * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' 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 * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Condition)
Called on well-formed 'nowait' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'schedule' clause.
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' 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 * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
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 * 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)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition SemaSYCL.cpp:143
RAII object used to change the argument pack substitution index within a Sema object.
Definition Sema.h:13588
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8407
A RAII object to enter scope of a compound statement.
Definition Sema.h:1290
A RAII object to temporarily push a declaration context.
Definition Sema.h:3467
A helper class for building up ExtParameterInfos.
Definition Sema.h:12958
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:12977
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:12965
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:13987
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:854
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:9297
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9305
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9300
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
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:1501
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:7803
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7805
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7804
ExprResult BuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP, SourceLocation loc, TemplateArgument Replacement, UnsignedOrNone PackIndex, bool Final)
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:438
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:485
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:1526
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:11924
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:1283
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:922
SemaObjC & ObjC()
Definition Sema.h:1486
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:925
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)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:83
const LangOptions & getLangOpts() const
Definition Sema.h:918
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1491
@ ReuseLambdaContextDecl
Definition Sema.h:6984
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 BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11727
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:1314
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:11722
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2514
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1414
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 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.
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition Sema.h:13582
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:6702
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6712
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6681
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6707
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:75
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:8276
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
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:11014
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:563
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:337
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:950
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:1275
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:7789
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:436
SemaPseudoObject & PseudoObject()
Definition Sema.h:1511
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:1274
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:568
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:532
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:8615
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:4577
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4443
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4505
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4528
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1709
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4533
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4502
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4508
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4511
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4951
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5011
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:4529
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:362
@ NoStmtClass
Definition Stmt.h:88
StmtClass getStmtClass() const
Definition Stmt.h:1472
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
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:4666
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4756
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:2509
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
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:1878
SourceLocation getRAngleLoc() const
Definition TypeLoc.h:1893
SourceLocation getTemplateNameLoc() const
Definition TypeLoc.h:1876
SourceLocation getTemplateKeywordLoc() const
Definition TypeLoc.h:1872
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:1862
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:1858
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(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
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)
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.
QualType RebuildDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new expression pack expansion.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
OMPClause * RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'message' clause.
ExprResult RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
ExprResult 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.
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.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc)
Build a new initializer list expression.
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.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
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.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
QualType RebuildMemberPointerType(QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the qualifier it refers into.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCCacheConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation EndLoc)
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 * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' 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.
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_ptr' clause.
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 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)
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)
TypeSourceInfo * TransformType(TypeSourceInfo *DI)
Transforms the given type-with-location into a new type-with-location.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
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)
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 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'.
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.
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 RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
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.
ExprResult RebuildCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
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)
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
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)
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)
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.
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *DI)
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.
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.
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:2706
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:6165
A container of type source information.
Definition TypeBase.h:8249
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:8260
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:2898
The base class of the type hierarchy.
Definition TypeBase.h:1833
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2782
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2405
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9014
bool isObjCObjectPointerType() const
Definition TypeBase.h:8684
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9091
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2171
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2625
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2289
Expr * getSubExpr() const
Definition Expr.h:2285
Opcode getOpcode() const
Definition Expr.h:2280
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1411
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2315
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:998
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:3392
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3466
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3461
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:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4128
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:5970
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition ExprCXX.h:640
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3399
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3463
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:4891
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:5513
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:926
@ CInit
C-style initialization with assignment.
Definition Decl.h:931
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:934
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3966
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2016
Represents a GCC generic vector type.
Definition TypeBase.h:4175
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2697
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:790
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition ScopeInfo.h:728
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition ScopeInfo.h:871
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition ScopeInfo.h:874
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
VE builtins.
const AstTypeMatcher< FunctionType > functionType
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition Descriptor.h:29
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition Interp.h:958
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:774
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
OpenACCDirectiveKind
bool isa(CodeGen::Address addr)
Definition Address.h:330
ArrayTypeTrait
Names for the array type traits.
Definition TypeTraits.h:42
@ CPlusPlus23
OpenACCAtomicKind
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1792
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
TryCaptureKind
Definition Sema.h:651
@ 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:39
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
CXXConstructionKind
Definition ExprCXX.h:1541
@ 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:161
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:602
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:236
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:918
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Expr * Cond
};
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition TypeTraits.h:51
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
ExprResult ExprEmpty()
Definition Ownership.h:272
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
StmtResult StmtError()
Definition Ownership.h:266
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3719
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:5878
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
ExprResult ExprError()
Definition Ownership.h:265
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:560
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
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
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:139
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition Sema.h:798
@ Exists
The symbol exists.
Definition Sema.h:791
@ Error
An error occurred.
Definition Sema.h:801
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:794
MutableArrayRef< Stmt * > MultiStmtArg
Definition Ownership.h:260
OpenMPNumThreadsClauseModifier
U cast(CodeGen::Address addr)
Definition Address.h:327
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:4938
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:5853
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5874
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5864
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:5871
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
TypeTrait
Names for traits that operate specifically on types.
Definition TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
Definition ExprCXX.h:2247
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:1989
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
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)
UnsignedOrNone ArgPackSubstIndex
Definition Decl.h:89
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
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:4991
Holds information about the various types of exception specification.
Definition TypeBase.h:5311
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5327
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5313
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5316
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5319
Extra information about a function prototype.
Definition TypeBase.h:5339
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5344
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:3275
const NamespaceBaseDecl * Namespace
Iterator range representation begin:end[:step].
Definition ExprOpenMP.h:154
Data for list of allocators.
This structure contains most locations needed for by an OMPVarListClause.
An element in an Objective-C dictionary literal.
Definition ExprObjC.h:261
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:13035
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13066
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1303
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3267
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions