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 /// Checks if the argument pack from \p In will need to be expanded and does
698 /// the necessary prework.
699 /// Whether the expansion is needed is captured in Info.Expand.
700 ///
701 /// - When the expansion is required, \p Out will be a template pattern that
702 /// would need to be expanded.
703 /// - When the expansion must not happen, \p Out will be a pack that must be
704 /// returned to the outputs directly.
705 ///
706 /// \return true iff the error occurred
709
710 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
712 TemplateArgumentLoc &ArgLoc);
713
714 /// Fakes up a TypeSourceInfo for a type.
716 return SemaRef.Context.getTrivialTypeSourceInfo(T,
718 }
719
720#define ABSTRACT_TYPELOC(CLASS, PARENT)
721#define TYPELOC(CLASS, PARENT) \
722 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
723#include "clang/AST/TypeLocNodes.def"
724
727 bool SuppressObjCLifetime);
731 bool SuppressObjCLifetime);
732
733 template<typename Fn>
736 CXXRecordDecl *ThisContext,
737 Qualifiers ThisTypeQuals,
739
742 SmallVectorImpl<QualType> &Exceptions,
743 bool &Changed);
744
746
749 QualType ObjectType,
750 NamedDecl *FirstQualifierInScope,
751 bool AllowInjectedClassName);
752
754
755 /// Transforms the parameters of a function type into the
756 /// given vectors.
757 ///
758 /// The result vectors should be kept in sync; null entries in the
759 /// variables vector are acceptable.
760 ///
761 /// LastParamTransformed, if non-null, will be set to the index of the last
762 /// parameter on which transformation was started. In the event of an error,
763 /// this will contain the parameter which failed to instantiate.
764 ///
765 /// Return true on error.
768 const QualType *ParamTypes,
769 const FunctionProtoType::ExtParameterInfo *ParamInfos,
771 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
772
775 const QualType *ParamTypes,
776 const FunctionProtoType::ExtParameterInfo *ParamInfos,
779 return getDerived().TransformFunctionTypeParams(
780 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
781 }
782
783 /// Transforms the parameters of a requires expresison into the given vectors.
784 ///
785 /// The result vectors should be kept in sync; null entries in the
786 /// variables vector are acceptable.
787 ///
788 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
789 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
790 /// which are cases where transformation shouldn't continue.
792 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
798 KWLoc, Params, /*ParamTypes=*/nullptr,
799 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
800 return ExprError();
801
802 return ExprResult{};
803 }
804
805 /// Transforms a single function-type parameter. Return null
806 /// on error.
807 ///
808 /// \param indexAdjustment - A number to add to the parameter's
809 /// scope index; can be negative
811 int indexAdjustment,
812 UnsignedOrNone NumExpansions,
813 bool ExpectParameterPack);
814
815 /// Transform the body of a lambda-expression.
817 /// Alternative implementation of TransformLambdaBody that skips transforming
818 /// the body.
820
826
828
831
836
838
840 bool IsAddressOfOperand,
841 TypeSourceInfo **RecoveryTSI);
842
844 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
845 TypeSourceInfo **RecoveryTSI);
846
848 bool IsAddressOfOperand);
849
851
853
854// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
855// amount of stack usage with clang.
856#define STMT(Node, Parent) \
857 LLVM_ATTRIBUTE_NOINLINE \
858 StmtResult Transform##Node(Node *S);
859#define VALUESTMT(Node, Parent) \
860 LLVM_ATTRIBUTE_NOINLINE \
861 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
862#define EXPR(Node, Parent) \
863 LLVM_ATTRIBUTE_NOINLINE \
864 ExprResult Transform##Node(Node *E);
865#define ABSTRACT_STMT(Stmt)
866#include "clang/AST/StmtNodes.inc"
867
868#define GEN_CLANG_CLAUSE_CLASS
869#define CLAUSE_CLASS(Enum, Str, Class) \
870 LLVM_ATTRIBUTE_NOINLINE \
871 OMPClause *Transform##Class(Class *S);
872#include "llvm/Frontend/OpenMP/OMP.inc"
873
874 /// Build a new qualified type given its unqualified type and type location.
875 ///
876 /// By default, this routine adds type qualifiers only to types that can
877 /// have qualifiers, and silently suppresses those qualifiers that are not
878 /// permitted. Subclasses may override this routine to provide different
879 /// behavior.
881
882 /// Build a new pointer type given its pointee type.
883 ///
884 /// By default, performs semantic analysis when building the pointer type.
885 /// Subclasses may override this routine to provide different behavior.
887
888 /// Build a new block pointer type given its pointee type.
889 ///
890 /// By default, performs semantic analysis when building the block pointer
891 /// type. Subclasses may override this routine to provide different behavior.
893
894 /// Build a new reference type given the type it references.
895 ///
896 /// By default, performs semantic analysis when building the
897 /// reference type. Subclasses may override this routine to provide
898 /// different behavior.
899 ///
900 /// \param LValue whether the type was written with an lvalue sigil
901 /// or an rvalue sigil.
903 bool LValue,
904 SourceLocation Sigil);
905
906 /// Build a new member pointer type given the pointee type and the
907 /// qualifier it refers into.
908 ///
909 /// By default, performs semantic analysis when building the member pointer
910 /// type. Subclasses may override this routine to provide different behavior.
912 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
913 SourceLocation Sigil);
914
916 SourceLocation ProtocolLAngleLoc,
918 ArrayRef<SourceLocation> ProtocolLocs,
919 SourceLocation ProtocolRAngleLoc);
920
921 /// Build an Objective-C object type.
922 ///
923 /// By default, performs semantic analysis when building the object type.
924 /// Subclasses may override this routine to provide different behavior.
926 SourceLocation Loc,
927 SourceLocation TypeArgsLAngleLoc,
929 SourceLocation TypeArgsRAngleLoc,
930 SourceLocation ProtocolLAngleLoc,
932 ArrayRef<SourceLocation> ProtocolLocs,
933 SourceLocation ProtocolRAngleLoc);
934
935 /// Build a new Objective-C object pointer type given the pointee type.
936 ///
937 /// By default, directly builds the pointer type, with no additional semantic
938 /// analysis.
941
942 /// Build a new array type given the element type, size
943 /// modifier, size of the array (if known), size expression, and index type
944 /// qualifiers.
945 ///
946 /// By default, performs semantic analysis when building the array type.
947 /// Subclasses may override this routine to provide different behavior.
948 /// Also by default, all of the other Rebuild*Array
950 const llvm::APInt *Size, Expr *SizeExpr,
951 unsigned IndexTypeQuals, SourceRange BracketsRange);
952
953 /// Build a new constant array type given the element type, size
954 /// modifier, (known) size of the array, and index type qualifiers.
955 ///
956 /// By default, performs semantic analysis when building the array type.
957 /// Subclasses may override this routine to provide different behavior.
959 ArraySizeModifier SizeMod,
960 const llvm::APInt &Size, Expr *SizeExpr,
961 unsigned IndexTypeQuals,
962 SourceRange BracketsRange);
963
964 /// Build a new incomplete array type given the element type, size
965 /// modifier, and index type qualifiers.
966 ///
967 /// By default, performs semantic analysis when building the array type.
968 /// Subclasses may override this routine to provide different behavior.
970 ArraySizeModifier SizeMod,
971 unsigned IndexTypeQuals,
972 SourceRange BracketsRange);
973
974 /// Build a new variable-length array type given the element type,
975 /// size modifier, size expression, and index type qualifiers.
976 ///
977 /// By default, performs semantic analysis when building the array type.
978 /// Subclasses may override this routine to provide different behavior.
980 ArraySizeModifier SizeMod, Expr *SizeExpr,
981 unsigned IndexTypeQuals,
982 SourceRange BracketsRange);
983
984 /// Build a new dependent-sized array type given the element type,
985 /// size modifier, size expression, and index type qualifiers.
986 ///
987 /// By default, performs semantic analysis when building the array type.
988 /// Subclasses may override this routine to provide different behavior.
990 ArraySizeModifier SizeMod,
991 Expr *SizeExpr,
992 unsigned IndexTypeQuals,
993 SourceRange BracketsRange);
994
995 /// Build a new vector type given the element type and
996 /// number of elements.
997 ///
998 /// By default, performs semantic analysis when building the vector type.
999 /// Subclasses may override this routine to provide different behavior.
1000 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1001 VectorKind VecKind);
1002
1003 /// Build a new potentially dependently-sized extended vector type
1004 /// given the element type and number of elements.
1005 ///
1006 /// By default, performs semantic analysis when building the vector type.
1007 /// Subclasses may override this routine to provide different behavior.
1009 SourceLocation AttributeLoc, VectorKind);
1010
1011 /// Build a new extended vector type given the element type and
1012 /// number of elements.
1013 ///
1014 /// By default, performs semantic analysis when building the vector type.
1015 /// Subclasses may override this routine to provide different behavior.
1016 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1017 SourceLocation AttributeLoc);
1018
1019 /// Build a new potentially dependently-sized extended vector type
1020 /// given the element type and number of elements.
1021 ///
1022 /// By default, performs semantic analysis when building the vector type.
1023 /// Subclasses may override this routine to provide different behavior.
1025 Expr *SizeExpr,
1026 SourceLocation AttributeLoc);
1027
1028 /// Build a new matrix type given the element type and dimensions.
1029 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1030 unsigned NumColumns);
1031
1032 /// Build a new matrix type given the type and dependently-defined
1033 /// dimensions.
1035 Expr *ColumnExpr,
1036 SourceLocation AttributeLoc);
1037
1038 /// Build a new DependentAddressSpaceType or return the pointee
1039 /// type variable with the correct address space (retrieved from
1040 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1041 /// where the address space remains dependent.
1042 ///
1043 /// By default, performs semantic analysis when building the type with address
1044 /// space applied. Subclasses may override this routine to provide different
1045 /// behavior.
1047 Expr *AddrSpaceExpr,
1048 SourceLocation AttributeLoc);
1049
1050 /// Build a new function type.
1051 ///
1052 /// By default, performs semantic analysis when building the function type.
1053 /// Subclasses may override this routine to provide different behavior.
1055 MutableArrayRef<QualType> ParamTypes,
1057
1058 /// Build a new unprototyped function type.
1060
1061 /// Rebuild an unresolved typename type, given the decl that
1062 /// the UnresolvedUsingTypenameDecl was transformed to.
1064 NestedNameSpecifier Qualifier,
1065 SourceLocation NameLoc, Decl *D);
1066
1067 /// Build a new type found via an alias.
1070 QualType UnderlyingType) {
1071 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1072 }
1073
1074 /// Build a new typedef type.
1076 NestedNameSpecifier Qualifier,
1078 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1079 }
1080
1081 /// Build a new MacroDefined type.
1083 const IdentifierInfo *MacroII) {
1084 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1085 }
1086
1087 /// Build a new class/struct/union/enum type.
1089 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1090 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1091 /*OwnsTag=*/false);
1092 }
1094 return SemaRef.Context.getCanonicalTagType(Tag);
1095 }
1096
1097 /// Build a new typeof(expr) type.
1098 ///
1099 /// By default, performs semantic analysis when building the typeof type.
1100 /// Subclasses may override this routine to provide different behavior.
1102 TypeOfKind Kind);
1103
1104 /// Build a new typeof(type) type.
1105 ///
1106 /// By default, builds a new TypeOfType with the given underlying type.
1108
1109 /// Build a new unary transform type.
1111 UnaryTransformType::UTTKind UKind,
1112 SourceLocation Loc);
1113
1114 /// Build a new C++11 decltype type.
1115 ///
1116 /// By default, performs semantic analysis when building the decltype type.
1117 /// Subclasses may override this routine to provide different behavior.
1119
1121 SourceLocation Loc,
1122 SourceLocation EllipsisLoc,
1123 bool FullySubstituted,
1124 ArrayRef<QualType> Expansions = {});
1125
1126 /// Build a new C++11 auto type.
1127 ///
1128 /// By default, builds a new AutoType with the given deduced type.
1130 ConceptDecl *TypeConstraintConcept,
1131 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1132 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1133 // which has been deduced to a dependent type into an undeduced 'auto', so
1134 // that we'll retry deduction after the transformation.
1135 return SemaRef.Context.getAutoType(Deduced, Keyword,
1136 /*IsDependent*/ false, /*IsPack=*/false,
1137 TypeConstraintConcept,
1138 TypeConstraintArgs);
1139 }
1140
1141 /// By default, builds a new DeducedTemplateSpecializationType with the given
1142 /// deduced type.
1145 return SemaRef.Context.getDeducedTemplateSpecializationType(
1146 Keyword, Template, Deduced, /*IsDependent*/ false);
1147 }
1148
1149 /// Build a new template specialization type.
1150 ///
1151 /// By default, performs semantic analysis when building the template
1152 /// specialization type. Subclasses may override this routine to provide
1153 /// different behavior.
1156 SourceLocation TemplateLoc,
1158
1159 /// Build a new parenthesized type.
1160 ///
1161 /// By default, builds a new ParenType type from the inner type.
1162 /// Subclasses may override this routine to provide different behavior.
1164 return SemaRef.BuildParenType(InnerType);
1165 }
1166
1167 /// Build a new typename type that refers to an identifier.
1168 ///
1169 /// By default, performs semantic analysis when building the typename type
1170 /// (or elaborated type). Subclasses may override this routine to provide
1171 /// different behavior.
1173 SourceLocation KeywordLoc,
1174 NestedNameSpecifierLoc QualifierLoc,
1175 const IdentifierInfo *Id,
1176 SourceLocation IdLoc,
1177 bool DeducedTSTContext) {
1178 CXXScopeSpec SS;
1179 SS.Adopt(QualifierLoc);
1180
1181 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1182 // If the name is still dependent, just build a new dependent name type.
1183 if (!SemaRef.computeDeclContext(SS))
1184 return SemaRef.Context.getDependentNameType(Keyword,
1185 QualifierLoc.getNestedNameSpecifier(),
1186 Id);
1187 }
1188
1191 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1192 *Id, IdLoc, DeducedTSTContext);
1193 }
1194
1196
1197 // We had a dependent elaborated-type-specifier that has been transformed
1198 // into a non-dependent elaborated-type-specifier. Find the tag we're
1199 // referring to.
1201 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1202 if (!DC)
1203 return QualType();
1204
1205 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1206 return QualType();
1207
1208 TagDecl *Tag = nullptr;
1209 SemaRef.LookupQualifiedName(Result, DC);
1210 switch (Result.getResultKind()) {
1213 break;
1214
1216 Tag = Result.getAsSingle<TagDecl>();
1217 break;
1218
1221 llvm_unreachable("Tag lookup cannot find non-tags");
1222
1224 // Let the LookupResult structure handle ambiguities.
1225 return QualType();
1226 }
1227
1228 if (!Tag) {
1229 // Check where the name exists but isn't a tag type and use that to emit
1230 // better diagnostics.
1232 SemaRef.LookupQualifiedName(Result, DC);
1233 switch (Result.getResultKind()) {
1237 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1238 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1239 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1240 << SomeDecl << NTK << Kind;
1241 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1242 break;
1243 }
1244 default:
1245 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1246 << Kind << Id << DC << QualifierLoc.getSourceRange();
1247 break;
1248 }
1249 return QualType();
1250 }
1251 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1252 IdLoc, Id)) {
1253 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1254 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1255 return QualType();
1256 }
1257 return getDerived().RebuildTagType(
1258 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1259 }
1260
1261 /// Build a new pack expansion type.
1262 ///
1263 /// By default, builds a new PackExpansionType type from the given pattern.
1264 /// Subclasses may override this routine to provide different behavior.
1266 SourceLocation EllipsisLoc,
1267 UnsignedOrNone NumExpansions) {
1268 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1269 NumExpansions);
1270 }
1271
1272 /// Build a new atomic type given its value type.
1273 ///
1274 /// By default, performs semantic analysis when building the atomic type.
1275 /// Subclasses may override this routine to provide different behavior.
1277
1278 /// Build a new pipe type given its value type.
1280 bool isReadPipe);
1281
1282 /// Build a bit-precise int given its value type.
1283 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1284 SourceLocation Loc);
1285
1286 /// Build a dependent bit-precise int given its value type.
1287 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1288 SourceLocation Loc);
1289
1290 /// Build a new template name given a nested name specifier, a flag
1291 /// indicating whether the "template" keyword was provided, and the template
1292 /// that the template name refers to.
1293 ///
1294 /// By default, builds the new template name directly. Subclasses may override
1295 /// this routine to provide different behavior.
1297 TemplateName Name);
1298
1299 /// Build a new template name given a nested name specifier and the
1300 /// name that is referred to as a template.
1301 ///
1302 /// By default, performs semantic analysis to determine whether the name can
1303 /// be resolved to a specific template, then builds the appropriate kind of
1304 /// template name. Subclasses may override this routine to provide different
1305 /// behavior.
1307 SourceLocation TemplateKWLoc,
1308 const IdentifierInfo &Name,
1309 SourceLocation NameLoc, QualType ObjectType,
1310 bool AllowInjectedClassName);
1311
1312 /// Build a new template name given a nested name specifier and the
1313 /// overloaded operator name that is referred to as a template.
1314 ///
1315 /// By default, performs semantic analysis to determine whether the name can
1316 /// be resolved to a specific template, then builds the appropriate kind of
1317 /// template name. Subclasses may override this routine to provide different
1318 /// behavior.
1320 SourceLocation TemplateKWLoc,
1321 OverloadedOperatorKind Operator,
1322 SourceLocation NameLoc, QualType ObjectType,
1323 bool AllowInjectedClassName);
1324
1326 SourceLocation TemplateKWLoc,
1328 SourceLocation NameLoc, QualType ObjectType,
1329 bool AllowInjectedClassName);
1330
1331 /// Build a new template name given a template template parameter pack
1332 /// and the
1333 ///
1334 /// By default, performs semantic analysis to determine whether the name can
1335 /// be resolved to a specific template, then builds the appropriate kind of
1336 /// template name. Subclasses may override this routine to provide different
1337 /// behavior.
1339 Decl *AssociatedDecl, unsigned Index,
1340 bool Final) {
1342 ArgPack, AssociatedDecl, Index, Final);
1343 }
1344
1345 /// Build a new compound statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
1350 MultiStmtArg Statements,
1351 SourceLocation RBraceLoc,
1352 bool IsStmtExpr) {
1353 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1354 IsStmtExpr);
1355 }
1356
1357 /// Build a new case statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1362 Expr *LHS,
1363 SourceLocation EllipsisLoc,
1364 Expr *RHS,
1365 SourceLocation ColonLoc) {
1366 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1367 ColonLoc);
1368 }
1369
1370 /// Attach the body to a new case statement.
1371 ///
1372 /// By default, performs semantic analysis to build the new statement.
1373 /// Subclasses may override this routine to provide different behavior.
1375 getSema().ActOnCaseStmtBody(S, Body);
1376 return S;
1377 }
1378
1379 /// Build a new default statement.
1380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
1384 SourceLocation ColonLoc,
1385 Stmt *SubStmt) {
1386 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1387 /*CurScope=*/nullptr);
1388 }
1389
1390 /// Build a new label statement.
1391 ///
1392 /// By default, performs semantic analysis to build the new statement.
1393 /// Subclasses may override this routine to provide different behavior.
1395 SourceLocation ColonLoc, Stmt *SubStmt) {
1396 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1397 }
1398
1399 /// Build a new attributed statement.
1400 ///
1401 /// By default, performs semantic analysis to build the new statement.
1402 /// Subclasses may override this routine to provide different behavior.
1405 Stmt *SubStmt) {
1406 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1407 return StmtError();
1408 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1409 }
1410
1411 /// Build a new "if" statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1417 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1418 SourceLocation ElseLoc, Stmt *Else) {
1419 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1420 Then, ElseLoc, Else);
1421 }
1422
1423 /// Start building a new switch statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1428 SourceLocation LParenLoc, Stmt *Init,
1430 SourceLocation RParenLoc) {
1431 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1432 RParenLoc);
1433 }
1434
1435 /// Attach the body to the switch statement.
1436 ///
1437 /// By default, performs semantic analysis to build the new statement.
1438 /// Subclasses may override this routine to provide different behavior.
1440 Stmt *Switch, Stmt *Body) {
1441 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1442 }
1443
1444 /// Build a new while statement.
1445 ///
1446 /// By default, performs semantic analysis to build the new statement.
1447 /// Subclasses may override this routine to provide different behavior.
1450 SourceLocation RParenLoc, Stmt *Body) {
1451 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1452 }
1453
1454 /// Build a new do-while statement.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1459 SourceLocation WhileLoc, SourceLocation LParenLoc,
1460 Expr *Cond, SourceLocation RParenLoc) {
1461 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1462 Cond, RParenLoc);
1463 }
1464
1465 /// Build a new for statement.
1466 ///
1467 /// By default, performs semantic analysis to build the new statement.
1468 /// Subclasses may override this routine to provide different behavior.
1471 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1472 Stmt *Body) {
1473 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1474 Inc, RParenLoc, Body);
1475 }
1476
1477 /// Build a new goto statement.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1482 LabelDecl *Label) {
1483 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1484 }
1485
1486 /// Build a new indirect goto statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
1491 SourceLocation StarLoc,
1492 Expr *Target) {
1493 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1494 }
1495
1496 /// Build a new return statement.
1497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
1501 return getSema().BuildReturnStmt(ReturnLoc, Result);
1502 }
1503
1504 /// Build a new declaration statement.
1505 ///
1506 /// By default, performs semantic analysis to build the new statement.
1507 /// Subclasses may override this routine to provide different behavior.
1509 SourceLocation StartLoc, SourceLocation EndLoc) {
1511 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1512 }
1513
1514 /// Build a new inline asm statement.
1515 ///
1516 /// By default, performs semantic analysis to build the new statement.
1517 /// Subclasses may override this routine to provide different behavior.
1519 bool IsVolatile, unsigned NumOutputs,
1520 unsigned NumInputs, IdentifierInfo **Names,
1521 MultiExprArg Constraints, MultiExprArg Exprs,
1522 Expr *AsmString, MultiExprArg Clobbers,
1523 unsigned NumLabels,
1524 SourceLocation RParenLoc) {
1525 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1526 NumInputs, Names, Constraints, Exprs,
1527 AsmString, Clobbers, NumLabels, RParenLoc);
1528 }
1529
1530 /// Build a new MS style inline asm statement.
1531 ///
1532 /// By default, performs semantic analysis to build the new statement.
1533 /// Subclasses may override this routine to provide different behavior.
1535 ArrayRef<Token> AsmToks,
1536 StringRef AsmString,
1537 unsigned NumOutputs, unsigned NumInputs,
1538 ArrayRef<StringRef> Constraints,
1539 ArrayRef<StringRef> Clobbers,
1540 ArrayRef<Expr*> Exprs,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1543 NumOutputs, NumInputs,
1544 Constraints, Clobbers, Exprs, EndLoc);
1545 }
1546
1547 /// Build a new co_return statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
1552 bool IsImplicit) {
1553 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1554 }
1555
1556 /// Build a new co_await expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
1561 UnresolvedLookupExpr *OpCoawaitLookup,
1562 bool IsImplicit) {
1563 // This function rebuilds a coawait-expr given its operator.
1564 // For an explicit coawait-expr, the rebuild involves the full set
1565 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1566 // including calling await_transform().
1567 // For an implicit coawait-expr, we need to rebuild the "operator
1568 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1569 // This mirrors how the implicit CoawaitExpr is originally created
1570 // in Sema::ActOnCoroutineBodyStart().
1571 if (IsImplicit) {
1573 CoawaitLoc, Operand, OpCoawaitLookup);
1574 if (Suspend.isInvalid())
1575 return ExprError();
1576 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1577 Suspend.get(), true);
1578 }
1579
1580 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1581 OpCoawaitLookup);
1582 }
1583
1584 /// Build a new co_await expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
1589 Expr *Result,
1590 UnresolvedLookupExpr *Lookup) {
1591 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1592 }
1593
1594 /// Build a new co_yield expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1599 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1600 }
1601
1605
1606 /// Build a new Objective-C \@try statement.
1607 ///
1608 /// By default, performs semantic analysis to build the new statement.
1609 /// Subclasses may override this routine to provide different behavior.
1611 Stmt *TryBody,
1612 MultiStmtArg CatchStmts,
1613 Stmt *Finally) {
1614 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1615 Finally);
1616 }
1617
1618 /// Rebuild an Objective-C exception declaration.
1619 ///
1620 /// By default, performs semantic analysis to build the new declaration.
1621 /// Subclasses may override this routine to provide different behavior.
1623 TypeSourceInfo *TInfo, QualType T) {
1625 TInfo, T, ExceptionDecl->getInnerLocStart(),
1626 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1627 }
1628
1629 /// Build a new Objective-C \@catch statement.
1630 ///
1631 /// By default, performs semantic analysis to build the new statement.
1632 /// Subclasses may override this routine to provide different behavior.
1634 SourceLocation RParenLoc,
1635 VarDecl *Var,
1636 Stmt *Body) {
1637 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1638 }
1639
1640 /// Build a new Objective-C \@finally statement.
1641 ///
1642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
1645 Stmt *Body) {
1646 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1647 }
1648
1649 /// Build a new Objective-C \@throw statement.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1654 Expr *Operand) {
1655 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1656 }
1657
1658 /// Build a new OpenMP Canonical loop.
1659 ///
1660 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1661 /// OMPCanonicalLoop.
1663 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1664 }
1665
1666 /// Build a new OpenMP executable directive.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1671 DeclarationNameInfo DirName,
1672 OpenMPDirectiveKind CancelRegion,
1673 ArrayRef<OMPClause *> Clauses,
1674 Stmt *AStmt, SourceLocation StartLoc,
1675 SourceLocation EndLoc) {
1676
1678 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1679 }
1680
1681 /// Build a new OpenMP informational directive.
1683 DeclarationNameInfo DirName,
1684 ArrayRef<OMPClause *> Clauses,
1685 Stmt *AStmt,
1686 SourceLocation StartLoc,
1687 SourceLocation EndLoc) {
1688
1690 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1691 }
1692
1693 /// Build a new OpenMP 'if' clause.
1694 ///
1695 /// By default, performs semantic analysis to build the new OpenMP clause.
1696 /// Subclasses may override this routine to provide different behavior.
1698 Expr *Condition, SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation NameModifierLoc,
1701 SourceLocation ColonLoc,
1702 SourceLocation EndLoc) {
1704 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1705 EndLoc);
1706 }
1707
1708 /// Build a new OpenMP 'final' clause.
1709 ///
1710 /// By default, performs semantic analysis to build the new OpenMP clause.
1711 /// Subclasses may override this routine to provide different behavior.
1713 SourceLocation LParenLoc,
1714 SourceLocation EndLoc) {
1715 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1716 LParenLoc, EndLoc);
1717 }
1718
1719 /// Build a new OpenMP 'num_threads' clause.
1720 ///
1721 /// By default, performs semantic analysis to build the new OpenMP clause.
1722 /// Subclasses may override this routine to provide different behavior.
1724 Expr *NumThreads,
1725 SourceLocation StartLoc,
1726 SourceLocation LParenLoc,
1727 SourceLocation ModifierLoc,
1728 SourceLocation EndLoc) {
1730 Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc);
1731 }
1732
1733 /// Build a new OpenMP 'safelen' clause.
1734 ///
1735 /// By default, performs semantic analysis to build the new OpenMP clause.
1736 /// Subclasses may override this routine to provide different behavior.
1738 SourceLocation LParenLoc,
1739 SourceLocation EndLoc) {
1740 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1741 EndLoc);
1742 }
1743
1744 /// Build a new OpenMP 'simdlen' clause.
1745 ///
1746 /// By default, performs semantic analysis to build the new OpenMP clause.
1747 /// Subclasses may override this routine to provide different behavior.
1749 SourceLocation LParenLoc,
1750 SourceLocation EndLoc) {
1751 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1752 EndLoc);
1753 }
1754
1756 SourceLocation StartLoc,
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1760 EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'permutation' clause.
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1769 LParenLoc, EndLoc);
1770 }
1771
1772 /// Build a new OpenMP 'full' clause.
1774 SourceLocation EndLoc) {
1775 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1776 }
1777
1778 /// Build a new OpenMP 'partial' clause.
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1783 LParenLoc, EndLoc);
1784 }
1785
1786 /// Build a new OpenMP 'allocator' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'collapse' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1805 LParenLoc, EndLoc);
1806 }
1807
1808 /// Build a new OpenMP 'default' clause.
1809 ///
1810 /// By default, performs semantic analysis to build the new OpenMP clause.
1811 /// Subclasses may override this routine to provide different behavior.
1814 SourceLocation VCLoc,
1815 SourceLocation StartLoc,
1816 SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
1819 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1820 }
1821
1822 /// Build a new OpenMP 'proc_bind' clause.
1823 ///
1824 /// By default, performs semantic analysis to build the new OpenMP clause.
1825 /// Subclasses may override this routine to provide different behavior.
1827 SourceLocation KindKwLoc,
1828 SourceLocation StartLoc,
1829 SourceLocation LParenLoc,
1830 SourceLocation EndLoc) {
1832 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1833 }
1834
1835 /// Build a new OpenMP 'schedule' clause.
1836 ///
1837 /// By default, performs semantic analysis to build the new OpenMP clause.
1838 /// Subclasses may override this routine to provide different behavior.
1841 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1842 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1843 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1845 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1846 CommaLoc, EndLoc);
1847 }
1848
1849 /// Build a new OpenMP 'ordered' clause.
1850 ///
1851 /// By default, performs semantic analysis to build the new OpenMP clause.
1852 /// Subclasses may override this routine to provide different behavior.
1854 SourceLocation EndLoc,
1855 SourceLocation LParenLoc, Expr *Num) {
1856 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1857 LParenLoc, Num);
1858 }
1859
1860 /// Build a new OpenMP 'private' clause.
1861 ///
1862 /// By default, performs semantic analysis to build the new OpenMP clause.
1863 /// Subclasses may override this routine to provide different behavior.
1865 SourceLocation StartLoc,
1866 SourceLocation LParenLoc,
1867 SourceLocation EndLoc) {
1868 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1869 LParenLoc, EndLoc);
1870 }
1871
1872 /// Build a new OpenMP 'firstprivate' clause.
1873 ///
1874 /// By default, performs semantic analysis to build the new OpenMP clause.
1875 /// Subclasses may override this routine to provide different behavior.
1877 SourceLocation StartLoc,
1878 SourceLocation LParenLoc,
1879 SourceLocation EndLoc) {
1880 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1881 LParenLoc, EndLoc);
1882 }
1883
1884 /// Build a new OpenMP 'lastprivate' clause.
1885 ///
1886 /// By default, performs semantic analysis to build the new OpenMP clause.
1887 /// Subclasses may override this routine to provide different behavior.
1890 SourceLocation LPKindLoc,
1891 SourceLocation ColonLoc,
1892 SourceLocation StartLoc,
1893 SourceLocation LParenLoc,
1894 SourceLocation EndLoc) {
1896 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1897 }
1898
1899 /// Build a new OpenMP 'shared' clause.
1900 ///
1901 /// By default, performs semantic analysis to build the new OpenMP clause.
1902 /// Subclasses may override this routine to provide different behavior.
1904 SourceLocation StartLoc,
1905 SourceLocation LParenLoc,
1906 SourceLocation EndLoc) {
1907 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1908 LParenLoc, EndLoc);
1909 }
1910
1911 /// Build a new OpenMP 'reduction' clause.
1912 ///
1913 /// By default, performs semantic analysis to build the new statement.
1914 /// Subclasses may override this routine to provide different behavior.
1917 OpenMPOriginalSharingModifier OriginalSharingModifier,
1918 SourceLocation StartLoc, SourceLocation LParenLoc,
1919 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1920 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1921 const DeclarationNameInfo &ReductionId,
1922 ArrayRef<Expr *> UnresolvedReductions) {
1924 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1925 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1926 UnresolvedReductions);
1927 }
1928
1929 /// Build a new OpenMP 'task_reduction' clause.
1930 ///
1931 /// By default, performs semantic analysis to build the new statement.
1932 /// Subclasses may override this routine to provide different behavior.
1934 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1935 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1936 CXXScopeSpec &ReductionIdScopeSpec,
1937 const DeclarationNameInfo &ReductionId,
1938 ArrayRef<Expr *> UnresolvedReductions) {
1940 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1941 ReductionId, UnresolvedReductions);
1942 }
1943
1944 /// Build a new OpenMP 'in_reduction' clause.
1945 ///
1946 /// By default, performs semantic analysis to build the new statement.
1947 /// Subclasses may override this routine to provide different behavior.
1948 OMPClause *
1950 SourceLocation LParenLoc, SourceLocation ColonLoc,
1951 SourceLocation EndLoc,
1952 CXXScopeSpec &ReductionIdScopeSpec,
1953 const DeclarationNameInfo &ReductionId,
1954 ArrayRef<Expr *> UnresolvedReductions) {
1956 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1957 ReductionId, UnresolvedReductions);
1958 }
1959
1960 /// Build a new OpenMP 'linear' clause.
1961 ///
1962 /// By default, performs semantic analysis to build the new OpenMP clause.
1963 /// Subclasses may override this routine to provide different behavior.
1965 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1966 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1967 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1968 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1970 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1971 StepModifierLoc, EndLoc);
1972 }
1973
1974 /// Build a new OpenMP 'aligned' clause.
1975 ///
1976 /// By default, performs semantic analysis to build the new OpenMP clause.
1977 /// Subclasses may override this routine to provide different behavior.
1979 SourceLocation StartLoc,
1980 SourceLocation LParenLoc,
1981 SourceLocation ColonLoc,
1982 SourceLocation EndLoc) {
1984 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1985 }
1986
1987 /// Build a new OpenMP 'copyin' clause.
1988 ///
1989 /// By default, performs semantic analysis to build the new OpenMP clause.
1990 /// Subclasses may override this routine to provide different behavior.
1992 SourceLocation StartLoc,
1993 SourceLocation LParenLoc,
1994 SourceLocation EndLoc) {
1995 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1996 LParenLoc, EndLoc);
1997 }
1998
1999 /// Build a new OpenMP 'copyprivate' 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 EndLoc) {
2007 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2008 LParenLoc, EndLoc);
2009 }
2010
2011 /// Build a new OpenMP 'flush' pseudo clause.
2012 ///
2013 /// By default, performs semantic analysis to build the new OpenMP clause.
2014 /// Subclasses may override this routine to provide different behavior.
2016 SourceLocation StartLoc,
2017 SourceLocation LParenLoc,
2018 SourceLocation EndLoc) {
2019 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2020 LParenLoc, EndLoc);
2021 }
2022
2023 /// Build a new OpenMP 'depobj' pseudo clause.
2024 ///
2025 /// By default, performs semantic analysis to build the new OpenMP clause.
2026 /// Subclasses may override this routine to provide different behavior.
2028 SourceLocation LParenLoc,
2029 SourceLocation EndLoc) {
2030 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2031 LParenLoc, EndLoc);
2032 }
2033
2034 /// Build a new OpenMP 'depend' pseudo clause.
2035 ///
2036 /// By default, performs semantic analysis to build the new OpenMP clause.
2037 /// Subclasses may override this routine to provide different behavior.
2039 Expr *DepModifier, ArrayRef<Expr *> VarList,
2040 SourceLocation StartLoc,
2041 SourceLocation LParenLoc,
2042 SourceLocation EndLoc) {
2044 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2045 }
2046
2047 /// Build a new OpenMP 'device' clause.
2048 ///
2049 /// By default, performs semantic analysis to build the new statement.
2050 /// Subclasses may override this routine to provide different behavior.
2052 Expr *Device, SourceLocation StartLoc,
2053 SourceLocation LParenLoc,
2054 SourceLocation ModifierLoc,
2055 SourceLocation EndLoc) {
2057 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2058 }
2059
2060 /// Build a new OpenMP 'map' clause.
2061 ///
2062 /// By default, performs semantic analysis to build the new OpenMP clause.
2063 /// Subclasses may override this routine to provide different behavior.
2065 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2066 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2067 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2068 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2069 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2070 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2072 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2073 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2074 ColonLoc, VarList, Locs,
2075 /*NoDiagnose=*/false, UnresolvedMappers);
2076 }
2077
2078 /// Build a new OpenMP 'allocate' clause.
2079 ///
2080 /// By default, performs semantic analysis to build the new OpenMP clause.
2081 /// Subclasses may override this routine to provide different behavior.
2082 OMPClause *
2083 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2084 OpenMPAllocateClauseModifier FirstModifier,
2085 SourceLocation FirstModifierLoc,
2086 OpenMPAllocateClauseModifier SecondModifier,
2087 SourceLocation SecondModifierLoc,
2088 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2089 SourceLocation LParenLoc, SourceLocation ColonLoc,
2090 SourceLocation EndLoc) {
2092 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2093 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2094 }
2095
2096 /// Build a new OpenMP 'num_teams' clause.
2097 ///
2098 /// By default, performs semantic analysis to build the new statement.
2099 /// Subclasses may override this routine to provide different behavior.
2101 SourceLocation StartLoc,
2102 SourceLocation LParenLoc,
2103 SourceLocation EndLoc) {
2104 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2105 LParenLoc, EndLoc);
2106 }
2107
2108 /// Build a new OpenMP 'thread_limit' clause.
2109 ///
2110 /// By default, performs semantic analysis to build the new statement.
2111 /// Subclasses may override this routine to provide different behavior.
2113 SourceLocation StartLoc,
2114 SourceLocation LParenLoc,
2115 SourceLocation EndLoc) {
2116 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2117 LParenLoc, EndLoc);
2118 }
2119
2120 /// Build a new OpenMP 'priority' clause.
2121 ///
2122 /// By default, performs semantic analysis to build the new statement.
2123 /// Subclasses may override this routine to provide different behavior.
2125 SourceLocation LParenLoc,
2126 SourceLocation EndLoc) {
2127 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2128 LParenLoc, EndLoc);
2129 }
2130
2131 /// Build a new OpenMP 'grainsize' clause.
2132 ///
2133 /// By default, performs semantic analysis to build the new statement.
2134 /// Subclasses may override this routine to provide different behavior.
2136 Expr *Device, SourceLocation StartLoc,
2137 SourceLocation LParenLoc,
2138 SourceLocation ModifierLoc,
2139 SourceLocation EndLoc) {
2141 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2142 }
2143
2144 /// Build a new OpenMP 'num_tasks' clause.
2145 ///
2146 /// By default, performs semantic analysis to build the new statement.
2147 /// Subclasses may override this routine to provide different behavior.
2149 Expr *NumTasks, SourceLocation StartLoc,
2150 SourceLocation LParenLoc,
2151 SourceLocation ModifierLoc,
2152 SourceLocation EndLoc) {
2154 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2155 }
2156
2157 /// Build a new OpenMP 'hint' clause.
2158 ///
2159 /// By default, performs semantic analysis to build the new statement.
2160 /// Subclasses may override this routine to provide different behavior.
2162 SourceLocation LParenLoc,
2163 SourceLocation EndLoc) {
2164 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2165 EndLoc);
2166 }
2167
2168 /// Build a new OpenMP 'detach' clause.
2169 ///
2170 /// By default, performs semantic analysis to build the new statement.
2171 /// Subclasses may override this routine to provide different behavior.
2173 SourceLocation LParenLoc,
2174 SourceLocation EndLoc) {
2175 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2176 EndLoc);
2177 }
2178
2179 /// Build a new OpenMP 'dist_schedule' clause.
2180 ///
2181 /// By default, performs semantic analysis to build the new OpenMP clause.
2182 /// Subclasses may override this routine to provide different behavior.
2183 OMPClause *
2185 Expr *ChunkSize, SourceLocation StartLoc,
2186 SourceLocation LParenLoc, SourceLocation KindLoc,
2187 SourceLocation CommaLoc, SourceLocation EndLoc) {
2189 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2190 }
2191
2192 /// Build a new OpenMP 'to' clause.
2193 ///
2194 /// By default, performs semantic analysis to build the new statement.
2195 /// Subclasses may override this routine to provide different behavior.
2196 OMPClause *
2198 ArrayRef<SourceLocation> MotionModifiersLoc,
2199 CXXScopeSpec &MapperIdScopeSpec,
2200 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2201 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2202 ArrayRef<Expr *> UnresolvedMappers) {
2204 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2205 ColonLoc, VarList, Locs, UnresolvedMappers);
2206 }
2207
2208 /// Build a new OpenMP 'from' clause.
2209 ///
2210 /// By default, performs semantic analysis to build the new statement.
2211 /// Subclasses may override this routine to provide different behavior.
2212 OMPClause *
2214 ArrayRef<SourceLocation> MotionModifiersLoc,
2215 CXXScopeSpec &MapperIdScopeSpec,
2216 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2217 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2218 ArrayRef<Expr *> UnresolvedMappers) {
2220 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2221 ColonLoc, VarList, Locs, UnresolvedMappers);
2222 }
2223
2224 /// Build a new OpenMP 'use_device_ptr' clause.
2225 ///
2226 /// By default, performs semantic analysis to build the new OpenMP clause.
2227 /// Subclasses may override this routine to provide different behavior.
2229 const OMPVarListLocTy &Locs) {
2230 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2231 }
2232
2233 /// Build a new OpenMP 'use_device_addr' clause.
2234 ///
2235 /// By default, performs semantic analysis to build the new OpenMP clause.
2236 /// Subclasses may override this routine to provide different behavior.
2241
2242 /// Build a new OpenMP 'is_device_ptr' clause.
2243 ///
2244 /// By default, performs semantic analysis to build the new OpenMP clause.
2245 /// Subclasses may override this routine to provide different behavior.
2247 const OMPVarListLocTy &Locs) {
2248 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2249 }
2250
2251 /// Build a new OpenMP 'has_device_addr' clause.
2252 ///
2253 /// By default, performs semantic analysis to build the new OpenMP clause.
2254 /// Subclasses may override this routine to provide different behavior.
2259
2260 /// Build a new OpenMP 'defaultmap' clause.
2261 ///
2262 /// By default, performs semantic analysis to build the new OpenMP clause.
2263 /// Subclasses may override this routine to provide different behavior.
2266 SourceLocation StartLoc,
2267 SourceLocation LParenLoc,
2268 SourceLocation MLoc,
2269 SourceLocation KindLoc,
2270 SourceLocation EndLoc) {
2272 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2273 }
2274
2275 /// Build a new OpenMP 'nontemporal' clause.
2276 ///
2277 /// By default, performs semantic analysis to build the new OpenMP clause.
2278 /// Subclasses may override this routine to provide different behavior.
2280 SourceLocation StartLoc,
2281 SourceLocation LParenLoc,
2282 SourceLocation EndLoc) {
2283 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2284 LParenLoc, EndLoc);
2285 }
2286
2287 /// Build a new OpenMP 'inclusive' clause.
2288 ///
2289 /// By default, performs semantic analysis to build the new OpenMP clause.
2290 /// Subclasses may override this routine to provide different behavior.
2292 SourceLocation StartLoc,
2293 SourceLocation LParenLoc,
2294 SourceLocation EndLoc) {
2295 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2296 LParenLoc, EndLoc);
2297 }
2298
2299 /// Build a new OpenMP 'exclusive' clause.
2300 ///
2301 /// By default, performs semantic analysis to build the new OpenMP clause.
2302 /// Subclasses may override this routine to provide different behavior.
2304 SourceLocation StartLoc,
2305 SourceLocation LParenLoc,
2306 SourceLocation EndLoc) {
2307 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2308 LParenLoc, EndLoc);
2309 }
2310
2311 /// Build a new OpenMP 'uses_allocators' clause.
2312 ///
2313 /// By default, performs semantic analysis to build the new OpenMP clause.
2314 /// Subclasses may override this routine to provide different behavior.
2321
2322 /// Build a new OpenMP 'affinity' clause.
2323 ///
2324 /// By default, performs semantic analysis to build the new OpenMP clause.
2325 /// Subclasses may override this routine to provide different behavior.
2327 SourceLocation LParenLoc,
2328 SourceLocation ColonLoc,
2329 SourceLocation EndLoc, Expr *Modifier,
2330 ArrayRef<Expr *> Locators) {
2332 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2333 }
2334
2335 /// Build a new OpenMP 'order' clause.
2336 ///
2337 /// By default, performs semantic analysis to build the new OpenMP clause.
2338 /// Subclasses may override this routine to provide different behavior.
2340 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2341 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2342 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2344 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2345 }
2346
2347 /// Build a new OpenMP 'init' 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 StartLoc,
2353 SourceLocation LParenLoc,
2354 SourceLocation VarLoc,
2355 SourceLocation EndLoc) {
2357 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2358 }
2359
2360 /// Build a new OpenMP 'use' 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 SourceLocation LParenLoc,
2366 SourceLocation VarLoc, SourceLocation EndLoc) {
2367 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2368 LParenLoc, VarLoc, EndLoc);
2369 }
2370
2371 /// Build a new OpenMP 'destroy' clause.
2372 ///
2373 /// By default, performs semantic analysis to build the new OpenMP clause.
2374 /// Subclasses may override this routine to provide different behavior.
2376 SourceLocation LParenLoc,
2377 SourceLocation VarLoc,
2378 SourceLocation EndLoc) {
2380 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2381 }
2382
2383 /// Build a new OpenMP 'novariants' clause.
2384 ///
2385 /// By default, performs semantic analysis to build the new OpenMP clause.
2386 /// Subclasses may override this routine to provide different behavior.
2388 SourceLocation StartLoc,
2389 SourceLocation LParenLoc,
2390 SourceLocation EndLoc) {
2392 LParenLoc, EndLoc);
2393 }
2394
2395 /// Build a new OpenMP 'nocontext' clause.
2396 ///
2397 /// By default, performs semantic analysis to build the new OpenMP clause.
2398 /// Subclasses may override this routine to provide different behavior.
2400 SourceLocation LParenLoc,
2401 SourceLocation EndLoc) {
2403 LParenLoc, EndLoc);
2404 }
2405
2406 /// Build a new OpenMP 'filter' clause.
2407 ///
2408 /// By default, performs semantic analysis to build the new OpenMP clause.
2409 /// Subclasses may override this routine to provide different behavior.
2411 SourceLocation LParenLoc,
2412 SourceLocation EndLoc) {
2413 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2414 LParenLoc, EndLoc);
2415 }
2416
2417 /// Build a new OpenMP 'bind' clause.
2418 ///
2419 /// By default, performs semantic analysis to build the new OpenMP clause.
2420 /// Subclasses may override this routine to provide different behavior.
2422 SourceLocation KindLoc,
2423 SourceLocation StartLoc,
2424 SourceLocation LParenLoc,
2425 SourceLocation EndLoc) {
2426 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2427 LParenLoc, EndLoc);
2428 }
2429
2430 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2431 ///
2432 /// By default, performs semantic analysis to build the new OpenMP clause.
2433 /// Subclasses may override this routine to provide different behavior.
2435 SourceLocation LParenLoc,
2436 SourceLocation EndLoc) {
2437 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2438 LParenLoc, EndLoc);
2439 }
2440
2441 /// Build a new OpenMP 'ompx_attribute' clause.
2442 ///
2443 /// By default, performs semantic analysis to build the new OpenMP clause.
2444 /// Subclasses may override this routine to provide different behavior.
2446 SourceLocation StartLoc,
2447 SourceLocation LParenLoc,
2448 SourceLocation EndLoc) {
2449 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2450 LParenLoc, EndLoc);
2451 }
2452
2453 /// Build a new OpenMP 'ompx_bare' clause.
2454 ///
2455 /// By default, performs semantic analysis to build the new OpenMP clause.
2456 /// Subclasses may override this routine to provide different behavior.
2458 SourceLocation EndLoc) {
2459 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2460 }
2461
2462 /// Build a new OpenMP 'align' clause.
2463 ///
2464 /// By default, performs semantic analysis to build the new OpenMP clause.
2465 /// Subclasses may override this routine to provide different behavior.
2467 SourceLocation LParenLoc,
2468 SourceLocation EndLoc) {
2469 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2470 EndLoc);
2471 }
2472
2473 /// Build a new OpenMP 'at' clause.
2474 ///
2475 /// By default, performs semantic analysis to build the new OpenMP clause.
2476 /// Subclasses may override this routine to provide different behavior.
2478 SourceLocation StartLoc,
2479 SourceLocation LParenLoc,
2480 SourceLocation EndLoc) {
2481 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2482 LParenLoc, EndLoc);
2483 }
2484
2485 /// Build a new OpenMP 'severity' clause.
2486 ///
2487 /// By default, performs semantic analysis to build the new OpenMP clause.
2488 /// Subclasses may override this routine to provide different behavior.
2490 SourceLocation KwLoc,
2491 SourceLocation StartLoc,
2492 SourceLocation LParenLoc,
2493 SourceLocation EndLoc) {
2494 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2495 LParenLoc, EndLoc);
2496 }
2497
2498 /// Build a new OpenMP 'message' 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 LParenLoc,
2504 SourceLocation EndLoc) {
2505 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2506 EndLoc);
2507 }
2508
2509 /// Build a new OpenMP 'doacross' clause.
2510 ///
2511 /// By default, performs semantic analysis to build the new OpenMP clause.
2512 /// Subclasses may override this routine to provide different behavior.
2513 OMPClause *
2515 SourceLocation DepLoc, SourceLocation ColonLoc,
2516 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2517 SourceLocation LParenLoc, SourceLocation EndLoc) {
2519 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2520 }
2521
2522 /// Build a new OpenMP 'holds' clause.
2524 SourceLocation LParenLoc,
2525 SourceLocation EndLoc) {
2526 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2527 EndLoc);
2528 }
2529
2530 /// Rebuild the operand to an Objective-C \@synchronized statement.
2531 ///
2532 /// By default, performs semantic analysis to build the new statement.
2533 /// Subclasses may override this routine to provide different behavior.
2538
2539 /// Build a new Objective-C \@synchronized statement.
2540 ///
2541 /// By default, performs semantic analysis to build the new statement.
2542 /// Subclasses may override this routine to provide different behavior.
2544 Expr *Object, Stmt *Body) {
2545 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2546 }
2547
2548 /// Build a new Objective-C \@autoreleasepool statement.
2549 ///
2550 /// By default, performs semantic analysis to build the new statement.
2551 /// Subclasses may override this routine to provide different behavior.
2556
2557 /// Build a new Objective-C fast enumeration statement.
2558 ///
2559 /// By default, performs semantic analysis to build the new statement.
2560 /// Subclasses may override this routine to provide different behavior.
2562 Stmt *Element,
2563 Expr *Collection,
2564 SourceLocation RParenLoc,
2565 Stmt *Body) {
2567 ForLoc, Element, Collection, RParenLoc);
2568 if (ForEachStmt.isInvalid())
2569 return StmtError();
2570
2571 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2572 Body);
2573 }
2574
2575 /// Build a new C++ exception declaration.
2576 ///
2577 /// By default, performs semantic analysis to build the new decaration.
2578 /// Subclasses may override this routine to provide different behavior.
2581 SourceLocation StartLoc,
2582 SourceLocation IdLoc,
2583 IdentifierInfo *Id) {
2585 StartLoc, IdLoc, Id);
2586 if (Var)
2587 getSema().CurContext->addDecl(Var);
2588 return Var;
2589 }
2590
2591 /// Build a new C++ catch statement.
2592 ///
2593 /// By default, performs semantic analysis to build the new statement.
2594 /// Subclasses may override this routine to provide different behavior.
2596 VarDecl *ExceptionDecl,
2597 Stmt *Handler) {
2598 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2599 Handler));
2600 }
2601
2602 /// Build a new C++ try statement.
2603 ///
2604 /// By default, performs semantic analysis to build the new statement.
2605 /// Subclasses may override this routine to provide different behavior.
2607 ArrayRef<Stmt *> Handlers) {
2608 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2609 }
2610
2611 /// Build a new C++0x range-based for statement.
2612 ///
2613 /// By default, performs semantic analysis to build the new statement.
2614 /// Subclasses may override this routine to provide different behavior.
2616 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2617 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2618 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2619 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2620 // If we've just learned that the range is actually an Objective-C
2621 // collection, treat this as an Objective-C fast enumeration loop.
2622 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2623 if (RangeStmt->isSingleDecl()) {
2624 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2625 if (RangeVar->isInvalidDecl())
2626 return StmtError();
2627
2628 Expr *RangeExpr = RangeVar->getInit();
2629 if (!RangeExpr->isTypeDependent() &&
2630 RangeExpr->getType()->isObjCObjectPointerType()) {
2631 // FIXME: Support init-statements in Objective-C++20 ranged for
2632 // statement.
2633 if (Init) {
2634 return SemaRef.Diag(Init->getBeginLoc(),
2635 diag::err_objc_for_range_init_stmt)
2636 << Init->getSourceRange();
2637 }
2639 ForLoc, LoopVar, RangeExpr, RParenLoc);
2640 }
2641 }
2642 }
2643 }
2644
2646 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2647 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2648 }
2649
2650 /// Build a new C++0x range-based for statement.
2651 ///
2652 /// By default, performs semantic analysis to build the new statement.
2653 /// Subclasses may override this routine to provide different behavior.
2655 bool IsIfExists,
2656 NestedNameSpecifierLoc QualifierLoc,
2657 DeclarationNameInfo NameInfo,
2658 Stmt *Nested) {
2659 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2660 QualifierLoc, NameInfo, Nested);
2661 }
2662
2663 /// Attach body to a C++0x range-based for statement.
2664 ///
2665 /// By default, performs semantic analysis to finish the new statement.
2666 /// Subclasses may override this routine to provide different behavior.
2668 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2669 }
2670
2672 Stmt *TryBlock, Stmt *Handler) {
2673 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2674 }
2675
2677 Stmt *Block) {
2678 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2679 }
2680
2682 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2683 }
2684
2686 SourceLocation LParen,
2687 SourceLocation RParen,
2688 TypeSourceInfo *TSI) {
2689 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2690 TSI);
2691 }
2692
2693 /// Build a new predefined expression.
2694 ///
2695 /// By default, performs semantic analysis to build the new expression.
2696 /// Subclasses may override this routine to provide different behavior.
2700
2701 /// Build a new expression that references a declaration.
2702 ///
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
2706 LookupResult &R,
2707 bool RequiresADL) {
2708 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2709 }
2710
2711
2712 /// Build a new expression that references a declaration.
2713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
2717 ValueDecl *VD,
2718 const DeclarationNameInfo &NameInfo,
2720 TemplateArgumentListInfo *TemplateArgs) {
2721 CXXScopeSpec SS;
2722 SS.Adopt(QualifierLoc);
2723 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2724 TemplateArgs);
2725 }
2726
2727 /// Build a new expression in parentheses.
2728 ///
2729 /// By default, performs semantic analysis to build the new expression.
2730 /// Subclasses may override this routine to provide different behavior.
2732 SourceLocation RParen) {
2733 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2734 }
2735
2736 /// Build a new pseudo-destructor expression.
2737 ///
2738 /// By default, performs semantic analysis to build the new expression.
2739 /// Subclasses may override this routine to provide different behavior.
2741 SourceLocation OperatorLoc,
2742 bool isArrow,
2743 CXXScopeSpec &SS,
2744 TypeSourceInfo *ScopeType,
2745 SourceLocation CCLoc,
2746 SourceLocation TildeLoc,
2747 PseudoDestructorTypeStorage Destroyed);
2748
2749 /// Build a new unary operator expression.
2750 ///
2751 /// By default, performs semantic analysis to build the new expression.
2752 /// Subclasses may override this routine to provide different behavior.
2755 Expr *SubExpr) {
2756 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2757 }
2758
2759 /// Build a new builtin offsetof expression.
2760 ///
2761 /// By default, performs semantic analysis to build the new expression.
2762 /// Subclasses may override this routine to provide different behavior.
2766 SourceLocation RParenLoc) {
2767 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2768 RParenLoc);
2769 }
2770
2771 /// Build a new sizeof, alignof or vec_step expression with a
2772 /// type argument.
2773 ///
2774 /// By default, performs semantic analysis to build the new expression.
2775 /// Subclasses may override this routine to provide different behavior.
2777 SourceLocation OpLoc,
2778 UnaryExprOrTypeTrait ExprKind,
2779 SourceRange R) {
2780 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2781 }
2782
2783 /// Build a new sizeof, alignof or vec step expression with an
2784 /// expression argument.
2785 ///
2786 /// By default, performs semantic analysis to build the new expression.
2787 /// Subclasses may override this routine to provide different behavior.
2789 UnaryExprOrTypeTrait ExprKind,
2790 SourceRange R) {
2792 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2793 if (Result.isInvalid())
2794 return ExprError();
2795
2796 return Result;
2797 }
2798
2799 /// Build a new array subscript expression.
2800 ///
2801 /// By default, performs semantic analysis to build the new expression.
2802 /// Subclasses may override this routine to provide different behavior.
2804 SourceLocation LBracketLoc,
2805 Expr *RHS,
2806 SourceLocation RBracketLoc) {
2807 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2808 LBracketLoc, RHS,
2809 RBracketLoc);
2810 }
2811
2812 /// Build a new matrix subscript expression.
2813 ///
2814 /// By default, performs semantic analysis to build the new expression.
2815 /// Subclasses may override this routine to provide different behavior.
2817 Expr *ColumnIdx,
2818 SourceLocation RBracketLoc) {
2819 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2820 RBracketLoc);
2821 }
2822
2823 /// Build a new array section expression.
2824 ///
2825 /// By default, performs semantic analysis to build the new expression.
2826 /// Subclasses may override this routine to provide different behavior.
2828 SourceLocation LBracketLoc,
2829 Expr *LowerBound,
2830 SourceLocation ColonLocFirst,
2831 SourceLocation ColonLocSecond,
2832 Expr *Length, Expr *Stride,
2833 SourceLocation RBracketLoc) {
2834 if (IsOMPArraySection)
2836 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2837 Stride, RBracketLoc);
2838
2839 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2840 "Stride/second colon not allowed for OpenACC");
2841
2843 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2844 }
2845
2846 /// Build a new array shaping expression.
2847 ///
2848 /// By default, performs semantic analysis to build the new expression.
2849 /// Subclasses may override this routine to provide different behavior.
2851 SourceLocation RParenLoc,
2852 ArrayRef<Expr *> Dims,
2853 ArrayRef<SourceRange> BracketsRanges) {
2855 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2856 }
2857
2858 /// Build a new iterator expression.
2859 ///
2860 /// By default, performs semantic analysis to build the new expression.
2861 /// Subclasses may override this routine to provide different behavior.
2864 SourceLocation RLoc,
2867 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2868 }
2869
2870 /// Build a new call expression.
2871 ///
2872 /// By default, performs semantic analysis to build the new expression.
2873 /// Subclasses may override this routine to provide different behavior.
2875 MultiExprArg Args,
2876 SourceLocation RParenLoc,
2877 Expr *ExecConfig = nullptr) {
2878 return getSema().ActOnCallExpr(
2879 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2880 }
2881
2883 MultiExprArg Args,
2884 SourceLocation RParenLoc) {
2886 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2887 }
2888
2889 /// Build a new member access expression.
2890 ///
2891 /// By default, performs semantic analysis to build the new expression.
2892 /// Subclasses may override this routine to provide different behavior.
2894 bool isArrow,
2895 NestedNameSpecifierLoc QualifierLoc,
2896 SourceLocation TemplateKWLoc,
2897 const DeclarationNameInfo &MemberNameInfo,
2899 NamedDecl *FoundDecl,
2900 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2901 NamedDecl *FirstQualifierInScope) {
2903 isArrow);
2904 if (!Member->getDeclName()) {
2905 // We have a reference to an unnamed field. This is always the
2906 // base of an anonymous struct/union member access, i.e. the
2907 // field is always of record type.
2908 assert(Member->getType()->isRecordType() &&
2909 "unnamed member not of record type?");
2910
2911 BaseResult =
2913 QualifierLoc.getNestedNameSpecifier(),
2914 FoundDecl, Member);
2915 if (BaseResult.isInvalid())
2916 return ExprError();
2917 Base = BaseResult.get();
2918
2919 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2920 // from the AST, so we need to re-insert them if needed (since
2921 // `BuildFieldRefereneExpr()` doesn't do this).
2922 if (!isArrow && Base->isPRValue()) {
2924 if (BaseResult.isInvalid())
2925 return ExprError();
2926 Base = BaseResult.get();
2927 }
2928
2929 CXXScopeSpec EmptySS;
2931 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2932 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2933 MemberNameInfo);
2934 }
2935
2936 CXXScopeSpec SS;
2937 SS.Adopt(QualifierLoc);
2938
2939 Base = BaseResult.get();
2940 if (Base->containsErrors())
2941 return ExprError();
2942
2943 QualType BaseType = Base->getType();
2944
2945 if (isArrow && !BaseType->isPointerType())
2946 return ExprError();
2947
2948 // FIXME: this involves duplicating earlier analysis in a lot of
2949 // cases; we should avoid this when possible.
2950 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2951 R.addDecl(FoundDecl);
2952 R.resolveKind();
2953
2954 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2956 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2957 ->getType()
2958 ->getPointeeType()
2959 ->getAsCXXRecordDecl()) {
2960 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2961 // In unevaluated contexts, an expression supposed to be a member access
2962 // might reference a member in an unrelated class.
2963 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2964 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2965 VK_LValue, Member->getLocation());
2966 }
2967 }
2968
2969 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2970 SS, TemplateKWLoc,
2971 FirstQualifierInScope,
2972 R, ExplicitTemplateArgs,
2973 /*S*/nullptr);
2974 }
2975
2976 /// Build a new binary operator expression.
2977 ///
2978 /// By default, performs semantic analysis to build the new expression.
2979 /// Subclasses may override this routine to provide different behavior.
2981 Expr *LHS, Expr *RHS,
2982 bool ForFoldExpression = false) {
2983 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
2984 ForFoldExpression);
2985 }
2986
2987 /// Build a new rewritten operator expression.
2988 ///
2989 /// By default, performs semantic analysis to build the new expression.
2990 /// Subclasses may override this routine to provide different behavior.
2992 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2993 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2994 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2995 RHS, /*RequiresADL*/false);
2996 }
2997
2998 /// Build a new conditional operator expression.
2999 ///
3000 /// By default, performs semantic analysis to build the new expression.
3001 /// Subclasses may override this routine to provide different behavior.
3003 SourceLocation QuestionLoc,
3004 Expr *LHS,
3005 SourceLocation ColonLoc,
3006 Expr *RHS) {
3007 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3008 LHS, RHS);
3009 }
3010
3011 /// Build a new C-style cast expression.
3012 ///
3013 /// By default, performs semantic analysis to build the new expression.
3014 /// Subclasses may override this routine to provide different behavior.
3016 TypeSourceInfo *TInfo,
3017 SourceLocation RParenLoc,
3018 Expr *SubExpr) {
3019 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3020 SubExpr);
3021 }
3022
3023 /// Build a new compound literal expression.
3024 ///
3025 /// By default, performs semantic analysis to build the new expression.
3026 /// Subclasses may override this routine to provide different behavior.
3028 TypeSourceInfo *TInfo,
3029 SourceLocation RParenLoc,
3030 Expr *Init) {
3031 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3032 Init);
3033 }
3034
3035 /// Build a new extended vector element access expression.
3036 ///
3037 /// By default, performs semantic analysis to build the new expression.
3038 /// Subclasses may override this routine to provide different behavior.
3040 bool IsArrow,
3041 SourceLocation AccessorLoc,
3042 IdentifierInfo &Accessor) {
3043
3044 CXXScopeSpec SS;
3045 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3047 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3048 /*FirstQualifierInScope*/ nullptr, NameInfo,
3049 /* TemplateArgs */ nullptr,
3050 /*S*/ nullptr);
3051 }
3052
3053 /// Build a new initializer list expression.
3054 ///
3055 /// By default, performs semantic analysis to build the new expression.
3056 /// Subclasses may override this routine to provide different behavior.
3058 MultiExprArg Inits,
3059 SourceLocation RBraceLoc) {
3060 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3061 }
3062
3063 /// Build a new designated initializer expression.
3064 ///
3065 /// By default, performs semantic analysis to build the new expression.
3066 /// Subclasses may override this routine to provide different behavior.
3068 MultiExprArg ArrayExprs,
3069 SourceLocation EqualOrColonLoc,
3070 bool GNUSyntax,
3071 Expr *Init) {
3073 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3074 Init);
3075 if (Result.isInvalid())
3076 return ExprError();
3077
3078 return Result;
3079 }
3080
3081 /// Build a new value-initialized expression.
3082 ///
3083 /// By default, builds the implicit value initialization without performing
3084 /// any semantic analysis. Subclasses may override this routine to provide
3085 /// different behavior.
3089
3090 /// Build a new \c va_arg expression.
3091 ///
3092 /// By default, performs semantic analysis to build the new expression.
3093 /// Subclasses may override this routine to provide different behavior.
3095 Expr *SubExpr, TypeSourceInfo *TInfo,
3096 SourceLocation RParenLoc) {
3097 return getSema().BuildVAArgExpr(BuiltinLoc,
3098 SubExpr, TInfo,
3099 RParenLoc);
3100 }
3101
3102 /// Build a new expression list in parentheses.
3103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
3107 MultiExprArg SubExprs,
3108 SourceLocation RParenLoc) {
3109 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3110 }
3111
3113 unsigned NumUserSpecifiedExprs,
3114 SourceLocation InitLoc,
3115 SourceLocation LParenLoc,
3116 SourceLocation RParenLoc) {
3117 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3118 InitLoc, LParenLoc, RParenLoc);
3119 }
3120
3121 /// Build a new address-of-label expression.
3122 ///
3123 /// By default, performs semantic analysis, using the name of the label
3124 /// rather than attempting to map the label statement itself.
3125 /// Subclasses may override this routine to provide different behavior.
3127 SourceLocation LabelLoc, LabelDecl *Label) {
3128 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3129 }
3130
3131 /// Build a new GNU statement expression.
3132 ///
3133 /// By default, performs semantic analysis to build the new expression.
3134 /// Subclasses may override this routine to provide different behavior.
3136 SourceLocation RParenLoc, unsigned TemplateDepth) {
3137 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3138 TemplateDepth);
3139 }
3140
3141 /// Build a new __builtin_choose_expr expression.
3142 ///
3143 /// By default, performs semantic analysis to build the new expression.
3144 /// Subclasses may override this routine to provide different behavior.
3146 Expr *Cond, Expr *LHS, Expr *RHS,
3147 SourceLocation RParenLoc) {
3148 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3149 Cond, LHS, RHS,
3150 RParenLoc);
3151 }
3152
3153 /// Build a new generic selection expression with an expression predicate.
3154 ///
3155 /// By default, performs semantic analysis to build the new expression.
3156 /// Subclasses may override this routine to provide different behavior.
3158 SourceLocation DefaultLoc,
3159 SourceLocation RParenLoc,
3160 Expr *ControllingExpr,
3162 ArrayRef<Expr *> Exprs) {
3163 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3164 /*PredicateIsExpr=*/true,
3165 ControllingExpr, Types, Exprs);
3166 }
3167
3168 /// Build a new generic selection expression with a type predicate.
3169 ///
3170 /// By default, performs semantic analysis to build the new expression.
3171 /// Subclasses may override this routine to provide different behavior.
3173 SourceLocation DefaultLoc,
3174 SourceLocation RParenLoc,
3175 TypeSourceInfo *ControllingType,
3177 ArrayRef<Expr *> Exprs) {
3178 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3179 /*PredicateIsExpr=*/false,
3180 ControllingType, Types, Exprs);
3181 }
3182
3183 /// Build a new overloaded operator call expression.
3184 ///
3185 /// By default, performs semantic analysis to build the new expression.
3186 /// The semantic analysis provides the behavior of template instantiation,
3187 /// copying with transformations that turn what looks like an overloaded
3188 /// operator call into a use of a builtin operator, performing
3189 /// argument-dependent lookup, etc. Subclasses may override this routine to
3190 /// provide different behavior.
3192 SourceLocation OpLoc,
3193 SourceLocation CalleeLoc,
3194 bool RequiresADL,
3195 const UnresolvedSetImpl &Functions,
3196 Expr *First, Expr *Second);
3197
3198 /// Build a new C++ "named" cast expression, such as static_cast or
3199 /// reinterpret_cast.
3200 ///
3201 /// By default, this routine dispatches to one of the more-specific routines
3202 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3203 /// Subclasses may override this routine to provide different behavior.
3206 SourceLocation LAngleLoc,
3207 TypeSourceInfo *TInfo,
3208 SourceLocation RAngleLoc,
3209 SourceLocation LParenLoc,
3210 Expr *SubExpr,
3211 SourceLocation RParenLoc) {
3212 switch (Class) {
3213 case Stmt::CXXStaticCastExprClass:
3214 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3215 RAngleLoc, LParenLoc,
3216 SubExpr, RParenLoc);
3217
3218 case Stmt::CXXDynamicCastExprClass:
3219 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3220 RAngleLoc, LParenLoc,
3221 SubExpr, RParenLoc);
3222
3223 case Stmt::CXXReinterpretCastExprClass:
3224 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3225 RAngleLoc, LParenLoc,
3226 SubExpr,
3227 RParenLoc);
3228
3229 case Stmt::CXXConstCastExprClass:
3230 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3231 RAngleLoc, LParenLoc,
3232 SubExpr, RParenLoc);
3233
3234 case Stmt::CXXAddrspaceCastExprClass:
3235 return getDerived().RebuildCXXAddrspaceCastExpr(
3236 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3237
3238 default:
3239 llvm_unreachable("Invalid C++ named cast");
3240 }
3241 }
3242
3243 /// Build a new C++ static_cast expression.
3244 ///
3245 /// By default, performs semantic analysis to build the new expression.
3246 /// Subclasses may override this routine to provide different behavior.
3248 SourceLocation LAngleLoc,
3249 TypeSourceInfo *TInfo,
3250 SourceLocation RAngleLoc,
3251 SourceLocation LParenLoc,
3252 Expr *SubExpr,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3260 /// Build a new C++ dynamic_cast expression.
3261 ///
3262 /// By default, performs semantic analysis to build the new expression.
3263 /// Subclasses may override this routine to provide different behavior.
3265 SourceLocation LAngleLoc,
3266 TypeSourceInfo *TInfo,
3267 SourceLocation RAngleLoc,
3268 SourceLocation LParenLoc,
3269 Expr *SubExpr,
3270 SourceLocation RParenLoc) {
3271 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3272 TInfo, SubExpr,
3273 SourceRange(LAngleLoc, RAngleLoc),
3274 SourceRange(LParenLoc, RParenLoc));
3275 }
3276
3277 /// Build a new C++ reinterpret_cast expression.
3278 ///
3279 /// By default, performs semantic analysis to build the new expression.
3280 /// Subclasses may override this routine to provide different behavior.
3282 SourceLocation LAngleLoc,
3283 TypeSourceInfo *TInfo,
3284 SourceLocation RAngleLoc,
3285 SourceLocation LParenLoc,
3286 Expr *SubExpr,
3287 SourceLocation RParenLoc) {
3288 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3289 TInfo, SubExpr,
3290 SourceRange(LAngleLoc, RAngleLoc),
3291 SourceRange(LParenLoc, RParenLoc));
3292 }
3293
3294 /// Build a new C++ const_cast expression.
3295 ///
3296 /// By default, performs semantic analysis to build the new expression.
3297 /// Subclasses may override this routine to provide different behavior.
3299 SourceLocation LAngleLoc,
3300 TypeSourceInfo *TInfo,
3301 SourceLocation RAngleLoc,
3302 SourceLocation LParenLoc,
3303 Expr *SubExpr,
3304 SourceLocation RParenLoc) {
3305 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3306 TInfo, SubExpr,
3307 SourceRange(LAngleLoc, RAngleLoc),
3308 SourceRange(LParenLoc, RParenLoc));
3309 }
3310
3313 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3314 SourceLocation LParenLoc, Expr *SubExpr,
3315 SourceLocation RParenLoc) {
3316 return getSema().BuildCXXNamedCast(
3317 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3318 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3319 }
3320
3321 /// Build a new C++ functional-style cast expression.
3322 ///
3323 /// By default, performs semantic analysis to build the new expression.
3324 /// Subclasses may override this routine to provide different behavior.
3326 SourceLocation LParenLoc,
3327 Expr *Sub,
3328 SourceLocation RParenLoc,
3329 bool ListInitialization) {
3330 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3331 // CXXParenListInitExpr. Pass its expanded arguments so that the
3332 // CXXParenListInitExpr can be rebuilt.
3333 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3335 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3336 RParenLoc, ListInitialization);
3337
3338 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3340 TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
3341
3342 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3343 MultiExprArg(&Sub, 1), RParenLoc,
3344 ListInitialization);
3345 }
3346
3347 /// Build a new C++ __builtin_bit_cast expression.
3348 ///
3349 /// By default, performs semantic analysis to build the new expression.
3350 /// Subclasses may override this routine to provide different behavior.
3352 TypeSourceInfo *TSI, Expr *Sub,
3353 SourceLocation RParenLoc) {
3354 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3355 }
3356
3357 /// Build a new C++ typeid(type) expression.
3358 ///
3359 /// By default, performs semantic analysis to build the new expression.
3360 /// Subclasses may override this routine to provide different behavior.
3362 SourceLocation TypeidLoc,
3363 TypeSourceInfo *Operand,
3364 SourceLocation RParenLoc) {
3365 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3366 RParenLoc);
3367 }
3368
3369
3370 /// Build a new C++ typeid(expr) expression.
3371 ///
3372 /// By default, performs semantic analysis to build the new expression.
3373 /// Subclasses may override this routine to provide different behavior.
3375 SourceLocation TypeidLoc,
3376 Expr *Operand,
3377 SourceLocation RParenLoc) {
3378 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3379 RParenLoc);
3380 }
3381
3382 /// Build a new C++ __uuidof(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 TypeSourceInfo *Operand,
3388 SourceLocation RParenLoc) {
3389 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3390 }
3391
3392 /// Build a new C++ __uuidof(expr) expression.
3393 ///
3394 /// By default, performs semantic analysis to build the new expression.
3395 /// Subclasses may override this routine to provide different behavior.
3397 Expr *Operand, SourceLocation RParenLoc) {
3398 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3399 }
3400
3401 /// Build a new C++ "this" expression.
3402 ///
3403 /// By default, performs semantic analysis to build a new "this" expression.
3404 /// Subclasses may override this routine to provide different behavior.
3406 QualType ThisType,
3407 bool isImplicit) {
3408 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3409 return ExprError();
3410 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3411 }
3412
3413 /// Build a new C++ throw expression.
3414 ///
3415 /// By default, performs semantic analysis to build the new expression.
3416 /// Subclasses may override this routine to provide different behavior.
3418 bool IsThrownVariableInScope) {
3419 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3420 }
3421
3422 /// Build a new C++ default-argument expression.
3423 ///
3424 /// By default, builds a new default-argument expression, which does not
3425 /// require any semantic analysis. Subclasses may override this routine to
3426 /// provide different behavior.
3428 Expr *RewrittenExpr) {
3429 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3430 RewrittenExpr, getSema().CurContext);
3431 }
3432
3433 /// Build a new C++11 default-initialization expression.
3434 ///
3435 /// By default, builds a new default field initialization expression, which
3436 /// does not require any semantic analysis. Subclasses may override this
3437 /// routine to provide different behavior.
3442
3443 /// Build a new C++ zero-initialization expression.
3444 ///
3445 /// By default, performs semantic analysis to build the new expression.
3446 /// Subclasses may override this routine to provide different behavior.
3448 SourceLocation LParenLoc,
3449 SourceLocation RParenLoc) {
3450 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3451 /*ListInitialization=*/false);
3452 }
3453
3454 /// Build a new C++ "new" expression.
3455 ///
3456 /// By default, performs semantic analysis to build the new expression.
3457 /// Subclasses may override this routine to provide different behavior.
3459 SourceLocation PlacementLParen,
3460 MultiExprArg PlacementArgs,
3461 SourceLocation PlacementRParen,
3462 SourceRange TypeIdParens, QualType AllocatedType,
3463 TypeSourceInfo *AllocatedTypeInfo,
3464 std::optional<Expr *> ArraySize,
3465 SourceRange DirectInitRange, Expr *Initializer) {
3466 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3467 PlacementLParen,
3468 PlacementArgs,
3469 PlacementRParen,
3470 TypeIdParens,
3471 AllocatedType,
3472 AllocatedTypeInfo,
3473 ArraySize,
3474 DirectInitRange,
3475 Initializer);
3476 }
3477
3478 /// Build a new C++ "delete" expression.
3479 ///
3480 /// By default, performs semantic analysis to build the new expression.
3481 /// Subclasses may override this routine to provide different behavior.
3483 bool IsGlobalDelete,
3484 bool IsArrayForm,
3485 Expr *Operand) {
3486 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3487 Operand);
3488 }
3489
3490 /// Build a new type trait expression.
3491 ///
3492 /// By default, performs semantic analysis to build the new expression.
3493 /// Subclasses may override this routine to provide different behavior.
3495 SourceLocation StartLoc,
3497 SourceLocation RParenLoc) {
3498 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3499 }
3500
3501 /// Build a new array type trait expression.
3502 ///
3503 /// By default, performs semantic analysis to build the new expression.
3504 /// Subclasses may override this routine to provide different behavior.
3506 SourceLocation StartLoc,
3507 TypeSourceInfo *TSInfo,
3508 Expr *DimExpr,
3509 SourceLocation RParenLoc) {
3510 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3511 }
3512
3513 /// Build a new expression trait expression.
3514 ///
3515 /// By default, performs semantic analysis to build the new expression.
3516 /// Subclasses may override this routine to provide different behavior.
3518 SourceLocation StartLoc,
3519 Expr *Queried,
3520 SourceLocation RParenLoc) {
3521 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3522 }
3523
3524 /// Build a new (previously unresolved) declaration reference
3525 /// expression.
3526 ///
3527 /// By default, performs semantic analysis to build the new expression.
3528 /// Subclasses may override this routine to provide different behavior.
3530 NestedNameSpecifierLoc QualifierLoc,
3531 SourceLocation TemplateKWLoc,
3532 const DeclarationNameInfo &NameInfo,
3533 const TemplateArgumentListInfo *TemplateArgs,
3534 bool IsAddressOfOperand,
3535 TypeSourceInfo **RecoveryTSI) {
3536 CXXScopeSpec SS;
3537 SS.Adopt(QualifierLoc);
3538
3539 if (TemplateArgs || TemplateKWLoc.isValid())
3541 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3542
3544 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3545 }
3546
3547 /// Build a new template-id expression.
3548 ///
3549 /// By default, performs semantic analysis to build the new expression.
3550 /// Subclasses may override this routine to provide different behavior.
3552 SourceLocation TemplateKWLoc,
3553 LookupResult &R,
3554 bool RequiresADL,
3555 const TemplateArgumentListInfo *TemplateArgs) {
3556 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3557 TemplateArgs);
3558 }
3559
3560 /// Build a new object-construction expression.
3561 ///
3562 /// By default, performs semantic analysis to build the new expression.
3563 /// Subclasses may override this routine to provide different behavior.
3566 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3567 bool ListInitialization, bool StdInitListInitialization,
3568 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3569 SourceRange ParenRange) {
3570 // Reconstruct the constructor we originally found, which might be
3571 // different if this is a call to an inherited constructor.
3572 CXXConstructorDecl *FoundCtor = Constructor;
3573 if (Constructor->isInheritingConstructor())
3574 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3575
3576 SmallVector<Expr *, 8> ConvertedArgs;
3577 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3578 ConvertedArgs))
3579 return ExprError();
3580
3582 IsElidable,
3583 ConvertedArgs,
3584 HadMultipleCandidates,
3585 ListInitialization,
3586 StdInitListInitialization,
3587 RequiresZeroInit, ConstructKind,
3588 ParenRange);
3589 }
3590
3591 /// Build a new implicit construction via inherited constructor
3592 /// expression.
3595 bool ConstructsVBase,
3596 bool InheritedFromVBase) {
3598 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3599 }
3600
3601 /// Build a new object-construction expression.
3602 ///
3603 /// By default, performs semantic analysis to build the new expression.
3604 /// Subclasses may override this routine to provide different behavior.
3606 SourceLocation LParenOrBraceLoc,
3607 MultiExprArg Args,
3608 SourceLocation RParenOrBraceLoc,
3609 bool ListInitialization) {
3611 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3612 }
3613
3614 /// Build a new object-construction expression.
3615 ///
3616 /// By default, performs semantic analysis to build the new expression.
3617 /// Subclasses may override this routine to provide different behavior.
3619 SourceLocation LParenLoc,
3620 MultiExprArg Args,
3621 SourceLocation RParenLoc,
3622 bool ListInitialization) {
3623 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3624 RParenLoc, ListInitialization);
3625 }
3626
3627 /// Build a new member reference expression.
3628 ///
3629 /// By default, performs semantic analysis to build the new expression.
3630 /// Subclasses may override this routine to provide different behavior.
3632 QualType BaseType,
3633 bool IsArrow,
3634 SourceLocation OperatorLoc,
3635 NestedNameSpecifierLoc QualifierLoc,
3636 SourceLocation TemplateKWLoc,
3637 NamedDecl *FirstQualifierInScope,
3638 const DeclarationNameInfo &MemberNameInfo,
3639 const TemplateArgumentListInfo *TemplateArgs) {
3640 CXXScopeSpec SS;
3641 SS.Adopt(QualifierLoc);
3642
3643 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3644 OperatorLoc, IsArrow,
3645 SS, TemplateKWLoc,
3646 FirstQualifierInScope,
3647 MemberNameInfo,
3648 TemplateArgs, /*S*/nullptr);
3649 }
3650
3651 /// Build a new member reference expression.
3652 ///
3653 /// By default, performs semantic analysis to build the new expression.
3654 /// Subclasses may override this routine to provide different behavior.
3656 SourceLocation OperatorLoc,
3657 bool IsArrow,
3658 NestedNameSpecifierLoc QualifierLoc,
3659 SourceLocation TemplateKWLoc,
3660 NamedDecl *FirstQualifierInScope,
3661 LookupResult &R,
3662 const TemplateArgumentListInfo *TemplateArgs) {
3663 CXXScopeSpec SS;
3664 SS.Adopt(QualifierLoc);
3665
3666 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3667 OperatorLoc, IsArrow,
3668 SS, TemplateKWLoc,
3669 FirstQualifierInScope,
3670 R, TemplateArgs, /*S*/nullptr);
3671 }
3672
3673 /// Build a new noexcept expression.
3674 ///
3675 /// By default, performs semantic analysis to build the new expression.
3676 /// Subclasses may override this routine to provide different behavior.
3678 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3679 }
3680
3683
3684 /// Build a new expression to compute the length of a parameter pack.
3686 SourceLocation PackLoc,
3687 SourceLocation RParenLoc,
3688 UnsignedOrNone Length,
3689 ArrayRef<TemplateArgument> PartialArgs) {
3690 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3691 RParenLoc, Length, PartialArgs);
3692 }
3693
3695 SourceLocation RSquareLoc,
3696 Expr *PackIdExpression, Expr *IndexExpr,
3697 ArrayRef<Expr *> ExpandedExprs,
3698 bool FullySubstituted = false) {
3699 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3700 IndexExpr, RSquareLoc, ExpandedExprs,
3701 FullySubstituted);
3702 }
3703
3704 /// Build a new expression representing a call to a source location
3705 /// builtin.
3706 ///
3707 /// By default, performs semantic analysis to build the new expression.
3708 /// Subclasses may override this routine to provide different behavior.
3710 SourceLocation BuiltinLoc,
3711 SourceLocation RPLoc,
3712 DeclContext *ParentContext) {
3713 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3714 ParentContext);
3715 }
3716
3717 /// Build a new Objective-C boxed expression.
3718 ///
3719 /// By default, performs semantic analysis to build the new expression.
3720 /// Subclasses may override this routine to provide different behavior.
3722 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3723 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3725 CXXScopeSpec SS;
3726 SS.Adopt(NNS);
3727 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3728 ConceptNameInfo,
3729 FoundDecl,
3730 NamedConcept, TALI);
3731 if (Result.isInvalid())
3732 return ExprError();
3733 return Result;
3734 }
3735
3736 /// \brief Build a new requires expression.
3737 ///
3738 /// By default, performs semantic analysis to build the new expression.
3739 /// Subclasses may override this routine to provide different behavior.
3742 SourceLocation LParenLoc,
3743 ArrayRef<ParmVarDecl *> LocalParameters,
3744 SourceLocation RParenLoc,
3746 SourceLocation ClosingBraceLoc) {
3747 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3748 LocalParameters, RParenLoc, Requirements,
3749 ClosingBraceLoc);
3750 }
3751
3755 return SemaRef.BuildTypeRequirement(SubstDiag);
3756 }
3757
3759 return SemaRef.BuildTypeRequirement(T);
3760 }
3761
3764 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3765 SourceLocation NoexceptLoc,
3767 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3768 std::move(Ret));
3769 }
3770
3772 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3774 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3775 std::move(Ret));
3776 }
3777
3779 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3780 const ASTConstraintSatisfaction &Satisfaction) {
3781 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3782 Satisfaction);
3783 }
3784
3786 return SemaRef.BuildNestedRequirement(Constraint);
3787 }
3788
3789 /// \brief Build a new Objective-C boxed expression.
3790 ///
3791 /// By default, performs semantic analysis to build the new expression.
3792 /// Subclasses may override this routine to provide different behavior.
3794 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3795 }
3796
3797 /// Build a new Objective-C array literal.
3798 ///
3799 /// By default, performs semantic analysis to build the new expression.
3800 /// Subclasses may override this routine to provide different behavior.
3802 Expr **Elements, unsigned NumElements) {
3804 Range, MultiExprArg(Elements, NumElements));
3805 }
3806
3808 Expr *Base, Expr *Key,
3809 ObjCMethodDecl *getterMethod,
3810 ObjCMethodDecl *setterMethod) {
3812 RB, Base, Key, getterMethod, setterMethod);
3813 }
3814
3815 /// Build a new Objective-C dictionary literal.
3816 ///
3817 /// By default, performs semantic analysis to build the new expression.
3818 /// Subclasses may override this routine to provide different behavior.
3823
3824 /// Build a new Objective-C \@encode expression.
3825 ///
3826 /// By default, performs semantic analysis to build the new expression.
3827 /// Subclasses may override this routine to provide different behavior.
3829 TypeSourceInfo *EncodeTypeInfo,
3830 SourceLocation RParenLoc) {
3831 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3832 RParenLoc);
3833 }
3834
3835 /// Build a new Objective-C class message.
3837 Selector Sel,
3838 ArrayRef<SourceLocation> SelectorLocs,
3840 SourceLocation LBracLoc,
3841 MultiExprArg Args,
3842 SourceLocation RBracLoc) {
3843 return SemaRef.ObjC().BuildClassMessage(
3844 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3845 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3846 RBracLoc, Args);
3847 }
3848
3849 /// Build a new Objective-C instance message.
3851 Selector Sel,
3852 ArrayRef<SourceLocation> SelectorLocs,
3854 SourceLocation LBracLoc,
3855 MultiExprArg Args,
3856 SourceLocation RBracLoc) {
3857 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3858 /*SuperLoc=*/SourceLocation(),
3859 Sel, Method, LBracLoc,
3860 SelectorLocs, RBracLoc, Args);
3861 }
3862
3863 /// Build a new Objective-C instance/class message to 'super'.
3865 Selector Sel,
3866 ArrayRef<SourceLocation> SelectorLocs,
3867 QualType SuperType,
3869 SourceLocation LBracLoc,
3870 MultiExprArg Args,
3871 SourceLocation RBracLoc) {
3872 return Method->isInstanceMethod()
3873 ? SemaRef.ObjC().BuildInstanceMessage(
3874 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3875 SelectorLocs, RBracLoc, Args)
3876 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3877 Sel, Method, LBracLoc,
3878 SelectorLocs, RBracLoc, Args);
3879 }
3880
3881 /// Build a new Objective-C ivar reference expression.
3882 ///
3883 /// By default, performs semantic analysis to build the new expression.
3884 /// Subclasses may override this routine to provide different behavior.
3886 SourceLocation IvarLoc,
3887 bool IsArrow, bool IsFreeIvar) {
3888 CXXScopeSpec SS;
3889 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3891 BaseArg, BaseArg->getType(),
3892 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3893 /*FirstQualifierInScope=*/nullptr, NameInfo,
3894 /*TemplateArgs=*/nullptr,
3895 /*S=*/nullptr);
3896 if (IsFreeIvar && Result.isUsable())
3897 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3898 return Result;
3899 }
3900
3901 /// Build a new Objective-C property reference expression.
3902 ///
3903 /// By default, performs semantic analysis to build the new expression.
3904 /// Subclasses may override this routine to provide different behavior.
3907 SourceLocation PropertyLoc) {
3908 CXXScopeSpec SS;
3909 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3910 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3911 /*FIXME:*/PropertyLoc,
3912 /*IsArrow=*/false,
3913 SS, SourceLocation(),
3914 /*FirstQualifierInScope=*/nullptr,
3915 NameInfo,
3916 /*TemplateArgs=*/nullptr,
3917 /*S=*/nullptr);
3918 }
3919
3920 /// Build a new Objective-C property reference expression.
3921 ///
3922 /// By default, performs semantic analysis to build the new expression.
3923 /// Subclasses may override this routine to provide different behavior.
3925 ObjCMethodDecl *Getter,
3926 ObjCMethodDecl *Setter,
3927 SourceLocation PropertyLoc) {
3928 // Since these expressions can only be value-dependent, we do not
3929 // need to perform semantic analysis again.
3930 return Owned(
3931 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3933 PropertyLoc, Base));
3934 }
3935
3936 /// Build a new Objective-C "isa" expression.
3937 ///
3938 /// By default, performs semantic analysis to build the new expression.
3939 /// Subclasses may override this routine to provide different behavior.
3941 SourceLocation OpLoc, bool IsArrow) {
3942 CXXScopeSpec SS;
3943 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3944 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3945 OpLoc, IsArrow,
3946 SS, SourceLocation(),
3947 /*FirstQualifierInScope=*/nullptr,
3948 NameInfo,
3949 /*TemplateArgs=*/nullptr,
3950 /*S=*/nullptr);
3951 }
3952
3953 /// Build a new shuffle vector expression.
3954 ///
3955 /// By default, performs semantic analysis to build the new expression.
3956 /// Subclasses may override this routine to provide different behavior.
3958 MultiExprArg SubExprs,
3959 SourceLocation RParenLoc) {
3960 // Find the declaration for __builtin_shufflevector
3961 const IdentifierInfo &Name
3962 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3963 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3964 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3965 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3966
3967 // Build a reference to the __builtin_shufflevector builtin
3969 Expr *Callee = new (SemaRef.Context)
3970 DeclRefExpr(SemaRef.Context, Builtin, false,
3971 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3972 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3973 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3974 CK_BuiltinFnToFnPtr).get();
3975
3976 // Build the CallExpr
3977 ExprResult TheCall = CallExpr::Create(
3978 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3979 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3981
3982 // Type-check the __builtin_shufflevector expression.
3983 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3984 }
3985
3986 /// Build a new convert vector expression.
3988 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3989 SourceLocation RParenLoc) {
3990 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3991 }
3992
3993 /// Build a new template argument pack expansion.
3994 ///
3995 /// By default, performs semantic analysis to build a new pack expansion
3996 /// for a template argument. Subclasses may override this routine to provide
3997 /// different behavior.
3999 SourceLocation EllipsisLoc,
4000 UnsignedOrNone NumExpansions) {
4001 switch (Pattern.getArgument().getKind()) {
4005 EllipsisLoc, NumExpansions);
4006 if (Result.isInvalid())
4007 return TemplateArgumentLoc();
4008
4010 /*IsCanonical=*/false),
4011 Result.get());
4012 }
4013
4015 return TemplateArgumentLoc(
4016 SemaRef.Context,
4018 NumExpansions),
4019 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4020 Pattern.getTemplateNameLoc(), EllipsisLoc);
4021
4029 llvm_unreachable("Pack expansion pattern has no parameter packs");
4030
4032 if (TypeSourceInfo *Expansion
4033 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4034 EllipsisLoc,
4035 NumExpansions))
4036 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4037 Expansion);
4038 break;
4039 }
4040
4041 return TemplateArgumentLoc();
4042 }
4043
4044 /// Build a new expression pack expansion.
4045 ///
4046 /// By default, performs semantic analysis to build a new pack expansion
4047 /// for an expression. Subclasses may override this routine to provide
4048 /// different behavior.
4050 UnsignedOrNone NumExpansions) {
4051 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4052 }
4053
4054 /// Build a new C++1z fold-expression.
4055 ///
4056 /// By default, performs semantic analysis in order to build a new fold
4057 /// expression.
4059 SourceLocation LParenLoc, Expr *LHS,
4060 BinaryOperatorKind Operator,
4061 SourceLocation EllipsisLoc, Expr *RHS,
4062 SourceLocation RParenLoc,
4063 UnsignedOrNone NumExpansions) {
4064 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4065 EllipsisLoc, RHS, RParenLoc,
4066 NumExpansions);
4067 }
4068
4070 LambdaScopeInfo *LSI) {
4071 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4072 if (Expr *Init = PVD->getInit())
4074 Init->containsUnexpandedParameterPack();
4075 else if (PVD->hasUninstantiatedDefaultArg())
4077 PVD->getUninstantiatedDefaultArg()
4078 ->containsUnexpandedParameterPack();
4079 }
4080 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4081 }
4082
4083 /// Build an empty C++1z fold-expression with the given operator.
4084 ///
4085 /// By default, produces the fallback value for the fold-expression, or
4086 /// produce an error if there is no fallback value.
4088 BinaryOperatorKind Operator) {
4089 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4090 }
4091
4092 /// Build a new atomic operation expression.
4093 ///
4094 /// By default, performs semantic analysis to build the new expression.
4095 /// Subclasses may override this routine to provide different behavior.
4098 SourceLocation RParenLoc) {
4099 // Use this for all of the locations, since we don't know the difference
4100 // between the call and the expr at this point.
4101 SourceRange Range{BuiltinLoc, RParenLoc};
4102 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4104 }
4105
4107 ArrayRef<Expr *> SubExprs, QualType Type) {
4108 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4109 }
4110
4112 SourceLocation BeginLoc,
4113 SourceLocation DirLoc,
4114 SourceLocation EndLoc,
4116 StmtResult StrBlock) {
4118 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4119 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4120 }
4121
4132
4134 SourceLocation BeginLoc,
4135 SourceLocation DirLoc,
4136 SourceLocation EndLoc,
4138 StmtResult Loop) {
4140 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4141 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4142 }
4143
4145 SourceLocation DirLoc,
4146 SourceLocation EndLoc,
4148 StmtResult StrBlock) {
4150 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4152 Clauses, StrBlock);
4153 }
4154
4164
4174
4176 SourceLocation DirLoc,
4177 SourceLocation EndLoc,
4179 StmtResult StrBlock) {
4183 Clauses, StrBlock);
4184 }
4185
4187 SourceLocation DirLoc,
4188 SourceLocation EndLoc,
4189 ArrayRef<OpenACCClause *> Clauses) {
4191 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4193 Clauses, {});
4194 }
4195
4205
4207 SourceLocation DirLoc,
4208 SourceLocation EndLoc,
4209 ArrayRef<OpenACCClause *> Clauses) {
4211 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4213 Clauses, {});
4214 }
4215
4217 SourceLocation DirLoc,
4218 SourceLocation EndLoc,
4219 ArrayRef<OpenACCClause *> Clauses) {
4221 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4223 Clauses, {});
4224 }
4225
4227 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4228 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4229 SourceLocation RParenLoc, SourceLocation EndLoc,
4230 ArrayRef<OpenACCClause *> Clauses) {
4232 Exprs.push_back(DevNumExpr);
4233 llvm::append_range(Exprs, QueueIdExprs);
4235 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4236 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4237 }
4238
4240 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4241 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4242 SourceLocation RParenLoc, SourceLocation EndLoc) {
4244 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4245 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4246 }
4247
4249 SourceLocation DirLoc,
4250 OpenACCAtomicKind AtKind,
4251 SourceLocation EndLoc,
4253 StmtResult AssociatedStmt) {
4255 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4256 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4257 AssociatedStmt);
4258 }
4259
4263
4264private:
4265 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4266 QualType ObjectType,
4267 NamedDecl *FirstQualifierInScope);
4268
4269 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4270 QualType ObjectType,
4271 NamedDecl *FirstQualifierInScope) {
4272 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4273 return TSInfo;
4274
4275 TypeLocBuilder TLB;
4276 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4277 ObjectType, FirstQualifierInScope);
4278 if (T.isNull())
4279 return nullptr;
4280 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4281 }
4282
4283 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4284 DependentNameTypeLoc TL,
4285 bool DeducibleTSTContext,
4286 QualType ObjectType = QualType(),
4287 NamedDecl *UnqualLookup = nullptr);
4288
4290 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4292
4293 OpenACCClause *
4294 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4295 OpenACCDirectiveKind DirKind,
4296 const OpenACCClause *OldClause);
4297};
4298
4299template <typename Derived>
4301 if (!S)
4302 return S;
4303
4304 switch (S->getStmtClass()) {
4305 case Stmt::NoStmtClass: break;
4306
4307 // Transform individual statement nodes
4308 // Pass SDK into statements that can produce a value
4309#define STMT(Node, Parent) \
4310 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4311#define VALUESTMT(Node, Parent) \
4312 case Stmt::Node##Class: \
4313 return getDerived().Transform##Node(cast<Node>(S), SDK);
4314#define ABSTRACT_STMT(Node)
4315#define EXPR(Node, Parent)
4316#include "clang/AST/StmtNodes.inc"
4317
4318 // Transform expressions by calling TransformExpr.
4319#define STMT(Node, Parent)
4320#define ABSTRACT_STMT(Stmt)
4321#define EXPR(Node, Parent) case Stmt::Node##Class:
4322#include "clang/AST/StmtNodes.inc"
4323 {
4324 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4325
4327 E = getSema().ActOnStmtExprResult(E);
4328 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4329 }
4330 }
4331
4332 return S;
4333}
4334
4335template<typename Derived>
4337 if (!S)
4338 return S;
4339
4340 switch (S->getClauseKind()) {
4341 default: break;
4342 // Transform individual clause nodes
4343#define GEN_CLANG_CLAUSE_CLASS
4344#define CLAUSE_CLASS(Enum, Str, Class) \
4345 case Enum: \
4346 return getDerived().Transform##Class(cast<Class>(S));
4347#include "llvm/Frontend/OpenMP/OMP.inc"
4348 }
4349
4350 return S;
4351}
4352
4353
4354template<typename Derived>
4356 if (!E)
4357 return E;
4358
4359 switch (E->getStmtClass()) {
4360 case Stmt::NoStmtClass: break;
4361#define STMT(Node, Parent) case Stmt::Node##Class: break;
4362#define ABSTRACT_STMT(Stmt)
4363#define EXPR(Node, Parent) \
4364 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4365#include "clang/AST/StmtNodes.inc"
4366 }
4367
4368 return E;
4369}
4370
4371template<typename Derived>
4373 bool NotCopyInit) {
4374 // Initializers are instantiated like expressions, except that various outer
4375 // layers are stripped.
4376 if (!Init)
4377 return Init;
4378
4379 if (auto *FE = dyn_cast<FullExpr>(Init))
4380 Init = FE->getSubExpr();
4381
4382 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4383 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4384 Init = OVE->getSourceExpr();
4385 }
4386
4387 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4388 Init = MTE->getSubExpr();
4389
4390 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4391 Init = Binder->getSubExpr();
4392
4393 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4394 Init = ICE->getSubExprAsWritten();
4395
4396 if (CXXStdInitializerListExpr *ILE =
4397 dyn_cast<CXXStdInitializerListExpr>(Init))
4398 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4399
4400 // If this is copy-initialization, we only need to reconstruct
4401 // InitListExprs. Other forms of copy-initialization will be a no-op if
4402 // the initializer is already the right type.
4403 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4404 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4405 return getDerived().TransformExpr(Init);
4406
4407 // Revert value-initialization back to empty parens.
4408 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4409 SourceRange Parens = VIE->getSourceRange();
4410 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4411 Parens.getEnd());
4412 }
4413
4414 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4416 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4417 SourceLocation());
4418
4419 // Revert initialization by constructor back to a parenthesized or braced list
4420 // of expressions. Any other form of initializer can just be reused directly.
4421 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4422 return getDerived().TransformExpr(Init);
4423
4424 // If the initialization implicitly converted an initializer list to a
4425 // std::initializer_list object, unwrap the std::initializer_list too.
4426 if (Construct && Construct->isStdInitListInitialization())
4427 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4428
4429 // Enter a list-init context if this was list initialization.
4432 Construct->isListInitialization());
4433
4434 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4435 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4436 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4437 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4438 SmallVector<Expr*, 8> NewArgs;
4439 bool ArgChanged = false;
4440 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4441 /*IsCall*/true, NewArgs, &ArgChanged))
4442 return ExprError();
4443
4444 // If this was list initialization, revert to syntactic list form.
4445 if (Construct->isListInitialization())
4446 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4447 Construct->getEndLoc());
4448
4449 // Build a ParenListExpr to represent anything else.
4451 if (Parens.isInvalid()) {
4452 // This was a variable declaration's initialization for which no initializer
4453 // was specified.
4454 assert(NewArgs.empty() &&
4455 "no parens or braces but have direct init with arguments?");
4456 return ExprEmpty();
4457 }
4458 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4459 Parens.getEnd());
4460}
4461
4462template<typename Derived>
4464 unsigned NumInputs,
4465 bool IsCall,
4466 SmallVectorImpl<Expr *> &Outputs,
4467 bool *ArgChanged) {
4468 for (unsigned I = 0; I != NumInputs; ++I) {
4469 // If requested, drop call arguments that need to be dropped.
4470 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4471 if (ArgChanged)
4472 *ArgChanged = true;
4473
4474 break;
4475 }
4476
4477 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4478 Expr *Pattern = Expansion->getPattern();
4479
4481 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4482 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4483
4484 // Determine whether the set of unexpanded parameter packs can and should
4485 // be expanded.
4486 bool Expand = true;
4487 bool RetainExpansion = false;
4488 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4489 UnsignedOrNone NumExpansions = OrigNumExpansions;
4491 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4492 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4493 RetainExpansion, NumExpansions))
4494 return true;
4495
4496 if (!Expand) {
4497 // The transform has determined that we should perform a simple
4498 // transformation on the pack expansion, producing another pack
4499 // expansion.
4500 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4501 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4502 if (OutPattern.isInvalid())
4503 return true;
4504
4505 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4506 Expansion->getEllipsisLoc(),
4507 NumExpansions);
4508 if (Out.isInvalid())
4509 return true;
4510
4511 if (ArgChanged)
4512 *ArgChanged = true;
4513 Outputs.push_back(Out.get());
4514 continue;
4515 }
4516
4517 // Record right away that the argument was changed. This needs
4518 // to happen even if the array expands to nothing.
4519 if (ArgChanged) *ArgChanged = true;
4520
4521 // The transform has determined that we should perform an elementwise
4522 // expansion of the pattern. Do so.
4523 for (unsigned I = 0; I != *NumExpansions; ++I) {
4524 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4525 ExprResult Out = getDerived().TransformExpr(Pattern);
4526 if (Out.isInvalid())
4527 return true;
4528
4529 if (Out.get()->containsUnexpandedParameterPack()) {
4530 Out = getDerived().RebuildPackExpansion(
4531 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4532 if (Out.isInvalid())
4533 return true;
4534 }
4535
4536 Outputs.push_back(Out.get());
4537 }
4538
4539 // If we're supposed to retain a pack expansion, do so by temporarily
4540 // forgetting the partially-substituted parameter pack.
4541 if (RetainExpansion) {
4542 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4543
4544 ExprResult Out = getDerived().TransformExpr(Pattern);
4545 if (Out.isInvalid())
4546 return true;
4547
4548 Out = getDerived().RebuildPackExpansion(
4549 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4550 if (Out.isInvalid())
4551 return true;
4552
4553 Outputs.push_back(Out.get());
4554 }
4555
4556 continue;
4557 }
4558
4560 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4561 : getDerived().TransformExpr(Inputs[I]);
4562 if (Result.isInvalid())
4563 return true;
4564
4565 if (Result.get() != Inputs[I] && ArgChanged)
4566 *ArgChanged = true;
4567
4568 Outputs.push_back(Result.get());
4569 }
4570
4571 return false;
4572}
4573
4574template <typename Derived>
4577
4580 /*LambdaContextDecl=*/nullptr,
4582 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4583
4584 if (Var) {
4585 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4587
4588 if (!ConditionVar)
4589 return Sema::ConditionError();
4590
4591 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4592 }
4593
4594 if (Expr) {
4595 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4596
4597 if (CondExpr.isInvalid())
4598 return Sema::ConditionError();
4599
4600 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4601 /*MissingOK=*/true);
4602 }
4603
4604 return Sema::ConditionResult();
4605}
4606
4607template <typename Derived>
4609 NestedNameSpecifierLoc NNS, QualType ObjectType,
4610 NamedDecl *FirstQualifierInScope) {
4612
4613 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4614 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4615 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4616 Qualifiers.push_back(Qualifier);
4617 };
4618 insertNNS(NNS);
4619
4620 CXXScopeSpec SS;
4621 while (!Qualifiers.empty()) {
4622 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4624
4625 switch (QNNS.getKind()) {
4627 llvm_unreachable("unexpected null nested name specifier");
4628
4631 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4633 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4634 break;
4635 }
4636
4638 // There is no meaningful transformation that one could perform on the
4639 // global scope.
4640 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4641 break;
4642
4644 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4646 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4647 Q.getEndLoc());
4648 break;
4649 }
4650
4652 assert(SS.isEmpty());
4653 TypeLoc TL = Q.castAsTypeLoc();
4654
4655 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4656 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4657 if (QualifierLoc) {
4658 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4659 QualifierLoc, ObjectType, FirstQualifierInScope);
4660 if (!QualifierLoc)
4661 return NestedNameSpecifierLoc();
4662 ObjectType = QualType();
4663 FirstQualifierInScope = nullptr;
4664 }
4665 SS.Adopt(QualifierLoc);
4667 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4668 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4669 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4670 false, SS,
4671 FirstQualifierInScope, false))
4672 return NestedNameSpecifierLoc();
4673 return SS.getWithLocInContext(SemaRef.Context);
4674 }
4675
4676 QualType T = TL.getType();
4677 TypeLocBuilder TLB;
4679 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4680 FirstQualifierInScope);
4681 if (T.isNull())
4682 return NestedNameSpecifierLoc();
4683 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4684 }
4685
4686 if (T->isDependentType() || T->isRecordType() ||
4687 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4688 if (T->isEnumeralType())
4689 SemaRef.Diag(TL.getBeginLoc(),
4690 diag::warn_cxx98_compat_enum_nested_name_spec);
4691 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4692 break;
4693 }
4694 // If the nested-name-specifier is an invalid type def, don't emit an
4695 // error because a previous error should have already been emitted.
4697 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4698 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4699 << T << SS.getRange();
4700 }
4701 return NestedNameSpecifierLoc();
4702 }
4703 }
4704 }
4705
4706 // Don't rebuild the nested-name-specifier if we don't have to.
4707 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4709 return NNS;
4710
4711 // If we can re-use the source-location data from the original
4712 // nested-name-specifier, do so.
4713 if (SS.location_size() == NNS.getDataLength() &&
4714 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4716
4717 // Allocate new nested-name-specifier location information.
4718 return SS.getWithLocInContext(SemaRef.Context);
4719}
4720
4721template<typename Derived>
4725 DeclarationName Name = NameInfo.getName();
4726 if (!Name)
4727 return DeclarationNameInfo();
4728
4729 switch (Name.getNameKind()) {
4737 return NameInfo;
4738
4740 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4741 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4742 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4743 if (!NewTemplate)
4744 return DeclarationNameInfo();
4745
4746 DeclarationNameInfo NewNameInfo(NameInfo);
4747 NewNameInfo.setName(
4748 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4749 return NewNameInfo;
4750 }
4751
4755 TypeSourceInfo *NewTInfo;
4756 CanQualType NewCanTy;
4757 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4758 NewTInfo = getDerived().TransformType(OldTInfo);
4759 if (!NewTInfo)
4760 return DeclarationNameInfo();
4761 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4762 }
4763 else {
4764 NewTInfo = nullptr;
4765 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4766 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4767 if (NewT.isNull())
4768 return DeclarationNameInfo();
4769 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4770 }
4771
4772 DeclarationName NewName
4773 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4774 NewCanTy);
4775 DeclarationNameInfo NewNameInfo(NameInfo);
4776 NewNameInfo.setName(NewName);
4777 NewNameInfo.setNamedTypeInfo(NewTInfo);
4778 return NewNameInfo;
4779 }
4780 }
4781
4782 llvm_unreachable("Unknown name kind.");
4783}
4784
4785template <typename Derived>
4787 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4789 QualType ObjectType, bool AllowInjectedClassName) {
4790 if (const IdentifierInfo *II = IO.getIdentifier())
4791 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4792 ObjectType, AllowInjectedClassName);
4793 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4794 NameLoc, ObjectType,
4795 AllowInjectedClassName);
4796}
4797
4798template <typename Derived>
4800 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4801 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4802 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4804 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4805
4806 if (QualifierLoc) {
4807 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4808 QualifierLoc, ObjectType, FirstQualifierInScope);
4809 if (!QualifierLoc)
4810 return TemplateName();
4811 }
4812
4813 NestedNameSpecifierLoc UnderlyingQualifier;
4814 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4815 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4816 FirstQualifierInScope, AllowInjectedClassName);
4817 if (NewUnderlyingName.isNull())
4818 return TemplateName();
4819 assert(!UnderlyingQualifier && "unexpected qualifier");
4820
4821 if (!getDerived().AlwaysRebuild() &&
4822 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4823 NewUnderlyingName == UnderlyingName)
4824 return Name;
4825 CXXScopeSpec SS;
4826 SS.Adopt(QualifierLoc);
4827 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4828 NewUnderlyingName);
4829 }
4830
4832 if (QualifierLoc) {
4833 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4834 QualifierLoc, ObjectType, FirstQualifierInScope);
4835 if (!QualifierLoc)
4836 return TemplateName();
4837 // The qualifier-in-scope and object type only apply to the leftmost
4838 // entity.
4839 ObjectType = QualType();
4840 }
4841
4842 if (!getDerived().AlwaysRebuild() &&
4843 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4844 ObjectType.isNull())
4845 return Name;
4846
4847 CXXScopeSpec SS;
4848 SS.Adopt(QualifierLoc);
4849 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4850 NameLoc, ObjectType,
4851 AllowInjectedClassName);
4852 }
4853
4856 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4857
4858 NestedNameSpecifierLoc ReplacementQualifierLoc;
4859 TemplateName ReplacementName = S->getReplacement();
4860 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4862 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4863 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4864 }
4865
4866 TemplateName NewName = getDerived().TransformTemplateName(
4867 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4868 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4869 if (NewName.isNull())
4870 return TemplateName();
4871 Decl *AssociatedDecl =
4872 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4873 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4874 AssociatedDecl == S->getAssociatedDecl())
4875 return Name;
4876 return SemaRef.Context.getSubstTemplateTemplateParm(
4877 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4878 S->getFinal());
4879 }
4880
4881 assert(!Name.getAsDeducedTemplateName() &&
4882 "DeducedTemplateName should not escape partial ordering");
4883
4884 // FIXME: Preserve UsingTemplateName.
4885 if (auto *Template = Name.getAsTemplateDecl()) {
4886 assert(!QualifierLoc && "Unexpected qualifier");
4887 return TemplateName(cast_or_null<TemplateDecl>(
4888 getDerived().TransformDecl(NameLoc, Template)));
4889 }
4890
4893 assert(!QualifierLoc &&
4894 "Unexpected qualified SubstTemplateTemplateParmPack");
4895 return getDerived().RebuildTemplateName(
4896 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4897 SubstPack->getIndex(), SubstPack->getFinal());
4898 }
4899
4900 // These should be getting filtered out before they reach the AST.
4901 llvm_unreachable("overloaded function decl survived to here");
4902}
4903
4904template <typename Derived>
4906 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4907 TemplateName Name, SourceLocation NameLoc) {
4908 TemplateName TN = getDerived().TransformTemplateName(
4909 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
4910 if (TN.isNull())
4911 return TemplateArgument();
4912 return TemplateArgument(TN);
4913}
4914
4915template<typename Derived>
4917 const TemplateArgument &Arg,
4918 TemplateArgumentLoc &Output) {
4919 Output = getSema().getTrivialTemplateArgumentLoc(
4920 Arg, QualType(), getDerived().getBaseLocation());
4921}
4922
4923template <typename Derived>
4925 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4926 bool Uneval) {
4927 const TemplateArgument &Arg = Input.getArgument();
4928 switch (Arg.getKind()) {
4931 llvm_unreachable("Unexpected TemplateArgument");
4932
4937 // Transform a resolved template argument straight to a resolved template
4938 // argument. We get here when substituting into an already-substituted
4939 // template type argument during concept satisfaction checking.
4941 QualType NewT = getDerived().TransformType(T);
4942 if (NewT.isNull())
4943 return true;
4944
4946 ? Arg.getAsDecl()
4947 : nullptr;
4948 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4950 : nullptr;
4951 if (D && !NewD)
4952 return true;
4953
4954 if (NewT == T && D == NewD)
4955 Output = Input;
4956 else if (Arg.getKind() == TemplateArgument::Integral)
4957 Output = TemplateArgumentLoc(
4958 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4960 else if (Arg.getKind() == TemplateArgument::NullPtr)
4961 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4963 else if (Arg.getKind() == TemplateArgument::Declaration)
4964 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4967 Output = TemplateArgumentLoc(
4968 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4970 else
4971 llvm_unreachable("unexpected template argument kind");
4972
4973 return false;
4974 }
4975
4977 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4978 if (!DI)
4980
4981 DI = getDerived().TransformType(DI);
4982 if (!DI)
4983 return true;
4984
4985 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4986 return false;
4987 }
4988
4990 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4991
4992 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
4993 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
4994 Input.getTemplateNameLoc());
4995 if (Out.isNull())
4996 return true;
4997 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
4998 QualifierLoc, Input.getTemplateNameLoc());
4999 return false;
5000 }
5001
5003 llvm_unreachable("Caller should expand pack expansions");
5004
5006 // Template argument expressions are constant expressions.
5008 getSema(),
5011 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5013
5014 Expr *InputExpr = Input.getSourceExpression();
5015 if (!InputExpr)
5016 InputExpr = Input.getArgument().getAsExpr();
5017
5018 ExprResult E = getDerived().TransformExpr(InputExpr);
5019 E = SemaRef.ActOnConstantExpression(E);
5020 if (E.isInvalid())
5021 return true;
5022 Output = TemplateArgumentLoc(
5023 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5024 return false;
5025 }
5026 }
5027
5028 // Work around bogus GCC warning
5029 return true;
5030}
5031
5032/// Iterator adaptor that invents template argument location information
5033/// for each of the template arguments in its underlying iterator.
5034template<typename Derived, typename InputIterator>
5037 InputIterator Iter;
5038
5039public:
5042 typedef typename std::iterator_traits<InputIterator>::difference_type
5044 typedef std::input_iterator_tag iterator_category;
5045
5046 class pointer {
5048
5049 public:
5050 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5051
5052 const TemplateArgumentLoc *operator->() const { return &Arg; }
5053 };
5054
5056 InputIterator Iter)
5057 : Self(Self), Iter(Iter) { }
5058
5060 ++Iter;
5061 return *this;
5062 }
5063
5066 ++(*this);
5067 return Old;
5068 }
5069
5072 Self.InventTemplateArgumentLoc(*Iter, Result);
5073 return Result;
5074 }
5075
5076 pointer operator->() const { return pointer(**this); }
5077
5080 return X.Iter == Y.Iter;
5081 }
5082
5085 return X.Iter != Y.Iter;
5086 }
5087};
5088
5089template<typename Derived>
5090template<typename InputIterator>
5092 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5093 bool Uneval) {
5094 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5096 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5097 // Unpack argument packs, which we translate them into separate
5098 // arguments.
5099 // FIXME: We could do much better if we could guarantee that the
5100 // TemplateArgumentLocInfo for the pack expansion would be usable for
5101 // all of the template arguments in the argument pack.
5102 typedef TemplateArgumentLocInventIterator<Derived,
5104 PackLocIterator;
5106 PackLocIterator(*this, In.getArgument().pack_begin()),
5107 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5108 Uneval))
5109 return true;
5110
5111 continue;
5112 }
5113
5114 if (In.getArgument().isPackExpansion()) {
5115 UnexpandedInfo Info;
5116 TemplateArgumentLoc Prepared;
5117 if (PreparePackForExpansion(In, Uneval, Prepared, Info))
5118 return true;
5119 if (!Info.Expand) {
5120 Outputs.addArgument(Prepared);
5121 continue;
5122 }
5123
5124 // The transform has determined that we should perform an elementwise
5125 // expansion of the pattern. Do so.
5126 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5128 ForgetSubst.emplace(getDerived());
5129 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5130 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5131
5133 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5134 return true;
5135
5136 if (Out.getArgument().containsUnexpandedParameterPack()) {
5137 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5138 Info.OrigNumExpansions);
5139 if (Out.getArgument().isNull())
5140 return true;
5141 }
5142
5143 Outputs.addArgument(Out);
5144 }
5145
5146 // If we're supposed to retain a pack expansion, do so by temporarily
5147 // forgetting the partially-substituted parameter pack.
5148 if (Info.RetainExpansion) {
5149 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5150
5152 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5153 return true;
5154
5155 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5156 Info.OrigNumExpansions);
5157 if (Out.getArgument().isNull())
5158 return true;
5159
5160 Outputs.addArgument(Out);
5161 }
5162
5163 continue;
5164 }
5165
5166 // The simple case:
5167 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5168 return true;
5169
5170 Outputs.addArgument(Out);
5171 }
5172
5173 return false;
5174
5175}
5176
5177// FIXME: Find ways to reduce code duplication for pack expansions.
5178template <typename Derived>
5180 bool Uneval,
5182 UnexpandedInfo &Info) {
5183 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5184 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5185 TemplateArgumentLoc &Pattern) {
5186 assert(Arg.getArgument().isPackExpansion());
5187 // We have a pack expansion, for which we will be substituting into the
5188 // pattern.
5189 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5190 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5192 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5193 if (IsLateExpansionAttempt) {
5194 // Request expansion only when there is an opportunity to expand a pack
5195 // that required a substituion first.
5196 bool SawPackTypes =
5197 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5198 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5199 });
5200 if (!SawPackTypes) {
5201 Info.Expand = false;
5202 return false;
5203 }
5204 }
5205 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5206
5207 // Determine whether the set of unexpanded parameter packs can and
5208 // should be expanded.
5209 Info.Expand = true;
5210 Info.RetainExpansion = false;
5211 Info.NumExpansions = Info.OrigNumExpansions;
5212 return getDerived().TryExpandParameterPacks(
5213 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5214 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5215 Info.RetainExpansion, Info.NumExpansions);
5216 };
5217
5218 TemplateArgumentLoc Pattern;
5219 if (ComputeInfo(In, false, Info, Pattern))
5220 return true;
5221
5222 if (Info.Expand) {
5223 Out = Pattern;
5224 return false;
5225 }
5226
5227 // The transform has determined that we should perform a simple
5228 // transformation on the pack expansion, producing another pack
5229 // expansion.
5230 TemplateArgumentLoc OutPattern;
5231 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5232 std::in_place, getSema(), std::nullopt);
5233 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5234 return true;
5235
5236 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5237 Info.NumExpansions);
5238 if (Out.getArgument().isNull())
5239 return true;
5240 SubstIndex.reset();
5241
5242 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5243 return false;
5244
5245 // Some packs will learn their length after substitution, e.g.
5246 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5247 // value of `T`.
5248 //
5249 // We only expand after we know sizes of all packs, check if this is the case
5250 // or not. However, we avoid a full template substitution and only do
5251 // expanstions after this point.
5252
5253 // E.g. when substituting template arguments of tuple with {T -> int} in the
5254 // following example:
5255 // template <class T>
5256 // struct TupleWithInt {
5257 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5258 // };
5259 // TupleWithInt<int>::type y;
5260 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5261 // lenght and run `ComputeInfo()` to provide the necessary information to our
5262 // caller.
5263 //
5264 // Note that we may still have situations where builtin is not going to be
5265 // expanded. For example:
5266 // template <class T>
5267 // struct Foo {
5268 // template <class U> using tuple_with_t =
5269 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5270 // tuple_with_t<short>;
5271 // }
5272 // Because the substitution into `type` happens in dependent context, `type`
5273 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5274 // and the caller will not be able to expand it.
5275 ForgetSubstitutionRAII ForgetSubst(getDerived());
5276 if (ComputeInfo(Out, true, Info, OutPattern))
5277 return true;
5278 if (!Info.Expand)
5279 return false;
5280 Out = OutPattern;
5281 Info.ExpandUnderForgetSubstitions = true;
5282 return false;
5283}
5284
5285//===----------------------------------------------------------------------===//
5286// Type transformation
5287//===----------------------------------------------------------------------===//
5288
5289template<typename Derived>
5292 return T;
5293
5294 // Temporary workaround. All of these transformations should
5295 // eventually turn into transformations on TypeLocs.
5296 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5298
5299 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5300
5301 if (!NewDI)
5302 return QualType();
5303
5304 return NewDI->getType();
5305}
5306
5307template<typename Derived>
5309 // Refine the base location to the type's location.
5310 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5313 return DI;
5314
5315 TypeLocBuilder TLB;
5316
5317 TypeLoc TL = DI->getTypeLoc();
5318 TLB.reserve(TL.getFullDataSize());
5319
5320 QualType Result = getDerived().TransformType(TLB, TL);
5321 if (Result.isNull())
5322 return nullptr;
5323
5324 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5325}
5326
5327template<typename Derived>
5330 switch (T.getTypeLocClass()) {
5331#define ABSTRACT_TYPELOC(CLASS, PARENT)
5332#define TYPELOC(CLASS, PARENT) \
5333 case TypeLoc::CLASS: \
5334 return getDerived().Transform##CLASS##Type(TLB, \
5335 T.castAs<CLASS##TypeLoc>());
5336#include "clang/AST/TypeLocNodes.def"
5337 }
5338
5339 llvm_unreachable("unhandled type loc!");
5340}
5341
5342template<typename Derived>
5345 return TransformType(T);
5346
5348 return T;
5349 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5351 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5352 return NewDI ? NewDI->getType() : QualType();
5353}
5354
5355template<typename Derived>
5358 if (!isa<DependentNameType>(DI->getType()))
5359 return TransformType(DI);
5360
5361 // Refine the base location to the type's location.
5362 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5365 return DI;
5366
5367 TypeLocBuilder TLB;
5368
5369 TypeLoc TL = DI->getTypeLoc();
5370 TLB.reserve(TL.getFullDataSize());
5371
5372 auto QTL = TL.getAs<QualifiedTypeLoc>();
5373 if (QTL)
5374 TL = QTL.getUnqualifiedLoc();
5375
5376 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5377
5378 QualType Result = getDerived().TransformDependentNameType(
5379 TLB, DNTL, /*DeducedTSTContext*/true);
5380 if (Result.isNull())
5381 return nullptr;
5382
5383 if (QTL) {
5384 Result = getDerived().RebuildQualifiedType(Result, QTL);
5385 if (Result.isNull())
5386 return nullptr;
5388 }
5389
5390 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5391}
5392
5393template<typename Derived>
5398 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5399 auto SuppressObjCLifetime =
5400 T.getType().getLocalQualifiers().hasObjCLifetime();
5401 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5402 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5403 SuppressObjCLifetime);
5404 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5405 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5406 TLB, STTP, SuppressObjCLifetime);
5407 } else {
5408 Result = getDerived().TransformType(TLB, UnqualTL);
5409 }
5410
5411 if (Result.isNull())
5412 return QualType();
5413
5414 Result = getDerived().RebuildQualifiedType(Result, T);
5415
5416 if (Result.isNull())
5417 return QualType();
5418
5419 // RebuildQualifiedType might have updated the type, but not in a way
5420 // that invalidates the TypeLoc. (There's no location information for
5421 // qualifiers.)
5423
5424 return Result;
5425}
5426
5427template <typename Derived>
5429 QualifiedTypeLoc TL) {
5430
5431 SourceLocation Loc = TL.getBeginLoc();
5432 Qualifiers Quals = TL.getType().getLocalQualifiers();
5433
5434 if ((T.getAddressSpace() != LangAS::Default &&
5435 Quals.getAddressSpace() != LangAS::Default) &&
5436 T.getAddressSpace() != Quals.getAddressSpace()) {
5437 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5438 << TL.getType() << T;
5439 return QualType();
5440 }
5441
5442 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5443 if (LocalPointerAuth.isPresent()) {
5444 if (T.getPointerAuth().isPresent()) {
5445 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5446 return QualType();
5447 }
5448 if (!T->isDependentType()) {
5449 if (!T->isSignableType(SemaRef.getASTContext())) {
5450 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5451 return QualType();
5452 }
5453 }
5454 }
5455 // C++ [dcl.fct]p7:
5456 // [When] adding cv-qualifications on top of the function type [...] the
5457 // cv-qualifiers are ignored.
5458 if (T->isFunctionType()) {
5459 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5460 Quals.getAddressSpace());
5461 return T;
5462 }
5463
5464 // C++ [dcl.ref]p1:
5465 // when the cv-qualifiers are introduced through the use of a typedef-name
5466 // or decltype-specifier [...] the cv-qualifiers are ignored.
5467 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5468 // applied to a reference type.
5469 if (T->isReferenceType()) {
5470 // The only qualifier that applies to a reference type is restrict.
5471 if (!Quals.hasRestrict())
5472 return T;
5474 }
5475
5476 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5477 // resulting type.
5478 if (Quals.hasObjCLifetime()) {
5479 if (!T->isObjCLifetimeType() && !T->isDependentType())
5480 Quals.removeObjCLifetime();
5481 else if (T.getObjCLifetime()) {
5482 // Objective-C ARC:
5483 // A lifetime qualifier applied to a substituted template parameter
5484 // overrides the lifetime qualifier from the template argument.
5485 const AutoType *AutoTy;
5486 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5487 // 'auto' types behave the same way as template parameters.
5488 QualType Deduced = AutoTy->getDeducedType();
5489 Qualifiers Qs = Deduced.getQualifiers();
5490 Qs.removeObjCLifetime();
5491 Deduced =
5492 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5493 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5494 AutoTy->isDependentType(),
5495 /*isPack=*/false,
5496 AutoTy->getTypeConstraintConcept(),
5497 AutoTy->getTypeConstraintArguments());
5498 } else {
5499 // Otherwise, complain about the addition of a qualifier to an
5500 // already-qualified type.
5501 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5502 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5503 Quals.removeObjCLifetime();
5504 }
5505 }
5506 }
5507
5508 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5509}
5510
5511template <typename Derived>
5512QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5513 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5514 NamedDecl *FirstQualifierInScope) {
5515 assert(!getDerived().AlreadyTransformed(TL.getType()));
5516
5517 switch (TL.getTypeLocClass()) {
5518 case TypeLoc::TemplateSpecialization:
5519 return getDerived().TransformTemplateSpecializationType(
5520 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5521 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5522 case TypeLoc::DependentName:
5523 return getDerived().TransformDependentNameType(
5524 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5525 ObjectType, FirstQualifierInScope);
5526 default:
5527 // Any dependent canonical type can appear here, through type alias
5528 // templates.
5529 return getDerived().TransformType(TLB, TL);
5530 }
5531}
5532
5533template <class TyLoc> static inline
5535 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5536 NewT.setNameLoc(T.getNameLoc());
5537 return T.getType();
5538}
5539
5540template<typename Derived>
5541QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5542 BuiltinTypeLoc T) {
5543 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5544 NewT.setBuiltinLoc(T.getBuiltinLoc());
5545 if (T.needsExtraLocalData())
5546 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5547 return T.getType();
5548}
5549
5550template<typename Derived>
5552 ComplexTypeLoc T) {
5553 // FIXME: recurse?
5554 return TransformTypeSpecType(TLB, T);
5555}
5556
5557template <typename Derived>
5559 AdjustedTypeLoc TL) {
5560 // Adjustments applied during transformation are handled elsewhere.
5561 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5562}
5563
5564template<typename Derived>
5566 DecayedTypeLoc TL) {
5567 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5568 if (OriginalType.isNull())
5569 return QualType();
5570
5571 QualType Result = TL.getType();
5572 if (getDerived().AlwaysRebuild() ||
5573 OriginalType != TL.getOriginalLoc().getType())
5574 Result = SemaRef.Context.getDecayedType(OriginalType);
5575 TLB.push<DecayedTypeLoc>(Result);
5576 // Nothing to set for DecayedTypeLoc.
5577 return Result;
5578}
5579
5580template <typename Derived>
5584 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5585 if (OriginalType.isNull())
5586 return QualType();
5587
5588 QualType Result = TL.getType();
5589 if (getDerived().AlwaysRebuild() ||
5590 OriginalType != TL.getElementLoc().getType())
5591 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5592 TLB.push<ArrayParameterTypeLoc>(Result);
5593 // Nothing to set for ArrayParameterTypeLoc.
5594 return Result;
5595}
5596
5597template<typename Derived>
5599 PointerTypeLoc TL) {
5600 QualType PointeeType
5601 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5602 if (PointeeType.isNull())
5603 return QualType();
5604
5605 QualType Result = TL.getType();
5606 if (PointeeType->getAs<ObjCObjectType>()) {
5607 // A dependent pointer type 'T *' has is being transformed such
5608 // that an Objective-C class type is being replaced for 'T'. The
5609 // resulting pointer type is an ObjCObjectPointerType, not a
5610 // PointerType.
5611 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5612
5614 NewT.setStarLoc(TL.getStarLoc());
5615 return Result;
5616 }
5617
5618 if (getDerived().AlwaysRebuild() ||
5619 PointeeType != TL.getPointeeLoc().getType()) {
5620 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5621 if (Result.isNull())
5622 return QualType();
5623 }
5624
5625 // Objective-C ARC can add lifetime qualifiers to the type that we're
5626 // pointing to.
5627 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5628
5629 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5630 NewT.setSigilLoc(TL.getSigilLoc());
5631 return Result;
5632}
5633
5634template<typename Derived>
5638 QualType PointeeType
5639 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5640 if (PointeeType.isNull())
5641 return QualType();
5642
5643 QualType Result = TL.getType();
5644 if (getDerived().AlwaysRebuild() ||
5645 PointeeType != TL.getPointeeLoc().getType()) {
5646 Result = getDerived().RebuildBlockPointerType(PointeeType,
5647 TL.getSigilLoc());
5648 if (Result.isNull())
5649 return QualType();
5650 }
5651
5653 NewT.setSigilLoc(TL.getSigilLoc());
5654 return Result;
5655}
5656
5657/// Transforms a reference type. Note that somewhat paradoxically we
5658/// don't care whether the type itself is an l-value type or an r-value
5659/// type; we only care if the type was *written* as an l-value type
5660/// or an r-value type.
5661template<typename Derived>
5664 ReferenceTypeLoc TL) {
5665 const ReferenceType *T = TL.getTypePtr();
5666
5667 // Note that this works with the pointee-as-written.
5668 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5669 if (PointeeType.isNull())
5670 return QualType();
5671
5672 QualType Result = TL.getType();
5673 if (getDerived().AlwaysRebuild() ||
5674 PointeeType != T->getPointeeTypeAsWritten()) {
5675 Result = getDerived().RebuildReferenceType(PointeeType,
5676 T->isSpelledAsLValue(),
5677 TL.getSigilLoc());
5678 if (Result.isNull())
5679 return QualType();
5680 }
5681
5682 // Objective-C ARC can add lifetime qualifiers to the type that we're
5683 // referring to.
5686
5687 // r-value references can be rebuilt as l-value references.
5688 ReferenceTypeLoc NewTL;
5690 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5691 else
5692 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5693 NewTL.setSigilLoc(TL.getSigilLoc());
5694
5695 return Result;
5696}
5697
5698template<typename Derived>
5702 return TransformReferenceType(TLB, TL);
5703}
5704
5705template<typename Derived>
5706QualType
5707TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5708 RValueReferenceTypeLoc TL) {
5709 return TransformReferenceType(TLB, TL);
5710}
5711
5712template<typename Derived>
5716 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5717 if (PointeeType.isNull())
5718 return QualType();
5719
5720 const MemberPointerType *T = TL.getTypePtr();
5721
5722 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5723 NestedNameSpecifierLoc NewQualifierLoc =
5724 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5725 if (!NewQualifierLoc)
5726 return QualType();
5727
5728 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5729 if (OldCls) {
5730 NewCls = cast_or_null<CXXRecordDecl>(
5731 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5732 if (!NewCls)
5733 return QualType();
5734 }
5735
5736 QualType Result = TL.getType();
5737 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5738 NewQualifierLoc.getNestedNameSpecifier() !=
5739 OldQualifierLoc.getNestedNameSpecifier() ||
5740 NewCls != OldCls) {
5741 CXXScopeSpec SS;
5742 SS.Adopt(NewQualifierLoc);
5743 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5744 TL.getStarLoc());
5745 if (Result.isNull())
5746 return QualType();
5747 }
5748
5749 // If we had to adjust the pointee type when building a member pointer, make
5750 // sure to push TypeLoc info for it.
5751 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5752 if (MPT && PointeeType != MPT->getPointeeType()) {
5753 assert(isa<AdjustedType>(MPT->getPointeeType()));
5754 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5755 }
5756
5758 NewTL.setSigilLoc(TL.getSigilLoc());
5759 NewTL.setQualifierLoc(NewQualifierLoc);
5760
5761 return Result;
5762}
5763
5764template<typename Derived>
5768 const ConstantArrayType *T = TL.getTypePtr();
5769 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5770 if (ElementType.isNull())
5771 return QualType();
5772
5773 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5774 Expr *OldSize = TL.getSizeExpr();
5775 if (!OldSize)
5776 OldSize = const_cast<Expr*>(T->getSizeExpr());
5777 Expr *NewSize = nullptr;
5778 if (OldSize) {
5781 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5782 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5783 }
5784
5785 QualType Result = TL.getType();
5786 if (getDerived().AlwaysRebuild() ||
5787 ElementType != T->getElementType() ||
5788 (T->getSizeExpr() && NewSize != OldSize)) {
5789 Result = getDerived().RebuildConstantArrayType(ElementType,
5790 T->getSizeModifier(),
5791 T->getSize(), NewSize,
5792 T->getIndexTypeCVRQualifiers(),
5793 TL.getBracketsRange());
5794 if (Result.isNull())
5795 return QualType();
5796 }
5797
5798 // We might have either a ConstantArrayType or a VariableArrayType now:
5799 // a ConstantArrayType is allowed to have an element type which is a
5800 // VariableArrayType if the type is dependent. Fortunately, all array
5801 // types have the same location layout.
5802 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5803 NewTL.setLBracketLoc(TL.getLBracketLoc());
5804 NewTL.setRBracketLoc(TL.getRBracketLoc());
5805 NewTL.setSizeExpr(NewSize);
5806
5807 return Result;
5808}
5809
5810template<typename Derived>
5812 TypeLocBuilder &TLB,
5814 const IncompleteArrayType *T = TL.getTypePtr();
5815 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5816 if (ElementType.isNull())
5817 return QualType();
5818
5819 QualType Result = TL.getType();
5820 if (getDerived().AlwaysRebuild() ||
5821 ElementType != T->getElementType()) {
5822 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5823 T->getSizeModifier(),
5824 T->getIndexTypeCVRQualifiers(),
5825 TL.getBracketsRange());
5826 if (Result.isNull())
5827 return QualType();
5828 }
5829
5831 NewTL.setLBracketLoc(TL.getLBracketLoc());
5832 NewTL.setRBracketLoc(TL.getRBracketLoc());
5833 NewTL.setSizeExpr(nullptr);
5834
5835 return Result;
5836}
5837
5838template<typename Derived>
5842 const VariableArrayType *T = TL.getTypePtr();
5843 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5844 if (ElementType.isNull())
5845 return QualType();
5846
5847 ExprResult SizeResult;
5848 {
5851 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5852 }
5853 if (SizeResult.isInvalid())
5854 return QualType();
5855 SizeResult =
5856 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5857 if (SizeResult.isInvalid())
5858 return QualType();
5859
5860 Expr *Size = SizeResult.get();
5861
5862 QualType Result = TL.getType();
5863 if (getDerived().AlwaysRebuild() ||
5864 ElementType != T->getElementType() ||
5865 Size != T->getSizeExpr()) {
5866 Result = getDerived().RebuildVariableArrayType(ElementType,
5867 T->getSizeModifier(),
5868 Size,
5869 T->getIndexTypeCVRQualifiers(),
5870 TL.getBracketsRange());
5871 if (Result.isNull())
5872 return QualType();
5873 }
5874
5875 // We might have constant size array now, but fortunately it has the same
5876 // location layout.
5877 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5878 NewTL.setLBracketLoc(TL.getLBracketLoc());
5879 NewTL.setRBracketLoc(TL.getRBracketLoc());
5880 NewTL.setSizeExpr(Size);
5881
5882 return Result;
5883}
5884
5885template<typename Derived>
5889 const DependentSizedArrayType *T = TL.getTypePtr();
5890 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5891 if (ElementType.isNull())
5892 return QualType();
5893
5894 // Array bounds are constant expressions.
5897
5898 // If we have a VLA then it won't be a constant.
5899 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5900
5901 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5902 Expr *origSize = TL.getSizeExpr();
5903 if (!origSize) origSize = T->getSizeExpr();
5904
5905 ExprResult sizeResult
5906 = getDerived().TransformExpr(origSize);
5907 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5908 if (sizeResult.isInvalid())
5909 return QualType();
5910
5911 Expr *size = sizeResult.get();
5912
5913 QualType Result = TL.getType();
5914 if (getDerived().AlwaysRebuild() ||
5915 ElementType != T->getElementType() ||
5916 size != origSize) {
5917 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5918 T->getSizeModifier(),
5919 size,
5920 T->getIndexTypeCVRQualifiers(),
5921 TL.getBracketsRange());
5922 if (Result.isNull())
5923 return QualType();
5924 }
5925
5926 // We might have any sort of array type now, but fortunately they
5927 // all have the same location layout.
5928 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5929 NewTL.setLBracketLoc(TL.getLBracketLoc());
5930 NewTL.setRBracketLoc(TL.getRBracketLoc());
5931 NewTL.setSizeExpr(size);
5932
5933 return Result;
5934}
5935
5936template <typename Derived>
5939 const DependentVectorType *T = TL.getTypePtr();
5940 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5941 if (ElementType.isNull())
5942 return QualType();
5943
5946
5947 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5948 Size = SemaRef.ActOnConstantExpression(Size);
5949 if (Size.isInvalid())
5950 return QualType();
5951
5952 QualType Result = TL.getType();
5953 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5954 Size.get() != T->getSizeExpr()) {
5955 Result = getDerived().RebuildDependentVectorType(
5956 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5957 if (Result.isNull())
5958 return QualType();
5959 }
5960
5961 // Result might be dependent or not.
5964 TLB.push<DependentVectorTypeLoc>(Result);
5965 NewTL.setNameLoc(TL.getNameLoc());
5966 } else {
5967 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5968 NewTL.setNameLoc(TL.getNameLoc());
5969 }
5970
5971 return Result;
5972}
5973
5974template<typename Derived>
5976 TypeLocBuilder &TLB,
5978 const DependentSizedExtVectorType *T = TL.getTypePtr();
5979
5980 // FIXME: ext vector locs should be nested
5981 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5982 if (ElementType.isNull())
5983 return QualType();
5984
5985 // Vector sizes are constant expressions.
5988
5989 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5990 Size = SemaRef.ActOnConstantExpression(Size);
5991 if (Size.isInvalid())
5992 return QualType();
5993
5994 QualType Result = TL.getType();
5995 if (getDerived().AlwaysRebuild() ||
5996 ElementType != T->getElementType() ||
5997 Size.get() != T->getSizeExpr()) {
5998 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5999 Size.get(),
6000 T->getAttributeLoc());
6001 if (Result.isNull())
6002 return QualType();
6003 }
6004
6005 // Result might be dependent or not.
6009 NewTL.setNameLoc(TL.getNameLoc());
6010 } else {
6011 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6012 NewTL.setNameLoc(TL.getNameLoc());
6013 }
6014
6015 return Result;
6016}
6017
6018template <typename Derived>
6022 const ConstantMatrixType *T = TL.getTypePtr();
6023 QualType ElementType = getDerived().TransformType(T->getElementType());
6024 if (ElementType.isNull())
6025 return QualType();
6026
6027 QualType Result = TL.getType();
6028 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6029 Result = getDerived().RebuildConstantMatrixType(
6030 ElementType, T->getNumRows(), T->getNumColumns());
6031 if (Result.isNull())
6032 return QualType();
6033 }
6034
6036 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6037 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6038 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6039 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6040
6041 return Result;
6042}
6043
6044template <typename Derived>
6047 const DependentSizedMatrixType *T = TL.getTypePtr();
6048
6049 QualType ElementType = getDerived().TransformType(T->getElementType());
6050 if (ElementType.isNull()) {
6051 return QualType();
6052 }
6053
6054 // Matrix dimensions are constant expressions.
6057
6058 Expr *origRows = TL.getAttrRowOperand();
6059 if (!origRows)
6060 origRows = T->getRowExpr();
6061 Expr *origColumns = TL.getAttrColumnOperand();
6062 if (!origColumns)
6063 origColumns = T->getColumnExpr();
6064
6065 ExprResult rowResult = getDerived().TransformExpr(origRows);
6066 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6067 if (rowResult.isInvalid())
6068 return QualType();
6069
6070 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6071 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6072 if (columnResult.isInvalid())
6073 return QualType();
6074
6075 Expr *rows = rowResult.get();
6076 Expr *columns = columnResult.get();
6077
6078 QualType Result = TL.getType();
6079 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6080 rows != origRows || columns != origColumns) {
6081 Result = getDerived().RebuildDependentSizedMatrixType(
6082 ElementType, rows, columns, T->getAttributeLoc());
6083
6084 if (Result.isNull())
6085 return QualType();
6086 }
6087
6088 // We might have any sort of matrix type now, but fortunately they
6089 // all have the same location layout.
6090 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6091 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6092 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6093 NewTL.setAttrRowOperand(rows);
6094 NewTL.setAttrColumnOperand(columns);
6095 return Result;
6096}
6097
6098template <typename Derived>
6101 const DependentAddressSpaceType *T = TL.getTypePtr();
6102
6103 QualType pointeeType =
6104 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6105
6106 if (pointeeType.isNull())
6107 return QualType();
6108
6109 // Address spaces are constant expressions.
6112
6113 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6114 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6115 if (AddrSpace.isInvalid())
6116 return QualType();
6117
6118 QualType Result = TL.getType();
6119 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6120 AddrSpace.get() != T->getAddrSpaceExpr()) {
6121 Result = getDerived().RebuildDependentAddressSpaceType(
6122 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6123 if (Result.isNull())
6124 return QualType();
6125 }
6126
6127 // Result might be dependent or not.
6131
6132 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6133 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6134 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6135
6136 } else {
6137 TLB.TypeWasModifiedSafely(Result);
6138 }
6139
6140 return Result;
6141}
6142
6143template <typename Derived>
6145 VectorTypeLoc TL) {
6146 const VectorType *T = TL.getTypePtr();
6147 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6148 if (ElementType.isNull())
6149 return QualType();
6150
6151 QualType Result = TL.getType();
6152 if (getDerived().AlwaysRebuild() ||
6153 ElementType != T->getElementType()) {
6154 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6155 T->getVectorKind());
6156 if (Result.isNull())
6157 return QualType();
6158 }
6159
6160 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6161 NewTL.setNameLoc(TL.getNameLoc());
6162
6163 return Result;
6164}
6165
6166template<typename Derived>
6168 ExtVectorTypeLoc TL) {
6169 const VectorType *T = TL.getTypePtr();
6170 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6171 if (ElementType.isNull())
6172 return QualType();
6173
6174 QualType Result = TL.getType();
6175 if (getDerived().AlwaysRebuild() ||
6176 ElementType != T->getElementType()) {
6177 Result = getDerived().RebuildExtVectorType(ElementType,
6178 T->getNumElements(),
6179 /*FIXME*/ SourceLocation());
6180 if (Result.isNull())
6181 return QualType();
6182 }
6183
6184 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6185 NewTL.setNameLoc(TL.getNameLoc());
6186
6187 return Result;
6188}
6189
6190template <typename Derived>
6192 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6193 bool ExpectParameterPack) {
6194 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6195 TypeSourceInfo *NewDI = nullptr;
6196
6197 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6198 // If we're substituting into a pack expansion type and we know the
6199 // length we want to expand to, just substitute for the pattern.
6200 TypeLoc OldTL = OldDI->getTypeLoc();
6201 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6202
6203 TypeLocBuilder TLB;
6204 TypeLoc NewTL = OldDI->getTypeLoc();
6205 TLB.reserve(NewTL.getFullDataSize());
6206
6207 QualType Result = getDerived().TransformType(TLB,
6208 OldExpansionTL.getPatternLoc());
6209 if (Result.isNull())
6210 return nullptr;
6211
6213 OldExpansionTL.getPatternLoc().getSourceRange(),
6214 OldExpansionTL.getEllipsisLoc(),
6215 NumExpansions);
6216 if (Result.isNull())
6217 return nullptr;
6218
6219 PackExpansionTypeLoc NewExpansionTL
6220 = TLB.push<PackExpansionTypeLoc>(Result);
6221 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6222 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6223 } else
6224 NewDI = getDerived().TransformType(OldDI);
6225 if (!NewDI)
6226 return nullptr;
6227
6228 if (NewDI == OldDI && indexAdjustment == 0)
6229 return OldParm;
6230
6231 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6232 OldParm->getDeclContext(),
6233 OldParm->getInnerLocStart(),
6234 OldParm->getLocation(),
6235 OldParm->getIdentifier(),
6236 NewDI->getType(),
6237 NewDI,
6238 OldParm->getStorageClass(),
6239 /* DefArg */ nullptr);
6240 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6241 OldParm->getFunctionScopeIndex() + indexAdjustment);
6242 transformedLocalDecl(OldParm, {newParm});
6243 return newParm;
6244}
6245
6246template <typename Derived>
6249 const QualType *ParamTypes,
6250 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6251 SmallVectorImpl<QualType> &OutParamTypes,
6254 unsigned *LastParamTransformed) {
6255 int indexAdjustment = 0;
6256
6257 unsigned NumParams = Params.size();
6258 for (unsigned i = 0; i != NumParams; ++i) {
6259 if (LastParamTransformed)
6260 *LastParamTransformed = i;
6261 if (ParmVarDecl *OldParm = Params[i]) {
6262 assert(OldParm->getFunctionScopeIndex() == i);
6263
6264 UnsignedOrNone NumExpansions = std::nullopt;
6265 ParmVarDecl *NewParm = nullptr;
6266 if (OldParm->isParameterPack()) {
6267 // We have a function parameter pack that may need to be expanded.
6269
6270 // Find the parameter packs that could be expanded.
6271 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6273 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6274 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6275
6276 // Determine whether we should expand the parameter packs.
6277 bool ShouldExpand = false;
6278 bool RetainExpansion = false;
6279 UnsignedOrNone OrigNumExpansions = std::nullopt;
6280 if (Unexpanded.size() > 0) {
6281 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6282 NumExpansions = OrigNumExpansions;
6284 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6285 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6286 ShouldExpand, RetainExpansion, NumExpansions)) {
6287 return true;
6288 }
6289 } else {
6290#ifndef NDEBUG
6291 const AutoType *AT =
6292 Pattern.getType().getTypePtr()->getContainedAutoType();
6293 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6294 "Could not find parameter packs or undeduced auto type!");
6295#endif
6296 }
6297
6298 if (ShouldExpand) {
6299 // Expand the function parameter pack into multiple, separate
6300 // parameters.
6301 getDerived().ExpandingFunctionParameterPack(OldParm);
6302 for (unsigned I = 0; I != *NumExpansions; ++I) {
6303 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6304 ParmVarDecl *NewParm
6305 = getDerived().TransformFunctionTypeParam(OldParm,
6306 indexAdjustment++,
6307 OrigNumExpansions,
6308 /*ExpectParameterPack=*/false);
6309 if (!NewParm)
6310 return true;
6311
6312 if (ParamInfos)
6313 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6314 OutParamTypes.push_back(NewParm->getType());
6315 if (PVars)
6316 PVars->push_back(NewParm);
6317 }
6318
6319 // If we're supposed to retain a pack expansion, do so by temporarily
6320 // forgetting the partially-substituted parameter pack.
6321 if (RetainExpansion) {
6322 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6323 ParmVarDecl *NewParm
6324 = getDerived().TransformFunctionTypeParam(OldParm,
6325 indexAdjustment++,
6326 OrigNumExpansions,
6327 /*ExpectParameterPack=*/false);
6328 if (!NewParm)
6329 return true;
6330
6331 if (ParamInfos)
6332 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6333 OutParamTypes.push_back(NewParm->getType());
6334 if (PVars)
6335 PVars->push_back(NewParm);
6336 }
6337
6338 // The next parameter should have the same adjustment as the
6339 // last thing we pushed, but we post-incremented indexAdjustment
6340 // on every push. Also, if we push nothing, the adjustment should
6341 // go down by one.
6342 indexAdjustment--;
6343
6344 // We're done with the pack expansion.
6345 continue;
6346 }
6347
6348 // We'll substitute the parameter now without expanding the pack
6349 // expansion.
6350 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6351 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6352 indexAdjustment,
6353 NumExpansions,
6354 /*ExpectParameterPack=*/true);
6355 assert(NewParm->isParameterPack() &&
6356 "Parameter pack no longer a parameter pack after "
6357 "transformation.");
6358 } else {
6359 NewParm = getDerived().TransformFunctionTypeParam(
6360 OldParm, indexAdjustment, std::nullopt,
6361 /*ExpectParameterPack=*/false);
6362 }
6363
6364 if (!NewParm)
6365 return true;
6366
6367 if (ParamInfos)
6368 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6369 OutParamTypes.push_back(NewParm->getType());
6370 if (PVars)
6371 PVars->push_back(NewParm);
6372 continue;
6373 }
6374
6375 // Deal with the possibility that we don't have a parameter
6376 // declaration for this parameter.
6377 assert(ParamTypes);
6378 QualType OldType = ParamTypes[i];
6379 bool IsPackExpansion = false;
6380 UnsignedOrNone NumExpansions = std::nullopt;
6381 QualType NewType;
6382 if (const PackExpansionType *Expansion
6383 = dyn_cast<PackExpansionType>(OldType)) {
6384 // We have a function parameter pack that may need to be expanded.
6385 QualType Pattern = Expansion->getPattern();
6387 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6388
6389 // Determine whether we should expand the parameter packs.
6390 bool ShouldExpand = false;
6391 bool RetainExpansion = false;
6393 Loc, SourceRange(), Unexpanded,
6394 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6395 RetainExpansion, NumExpansions)) {
6396 return true;
6397 }
6398
6399 if (ShouldExpand) {
6400 // Expand the function parameter pack into multiple, separate
6401 // parameters.
6402 for (unsigned I = 0; I != *NumExpansions; ++I) {
6403 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6404 QualType NewType = getDerived().TransformType(Pattern);
6405 if (NewType.isNull())
6406 return true;
6407
6408 if (NewType->containsUnexpandedParameterPack()) {
6409 NewType = getSema().getASTContext().getPackExpansionType(
6410 NewType, std::nullopt);
6411
6412 if (NewType.isNull())
6413 return true;
6414 }
6415
6416 if (ParamInfos)
6417 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6418 OutParamTypes.push_back(NewType);
6419 if (PVars)
6420 PVars->push_back(nullptr);
6421 }
6422
6423 // We're done with the pack expansion.
6424 continue;
6425 }
6426
6427 // If we're supposed to retain a pack expansion, do so by temporarily
6428 // forgetting the partially-substituted parameter pack.
6429 if (RetainExpansion) {
6430 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6431 QualType NewType = getDerived().TransformType(Pattern);
6432 if (NewType.isNull())
6433 return true;
6434
6435 if (ParamInfos)
6436 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6437 OutParamTypes.push_back(NewType);
6438 if (PVars)
6439 PVars->push_back(nullptr);
6440 }
6441
6442 // We'll substitute the parameter now without expanding the pack
6443 // expansion.
6444 OldType = Expansion->getPattern();
6445 IsPackExpansion = true;
6446 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6447 NewType = getDerived().TransformType(OldType);
6448 } else {
6449 NewType = getDerived().TransformType(OldType);
6450 }
6451
6452 if (NewType.isNull())
6453 return true;
6454
6455 if (IsPackExpansion)
6456 NewType = getSema().Context.getPackExpansionType(NewType,
6457 NumExpansions);
6458
6459 if (ParamInfos)
6460 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6461 OutParamTypes.push_back(NewType);
6462 if (PVars)
6463 PVars->push_back(nullptr);
6464 }
6465
6466#ifndef NDEBUG
6467 if (PVars) {
6468 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6469 if (ParmVarDecl *parm = (*PVars)[i])
6470 assert(parm->getFunctionScopeIndex() == i);
6471 }
6472#endif
6473
6474 return false;
6475}
6476
6477template<typename Derived>
6481 SmallVector<QualType, 4> ExceptionStorage;
6482 return getDerived().TransformFunctionProtoType(
6483 TLB, TL, nullptr, Qualifiers(),
6484 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6485 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6486 ExceptionStorage, Changed);
6487 });
6488}
6489
6490template<typename Derived> template<typename Fn>
6492 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6493 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6494
6495 // Transform the parameters and return type.
6496 //
6497 // We are required to instantiate the params and return type in source order.
6498 // When the function has a trailing return type, we instantiate the
6499 // parameters before the return type, since the return type can then refer
6500 // to the parameters themselves (via decltype, sizeof, etc.).
6501 //
6502 SmallVector<QualType, 4> ParamTypes;
6504 Sema::ExtParameterInfoBuilder ExtParamInfos;
6505 const FunctionProtoType *T = TL.getTypePtr();
6506
6507 QualType ResultType;
6508
6509 if (T->hasTrailingReturn()) {
6511 TL.getBeginLoc(), TL.getParams(),
6513 T->getExtParameterInfosOrNull(),
6514 ParamTypes, &ParamDecls, ExtParamInfos))
6515 return QualType();
6516
6517 {
6518 // C++11 [expr.prim.general]p3:
6519 // If a declaration declares a member function or member function
6520 // template of a class X, the expression this is a prvalue of type
6521 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6522 // and the end of the function-definition, member-declarator, or
6523 // declarator.
6524 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6525 Sema::CXXThisScopeRAII ThisScope(
6526 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6527
6528 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6529 if (ResultType.isNull())
6530 return QualType();
6531 }
6532 }
6533 else {
6534 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6535 if (ResultType.isNull())
6536 return QualType();
6537
6539 TL.getBeginLoc(), TL.getParams(),
6541 T->getExtParameterInfosOrNull(),
6542 ParamTypes, &ParamDecls, ExtParamInfos))
6543 return QualType();
6544 }
6545
6546 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6547
6548 bool EPIChanged = false;
6549 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6550 return QualType();
6551
6552 // Handle extended parameter information.
6553 if (auto NewExtParamInfos =
6554 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6555 if (!EPI.ExtParameterInfos ||
6557 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6558 EPIChanged = true;
6559 }
6560 EPI.ExtParameterInfos = NewExtParamInfos;
6561 } else if (EPI.ExtParameterInfos) {
6562 EPIChanged = true;
6563 EPI.ExtParameterInfos = nullptr;
6564 }
6565
6566 // Transform any function effects with unevaluated conditions.
6567 // Hold this set in a local for the rest of this function, since EPI
6568 // may need to hold a FunctionEffectsRef pointing into it.
6569 std::optional<FunctionEffectSet> NewFX;
6570 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6571 NewFX.emplace();
6574
6575 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6576 FunctionEffectWithCondition NewEC = PrevEC;
6577 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6578 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6579 if (NewExpr.isInvalid())
6580 return QualType();
6581 std::optional<FunctionEffectMode> Mode =
6582 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6583 if (!Mode)
6584 return QualType();
6585
6586 // The condition expression has been transformed, and re-evaluated.
6587 // It may or may not have become constant.
6588 switch (*Mode) {
6590 NewEC.Cond = {};
6591 break;
6593 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6594 NewEC.Cond = {};
6595 break;
6597 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6598 break;
6600 llvm_unreachable(
6601 "FunctionEffectMode::None shouldn't be possible here");
6602 }
6603 }
6604 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6605 TL.getBeginLoc())) {
6607 NewFX->insert(NewEC, Errs);
6608 assert(Errs.empty());
6609 }
6610 }
6611 EPI.FunctionEffects = *NewFX;
6612 EPIChanged = true;
6613 }
6614
6615 QualType Result = TL.getType();
6616 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6617 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6618 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6619 if (Result.isNull())
6620 return QualType();
6621 }
6622
6625 NewTL.setLParenLoc(TL.getLParenLoc());
6626 NewTL.setRParenLoc(TL.getRParenLoc());
6629 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6630 NewTL.setParam(i, ParamDecls[i]);
6631
6632 return Result;
6633}
6634
6635template<typename Derived>
6638 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6639 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6640
6641 // Instantiate a dynamic noexcept expression, if any.
6642 if (isComputedNoexcept(ESI.Type)) {
6643 // Update this scrope because ContextDecl in Sema will be used in
6644 // TransformExpr.
6645 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6646 Sema::CXXThisScopeRAII ThisScope(
6647 SemaRef, Method ? Method->getParent() : nullptr,
6648 Method ? Method->getMethodQualifiers() : Qualifiers{},
6649 Method != nullptr);
6652 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6653 if (NoexceptExpr.isInvalid())
6654 return true;
6655
6657 NoexceptExpr =
6658 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6659 if (NoexceptExpr.isInvalid())
6660 return true;
6661
6662 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6663 Changed = true;
6664 ESI.NoexceptExpr = NoexceptExpr.get();
6665 ESI.Type = EST;
6666 }
6667
6668 if (ESI.Type != EST_Dynamic)
6669 return false;
6670
6671 // Instantiate a dynamic exception specification's type.
6672 for (QualType T : ESI.Exceptions) {
6673 if (const PackExpansionType *PackExpansion =
6674 T->getAs<PackExpansionType>()) {
6675 Changed = true;
6676
6677 // We have a pack expansion. Instantiate it.
6679 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6680 Unexpanded);
6681 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6682
6683 // Determine whether the set of unexpanded parameter packs can and
6684 // should
6685 // be expanded.
6686 bool Expand = false;
6687 bool RetainExpansion = false;
6688 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6689 // FIXME: Track the location of the ellipsis (and track source location
6690 // information for the types in the exception specification in general).
6692 Loc, SourceRange(), Unexpanded,
6693 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6694 NumExpansions))
6695 return true;
6696
6697 if (!Expand) {
6698 // We can't expand this pack expansion into separate arguments yet;
6699 // just substitute into the pattern and create a new pack expansion
6700 // type.
6701 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6702 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6703 if (U.isNull())
6704 return true;
6705
6706 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6707 Exceptions.push_back(U);
6708 continue;
6709 }
6710
6711 // Substitute into the pack expansion pattern for each slice of the
6712 // pack.
6713 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6714 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6715
6716 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6717 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6718 return true;
6719
6720 Exceptions.push_back(U);
6721 }
6722 } else {
6723 QualType U = getDerived().TransformType(T);
6724 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6725 return true;
6726 if (T != U)
6727 Changed = true;
6728
6729 Exceptions.push_back(U);
6730 }
6731 }
6732
6733 ESI.Exceptions = Exceptions;
6734 if (ESI.Exceptions.empty())
6735 ESI.Type = EST_DynamicNone;
6736 return false;
6737}
6738
6739template<typename Derived>
6741 TypeLocBuilder &TLB,
6743 const FunctionNoProtoType *T = TL.getTypePtr();
6744 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6745 if (ResultType.isNull())
6746 return QualType();
6747
6748 QualType Result = TL.getType();
6749 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6750 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6751
6754 NewTL.setLParenLoc(TL.getLParenLoc());
6755 NewTL.setRParenLoc(TL.getRParenLoc());
6757
6758 return Result;
6759}
6760
6761template <typename Derived>
6762QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6763 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6764
6765 const UnresolvedUsingType *T = TL.getTypePtr();
6766 bool Changed = false;
6767
6768 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6769 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6770 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6771 if (!QualifierLoc)
6772 return QualType();
6773 Changed |= QualifierLoc != OldQualifierLoc;
6774 }
6775
6776 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6777 if (!D)
6778 return QualType();
6779 Changed |= D != T->getDecl();
6780
6781 QualType Result = TL.getType();
6782 if (getDerived().AlwaysRebuild() || Changed) {
6783 Result = getDerived().RebuildUnresolvedUsingType(
6784 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6785 D);
6786 if (Result.isNull())
6787 return QualType();
6788 }
6789
6791 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6792 QualifierLoc, TL.getNameLoc());
6793 else
6794 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6795 QualifierLoc, TL.getNameLoc());
6796 return Result;
6797}
6798
6799template <typename Derived>
6801 UsingTypeLoc TL) {
6802 const UsingType *T = TL.getTypePtr();
6803 bool Changed = false;
6804
6805 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6806 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6807 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6808 if (!QualifierLoc)
6809 return QualType();
6810 Changed |= QualifierLoc != OldQualifierLoc;
6811 }
6812
6813 auto *D = cast_or_null<UsingShadowDecl>(
6814 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6815 if (!D)
6816 return QualType();
6817 Changed |= D != T->getDecl();
6818
6819 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6820 if (UnderlyingType.isNull())
6821 return QualType();
6822 Changed |= UnderlyingType != T->desugar();
6823
6824 QualType Result = TL.getType();
6825 if (getDerived().AlwaysRebuild() || Changed) {
6826 Result = getDerived().RebuildUsingType(
6827 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6828 UnderlyingType);
6829 if (Result.isNull())
6830 return QualType();
6831 }
6832 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6833 TL.getNameLoc());
6834 return Result;
6835}
6836
6837template<typename Derived>
6839 TypedefTypeLoc TL) {
6840 const TypedefType *T = TL.getTypePtr();
6841 bool Changed = false;
6842
6843 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6844 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6845 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6846 if (!QualifierLoc)
6847 return QualType();
6848 Changed |= QualifierLoc != OldQualifierLoc;
6849 }
6850
6851 auto *Typedef = cast_or_null<TypedefNameDecl>(
6852 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6853 if (!Typedef)
6854 return QualType();
6855 Changed |= Typedef != T->getDecl();
6856
6857 // FIXME: Transform the UnderlyingType if different from decl.
6858
6859 QualType Result = TL.getType();
6860 if (getDerived().AlwaysRebuild() || Changed) {
6861 Result = getDerived().RebuildTypedefType(
6862 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6863 if (Result.isNull())
6864 return QualType();
6865 }
6866
6867 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6868 QualifierLoc, TL.getNameLoc());
6869 return Result;
6870}
6871
6872template<typename Derived>
6874 TypeOfExprTypeLoc TL) {
6875 // typeof expressions are not potentially evaluated contexts
6879
6880 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6881 if (E.isInvalid())
6882 return QualType();
6883
6884 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6885 if (E.isInvalid())
6886 return QualType();
6887
6888 QualType Result = TL.getType();
6890 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6891 Result =
6892 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6893 if (Result.isNull())
6894 return QualType();
6895 }
6896
6897 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6898 NewTL.setTypeofLoc(TL.getTypeofLoc());
6899 NewTL.setLParenLoc(TL.getLParenLoc());
6900 NewTL.setRParenLoc(TL.getRParenLoc());
6901
6902 return Result;
6903}
6904
6905template<typename Derived>
6907 TypeOfTypeLoc TL) {
6908 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6909 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6910 if (!New_Under_TI)
6911 return QualType();
6912
6913 QualType Result = TL.getType();
6914 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6915 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6916 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6917 if (Result.isNull())
6918 return QualType();
6919 }
6920
6921 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6922 NewTL.setTypeofLoc(TL.getTypeofLoc());
6923 NewTL.setLParenLoc(TL.getLParenLoc());
6924 NewTL.setRParenLoc(TL.getRParenLoc());
6925 NewTL.setUnmodifiedTInfo(New_Under_TI);
6926
6927 return Result;
6928}
6929
6930template<typename Derived>
6932 DecltypeTypeLoc TL) {
6933 const DecltypeType *T = TL.getTypePtr();
6934
6935 // decltype expressions are not potentially evaluated contexts
6939
6940 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6941 if (E.isInvalid())
6942 return QualType();
6943
6944 E = getSema().ActOnDecltypeExpression(E.get());
6945 if (E.isInvalid())
6946 return QualType();
6947
6948 QualType Result = TL.getType();
6949 if (getDerived().AlwaysRebuild() ||
6950 E.get() != T->getUnderlyingExpr()) {
6951 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6952 if (Result.isNull())
6953 return QualType();
6954 }
6955 else E.get();
6956
6957 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6958 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6959 NewTL.setRParenLoc(TL.getRParenLoc());
6960 return Result;
6961}
6962
6963template <typename Derived>
6967 // Transform the index
6968 ExprResult IndexExpr;
6969 {
6970 EnterExpressionEvaluationContext ConstantContext(
6972
6973 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6974 if (IndexExpr.isInvalid())
6975 return QualType();
6976 }
6977 QualType Pattern = TL.getPattern();
6978
6979 const PackIndexingType *PIT = TL.getTypePtr();
6980 SmallVector<QualType, 5> SubtitutedTypes;
6981 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6982
6983 bool NotYetExpanded = Types.empty();
6984 bool FullySubstituted = true;
6985
6986 if (Types.empty() && !PIT->expandsToEmptyPack())
6987 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6988
6989 for (QualType T : Types) {
6990 if (!T->containsUnexpandedParameterPack()) {
6991 QualType Transformed = getDerived().TransformType(T);
6992 if (Transformed.isNull())
6993 return QualType();
6994 SubtitutedTypes.push_back(Transformed);
6995 continue;
6996 }
6997
6999 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7000 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7001 // Determine whether the set of unexpanded parameter packs can and should
7002 // be expanded.
7003 bool ShouldExpand = true;
7004 bool RetainExpansion = false;
7005 UnsignedOrNone NumExpansions = std::nullopt;
7006 if (getDerived().TryExpandParameterPacks(
7007 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7008 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7009 RetainExpansion, NumExpansions))
7010 return QualType();
7011 if (!ShouldExpand) {
7012 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7013 // FIXME: should we keep TypeLoc for individual expansions in
7014 // PackIndexingTypeLoc?
7015 TypeSourceInfo *TI =
7016 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7017 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7018 if (Pack.isNull())
7019 return QualType();
7020 if (NotYetExpanded) {
7021 FullySubstituted = false;
7022 QualType Out = getDerived().RebuildPackIndexingType(
7023 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7024 FullySubstituted);
7025 if (Out.isNull())
7026 return QualType();
7027
7029 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7030 return Out;
7031 }
7032 SubtitutedTypes.push_back(Pack);
7033 continue;
7034 }
7035 for (unsigned I = 0; I != *NumExpansions; ++I) {
7036 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7037 QualType Out = getDerived().TransformType(T);
7038 if (Out.isNull())
7039 return QualType();
7040 SubtitutedTypes.push_back(Out);
7041 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7042 }
7043 // If we're supposed to retain a pack expansion, do so by temporarily
7044 // forgetting the partially-substituted parameter pack.
7045 if (RetainExpansion) {
7046 FullySubstituted = false;
7047 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7048 QualType Out = getDerived().TransformType(T);
7049 if (Out.isNull())
7050 return QualType();
7051 SubtitutedTypes.push_back(Out);
7052 }
7053 }
7054
7055 // A pack indexing type can appear in a larger pack expansion,
7056 // e.g. `Pack...[pack_of_indexes]...`
7057 // so we need to temporarily disable substitution of pack elements
7058 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7059 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7060
7061 QualType Out = getDerived().RebuildPackIndexingType(
7062 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7063 FullySubstituted, SubtitutedTypes);
7064 if (Out.isNull())
7065 return Out;
7066
7068 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7069 return Out;
7070}
7071
7072template<typename Derived>
7074 TypeLocBuilder &TLB,
7076 QualType Result = TL.getType();
7077 if (Result->isDependentType()) {
7078 const UnaryTransformType *T = TL.getTypePtr();
7079
7080 TypeSourceInfo *NewBaseTSI =
7081 getDerived().TransformType(TL.getUnderlyingTInfo());
7082 if (!NewBaseTSI)
7083 return QualType();
7084 QualType NewBase = NewBaseTSI->getType();
7085
7086 Result = getDerived().RebuildUnaryTransformType(NewBase,
7087 T->getUTTKind(),
7088 TL.getKWLoc());
7089 if (Result.isNull())
7090 return QualType();
7091 }
7092
7094 NewTL.setKWLoc(TL.getKWLoc());
7095 NewTL.setParensRange(TL.getParensRange());
7096 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
7097 return Result;
7098}
7099
7100template<typename Derived>
7103 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7104
7105 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7106 TemplateName TemplateName = getDerived().TransformTemplateName(
7107 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7108 TL.getTemplateNameLoc());
7109 if (TemplateName.isNull())
7110 return QualType();
7111
7112 QualType OldDeduced = T->getDeducedType();
7113 QualType NewDeduced;
7114 if (!OldDeduced.isNull()) {
7115 NewDeduced = getDerived().TransformType(OldDeduced);
7116 if (NewDeduced.isNull())
7117 return QualType();
7118 }
7119
7120 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7121 T->getKeyword(), TemplateName, NewDeduced);
7122 if (Result.isNull())
7123 return QualType();
7124
7125 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7126 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7127 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7128 NewTL.setQualifierLoc(QualifierLoc);
7129 return Result;
7130}
7131
7132template <typename Derived>
7134 TagTypeLoc TL) {
7135 const TagType *T = TL.getTypePtr();
7136
7137 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7138 if (QualifierLoc) {
7139 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7140 if (!QualifierLoc)
7141 return QualType();
7142 }
7143
7144 auto *TD = cast_or_null<TagDecl>(
7145 getDerived().TransformDecl(TL.getNameLoc(), T->getOriginalDecl()));
7146 if (!TD)
7147 return QualType();
7148
7149 QualType Result = TL.getType();
7150 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7151 TD != T->getOriginalDecl()) {
7152 if (T->isCanonicalUnqualified())
7153 Result = getDerived().RebuildCanonicalTagType(TD);
7154 else
7155 Result = getDerived().RebuildTagType(
7156 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7157 if (Result.isNull())
7158 return QualType();
7159 }
7160
7161 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7163 NewTL.setQualifierLoc(QualifierLoc);
7164 NewTL.setNameLoc(TL.getNameLoc());
7165
7166 return Result;
7167}
7168
7169template <typename Derived>
7171 EnumTypeLoc TL) {
7172 return getDerived().TransformTagType(TLB, TL);
7173}
7174
7175template <typename Derived>
7176QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7177 RecordTypeLoc TL) {
7178 return getDerived().TransformTagType(TLB, TL);
7179}
7180
7181template<typename Derived>
7183 TypeLocBuilder &TLB,
7185 return getDerived().TransformTagType(TLB, TL);
7186}
7187
7188template<typename Derived>
7190 TypeLocBuilder &TLB,
7192 return getDerived().TransformTemplateTypeParmType(
7193 TLB, TL,
7194 /*SuppressObjCLifetime=*/false);
7195}
7196
7197template <typename Derived>
7199 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7200 return TransformTypeSpecType(TLB, TL);
7201}
7202
7203template<typename Derived>
7204QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7205 TypeLocBuilder &TLB,
7206 SubstTemplateTypeParmTypeLoc TL) {
7207 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7208
7209 Decl *NewReplaced =
7210 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7211
7212 // Substitute into the replacement type, which itself might involve something
7213 // that needs to be transformed. This only tends to occur with default
7214 // template arguments of template template parameters.
7215 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7216 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7217 if (Replacement.isNull())
7218 return QualType();
7219
7220 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7221 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7222 T->getFinal());
7223
7224 // Propagate type-source information.
7225 SubstTemplateTypeParmTypeLoc NewTL
7226 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7227 NewTL.setNameLoc(TL.getNameLoc());
7228 return Result;
7229
7230}
7231template <typename Derived>
7234 return TransformTypeSpecType(TLB, TL);
7235}
7236
7237template<typename Derived>
7239 TypeLocBuilder &TLB,
7241 return getDerived().TransformSubstTemplateTypeParmPackType(
7242 TLB, TL, /*SuppressObjCLifetime=*/false);
7243}
7244
7245template <typename Derived>
7248 return TransformTypeSpecType(TLB, TL);
7249}
7250
7251template<typename Derived>
7252QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7253 AtomicTypeLoc TL) {
7254 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7255 if (ValueType.isNull())
7256 return QualType();
7257
7258 QualType Result = TL.getType();
7259 if (getDerived().AlwaysRebuild() ||
7260 ValueType != TL.getValueLoc().getType()) {
7261 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7262 if (Result.isNull())
7263 return QualType();
7264 }
7265
7266 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7267 NewTL.setKWLoc(TL.getKWLoc());
7268 NewTL.setLParenLoc(TL.getLParenLoc());
7269 NewTL.setRParenLoc(TL.getRParenLoc());
7270
7271 return Result;
7272}
7273
7274template <typename Derived>
7276 PipeTypeLoc TL) {
7277 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7278 if (ValueType.isNull())
7279 return QualType();
7280
7281 QualType Result = TL.getType();
7282 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7283 const PipeType *PT = Result->castAs<PipeType>();
7284 bool isReadPipe = PT->isReadOnly();
7285 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7286 if (Result.isNull())
7287 return QualType();
7288 }
7289
7290 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7291 NewTL.setKWLoc(TL.getKWLoc());
7292
7293 return Result;
7294}
7295
7296template <typename Derived>
7298 BitIntTypeLoc TL) {
7299 const BitIntType *EIT = TL.getTypePtr();
7300 QualType Result = TL.getType();
7301
7302 if (getDerived().AlwaysRebuild()) {
7303 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7304 EIT->getNumBits(), TL.getNameLoc());
7305 if (Result.isNull())
7306 return QualType();
7307 }
7308
7309 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7310 NewTL.setNameLoc(TL.getNameLoc());
7311 return Result;
7312}
7313
7314template <typename Derived>
7317 const DependentBitIntType *EIT = TL.getTypePtr();
7318
7321 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7322 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7323
7324 if (BitsExpr.isInvalid())
7325 return QualType();
7326
7327 QualType Result = TL.getType();
7328
7329 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7330 Result = getDerived().RebuildDependentBitIntType(
7331 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7332
7333 if (Result.isNull())
7334 return QualType();
7335 }
7336
7339 NewTL.setNameLoc(TL.getNameLoc());
7340 } else {
7341 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7342 NewTL.setNameLoc(TL.getNameLoc());
7343 }
7344 return Result;
7345}
7346
7347template <typename Derived>
7350 llvm_unreachable("This type does not need to be transformed.");
7351}
7352
7353 /// Simple iterator that traverses the template arguments in a
7354 /// container that provides a \c getArgLoc() member function.
7355 ///
7356 /// This iterator is intended to be used with the iterator form of
7357 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7358 template<typename ArgLocContainer>
7360 ArgLocContainer *Container;
7361 unsigned Index;
7362
7363 public:
7366 typedef int difference_type;
7367 typedef std::input_iterator_tag iterator_category;
7368
7369 class pointer {
7371
7372 public:
7373 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7374
7376 return &Arg;
7377 }
7378 };
7379
7380
7382
7383 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7384 unsigned Index)
7385 : Container(&Container), Index(Index) { }
7386
7388 ++Index;
7389 return *this;
7390 }
7391
7394 ++(*this);
7395 return Old;
7396 }
7397
7399 return Container->getArgLoc(Index);
7400 }
7401
7403 return pointer(Container->getArgLoc(Index));
7404 }
7405
7408 return X.Container == Y.Container && X.Index == Y.Index;
7409 }
7410
7413 return !(X == Y);
7414 }
7415 };
7416
7417template<typename Derived>
7418QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7419 AutoTypeLoc TL) {
7420 const AutoType *T = TL.getTypePtr();
7421 QualType OldDeduced = T->getDeducedType();
7422 QualType NewDeduced;
7423 if (!OldDeduced.isNull()) {
7424 NewDeduced = getDerived().TransformType(OldDeduced);
7425 if (NewDeduced.isNull())
7426 return QualType();
7427 }
7428
7429 ConceptDecl *NewCD = nullptr;
7430 TemplateArgumentListInfo NewTemplateArgs;
7431 NestedNameSpecifierLoc NewNestedNameSpec;
7432 if (T->isConstrained()) {
7433 assert(TL.getConceptReference());
7434 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7435 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7436
7437 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7438 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7440 if (getDerived().TransformTemplateArguments(
7441 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7442 NewTemplateArgs))
7443 return QualType();
7444
7445 if (TL.getNestedNameSpecifierLoc()) {
7446 NewNestedNameSpec
7447 = getDerived().TransformNestedNameSpecifierLoc(
7448 TL.getNestedNameSpecifierLoc());
7449 if (!NewNestedNameSpec)
7450 return QualType();
7451 }
7452 }
7453
7454 QualType Result = TL.getType();
7455 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7456 T->isDependentType() || T->isConstrained()) {
7457 // FIXME: Maybe don't rebuild if all template arguments are the same.
7459 NewArgList.reserve(NewTemplateArgs.size());
7460 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7461 NewArgList.push_back(ArgLoc.getArgument());
7462 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7463 NewArgList);
7464 if (Result.isNull())
7465 return QualType();
7466 }
7467
7468 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7469 NewTL.setNameLoc(TL.getNameLoc());
7470 NewTL.setRParenLoc(TL.getRParenLoc());
7471 NewTL.setConceptReference(nullptr);
7472
7473 if (T->isConstrained()) {
7475 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7476 TL.getConceptNameLoc(),
7477 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7478 auto *CR = ConceptReference::Create(
7479 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7480 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7481 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7482 NewTL.setConceptReference(CR);
7483 }
7484
7485 return Result;
7486}
7487
7488template <typename Derived>
7491 return getDerived().TransformTemplateSpecializationType(
7492 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7493 /*AllowInjectedClassName=*/false);
7494}
7495
7496template <typename Derived>
7499 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7500 const TemplateSpecializationType *T = TL.getTypePtr();
7501
7502 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7503 TemplateName Template = getDerived().TransformTemplateName(
7504 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7505 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7506 AllowInjectedClassName);
7507 if (Template.isNull())
7508 return QualType();
7509
7510 TemplateArgumentListInfo NewTemplateArgs;
7511 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7512 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7514 ArgIterator;
7515 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7516 ArgIterator(TL, TL.getNumArgs()),
7517 NewTemplateArgs))
7518 return QualType();
7519
7520 // This needs to be rebuilt if either the arguments changed, or if the
7521 // original template changed. If the template changed, and even if the
7522 // arguments didn't change, these arguments might not correspond to their
7523 // respective parameters, therefore needing conversions.
7524 QualType Result = getDerived().RebuildTemplateSpecializationType(
7525 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7526 NewTemplateArgs);
7527
7528 if (!Result.isNull()) {
7530 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7531 TL.getTemplateNameLoc(), NewTemplateArgs);
7532 }
7533
7534 return Result;
7535}
7536
7537template <typename Derived>
7539 AttributedTypeLoc TL) {
7540 const AttributedType *oldType = TL.getTypePtr();
7541 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7542 if (modifiedType.isNull())
7543 return QualType();
7544
7545 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7546 const Attr *oldAttr = TL.getAttr();
7547 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7548 if (oldAttr && !newAttr)
7549 return QualType();
7550
7551 QualType result = TL.getType();
7552
7553 // FIXME: dependent operand expressions?
7554 if (getDerived().AlwaysRebuild() ||
7555 modifiedType != oldType->getModifiedType()) {
7556 // If the equivalent type is equal to the modified type, we don't want to
7557 // transform it as well because:
7558 //
7559 // 1. The transformation would yield the same result and is therefore
7560 // superfluous, and
7561 //
7562 // 2. Transforming the same type twice can cause problems, e.g. if it
7563 // is a FunctionProtoType, we may end up instantiating the function
7564 // parameters twice, which causes an assertion since the parameters
7565 // are already bound to their counterparts in the template for this
7566 // instantiation.
7567 //
7568 QualType equivalentType = modifiedType;
7569 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7570 TypeLocBuilder AuxiliaryTLB;
7571 AuxiliaryTLB.reserve(TL.getFullDataSize());
7572 equivalentType =
7573 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7574 if (equivalentType.isNull())
7575 return QualType();
7576 }
7577
7578 // Check whether we can add nullability; it is only represented as
7579 // type sugar, and therefore cannot be diagnosed in any other way.
7580 if (auto nullability = oldType->getImmediateNullability()) {
7581 if (!modifiedType->canHaveNullability()) {
7582 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7583 : TL.getModifiedLoc().getBeginLoc()),
7584 diag::err_nullability_nonpointer)
7585 << DiagNullabilityKind(*nullability, false) << modifiedType;
7586 return QualType();
7587 }
7588 }
7589
7590 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7591 modifiedType,
7592 equivalentType,
7593 TL.getAttr());
7594 }
7595
7596 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7597 newTL.setAttr(newAttr);
7598 return result;
7599}
7600
7601template <typename Derived>
7604 const CountAttributedType *OldTy = TL.getTypePtr();
7605 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7606 if (InnerTy.isNull())
7607 return QualType();
7608
7609 Expr *OldCount = TL.getCountExpr();
7610 Expr *NewCount = nullptr;
7611 if (OldCount) {
7612 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7613 if (CountResult.isInvalid())
7614 return QualType();
7615 NewCount = CountResult.get();
7616 }
7617
7618 QualType Result = TL.getType();
7619 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7620 OldCount != NewCount) {
7621 // Currently, CountAttributedType can only wrap incomplete array types.
7623 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7624 }
7625
7626 TLB.push<CountAttributedTypeLoc>(Result);
7627 return Result;
7628}
7629
7630template <typename Derived>
7633 // The BTFTagAttributedType is available for C only.
7634 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7635}
7636
7637template <typename Derived>
7640
7641 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7642
7643 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7644 if (WrappedTy.isNull())
7645 return QualType();
7646
7647 QualType ContainedTy = QualType();
7648 QualType OldContainedTy = oldType->getContainedType();
7649 if (!OldContainedTy.isNull()) {
7650 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7651 if (!oldContainedTSI)
7652 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7653 OldContainedTy, SourceLocation());
7654 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7655 if (!ContainedTSI)
7656 return QualType();
7657 ContainedTy = ContainedTSI->getType();
7658 }
7659
7660 QualType Result = TL.getType();
7661 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7662 ContainedTy != oldType->getContainedType()) {
7664 WrappedTy, ContainedTy, oldType->getAttrs());
7665 }
7666
7668 return Result;
7669}
7670
7671template <typename Derived>
7674 // No transformations needed.
7675 return TL.getType();
7676}
7677
7678template<typename Derived>
7681 ParenTypeLoc TL) {
7682 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7683 if (Inner.isNull())
7684 return QualType();
7685
7686 QualType Result = TL.getType();
7687 if (getDerived().AlwaysRebuild() ||
7688 Inner != TL.getInnerLoc().getType()) {
7689 Result = getDerived().RebuildParenType(Inner);
7690 if (Result.isNull())
7691 return QualType();
7692 }
7693
7694 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7695 NewTL.setLParenLoc(TL.getLParenLoc());
7696 NewTL.setRParenLoc(TL.getRParenLoc());
7697 return Result;
7698}
7699
7700template <typename Derived>
7704 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7705 if (Inner.isNull())
7706 return QualType();
7707
7708 QualType Result = TL.getType();
7709 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7710 Result =
7711 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7712 if (Result.isNull())
7713 return QualType();
7714 }
7715
7717 NewTL.setExpansionLoc(TL.getExpansionLoc());
7718 return Result;
7719}
7720
7721template<typename Derived>
7722QualType TreeTransform<Derived>::TransformDependentNameType(
7724 return TransformDependentNameType(TLB, TL, false);
7725}
7726
7727template <typename Derived>
7728QualType TreeTransform<Derived>::TransformDependentNameType(
7729 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7730 QualType ObjectType, NamedDecl *UnqualLookup) {
7731 const DependentNameType *T = TL.getTypePtr();
7732
7733 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7734 if (QualifierLoc) {
7735 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7736 QualifierLoc, ObjectType, UnqualLookup);
7737 if (!QualifierLoc)
7738 return QualType();
7739 } else {
7740 assert((ObjectType.isNull() && !UnqualLookup) &&
7741 "must be transformed by TransformNestedNameSpecifierLoc");
7742 }
7743
7745 = getDerived().RebuildDependentNameType(T->getKeyword(),
7746 TL.getElaboratedKeywordLoc(),
7747 QualifierLoc,
7748 T->getIdentifier(),
7749 TL.getNameLoc(),
7750 DeducedTSTContext);
7751 if (Result.isNull())
7752 return QualType();
7753
7754 if (isa<TagType>(Result)) {
7755 auto NewTL = TLB.push<TagTypeLoc>(Result);
7756 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7757 NewTL.setQualifierLoc(QualifierLoc);
7758 NewTL.setNameLoc(TL.getNameLoc());
7760 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7761 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7762 NewTL.setTemplateNameLoc(TL.getNameLoc());
7763 NewTL.setQualifierLoc(QualifierLoc);
7764 } else if (isa<TypedefType>(Result)) {
7765 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7766 QualifierLoc, TL.getNameLoc());
7767 } else if (isa<UnresolvedUsingType>(Result)) {
7768 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7769 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7770 } else {
7771 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7772 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7773 NewTL.setQualifierLoc(QualifierLoc);
7774 NewTL.setNameLoc(TL.getNameLoc());
7775 }
7776 return Result;
7777}
7778
7779template<typename Derived>
7782 QualType Pattern
7783 = getDerived().TransformType(TLB, TL.getPatternLoc());
7784 if (Pattern.isNull())
7785 return QualType();
7786
7787 QualType Result = TL.getType();
7788 if (getDerived().AlwaysRebuild() ||
7789 Pattern != TL.getPatternLoc().getType()) {
7790 Result = getDerived().RebuildPackExpansionType(Pattern,
7791 TL.getPatternLoc().getSourceRange(),
7792 TL.getEllipsisLoc(),
7793 TL.getTypePtr()->getNumExpansions());
7794 if (Result.isNull())
7795 return QualType();
7796 }
7797
7799 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7800 return Result;
7801}
7802
7803template<typename Derived>
7807 // ObjCInterfaceType is never dependent.
7808 TLB.pushFullCopy(TL);
7809 return TL.getType();
7810}
7811
7812template<typename Derived>
7816 const ObjCTypeParamType *T = TL.getTypePtr();
7817 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7818 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7819 if (!OTP)
7820 return QualType();
7821
7822 QualType Result = TL.getType();
7823 if (getDerived().AlwaysRebuild() ||
7824 OTP != T->getDecl()) {
7825 Result = getDerived().RebuildObjCTypeParamType(
7826 OTP, TL.getProtocolLAngleLoc(),
7827 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7828 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7829 if (Result.isNull())
7830 return QualType();
7831 }
7832
7834 if (TL.getNumProtocols()) {
7835 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7836 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7837 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7838 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7839 }
7840 return Result;
7841}
7842
7843template<typename Derived>
7846 ObjCObjectTypeLoc TL) {
7847 // Transform base type.
7848 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7849 if (BaseType.isNull())
7850 return QualType();
7851
7852 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7853
7854 // Transform type arguments.
7855 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7856 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7857 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7858 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7859 QualType TypeArg = TypeArgInfo->getType();
7860 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7861 AnyChanged = true;
7862
7863 // We have a pack expansion. Instantiate it.
7864 const auto *PackExpansion = PackExpansionLoc.getType()
7865 ->castAs<PackExpansionType>();
7867 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7868 Unexpanded);
7869 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7870
7871 // Determine whether the set of unexpanded parameter packs can
7872 // and should be expanded.
7873 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7874 bool Expand = false;
7875 bool RetainExpansion = false;
7876 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7877 if (getDerived().TryExpandParameterPacks(
7878 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7879 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
7880 RetainExpansion, NumExpansions))
7881 return QualType();
7882
7883 if (!Expand) {
7884 // We can't expand this pack expansion into separate arguments yet;
7885 // just substitute into the pattern and create a new pack expansion
7886 // type.
7887 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7888
7889 TypeLocBuilder TypeArgBuilder;
7890 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7891 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7892 PatternLoc);
7893 if (NewPatternType.isNull())
7894 return QualType();
7895
7896 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7897 NewPatternType, NumExpansions);
7898 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7899 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7900 NewTypeArgInfos.push_back(
7901 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7902 continue;
7903 }
7904
7905 // Substitute into the pack expansion pattern for each slice of the
7906 // pack.
7907 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7908 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
7909
7910 TypeLocBuilder TypeArgBuilder;
7911 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7912
7913 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7914 PatternLoc);
7915 if (NewTypeArg.isNull())
7916 return QualType();
7917
7918 NewTypeArgInfos.push_back(
7919 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7920 }
7921
7922 continue;
7923 }
7924
7925 TypeLocBuilder TypeArgBuilder;
7926 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7927 QualType NewTypeArg =
7928 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7929 if (NewTypeArg.isNull())
7930 return QualType();
7931
7932 // If nothing changed, just keep the old TypeSourceInfo.
7933 if (NewTypeArg == TypeArg) {
7934 NewTypeArgInfos.push_back(TypeArgInfo);
7935 continue;
7936 }
7937
7938 NewTypeArgInfos.push_back(
7939 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7940 AnyChanged = true;
7941 }
7942
7943 QualType Result = TL.getType();
7944 if (getDerived().AlwaysRebuild() || AnyChanged) {
7945 // Rebuild the type.
7946 Result = getDerived().RebuildObjCObjectType(
7947 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7948 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7949 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7950 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7951
7952 if (Result.isNull())
7953 return QualType();
7954 }
7955
7956 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7957 NewT.setHasBaseTypeAsWritten(true);
7958 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7959 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7960 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7961 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7962 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7963 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7964 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7965 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7966 return Result;
7967}
7968
7969template<typename Derived>
7973 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7974 if (PointeeType.isNull())
7975 return QualType();
7976
7977 QualType Result = TL.getType();
7978 if (getDerived().AlwaysRebuild() ||
7979 PointeeType != TL.getPointeeLoc().getType()) {
7980 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7981 TL.getStarLoc());
7982 if (Result.isNull())
7983 return QualType();
7984 }
7985
7987 NewT.setStarLoc(TL.getStarLoc());
7988 return Result;
7989}
7990
7991//===----------------------------------------------------------------------===//
7992// Statement transformation
7993//===----------------------------------------------------------------------===//
7994template<typename Derived>
7997 return S;
7998}
7999
8000template<typename Derived>
8003 return getDerived().TransformCompoundStmt(S, false);
8004}
8005
8006template<typename Derived>
8009 bool IsStmtExpr) {
8010 Sema::CompoundScopeRAII CompoundScope(getSema());
8011 Sema::FPFeaturesStateRAII FPSave(getSema());
8012 if (S->hasStoredFPFeatures())
8013 getSema().resetFPOptions(
8014 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8015
8016 const Stmt *ExprResult = S->getStmtExprResult();
8017 bool SubStmtInvalid = false;
8018 bool SubStmtChanged = false;
8019 SmallVector<Stmt*, 8> Statements;
8020 for (auto *B : S->body()) {
8021 StmtResult Result = getDerived().TransformStmt(
8022 B, IsStmtExpr && B == ExprResult ? StmtDiscardKind::StmtExprResult
8023 : StmtDiscardKind::Discarded);
8024
8025 if (Result.isInvalid()) {
8026 // Immediately fail if this was a DeclStmt, since it's very
8027 // likely that this will cause problems for future statements.
8028 if (isa<DeclStmt>(B))
8029 return StmtError();
8030
8031 // Otherwise, just keep processing substatements and fail later.
8032 SubStmtInvalid = true;
8033 continue;
8034 }
8035
8036 SubStmtChanged = SubStmtChanged || Result.get() != B;
8037 Statements.push_back(Result.getAs<Stmt>());
8038 }
8039
8040 if (SubStmtInvalid)
8041 return StmtError();
8042
8043 if (!getDerived().AlwaysRebuild() &&
8044 !SubStmtChanged)
8045 return S;
8046
8047 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8048 Statements,
8049 S->getRBracLoc(),
8050 IsStmtExpr);
8051}
8052
8053template<typename Derived>
8056 ExprResult LHS, RHS;
8057 {
8060
8061 // Transform the left-hand case value.
8062 LHS = getDerived().TransformExpr(S->getLHS());
8063 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8064 if (LHS.isInvalid())
8065 return StmtError();
8066
8067 // Transform the right-hand case value (for the GNU case-range extension).
8068 RHS = getDerived().TransformExpr(S->getRHS());
8069 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8070 if (RHS.isInvalid())
8071 return StmtError();
8072 }
8073
8074 // Build the case statement.
8075 // Case statements are always rebuilt so that they will attached to their
8076 // transformed switch statement.
8077 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8078 LHS.get(),
8079 S->getEllipsisLoc(),
8080 RHS.get(),
8081 S->getColonLoc());
8082 if (Case.isInvalid())
8083 return StmtError();
8084
8085 // Transform the statement following the case
8086 StmtResult SubStmt =
8087 getDerived().TransformStmt(S->getSubStmt());
8088 if (SubStmt.isInvalid())
8089 return StmtError();
8090
8091 // Attach the body to the case statement
8092 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8093}
8094
8095template <typename Derived>
8097 // Transform the statement following the default case
8098 StmtResult SubStmt =
8099 getDerived().TransformStmt(S->getSubStmt());
8100 if (SubStmt.isInvalid())
8101 return StmtError();
8102
8103 // Default statements are always rebuilt
8104 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8105 SubStmt.get());
8106}
8107
8108template<typename Derived>
8111 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8112 if (SubStmt.isInvalid())
8113 return StmtError();
8114
8115 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8116 S->getDecl());
8117 if (!LD)
8118 return StmtError();
8119
8120 // If we're transforming "in-place" (we're not creating new local
8121 // declarations), assume we're replacing the old label statement
8122 // and clear out the reference to it.
8123 if (LD == S->getDecl())
8124 S->getDecl()->setStmt(nullptr);
8125
8126 // FIXME: Pass the real colon location in.
8127 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8129 SubStmt.get());
8130}
8131
8132template <typename Derived>
8134 if (!R)
8135 return R;
8136
8137 switch (R->getKind()) {
8138// Transform attributes by calling TransformXXXAttr.
8139#define ATTR(X) \
8140 case attr::X: \
8141 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8142#include "clang/Basic/AttrList.inc"
8143 }
8144 return R;
8145}
8146
8147template <typename Derived>
8149 const Stmt *InstS,
8150 const Attr *R) {
8151 if (!R)
8152 return R;
8153
8154 switch (R->getKind()) {
8155// Transform attributes by calling TransformStmtXXXAttr.
8156#define ATTR(X) \
8157 case attr::X: \
8158 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8159#include "clang/Basic/AttrList.inc"
8160 }
8161 return TransformAttr(R);
8162}
8163
8164template <typename Derived>
8167 StmtDiscardKind SDK) {
8168 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8169 if (SubStmt.isInvalid())
8170 return StmtError();
8171
8172 bool AttrsChanged = false;
8174
8175 // Visit attributes and keep track if any are transformed.
8176 for (const auto *I : S->getAttrs()) {
8177 const Attr *R =
8178 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8179 AttrsChanged |= (I != R);
8180 if (R)
8181 Attrs.push_back(R);
8182 }
8183
8184 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8185 return S;
8186
8187 // If transforming the attributes failed for all of the attributes in the
8188 // statement, don't make an AttributedStmt without attributes.
8189 if (Attrs.empty())
8190 return SubStmt;
8191
8192 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8193 SubStmt.get());
8194}
8195
8196template<typename Derived>
8199 // Transform the initialization statement
8200 StmtResult Init = getDerived().TransformStmt(S->getInit());
8201 if (Init.isInvalid())
8202 return StmtError();
8203
8205 if (!S->isConsteval()) {
8206 // Transform the condition
8207 Cond = getDerived().TransformCondition(
8208 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8209 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8211 if (Cond.isInvalid())
8212 return StmtError();
8213 }
8214
8215 // If this is a constexpr if, determine which arm we should instantiate.
8216 std::optional<bool> ConstexprConditionValue;
8217 if (S->isConstexpr())
8218 ConstexprConditionValue = Cond.getKnownValue();
8219
8220 // Transform the "then" branch.
8221 StmtResult Then;
8222 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8226 S->isNonNegatedConsteval());
8227
8228 Then = getDerived().TransformStmt(S->getThen());
8229 if (Then.isInvalid())
8230 return StmtError();
8231 } else {
8232 // Discarded branch is replaced with empty CompoundStmt so we can keep
8233 // proper source location for start and end of original branch, so
8234 // subsequent transformations like CoverageMapping work properly
8235 Then = new (getSema().Context)
8236 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8237 }
8238
8239 // Transform the "else" branch.
8240 StmtResult Else;
8241 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8245 S->isNegatedConsteval());
8246
8247 Else = getDerived().TransformStmt(S->getElse());
8248 if (Else.isInvalid())
8249 return StmtError();
8250 } else if (S->getElse() && ConstexprConditionValue &&
8251 *ConstexprConditionValue) {
8252 // Same thing here as with <then> branch, we are discarding it, we can't
8253 // replace it with NULL nor NullStmt as we need to keep for source location
8254 // range, for CoverageMapping
8255 Else = new (getSema().Context)
8256 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8257 }
8258
8259 if (!getDerived().AlwaysRebuild() &&
8260 Init.get() == S->getInit() &&
8261 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8262 Then.get() == S->getThen() &&
8263 Else.get() == S->getElse())
8264 return S;
8265
8266 return getDerived().RebuildIfStmt(
8267 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8268 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8269}
8270
8271template<typename Derived>
8274 // Transform the initialization statement
8275 StmtResult Init = getDerived().TransformStmt(S->getInit());
8276 if (Init.isInvalid())
8277 return StmtError();
8278
8279 // Transform the condition.
8280 Sema::ConditionResult Cond = getDerived().TransformCondition(
8281 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8283 if (Cond.isInvalid())
8284 return StmtError();
8285
8286 // Rebuild the switch statement.
8288 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8289 Init.get(), Cond, S->getRParenLoc());
8290 if (Switch.isInvalid())
8291 return StmtError();
8292
8293 // Transform the body of the switch statement.
8294 StmtResult Body = getDerived().TransformStmt(S->getBody());
8295 if (Body.isInvalid())
8296 return StmtError();
8297
8298 // Complete the switch statement.
8299 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8300 Body.get());
8301}
8302
8303template<typename Derived>
8306 // Transform the condition
8307 Sema::ConditionResult Cond = getDerived().TransformCondition(
8308 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8310 if (Cond.isInvalid())
8311 return StmtError();
8312
8313 // OpenACC Restricts a while-loop inside of certain construct/clause
8314 // combinations, so diagnose that here in OpenACC mode.
8316 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8317
8318 // Transform the body
8319 StmtResult Body = getDerived().TransformStmt(S->getBody());
8320 if (Body.isInvalid())
8321 return StmtError();
8322
8323 if (!getDerived().AlwaysRebuild() &&
8324 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8325 Body.get() == S->getBody())
8326 return Owned(S);
8327
8328 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8329 Cond, S->getRParenLoc(), Body.get());
8330}
8331
8332template<typename Derived>
8335 // OpenACC Restricts a do-loop inside of certain construct/clause
8336 // combinations, so diagnose that here in OpenACC mode.
8338 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8339
8340 // Transform the body
8341 StmtResult Body = getDerived().TransformStmt(S->getBody());
8342 if (Body.isInvalid())
8343 return StmtError();
8344
8345 // Transform the condition
8346 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8347 if (Cond.isInvalid())
8348 return StmtError();
8349
8350 if (!getDerived().AlwaysRebuild() &&
8351 Cond.get() == S->getCond() &&
8352 Body.get() == S->getBody())
8353 return S;
8354
8355 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8356 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8357 S->getRParenLoc());
8358}
8359
8360template<typename Derived>
8363 if (getSema().getLangOpts().OpenMP)
8364 getSema().OpenMP().startOpenMPLoop();
8365
8366 // Transform the initialization statement
8367 StmtResult Init = getDerived().TransformStmt(S->getInit());
8368 if (Init.isInvalid())
8369 return StmtError();
8370
8371 // In OpenMP loop region loop control variable must be captured and be
8372 // private. Perform analysis of first part (if any).
8373 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8374 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8375 Init.get());
8376
8377 // Transform the condition
8378 Sema::ConditionResult Cond = getDerived().TransformCondition(
8379 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8381 if (Cond.isInvalid())
8382 return StmtError();
8383
8384 // Transform the increment
8385 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8386 if (Inc.isInvalid())
8387 return StmtError();
8388
8389 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8390 if (S->getInc() && !FullInc.get())
8391 return StmtError();
8392
8393 // OpenACC Restricts a for-loop inside of certain construct/clause
8394 // combinations, so diagnose that here in OpenACC mode.
8396 SemaRef.OpenACC().ActOnForStmtBegin(
8397 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8398 Cond.get().second, S->getInc(), Inc.get());
8399
8400 // Transform the body
8401 StmtResult Body = getDerived().TransformStmt(S->getBody());
8402 if (Body.isInvalid())
8403 return StmtError();
8404
8405 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8406
8407 if (!getDerived().AlwaysRebuild() &&
8408 Init.get() == S->getInit() &&
8409 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8410 Inc.get() == S->getInc() &&
8411 Body.get() == S->getBody())
8412 return S;
8413
8414 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8415 Init.get(), Cond, FullInc,
8416 S->getRParenLoc(), Body.get());
8417}
8418
8419template<typename Derived>
8422 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8423 S->getLabel());
8424 if (!LD)
8425 return StmtError();
8426
8427 // Goto statements must always be rebuilt, to resolve the label.
8428 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8429 cast<LabelDecl>(LD));
8430}
8431
8432template<typename Derived>
8435 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8436 if (Target.isInvalid())
8437 return StmtError();
8438 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8439
8440 if (!getDerived().AlwaysRebuild() &&
8441 Target.get() == S->getTarget())
8442 return S;
8443
8444 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8445 Target.get());
8446}
8447
8448template<typename Derived>
8451 if (!S->hasLabelTarget())
8452 return S;
8453
8454 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8455 S->getLabelDecl());
8456 if (!LD)
8457 return StmtError();
8458
8459 return new (SemaRef.Context)
8460 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8461}
8462
8463template<typename Derived>
8466 if (!S->hasLabelTarget())
8467 return S;
8468
8469 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8470 S->getLabelDecl());
8471 if (!LD)
8472 return StmtError();
8473
8474 return new (SemaRef.Context)
8475 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8476}
8477
8478template<typename Derived>
8481 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8482 /*NotCopyInit*/false);
8483 if (Result.isInvalid())
8484 return StmtError();
8485
8486 // FIXME: We always rebuild the return statement because there is no way
8487 // to tell whether the return type of the function has changed.
8488 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8489}
8490
8491template<typename Derived>
8494 bool DeclChanged = false;
8496 LambdaScopeInfo *LSI = getSema().getCurLambda();
8497 for (auto *D : S->decls()) {
8498 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8499 if (!Transformed)
8500 return StmtError();
8501
8502 if (Transformed != D)
8503 DeclChanged = true;
8504
8505 if (LSI) {
8506 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8507 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8508 LSI->ContainsUnexpandedParameterPack |=
8509 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8510 } else {
8511 LSI->ContainsUnexpandedParameterPack |=
8512 getSema()
8513 .getASTContext()
8514 .getTypeDeclType(TD)
8515 ->containsUnexpandedParameterPack();
8516 }
8517 }
8518 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8519 LSI->ContainsUnexpandedParameterPack |=
8520 VD->getType()->containsUnexpandedParameterPack();
8521 }
8522
8523 Decls.push_back(Transformed);
8524 }
8525
8526 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8527 return S;
8528
8529 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8530}
8531
8532template<typename Derived>
8535
8536 SmallVector<Expr*, 8> Constraints;
8539
8540 SmallVector<Expr*, 8> Clobbers;
8541
8542 bool ExprsChanged = false;
8543
8544 auto RebuildString = [&](Expr *E) {
8545 ExprResult Result = getDerived().TransformExpr(E);
8546 if (!Result.isUsable())
8547 return Result;
8548 if (Result.get() != E) {
8549 ExprsChanged = true;
8550 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8551 }
8552 return Result;
8553 };
8554
8555 // Go through the outputs.
8556 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8557 Names.push_back(S->getOutputIdentifier(I));
8558
8559 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8560 if (Result.isInvalid())
8561 return StmtError();
8562
8563 Constraints.push_back(Result.get());
8564
8565 // Transform the output expr.
8566 Expr *OutputExpr = S->getOutputExpr(I);
8567 Result = getDerived().TransformExpr(OutputExpr);
8568 if (Result.isInvalid())
8569 return StmtError();
8570
8571 ExprsChanged |= Result.get() != OutputExpr;
8572
8573 Exprs.push_back(Result.get());
8574 }
8575
8576 // Go through the inputs.
8577 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8578 Names.push_back(S->getInputIdentifier(I));
8579
8580 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8581 if (Result.isInvalid())
8582 return StmtError();
8583
8584 Constraints.push_back(Result.get());
8585
8586 // Transform the input expr.
8587 Expr *InputExpr = S->getInputExpr(I);
8588 Result = getDerived().TransformExpr(InputExpr);
8589 if (Result.isInvalid())
8590 return StmtError();
8591
8592 ExprsChanged |= Result.get() != InputExpr;
8593
8594 Exprs.push_back(Result.get());
8595 }
8596
8597 // Go through the Labels.
8598 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8599 Names.push_back(S->getLabelIdentifier(I));
8600
8601 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8602 if (Result.isInvalid())
8603 return StmtError();
8604 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8605 Exprs.push_back(Result.get());
8606 }
8607
8608 // Go through the clobbers.
8609 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8610 ExprResult Result = RebuildString(S->getClobberExpr(I));
8611 if (Result.isInvalid())
8612 return StmtError();
8613 Clobbers.push_back(Result.get());
8614 }
8615
8616 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8617 if (AsmString.isInvalid())
8618 return StmtError();
8619
8620 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8621 return S;
8622
8623 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8624 S->isVolatile(), S->getNumOutputs(),
8625 S->getNumInputs(), Names.data(),
8626 Constraints, Exprs, AsmString.get(),
8627 Clobbers, S->getNumLabels(),
8628 S->getRParenLoc());
8629}
8630
8631template<typename Derived>
8634 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8635
8636 bool HadError = false, HadChange = false;
8637
8638 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8639 SmallVector<Expr*, 8> TransformedExprs;
8640 TransformedExprs.reserve(SrcExprs.size());
8641 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8642 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8643 if (!Result.isUsable()) {
8644 HadError = true;
8645 } else {
8646 HadChange |= (Result.get() != SrcExprs[i]);
8647 TransformedExprs.push_back(Result.get());
8648 }
8649 }
8650
8651 if (HadError) return StmtError();
8652 if (!HadChange && !getDerived().AlwaysRebuild())
8653 return Owned(S);
8654
8655 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8656 AsmToks, S->getAsmString(),
8657 S->getNumOutputs(), S->getNumInputs(),
8658 S->getAllConstraints(), S->getClobbers(),
8659 TransformedExprs, S->getEndLoc());
8660}
8661
8662// C++ Coroutines
8663template<typename Derived>
8666 auto *ScopeInfo = SemaRef.getCurFunction();
8667 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8668 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8669 ScopeInfo->NeedsCoroutineSuspends &&
8670 ScopeInfo->CoroutineSuspends.first == nullptr &&
8671 ScopeInfo->CoroutineSuspends.second == nullptr &&
8672 "expected clean scope info");
8673
8674 // Set that we have (possibly-invalid) suspend points before we do anything
8675 // that may fail.
8676 ScopeInfo->setNeedsCoroutineSuspends(false);
8677
8678 // We re-build the coroutine promise object (and the coroutine parameters its
8679 // type and constructor depend on) based on the types used in our current
8680 // function. We must do so, and set it on the current FunctionScopeInfo,
8681 // before attempting to transform the other parts of the coroutine body
8682 // statement, such as the implicit suspend statements (because those
8683 // statements reference the FunctionScopeInfo::CoroutinePromise).
8684 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8685 return StmtError();
8686 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8687 if (!Promise)
8688 return StmtError();
8689 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8690 ScopeInfo->CoroutinePromise = Promise;
8691
8692 // Transform the implicit coroutine statements constructed using dependent
8693 // types during the previous parse: initial and final suspensions, the return
8694 // object, and others. We also transform the coroutine function's body.
8695 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8696 if (InitSuspend.isInvalid())
8697 return StmtError();
8698 StmtResult FinalSuspend =
8699 getDerived().TransformStmt(S->getFinalSuspendStmt());
8700 if (FinalSuspend.isInvalid() ||
8701 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8702 return StmtError();
8703 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8704 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8705
8706 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8707 if (BodyRes.isInvalid())
8708 return StmtError();
8709
8710 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8711 if (Builder.isInvalid())
8712 return StmtError();
8713
8714 Expr *ReturnObject = S->getReturnValueInit();
8715 assert(ReturnObject && "the return object is expected to be valid");
8716 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8717 /*NoCopyInit*/ false);
8718 if (Res.isInvalid())
8719 return StmtError();
8720 Builder.ReturnValue = Res.get();
8721
8722 // If during the previous parse the coroutine still had a dependent promise
8723 // statement, we may need to build some implicit coroutine statements
8724 // (such as exception and fallthrough handlers) for the first time.
8725 if (S->hasDependentPromiseType()) {
8726 // We can only build these statements, however, if the current promise type
8727 // is not dependent.
8728 if (!Promise->getType()->isDependentType()) {
8729 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8730 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8731 "these nodes should not have been built yet");
8732 if (!Builder.buildDependentStatements())
8733 return StmtError();
8734 }
8735 } else {
8736 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8737 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8738 if (Res.isInvalid())
8739 return StmtError();
8740 Builder.OnFallthrough = Res.get();
8741 }
8742
8743 if (auto *OnException = S->getExceptionHandler()) {
8744 StmtResult Res = getDerived().TransformStmt(OnException);
8745 if (Res.isInvalid())
8746 return StmtError();
8747 Builder.OnException = Res.get();
8748 }
8749
8750 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8751 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8752 if (Res.isInvalid())
8753 return StmtError();
8754 Builder.ReturnStmtOnAllocFailure = Res.get();
8755 }
8756
8757 // Transform any additional statements we may have already built
8758 assert(S->getAllocate() && S->getDeallocate() &&
8759 "allocation and deallocation calls must already be built");
8760 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8761 if (AllocRes.isInvalid())
8762 return StmtError();
8763 Builder.Allocate = AllocRes.get();
8764
8765 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8766 if (DeallocRes.isInvalid())
8767 return StmtError();
8768 Builder.Deallocate = DeallocRes.get();
8769
8770 if (auto *ResultDecl = S->getResultDecl()) {
8771 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8772 if (Res.isInvalid())
8773 return StmtError();
8774 Builder.ResultDecl = Res.get();
8775 }
8776
8777 if (auto *ReturnStmt = S->getReturnStmt()) {
8778 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8779 if (Res.isInvalid())
8780 return StmtError();
8781 Builder.ReturnStmt = Res.get();
8782 }
8783 }
8784
8785 return getDerived().RebuildCoroutineBodyStmt(Builder);
8786}
8787
8788template<typename Derived>
8791 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8792 /*NotCopyInit*/false);
8793 if (Result.isInvalid())
8794 return StmtError();
8795
8796 // Always rebuild; we don't know if this needs to be injected into a new
8797 // context or if the promise type has changed.
8798 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8799 S->isImplicit());
8800}
8801
8802template <typename Derived>
8804 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8805 /*NotCopyInit*/ false);
8806 if (Operand.isInvalid())
8807 return ExprError();
8808
8809 // Rebuild the common-expr from the operand rather than transforming it
8810 // separately.
8811
8812 // FIXME: getCurScope() should not be used during template instantiation.
8813 // We should pick up the set of unqualified lookup results for operator
8814 // co_await during the initial parse.
8815 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8816 getSema().getCurScope(), E->getKeywordLoc());
8817
8818 // Always rebuild; we don't know if this needs to be injected into a new
8819 // context or if the promise type has changed.
8820 return getDerived().RebuildCoawaitExpr(
8821 E->getKeywordLoc(), Operand.get(),
8822 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8823}
8824
8825template <typename Derived>
8828 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8829 /*NotCopyInit*/ false);
8830 if (OperandResult.isInvalid())
8831 return ExprError();
8832
8833 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8834 E->getOperatorCoawaitLookup());
8835
8836 if (LookupResult.isInvalid())
8837 return ExprError();
8838
8839 // Always rebuild; we don't know if this needs to be injected into a new
8840 // context or if the promise type has changed.
8841 return getDerived().RebuildDependentCoawaitExpr(
8842 E->getKeywordLoc(), OperandResult.get(),
8844}
8845
8846template<typename Derived>
8849 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8850 /*NotCopyInit*/false);
8851 if (Result.isInvalid())
8852 return ExprError();
8853
8854 // Always rebuild; we don't know if this needs to be injected into a new
8855 // context or if the promise type has changed.
8856 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8857}
8858
8859// Objective-C Statements.
8860
8861template<typename Derived>
8864 // Transform the body of the @try.
8865 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8866 if (TryBody.isInvalid())
8867 return StmtError();
8868
8869 // Transform the @catch statements (if present).
8870 bool AnyCatchChanged = false;
8871 SmallVector<Stmt*, 8> CatchStmts;
8872 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8873 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8874 if (Catch.isInvalid())
8875 return StmtError();
8876 if (Catch.get() != S->getCatchStmt(I))
8877 AnyCatchChanged = true;
8878 CatchStmts.push_back(Catch.get());
8879 }
8880
8881 // Transform the @finally statement (if present).
8882 StmtResult Finally;
8883 if (S->getFinallyStmt()) {
8884 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8885 if (Finally.isInvalid())
8886 return StmtError();
8887 }
8888
8889 // If nothing changed, just retain this statement.
8890 if (!getDerived().AlwaysRebuild() &&
8891 TryBody.get() == S->getTryBody() &&
8892 !AnyCatchChanged &&
8893 Finally.get() == S->getFinallyStmt())
8894 return S;
8895
8896 // Build a new statement.
8897 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8898 CatchStmts, Finally.get());
8899}
8900
8901template<typename Derived>
8904 // Transform the @catch parameter, if there is one.
8905 VarDecl *Var = nullptr;
8906 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8907 TypeSourceInfo *TSInfo = nullptr;
8908 if (FromVar->getTypeSourceInfo()) {
8909 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8910 if (!TSInfo)
8911 return StmtError();
8912 }
8913
8914 QualType T;
8915 if (TSInfo)
8916 T = TSInfo->getType();
8917 else {
8918 T = getDerived().TransformType(FromVar->getType());
8919 if (T.isNull())
8920 return StmtError();
8921 }
8922
8923 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8924 if (!Var)
8925 return StmtError();
8926 }
8927
8928 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8929 if (Body.isInvalid())
8930 return StmtError();
8931
8932 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8933 S->getRParenLoc(),
8934 Var, Body.get());
8935}
8936
8937template<typename Derived>
8940 // Transform the body.
8941 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8942 if (Body.isInvalid())
8943 return StmtError();
8944
8945 // If nothing changed, just retain this statement.
8946 if (!getDerived().AlwaysRebuild() &&
8947 Body.get() == S->getFinallyBody())
8948 return S;
8949
8950 // Build a new statement.
8951 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8952 Body.get());
8953}
8954
8955template<typename Derived>
8959 if (S->getThrowExpr()) {
8960 Operand = getDerived().TransformExpr(S->getThrowExpr());
8961 if (Operand.isInvalid())
8962 return StmtError();
8963 }
8964
8965 if (!getDerived().AlwaysRebuild() &&
8966 Operand.get() == S->getThrowExpr())
8967 return S;
8968
8969 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8970}
8971
8972template<typename Derived>
8976 // Transform the object we are locking.
8977 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8978 if (Object.isInvalid())
8979 return StmtError();
8980 Object =
8981 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8982 Object.get());
8983 if (Object.isInvalid())
8984 return StmtError();
8985
8986 // Transform the body.
8987 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8988 if (Body.isInvalid())
8989 return StmtError();
8990
8991 // If nothing change, just retain the current statement.
8992 if (!getDerived().AlwaysRebuild() &&
8993 Object.get() == S->getSynchExpr() &&
8994 Body.get() == S->getSynchBody())
8995 return S;
8996
8997 // Build a new statement.
8998 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8999 Object.get(), Body.get());
9000}
9001
9002template<typename Derived>
9006 // Transform the body.
9007 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9008 if (Body.isInvalid())
9009 return StmtError();
9010
9011 // If nothing changed, just retain this statement.
9012 if (!getDerived().AlwaysRebuild() &&
9013 Body.get() == S->getSubStmt())
9014 return S;
9015
9016 // Build a new statement.
9017 return getDerived().RebuildObjCAutoreleasePoolStmt(
9018 S->getAtLoc(), Body.get());
9019}
9020
9021template<typename Derived>
9025 // Transform the element statement.
9026 StmtResult Element = getDerived().TransformStmt(
9027 S->getElement(), StmtDiscardKind::NotDiscarded);
9028 if (Element.isInvalid())
9029 return StmtError();
9030
9031 // Transform the collection expression.
9032 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9033 if (Collection.isInvalid())
9034 return StmtError();
9035
9036 // Transform the body.
9037 StmtResult Body = getDerived().TransformStmt(S->getBody());
9038 if (Body.isInvalid())
9039 return StmtError();
9040
9041 // If nothing changed, just retain this statement.
9042 if (!getDerived().AlwaysRebuild() &&
9043 Element.get() == S->getElement() &&
9044 Collection.get() == S->getCollection() &&
9045 Body.get() == S->getBody())
9046 return S;
9047
9048 // Build a new statement.
9049 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9050 Element.get(),
9051 Collection.get(),
9052 S->getRParenLoc(),
9053 Body.get());
9054}
9055
9056template <typename Derived>
9058 // Transform the exception declaration, if any.
9059 VarDecl *Var = nullptr;
9060 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9061 TypeSourceInfo *T =
9062 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9063 if (!T)
9064 return StmtError();
9065
9066 Var = getDerived().RebuildExceptionDecl(
9067 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9068 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9069 if (!Var || Var->isInvalidDecl())
9070 return StmtError();
9071 }
9072
9073 // Transform the actual exception handler.
9074 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9075 if (Handler.isInvalid())
9076 return StmtError();
9077
9078 if (!getDerived().AlwaysRebuild() && !Var &&
9079 Handler.get() == S->getHandlerBlock())
9080 return S;
9081
9082 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9083}
9084
9085template <typename Derived>
9087 // Transform the try block itself.
9088 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9089 if (TryBlock.isInvalid())
9090 return StmtError();
9091
9092 // Transform the handlers.
9093 bool HandlerChanged = false;
9094 SmallVector<Stmt *, 8> Handlers;
9095 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9096 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9097 if (Handler.isInvalid())
9098 return StmtError();
9099
9100 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9101 Handlers.push_back(Handler.getAs<Stmt>());
9102 }
9103
9104 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9105
9106 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9107 !HandlerChanged)
9108 return S;
9109
9110 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9111 Handlers);
9112}
9113
9114template<typename Derived>
9117 EnterExpressionEvaluationContext ForRangeInitContext(
9119 /*LambdaContextDecl=*/nullptr,
9121 getSema().getLangOpts().CPlusPlus23);
9122
9123 // P2718R0 - Lifetime extension in range-based for loops.
9124 if (getSema().getLangOpts().CPlusPlus23) {
9125 auto &LastRecord = getSema().currentEvaluationContext();
9126 LastRecord.InLifetimeExtendingContext = true;
9127 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9128 }
9130 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9131 if (Init.isInvalid())
9132 return StmtError();
9133
9134 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9135 if (Range.isInvalid())
9136 return StmtError();
9137
9138 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9139 assert(getSema().getLangOpts().CPlusPlus23 ||
9140 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9141 auto ForRangeLifetimeExtendTemps =
9142 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9143
9144 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9145 if (Begin.isInvalid())
9146 return StmtError();
9147 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9148 if (End.isInvalid())
9149 return StmtError();
9150
9151 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9152 if (Cond.isInvalid())
9153 return StmtError();
9154 if (Cond.get())
9155 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9156 if (Cond.isInvalid())
9157 return StmtError();
9158 if (Cond.get())
9159 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9160
9161 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9162 if (Inc.isInvalid())
9163 return StmtError();
9164 if (Inc.get())
9165 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9166
9167 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9168 if (LoopVar.isInvalid())
9169 return StmtError();
9170
9171 StmtResult NewStmt = S;
9172 if (getDerived().AlwaysRebuild() ||
9173 Init.get() != S->getInit() ||
9174 Range.get() != S->getRangeStmt() ||
9175 Begin.get() != S->getBeginStmt() ||
9176 End.get() != S->getEndStmt() ||
9177 Cond.get() != S->getCond() ||
9178 Inc.get() != S->getInc() ||
9179 LoopVar.get() != S->getLoopVarStmt()) {
9180 NewStmt = getDerived().RebuildCXXForRangeStmt(
9181 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9182 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9183 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9184 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9185 // Might not have attached any initializer to the loop variable.
9186 getSema().ActOnInitializerError(
9187 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9188 return StmtError();
9189 }
9190 }
9191
9192 // OpenACC Restricts a while-loop inside of certain construct/clause
9193 // combinations, so diagnose that here in OpenACC mode.
9195 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9196
9197 StmtResult Body = getDerived().TransformStmt(S->getBody());
9198 if (Body.isInvalid())
9199 return StmtError();
9200
9201 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9202
9203 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9204 // it now so we have a new statement to attach the body to.
9205 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9206 NewStmt = getDerived().RebuildCXXForRangeStmt(
9207 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9208 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9209 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9210 if (NewStmt.isInvalid())
9211 return StmtError();
9212 }
9213
9214 if (NewStmt.get() == S)
9215 return S;
9216
9217 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9218}
9219
9220template<typename Derived>
9224 // Transform the nested-name-specifier, if any.
9225 NestedNameSpecifierLoc QualifierLoc;
9226 if (S->getQualifierLoc()) {
9227 QualifierLoc
9228 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9229 if (!QualifierLoc)
9230 return StmtError();
9231 }
9232
9233 // Transform the declaration name.
9234 DeclarationNameInfo NameInfo = S->getNameInfo();
9235 if (NameInfo.getName()) {
9236 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9237 if (!NameInfo.getName())
9238 return StmtError();
9239 }
9240
9241 // Check whether anything changed.
9242 if (!getDerived().AlwaysRebuild() &&
9243 QualifierLoc == S->getQualifierLoc() &&
9244 NameInfo.getName() == S->getNameInfo().getName())
9245 return S;
9246
9247 // Determine whether this name exists, if we can.
9248 CXXScopeSpec SS;
9249 SS.Adopt(QualifierLoc);
9250 bool Dependent = false;
9251 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9253 if (S->isIfExists())
9254 break;
9255
9256 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9257
9259 if (S->isIfNotExists())
9260 break;
9261
9262 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9263
9265 Dependent = true;
9266 break;
9267
9269 return StmtError();
9270 }
9271
9272 // We need to continue with the instantiation, so do so now.
9273 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9274 if (SubStmt.isInvalid())
9275 return StmtError();
9276
9277 // If we have resolved the name, just transform to the substatement.
9278 if (!Dependent)
9279 return SubStmt;
9280
9281 // The name is still dependent, so build a dependent expression again.
9282 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9283 S->isIfExists(),
9284 QualifierLoc,
9285 NameInfo,
9286 SubStmt.get());
9287}
9288
9289template<typename Derived>
9292 NestedNameSpecifierLoc QualifierLoc;
9293 if (E->getQualifierLoc()) {
9294 QualifierLoc
9295 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9296 if (!QualifierLoc)
9297 return ExprError();
9298 }
9299
9300 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9301 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9302 if (!PD)
9303 return ExprError();
9304
9305 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9306 if (Base.isInvalid())
9307 return ExprError();
9308
9309 return new (SemaRef.getASTContext())
9310 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9312 QualifierLoc, E->getMemberLoc());
9313}
9314
9315template <typename Derived>
9318 auto BaseRes = getDerived().TransformExpr(E->getBase());
9319 if (BaseRes.isInvalid())
9320 return ExprError();
9321 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9322 if (IdxRes.isInvalid())
9323 return ExprError();
9324
9325 if (!getDerived().AlwaysRebuild() &&
9326 BaseRes.get() == E->getBase() &&
9327 IdxRes.get() == E->getIdx())
9328 return E;
9329
9330 return getDerived().RebuildArraySubscriptExpr(
9331 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9332}
9333
9334template <typename Derived>
9336 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9337 if (TryBlock.isInvalid())
9338 return StmtError();
9339
9340 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9341 if (Handler.isInvalid())
9342 return StmtError();
9343
9344 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9345 Handler.get() == S->getHandler())
9346 return S;
9347
9348 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9349 TryBlock.get(), Handler.get());
9350}
9351
9352template <typename Derived>
9354 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9355 if (Block.isInvalid())
9356 return StmtError();
9357
9358 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9359}
9360
9361template <typename Derived>
9363 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9364 if (FilterExpr.isInvalid())
9365 return StmtError();
9366
9367 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9368 if (Block.isInvalid())
9369 return StmtError();
9370
9371 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9372 Block.get());
9373}
9374
9375template <typename Derived>
9377 if (isa<SEHFinallyStmt>(Handler))
9378 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9379 else
9380 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9381}
9382
9383template<typename Derived>
9386 return S;
9387}
9388
9389//===----------------------------------------------------------------------===//
9390// OpenMP directive transformation
9391//===----------------------------------------------------------------------===//
9392
9393template <typename Derived>
9394StmtResult
9395TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9396 // OMPCanonicalLoops are eliminated during transformation, since they will be
9397 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9398 // after transformation.
9399 return getDerived().TransformStmt(L->getLoopStmt());
9400}
9401
9402template <typename Derived>
9405
9406 // Transform the clauses
9408 ArrayRef<OMPClause *> Clauses = D->clauses();
9409 TClauses.reserve(Clauses.size());
9410 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9411 I != E; ++I) {
9412 if (*I) {
9413 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9414 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9415 getDerived().getSema().OpenMP().EndOpenMPClause();
9416 if (Clause)
9417 TClauses.push_back(Clause);
9418 } else {
9419 TClauses.push_back(nullptr);
9420 }
9421 }
9422 StmtResult AssociatedStmt;
9423 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9424 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9425 D->getDirectiveKind(),
9426 /*CurScope=*/nullptr);
9427 StmtResult Body;
9428 {
9429 Sema::CompoundScopeRAII CompoundScope(getSema());
9430 Stmt *CS;
9431 if (D->getDirectiveKind() == OMPD_atomic ||
9432 D->getDirectiveKind() == OMPD_critical ||
9433 D->getDirectiveKind() == OMPD_section ||
9434 D->getDirectiveKind() == OMPD_master)
9435 CS = D->getAssociatedStmt();
9436 else
9437 CS = D->getRawStmt();
9438 Body = getDerived().TransformStmt(CS);
9439 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9440 getSema().getLangOpts().OpenMPIRBuilder)
9441 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9442 }
9443 AssociatedStmt =
9444 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9445 if (AssociatedStmt.isInvalid()) {
9446 return StmtError();
9447 }
9448 }
9449 if (TClauses.size() != Clauses.size()) {
9450 return StmtError();
9451 }
9452
9453 // Transform directive name for 'omp critical' directive.
9454 DeclarationNameInfo DirName;
9455 if (D->getDirectiveKind() == OMPD_critical) {
9456 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9457 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9458 }
9459 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9460 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9461 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9462 } else if (D->getDirectiveKind() == OMPD_cancel) {
9463 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9464 }
9465
9466 return getDerived().RebuildOMPExecutableDirective(
9467 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9468 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9469}
9470
9471/// This is mostly the same as above, but allows 'informational' class
9472/// directives when rebuilding the stmt. It still takes an
9473/// OMPExecutableDirective-type argument because we're reusing that as the
9474/// superclass for the 'assume' directive at present, instead of defining a
9475/// mostly-identical OMPInformationalDirective parent class.
9476template <typename Derived>
9479
9480 // Transform the clauses
9482 ArrayRef<OMPClause *> Clauses = D->clauses();
9483 TClauses.reserve(Clauses.size());
9484 for (OMPClause *C : Clauses) {
9485 if (C) {
9486 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9487 OMPClause *Clause = getDerived().TransformOMPClause(C);
9488 getDerived().getSema().OpenMP().EndOpenMPClause();
9489 if (Clause)
9490 TClauses.push_back(Clause);
9491 } else {
9492 TClauses.push_back(nullptr);
9493 }
9494 }
9495 StmtResult AssociatedStmt;
9496 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9497 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9498 D->getDirectiveKind(),
9499 /*CurScope=*/nullptr);
9500 StmtResult Body;
9501 {
9502 Sema::CompoundScopeRAII CompoundScope(getSema());
9503 assert(D->getDirectiveKind() == OMPD_assume &&
9504 "Unexpected informational directive");
9505 Stmt *CS = D->getAssociatedStmt();
9506 Body = getDerived().TransformStmt(CS);
9507 }
9508 AssociatedStmt =
9509 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9510 if (AssociatedStmt.isInvalid())
9511 return StmtError();
9512 }
9513 if (TClauses.size() != Clauses.size())
9514 return StmtError();
9515
9516 DeclarationNameInfo DirName;
9517
9518 return getDerived().RebuildOMPInformationalDirective(
9519 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9520 D->getBeginLoc(), D->getEndLoc());
9521}
9522
9523template <typename Derived>
9526 // TODO: Fix This
9527 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9528 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9529 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9530 return StmtError();
9531}
9532
9533template <typename Derived>
9534StmtResult
9535TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9536 DeclarationNameInfo DirName;
9537 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9538 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9539 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9540 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9541 return Res;
9542}
9543
9544template <typename Derived>
9547 DeclarationNameInfo DirName;
9548 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9549 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9550 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9551 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9552 return Res;
9553}
9554
9555template <typename Derived>
9558 DeclarationNameInfo DirName;
9559 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9560 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9561 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9562 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9563 return Res;
9564}
9565
9566template <typename Derived>
9569 DeclarationNameInfo DirName;
9570 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9571 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9572 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9573 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9574 return Res;
9575}
9576
9577template <typename Derived>
9580 DeclarationNameInfo DirName;
9581 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9582 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9583 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9584 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9585 return Res;
9586}
9587
9588template <typename Derived>
9591 DeclarationNameInfo DirName;
9592 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9593 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9594 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9595 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9596 return Res;
9597}
9598
9599template <typename Derived>
9601 OMPInterchangeDirective *D) {
9602 DeclarationNameInfo DirName;
9603 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9604 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9605 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9606 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9607 return Res;
9608}
9609
9610template <typename Derived>
9613 DeclarationNameInfo DirName;
9614 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9615 OMPD_for, DirName, nullptr, D->getBeginLoc());
9616 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9617 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9618 return Res;
9619}
9620
9621template <typename Derived>
9624 DeclarationNameInfo DirName;
9625 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9626 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9627 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9628 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9629 return Res;
9630}
9631
9632template <typename Derived>
9635 DeclarationNameInfo DirName;
9636 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9637 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9638 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9639 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9640 return Res;
9641}
9642
9643template <typename Derived>
9646 DeclarationNameInfo DirName;
9647 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9648 OMPD_section, DirName, nullptr, D->getBeginLoc());
9649 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9650 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9651 return Res;
9652}
9653
9654template <typename Derived>
9657 DeclarationNameInfo DirName;
9658 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9659 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9660 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9661 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9662 return Res;
9663}
9664
9665template <typename Derived>
9668 DeclarationNameInfo DirName;
9669 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9670 OMPD_single, DirName, nullptr, D->getBeginLoc());
9671 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9672 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9673 return Res;
9674}
9675
9676template <typename Derived>
9679 DeclarationNameInfo DirName;
9680 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9681 OMPD_master, DirName, nullptr, D->getBeginLoc());
9682 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9683 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9684 return Res;
9685}
9686
9687template <typename Derived>
9690 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9691 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9692 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9693 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9694 return Res;
9695}
9696
9697template <typename Derived>
9699 OMPParallelForDirective *D) {
9700 DeclarationNameInfo DirName;
9701 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9702 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9703 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9704 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9705 return Res;
9706}
9707
9708template <typename Derived>
9710 OMPParallelForSimdDirective *D) {
9711 DeclarationNameInfo DirName;
9712 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9713 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9714 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9715 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9716 return Res;
9717}
9718
9719template <typename Derived>
9721 OMPParallelMasterDirective *D) {
9722 DeclarationNameInfo DirName;
9723 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9724 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9725 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9726 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9727 return Res;
9728}
9729
9730template <typename Derived>
9732 OMPParallelMaskedDirective *D) {
9733 DeclarationNameInfo DirName;
9734 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9735 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9736 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9737 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9738 return Res;
9739}
9740
9741template <typename Derived>
9743 OMPParallelSectionsDirective *D) {
9744 DeclarationNameInfo DirName;
9745 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9746 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9747 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9748 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9749 return Res;
9750}
9751
9752template <typename Derived>
9755 DeclarationNameInfo DirName;
9756 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9757 OMPD_task, DirName, nullptr, D->getBeginLoc());
9758 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9759 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9760 return Res;
9761}
9762
9763template <typename Derived>
9765 OMPTaskyieldDirective *D) {
9766 DeclarationNameInfo DirName;
9767 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9768 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9769 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9770 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9771 return Res;
9772}
9773
9774template <typename Derived>
9777 DeclarationNameInfo DirName;
9778 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9779 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9780 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9781 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9782 return Res;
9783}
9784
9785template <typename Derived>
9788 DeclarationNameInfo DirName;
9789 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9790 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9791 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9792 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9793 return Res;
9794}
9795
9796template <typename Derived>
9799 DeclarationNameInfo DirName;
9800 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9801 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9802 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9803 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9804 return Res;
9805}
9806
9807template <typename Derived>
9810 DeclarationNameInfo DirName;
9811 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9812 OMPD_error, DirName, nullptr, D->getBeginLoc());
9813 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9814 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9815 return Res;
9816}
9817
9818template <typename Derived>
9820 OMPTaskgroupDirective *D) {
9821 DeclarationNameInfo DirName;
9822 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9823 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9824 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9825 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9826 return Res;
9827}
9828
9829template <typename Derived>
9832 DeclarationNameInfo DirName;
9833 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9834 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9835 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9836 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9837 return Res;
9838}
9839
9840template <typename Derived>
9843 DeclarationNameInfo DirName;
9844 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9845 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9846 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9847 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9848 return Res;
9849}
9850
9851template <typename Derived>
9854 DeclarationNameInfo DirName;
9855 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9856 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9857 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9858 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9859 return Res;
9860}
9861
9862template <typename Derived>
9865 DeclarationNameInfo DirName;
9866 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9867 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9869 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9870 return Res;
9871}
9872
9873template <typename Derived>
9876 DeclarationNameInfo DirName;
9877 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9878 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9879 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9880 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9881 return Res;
9882}
9883
9884template <typename Derived>
9887 DeclarationNameInfo DirName;
9888 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9889 OMPD_target, DirName, nullptr, D->getBeginLoc());
9890 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9891 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9892 return Res;
9893}
9894
9895template <typename Derived>
9897 OMPTargetDataDirective *D) {
9898 DeclarationNameInfo DirName;
9899 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9900 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9902 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9903 return Res;
9904}
9905
9906template <typename Derived>
9908 OMPTargetEnterDataDirective *D) {
9909 DeclarationNameInfo DirName;
9910 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9911 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9913 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9914 return Res;
9915}
9916
9917template <typename Derived>
9919 OMPTargetExitDataDirective *D) {
9920 DeclarationNameInfo DirName;
9921 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9922 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9924 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9925 return Res;
9926}
9927
9928template <typename Derived>
9930 OMPTargetParallelDirective *D) {
9931 DeclarationNameInfo DirName;
9932 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9933 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9935 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9936 return Res;
9937}
9938
9939template <typename Derived>
9941 OMPTargetParallelForDirective *D) {
9942 DeclarationNameInfo DirName;
9943 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9944 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9946 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9947 return Res;
9948}
9949
9950template <typename Derived>
9952 OMPTargetUpdateDirective *D) {
9953 DeclarationNameInfo DirName;
9954 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9955 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9957 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9958 return Res;
9959}
9960
9961template <typename Derived>
9964 DeclarationNameInfo DirName;
9965 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9966 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9968 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9969 return Res;
9970}
9971
9972template <typename Derived>
9974 OMPCancellationPointDirective *D) {
9975 DeclarationNameInfo DirName;
9976 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9977 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9979 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9980 return Res;
9981}
9982
9983template <typename Derived>
9986 DeclarationNameInfo DirName;
9987 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9988 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9990 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9991 return Res;
9992}
9993
9994template <typename Derived>
9997 DeclarationNameInfo DirName;
9998 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9999 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10001 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10002 return Res;
10003}
10004
10005template <typename Derived>
10007 OMPTaskLoopSimdDirective *D) {
10008 DeclarationNameInfo DirName;
10009 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10010 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10012 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10013 return Res;
10014}
10015
10016template <typename Derived>
10018 OMPMasterTaskLoopDirective *D) {
10019 DeclarationNameInfo DirName;
10020 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10021 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10023 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10024 return Res;
10025}
10026
10027template <typename Derived>
10029 OMPMaskedTaskLoopDirective *D) {
10030 DeclarationNameInfo DirName;
10031 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10032 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10034 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10035 return Res;
10036}
10037
10038template <typename Derived>
10040 OMPMasterTaskLoopSimdDirective *D) {
10041 DeclarationNameInfo DirName;
10042 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10043 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10045 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10046 return Res;
10047}
10048
10049template <typename Derived>
10051 OMPMaskedTaskLoopSimdDirective *D) {
10052 DeclarationNameInfo DirName;
10053 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10054 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10056 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10057 return Res;
10058}
10059
10060template <typename Derived>
10062 OMPParallelMasterTaskLoopDirective *D) {
10063 DeclarationNameInfo DirName;
10064 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10065 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10067 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10068 return Res;
10069}
10070
10071template <typename Derived>
10073 OMPParallelMaskedTaskLoopDirective *D) {
10074 DeclarationNameInfo DirName;
10075 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10076 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10077 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10078 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10079 return Res;
10080}
10081
10082template <typename Derived>
10085 OMPParallelMasterTaskLoopSimdDirective *D) {
10086 DeclarationNameInfo DirName;
10087 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10088 OMPD_parallel_master_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>
10097 OMPParallelMaskedTaskLoopSimdDirective *D) {
10098 DeclarationNameInfo DirName;
10099 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10100 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10101 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10102 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10103 return Res;
10104}
10105
10106template <typename Derived>
10108 OMPDistributeDirective *D) {
10109 DeclarationNameInfo DirName;
10110 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10111 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10112 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10113 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10114 return Res;
10115}
10116
10117template <typename Derived>
10119 OMPDistributeParallelForDirective *D) {
10120 DeclarationNameInfo DirName;
10121 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10122 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10123 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10124 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10125 return Res;
10126}
10127
10128template <typename Derived>
10131 OMPDistributeParallelForSimdDirective *D) {
10132 DeclarationNameInfo DirName;
10133 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10134 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10135 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10136 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10137 return Res;
10138}
10139
10140template <typename Derived>
10142 OMPDistributeSimdDirective *D) {
10143 DeclarationNameInfo DirName;
10144 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10145 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10146 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10147 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10148 return Res;
10149}
10150
10151template <typename Derived>
10153 OMPTargetParallelForSimdDirective *D) {
10154 DeclarationNameInfo DirName;
10155 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10156 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10157 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10158 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10159 return Res;
10160}
10161
10162template <typename Derived>
10164 OMPTargetSimdDirective *D) {
10165 DeclarationNameInfo DirName;
10166 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10167 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10168 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10169 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10170 return Res;
10171}
10172
10173template <typename Derived>
10175 OMPTeamsDistributeDirective *D) {
10176 DeclarationNameInfo DirName;
10177 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10178 OMPD_teams_distribute, 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 OMPTeamsDistributeSimdDirective *D) {
10187 DeclarationNameInfo DirName;
10188 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10189 OMPD_teams_distribute_simd, 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 OMPTeamsDistributeParallelForSimdDirective *D) {
10198 DeclarationNameInfo DirName;
10199 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10200 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10201 D->getBeginLoc());
10202 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10203 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10204 return Res;
10205}
10206
10207template <typename Derived>
10209 OMPTeamsDistributeParallelForDirective *D) {
10210 DeclarationNameInfo DirName;
10211 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10212 OMPD_teams_distribute_parallel_for, 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 OMPTargetTeamsDirective *D) {
10221 DeclarationNameInfo DirName;
10222 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10223 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10224 auto Res = getDerived().TransformOMPExecutableDirective(D);
10225 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10226 return Res;
10227}
10228
10229template <typename Derived>
10231 OMPTargetTeamsDistributeDirective *D) {
10232 DeclarationNameInfo DirName;
10233 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10234 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10235 auto Res = getDerived().TransformOMPExecutableDirective(D);
10236 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10237 return Res;
10238}
10239
10240template <typename Derived>
10243 OMPTargetTeamsDistributeParallelForDirective *D) {
10244 DeclarationNameInfo DirName;
10245 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10246 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10247 D->getBeginLoc());
10248 auto Res = getDerived().TransformOMPExecutableDirective(D);
10249 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10250 return Res;
10251}
10252
10253template <typename Derived>
10256 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10257 DeclarationNameInfo DirName;
10258 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10259 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10260 D->getBeginLoc());
10261 auto Res = getDerived().TransformOMPExecutableDirective(D);
10262 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10263 return Res;
10264}
10265
10266template <typename Derived>
10269 OMPTargetTeamsDistributeSimdDirective *D) {
10270 DeclarationNameInfo DirName;
10271 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10272 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10273 auto Res = getDerived().TransformOMPExecutableDirective(D);
10274 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10275 return Res;
10276}
10277
10278template <typename Derived>
10281 DeclarationNameInfo DirName;
10282 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10283 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10285 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10286 return Res;
10287}
10288
10289template <typename Derived>
10292 DeclarationNameInfo DirName;
10293 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10294 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10295 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10296 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10297 return Res;
10298}
10299
10300template <typename Derived>
10303 DeclarationNameInfo DirName;
10304 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10305 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10307 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10308 return Res;
10309}
10310
10311template <typename Derived>
10313 OMPGenericLoopDirective *D) {
10314 DeclarationNameInfo DirName;
10315 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10316 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10318 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10319 return Res;
10320}
10321
10322template <typename Derived>
10324 OMPTeamsGenericLoopDirective *D) {
10325 DeclarationNameInfo DirName;
10326 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10327 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10329 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10330 return Res;
10331}
10332
10333template <typename Derived>
10335 OMPTargetTeamsGenericLoopDirective *D) {
10336 DeclarationNameInfo DirName;
10337 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10338 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10340 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10341 return Res;
10342}
10343
10344template <typename Derived>
10346 OMPParallelGenericLoopDirective *D) {
10347 DeclarationNameInfo DirName;
10348 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10349 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10350 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10351 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10352 return Res;
10353}
10354
10355template <typename Derived>
10358 OMPTargetParallelGenericLoopDirective *D) {
10359 DeclarationNameInfo DirName;
10360 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10361 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10363 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10364 return Res;
10365}
10366
10367//===----------------------------------------------------------------------===//
10368// OpenMP clause transformation
10369//===----------------------------------------------------------------------===//
10370template <typename Derived>
10372 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10373 if (Cond.isInvalid())
10374 return nullptr;
10375 return getDerived().RebuildOMPIfClause(
10376 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10377 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10378}
10379
10380template <typename Derived>
10382 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10383 if (Cond.isInvalid())
10384 return nullptr;
10385 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10386 C->getLParenLoc(), C->getEndLoc());
10387}
10388
10389template <typename Derived>
10390OMPClause *
10392 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10393 if (NumThreads.isInvalid())
10394 return nullptr;
10395 return getDerived().RebuildOMPNumThreadsClause(
10396 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10397 C->getModifierLoc(), C->getEndLoc());
10398}
10399
10400template <typename Derived>
10401OMPClause *
10403 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10404 if (E.isInvalid())
10405 return nullptr;
10406 return getDerived().RebuildOMPSafelenClause(
10407 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10408}
10409
10410template <typename Derived>
10411OMPClause *
10413 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10414 if (E.isInvalid())
10415 return nullptr;
10416 return getDerived().RebuildOMPAllocatorClause(
10417 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10418}
10419
10420template <typename Derived>
10421OMPClause *
10423 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10424 if (E.isInvalid())
10425 return nullptr;
10426 return getDerived().RebuildOMPSimdlenClause(
10427 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10428}
10429
10430template <typename Derived>
10432 SmallVector<Expr *, 4> TransformedSizes;
10433 TransformedSizes.reserve(C->getNumSizes());
10434 bool Changed = false;
10435 for (Expr *E : C->getSizesRefs()) {
10436 if (!E) {
10437 TransformedSizes.push_back(nullptr);
10438 continue;
10439 }
10440
10441 ExprResult T = getDerived().TransformExpr(E);
10442 if (T.isInvalid())
10443 return nullptr;
10444 if (E != T.get())
10445 Changed = true;
10446 TransformedSizes.push_back(T.get());
10447 }
10448
10449 if (!Changed && !getDerived().AlwaysRebuild())
10450 return C;
10451 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10452 C->getLParenLoc(), C->getEndLoc());
10453}
10454
10455template <typename Derived>
10456OMPClause *
10458 SmallVector<Expr *> TransformedArgs;
10459 TransformedArgs.reserve(C->getNumLoops());
10460 bool Changed = false;
10461 for (Expr *E : C->getArgsRefs()) {
10462 if (!E) {
10463 TransformedArgs.push_back(nullptr);
10464 continue;
10465 }
10466
10467 ExprResult T = getDerived().TransformExpr(E);
10468 if (T.isInvalid())
10469 return nullptr;
10470 if (E != T.get())
10471 Changed = true;
10472 TransformedArgs.push_back(T.get());
10473 }
10474
10475 if (!Changed && !getDerived().AlwaysRebuild())
10476 return C;
10477 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10478 C->getLParenLoc(), C->getEndLoc());
10479}
10480
10481template <typename Derived>
10483 if (!getDerived().AlwaysRebuild())
10484 return C;
10485 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10486}
10487
10488template <typename Derived>
10489OMPClause *
10491 ExprResult T = getDerived().TransformExpr(C->getFactor());
10492 if (T.isInvalid())
10493 return nullptr;
10494 Expr *Factor = T.get();
10495 bool Changed = Factor != C->getFactor();
10496
10497 if (!Changed && !getDerived().AlwaysRebuild())
10498 return C;
10499 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10500 C->getEndLoc());
10501}
10502
10503template <typename Derived>
10504OMPClause *
10506 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10507 if (E.isInvalid())
10508 return nullptr;
10509 return getDerived().RebuildOMPCollapseClause(
10510 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10511}
10512
10513template <typename Derived>
10514OMPClause *
10516 return getDerived().RebuildOMPDefaultClause(
10517 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10518 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10519 C->getEndLoc());
10520}
10521
10522template <typename Derived>
10523OMPClause *
10525 return getDerived().RebuildOMPProcBindClause(
10526 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10527 C->getLParenLoc(), C->getEndLoc());
10528}
10529
10530template <typename Derived>
10531OMPClause *
10533 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10534 if (E.isInvalid())
10535 return nullptr;
10536 return getDerived().RebuildOMPScheduleClause(
10537 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10538 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10539 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10540 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10541}
10542
10543template <typename Derived>
10544OMPClause *
10546 ExprResult E;
10547 if (auto *Num = C->getNumForLoops()) {
10548 E = getDerived().TransformExpr(Num);
10549 if (E.isInvalid())
10550 return nullptr;
10551 }
10552 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10553 C->getLParenLoc(), E.get());
10554}
10555
10556template <typename Derived>
10557OMPClause *
10559 ExprResult E;
10560 if (Expr *Evt = C->getEventHandler()) {
10561 E = getDerived().TransformExpr(Evt);
10562 if (E.isInvalid())
10563 return nullptr;
10564 }
10565 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10566 C->getLParenLoc(), C->getEndLoc());
10567}
10568
10569template <typename Derived>
10570OMPClause *
10572 // No need to rebuild this clause, no template-dependent parameters.
10573 return C;
10574}
10575
10576template <typename Derived>
10577OMPClause *
10579 // No need to rebuild this clause, no template-dependent parameters.
10580 return C;
10581}
10582
10583template <typename Derived>
10584OMPClause *
10586 // No need to rebuild this clause, no template-dependent parameters.
10587 return C;
10588}
10589
10590template <typename Derived>
10592 // No need to rebuild this clause, no template-dependent parameters.
10593 return C;
10594}
10595
10596template <typename Derived>
10598 // No need to rebuild this clause, no template-dependent parameters.
10599 return C;
10600}
10601
10602template <typename Derived>
10603OMPClause *
10605 // No need to rebuild this clause, no template-dependent parameters.
10606 return C;
10607}
10608
10609template <typename Derived>
10610OMPClause *
10612 // No need to rebuild this clause, no template-dependent parameters.
10613 return C;
10614}
10615
10616template <typename Derived>
10617OMPClause *
10619 // No need to rebuild this clause, no template-dependent parameters.
10620 return C;
10621}
10622
10623template <typename Derived>
10625 // No need to rebuild this clause, no template-dependent parameters.
10626 return C;
10627}
10628
10629template <typename Derived>
10630OMPClause *
10632 return C;
10633}
10634
10635template <typename Derived>
10637 ExprResult E = getDerived().TransformExpr(C->getExpr());
10638 if (E.isInvalid())
10639 return nullptr;
10640 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10641 C->getLParenLoc(), C->getEndLoc());
10642}
10643
10644template <typename Derived>
10645OMPClause *
10647 return C;
10648}
10649
10650template <typename Derived>
10651OMPClause *
10653 return C;
10654}
10655template <typename Derived>
10658 return C;
10659}
10660template <typename Derived>
10663 return C;
10664}
10665template <typename Derived>
10668 return C;
10669}
10670
10671template <typename Derived>
10672OMPClause *
10674 // No need to rebuild this clause, no template-dependent parameters.
10675 return C;
10676}
10677
10678template <typename Derived>
10679OMPClause *
10681 // No need to rebuild this clause, no template-dependent parameters.
10682 return C;
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>
10700OMPClause *
10702 // No need to rebuild this clause, no template-dependent parameters.
10703 return C;
10704}
10705
10706template <typename Derived>
10708 // No need to rebuild this clause, no template-dependent parameters.
10709 return C;
10710}
10711
10712template <typename Derived>
10713OMPClause *
10715 // No need to rebuild this clause, no template-dependent parameters.
10716 return C;
10717}
10718
10719template <typename Derived>
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 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10735 if (IVR.isInvalid())
10736 return nullptr;
10737
10738 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10739 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10740 for (Expr *E : llvm::drop_begin(C->varlist())) {
10741 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10742 if (ER.isInvalid())
10743 return nullptr;
10744 InteropInfo.PreferTypes.push_back(ER.get());
10745 }
10746 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10747 C->getBeginLoc(), C->getLParenLoc(),
10748 C->getVarLoc(), C->getEndLoc());
10749}
10750
10751template <typename Derived>
10753 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10754 if (ER.isInvalid())
10755 return nullptr;
10756 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10757 C->getLParenLoc(), C->getVarLoc(),
10758 C->getEndLoc());
10759}
10760
10761template <typename Derived>
10762OMPClause *
10764 ExprResult ER;
10765 if (Expr *IV = C->getInteropVar()) {
10766 ER = getDerived().TransformExpr(IV);
10767 if (ER.isInvalid())
10768 return nullptr;
10769 }
10770 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10771 C->getLParenLoc(), C->getVarLoc(),
10772 C->getEndLoc());
10773}
10774
10775template <typename Derived>
10776OMPClause *
10778 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10779 if (Cond.isInvalid())
10780 return nullptr;
10781 return getDerived().RebuildOMPNovariantsClause(
10782 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10783}
10784
10785template <typename Derived>
10786OMPClause *
10788 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10789 if (Cond.isInvalid())
10790 return nullptr;
10791 return getDerived().RebuildOMPNocontextClause(
10792 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10793}
10794
10795template <typename Derived>
10796OMPClause *
10798 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10799 if (ThreadID.isInvalid())
10800 return nullptr;
10801 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10802 C->getLParenLoc(), C->getEndLoc());
10803}
10804
10805template <typename Derived>
10807 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10808 if (E.isInvalid())
10809 return nullptr;
10810 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10811 C->getLParenLoc(), C->getEndLoc());
10812}
10813
10814template <typename Derived>
10817 llvm_unreachable("unified_address clause cannot appear in dependent context");
10818}
10819
10820template <typename Derived>
10823 llvm_unreachable(
10824 "unified_shared_memory clause cannot appear in dependent context");
10825}
10826
10827template <typename Derived>
10830 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10831}
10832
10833template <typename Derived>
10836 llvm_unreachable(
10837 "dynamic_allocators clause cannot appear in dependent context");
10838}
10839
10840template <typename Derived>
10843 llvm_unreachable(
10844 "atomic_default_mem_order clause cannot appear in dependent context");
10845}
10846
10847template <typename Derived>
10848OMPClause *
10850 llvm_unreachable("self_maps clause cannot appear in dependent context");
10851}
10852
10853template <typename Derived>
10855 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10856 C->getBeginLoc(), C->getLParenLoc(),
10857 C->getEndLoc());
10858}
10859
10860template <typename Derived>
10861OMPClause *
10863 return getDerived().RebuildOMPSeverityClause(
10864 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10865 C->getLParenLoc(), C->getEndLoc());
10866}
10867
10868template <typename Derived>
10869OMPClause *
10871 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10872 if (E.isInvalid())
10873 return nullptr;
10874 return getDerived().RebuildOMPMessageClause(
10875 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10876}
10877
10878template <typename Derived>
10879OMPClause *
10882 Vars.reserve(C->varlist_size());
10883 for (auto *VE : C->varlist()) {
10884 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10885 if (EVar.isInvalid())
10886 return nullptr;
10887 Vars.push_back(EVar.get());
10888 }
10889 return getDerived().RebuildOMPPrivateClause(
10890 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10891}
10892
10893template <typename Derived>
10897 Vars.reserve(C->varlist_size());
10898 for (auto *VE : C->varlist()) {
10899 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10900 if (EVar.isInvalid())
10901 return nullptr;
10902 Vars.push_back(EVar.get());
10903 }
10904 return getDerived().RebuildOMPFirstprivateClause(
10905 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10906}
10907
10908template <typename Derived>
10909OMPClause *
10912 Vars.reserve(C->varlist_size());
10913 for (auto *VE : C->varlist()) {
10914 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10915 if (EVar.isInvalid())
10916 return nullptr;
10917 Vars.push_back(EVar.get());
10918 }
10919 return getDerived().RebuildOMPLastprivateClause(
10920 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10921 C->getLParenLoc(), C->getEndLoc());
10922}
10923
10924template <typename Derived>
10925OMPClause *
10928 Vars.reserve(C->varlist_size());
10929 for (auto *VE : C->varlist()) {
10930 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10931 if (EVar.isInvalid())
10932 return nullptr;
10933 Vars.push_back(EVar.get());
10934 }
10935 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10936 C->getLParenLoc(), C->getEndLoc());
10937}
10938
10939template <typename Derived>
10940OMPClause *
10943 Vars.reserve(C->varlist_size());
10944 for (auto *VE : C->varlist()) {
10945 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10946 if (EVar.isInvalid())
10947 return nullptr;
10948 Vars.push_back(EVar.get());
10949 }
10950 CXXScopeSpec ReductionIdScopeSpec;
10951 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10952
10953 DeclarationNameInfo NameInfo = C->getNameInfo();
10954 if (NameInfo.getName()) {
10955 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10956 if (!NameInfo.getName())
10957 return nullptr;
10958 }
10959 // Build a list of all UDR decls with the same names ranged by the Scopes.
10960 // The Scope boundary is a duplication of the previous decl.
10961 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10962 for (auto *E : C->reduction_ops()) {
10963 // Transform all the decls.
10964 if (E) {
10965 auto *ULE = cast<UnresolvedLookupExpr>(E);
10966 UnresolvedSet<8> Decls;
10967 for (auto *D : ULE->decls()) {
10968 NamedDecl *InstD =
10969 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10970 Decls.addDecl(InstD, InstD->getAccess());
10971 }
10972 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10973 SemaRef.Context, /*NamingClass=*/nullptr,
10974 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10975 /*ADL=*/true, Decls.begin(), Decls.end(),
10976 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10977 } else
10978 UnresolvedReductions.push_back(nullptr);
10979 }
10980 return getDerived().RebuildOMPReductionClause(
10981 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
10982 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10983 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10984}
10985
10986template <typename Derived>
10990 Vars.reserve(C->varlist_size());
10991 for (auto *VE : C->varlist()) {
10992 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10993 if (EVar.isInvalid())
10994 return nullptr;
10995 Vars.push_back(EVar.get());
10996 }
10997 CXXScopeSpec ReductionIdScopeSpec;
10998 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10999
11000 DeclarationNameInfo NameInfo = C->getNameInfo();
11001 if (NameInfo.getName()) {
11002 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11003 if (!NameInfo.getName())
11004 return nullptr;
11005 }
11006 // Build a list of all UDR decls with the same names ranged by the Scopes.
11007 // The Scope boundary is a duplication of the previous decl.
11008 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11009 for (auto *E : C->reduction_ops()) {
11010 // Transform all the decls.
11011 if (E) {
11012 auto *ULE = cast<UnresolvedLookupExpr>(E);
11013 UnresolvedSet<8> Decls;
11014 for (auto *D : ULE->decls()) {
11015 NamedDecl *InstD =
11016 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11017 Decls.addDecl(InstD, InstD->getAccess());
11018 }
11019 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11020 SemaRef.Context, /*NamingClass=*/nullptr,
11021 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11022 /*ADL=*/true, Decls.begin(), Decls.end(),
11023 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11024 } else
11025 UnresolvedReductions.push_back(nullptr);
11026 }
11027 return getDerived().RebuildOMPTaskReductionClause(
11028 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11029 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11030}
11031
11032template <typename Derived>
11033OMPClause *
11036 Vars.reserve(C->varlist_size());
11037 for (auto *VE : C->varlist()) {
11038 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11039 if (EVar.isInvalid())
11040 return nullptr;
11041 Vars.push_back(EVar.get());
11042 }
11043 CXXScopeSpec ReductionIdScopeSpec;
11044 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11045
11046 DeclarationNameInfo NameInfo = C->getNameInfo();
11047 if (NameInfo.getName()) {
11048 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11049 if (!NameInfo.getName())
11050 return nullptr;
11051 }
11052 // Build a list of all UDR decls with the same names ranged by the Scopes.
11053 // The Scope boundary is a duplication of the previous decl.
11054 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11055 for (auto *E : C->reduction_ops()) {
11056 // Transform all the decls.
11057 if (E) {
11058 auto *ULE = cast<UnresolvedLookupExpr>(E);
11059 UnresolvedSet<8> Decls;
11060 for (auto *D : ULE->decls()) {
11061 NamedDecl *InstD =
11062 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11063 Decls.addDecl(InstD, InstD->getAccess());
11064 }
11065 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11066 SemaRef.Context, /*NamingClass=*/nullptr,
11067 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11068 /*ADL=*/true, Decls.begin(), Decls.end(),
11069 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11070 } else
11071 UnresolvedReductions.push_back(nullptr);
11072 }
11073 return getDerived().RebuildOMPInReductionClause(
11074 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11075 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11076}
11077
11078template <typename Derived>
11079OMPClause *
11082 Vars.reserve(C->varlist_size());
11083 for (auto *VE : C->varlist()) {
11084 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11085 if (EVar.isInvalid())
11086 return nullptr;
11087 Vars.push_back(EVar.get());
11088 }
11089 ExprResult Step = getDerived().TransformExpr(C->getStep());
11090 if (Step.isInvalid())
11091 return nullptr;
11092 return getDerived().RebuildOMPLinearClause(
11093 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11094 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11095 C->getEndLoc());
11096}
11097
11098template <typename Derived>
11099OMPClause *
11102 Vars.reserve(C->varlist_size());
11103 for (auto *VE : C->varlist()) {
11104 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11105 if (EVar.isInvalid())
11106 return nullptr;
11107 Vars.push_back(EVar.get());
11108 }
11109 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11110 if (Alignment.isInvalid())
11111 return nullptr;
11112 return getDerived().RebuildOMPAlignedClause(
11113 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11114 C->getColonLoc(), C->getEndLoc());
11115}
11116
11117template <typename Derived>
11118OMPClause *
11121 Vars.reserve(C->varlist_size());
11122 for (auto *VE : C->varlist()) {
11123 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11124 if (EVar.isInvalid())
11125 return nullptr;
11126 Vars.push_back(EVar.get());
11127 }
11128 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11129 C->getLParenLoc(), C->getEndLoc());
11130}
11131
11132template <typename Derived>
11133OMPClause *
11136 Vars.reserve(C->varlist_size());
11137 for (auto *VE : C->varlist()) {
11138 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11139 if (EVar.isInvalid())
11140 return nullptr;
11141 Vars.push_back(EVar.get());
11142 }
11143 return getDerived().RebuildOMPCopyprivateClause(
11144 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11145}
11146
11147template <typename Derived>
11150 Vars.reserve(C->varlist_size());
11151 for (auto *VE : C->varlist()) {
11152 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11153 if (EVar.isInvalid())
11154 return nullptr;
11155 Vars.push_back(EVar.get());
11156 }
11157 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11158 C->getLParenLoc(), C->getEndLoc());
11159}
11160
11161template <typename Derived>
11162OMPClause *
11164 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11165 if (E.isInvalid())
11166 return nullptr;
11167 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11168 C->getLParenLoc(), C->getEndLoc());
11169}
11170
11171template <typename Derived>
11172OMPClause *
11175 Expr *DepModifier = C->getModifier();
11176 if (DepModifier) {
11177 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11178 if (DepModRes.isInvalid())
11179 return nullptr;
11180 DepModifier = DepModRes.get();
11181 }
11182 Vars.reserve(C->varlist_size());
11183 for (auto *VE : C->varlist()) {
11184 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11185 if (EVar.isInvalid())
11186 return nullptr;
11187 Vars.push_back(EVar.get());
11188 }
11189 return getDerived().RebuildOMPDependClause(
11190 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11191 C->getOmpAllMemoryLoc()},
11192 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11193}
11194
11195template <typename Derived>
11196OMPClause *
11198 ExprResult E = getDerived().TransformExpr(C->getDevice());
11199 if (E.isInvalid())
11200 return nullptr;
11201 return getDerived().RebuildOMPDeviceClause(
11202 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11203 C->getModifierLoc(), C->getEndLoc());
11204}
11205
11206template <typename Derived, class T>
11209 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11210 DeclarationNameInfo &MapperIdInfo,
11211 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11212 // Transform expressions in the list.
11213 Vars.reserve(C->varlist_size());
11214 for (auto *VE : C->varlist()) {
11215 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11216 if (EVar.isInvalid())
11217 return true;
11218 Vars.push_back(EVar.get());
11219 }
11220 // Transform mapper scope specifier and identifier.
11221 NestedNameSpecifierLoc QualifierLoc;
11222 if (C->getMapperQualifierLoc()) {
11223 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11224 C->getMapperQualifierLoc());
11225 if (!QualifierLoc)
11226 return true;
11227 }
11228 MapperIdScopeSpec.Adopt(QualifierLoc);
11229 MapperIdInfo = C->getMapperIdInfo();
11230 if (MapperIdInfo.getName()) {
11231 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11232 if (!MapperIdInfo.getName())
11233 return true;
11234 }
11235 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11236 // the previous user-defined mapper lookup in dependent environment.
11237 for (auto *E : C->mapperlists()) {
11238 // Transform all the decls.
11239 if (E) {
11240 auto *ULE = cast<UnresolvedLookupExpr>(E);
11241 UnresolvedSet<8> Decls;
11242 for (auto *D : ULE->decls()) {
11243 NamedDecl *InstD =
11244 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11245 Decls.addDecl(InstD, InstD->getAccess());
11246 }
11247 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11248 TT.getSema().Context, /*NamingClass=*/nullptr,
11249 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11250 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11251 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11252 } else {
11253 UnresolvedMappers.push_back(nullptr);
11254 }
11255 }
11256 return false;
11257}
11258
11259template <typename Derived>
11260OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11261 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11263 Expr *IteratorModifier = C->getIteratorModifier();
11264 if (IteratorModifier) {
11265 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11266 if (MapModRes.isInvalid())
11267 return nullptr;
11268 IteratorModifier = MapModRes.get();
11269 }
11270 CXXScopeSpec MapperIdScopeSpec;
11271 DeclarationNameInfo MapperIdInfo;
11272 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11274 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11275 return nullptr;
11276 return getDerived().RebuildOMPMapClause(
11277 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11278 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11279 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11280}
11281
11282template <typename Derived>
11283OMPClause *
11285 Expr *Allocator = C->getAllocator();
11286 if (Allocator) {
11287 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11288 if (AllocatorRes.isInvalid())
11289 return nullptr;
11290 Allocator = AllocatorRes.get();
11291 }
11292 Expr *Alignment = C->getAlignment();
11293 if (Alignment) {
11294 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11295 if (AlignmentRes.isInvalid())
11296 return nullptr;
11297 Alignment = AlignmentRes.get();
11298 }
11300 Vars.reserve(C->varlist_size());
11301 for (auto *VE : C->varlist()) {
11302 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11303 if (EVar.isInvalid())
11304 return nullptr;
11305 Vars.push_back(EVar.get());
11306 }
11307 return getDerived().RebuildOMPAllocateClause(
11308 Allocator, Alignment, C->getFirstAllocateModifier(),
11309 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11310 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11311 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11312}
11313
11314template <typename Derived>
11315OMPClause *
11318 Vars.reserve(C->varlist_size());
11319 for (auto *VE : C->varlist()) {
11320 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11321 if (EVar.isInvalid())
11322 return nullptr;
11323 Vars.push_back(EVar.get());
11324 }
11325 return getDerived().RebuildOMPNumTeamsClause(
11326 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11327}
11328
11329template <typename Derived>
11330OMPClause *
11333 Vars.reserve(C->varlist_size());
11334 for (auto *VE : C->varlist()) {
11335 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11336 if (EVar.isInvalid())
11337 return nullptr;
11338 Vars.push_back(EVar.get());
11339 }
11340 return getDerived().RebuildOMPThreadLimitClause(
11341 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11342}
11343
11344template <typename Derived>
11345OMPClause *
11347 ExprResult E = getDerived().TransformExpr(C->getPriority());
11348 if (E.isInvalid())
11349 return nullptr;
11350 return getDerived().RebuildOMPPriorityClause(
11351 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11352}
11353
11354template <typename Derived>
11355OMPClause *
11357 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11358 if (E.isInvalid())
11359 return nullptr;
11360 return getDerived().RebuildOMPGrainsizeClause(
11361 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11362 C->getModifierLoc(), C->getEndLoc());
11363}
11364
11365template <typename Derived>
11366OMPClause *
11368 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11369 if (E.isInvalid())
11370 return nullptr;
11371 return getDerived().RebuildOMPNumTasksClause(
11372 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11373 C->getModifierLoc(), C->getEndLoc());
11374}
11375
11376template <typename Derived>
11378 ExprResult E = getDerived().TransformExpr(C->getHint());
11379 if (E.isInvalid())
11380 return nullptr;
11381 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11382 C->getLParenLoc(), C->getEndLoc());
11383}
11384
11385template <typename Derived>
11388 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11389 if (E.isInvalid())
11390 return nullptr;
11391 return getDerived().RebuildOMPDistScheduleClause(
11392 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11393 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11394}
11395
11396template <typename Derived>
11397OMPClause *
11399 // Rebuild Defaultmap Clause since we need to invoke the checking of
11400 // defaultmap(none:variable-category) after template initialization.
11401 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11402 C->getDefaultmapKind(),
11403 C->getBeginLoc(),
11404 C->getLParenLoc(),
11405 C->getDefaultmapModifierLoc(),
11406 C->getDefaultmapKindLoc(),
11407 C->getEndLoc());
11408}
11409
11410template <typename Derived>
11412 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11414 CXXScopeSpec MapperIdScopeSpec;
11415 DeclarationNameInfo MapperIdInfo;
11416 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11418 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11419 return nullptr;
11420 return getDerived().RebuildOMPToClause(
11421 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11422 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11423}
11424
11425template <typename Derived>
11427 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11429 CXXScopeSpec MapperIdScopeSpec;
11430 DeclarationNameInfo MapperIdInfo;
11431 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11433 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11434 return nullptr;
11435 return getDerived().RebuildOMPFromClause(
11436 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11437 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11438}
11439
11440template <typename Derived>
11444 Vars.reserve(C->varlist_size());
11445 for (auto *VE : C->varlist()) {
11446 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11447 if (EVar.isInvalid())
11448 return nullptr;
11449 Vars.push_back(EVar.get());
11450 }
11451 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11452 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11453}
11454
11455template <typename Derived>
11459 Vars.reserve(C->varlist_size());
11460 for (auto *VE : C->varlist()) {
11461 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11462 if (EVar.isInvalid())
11463 return nullptr;
11464 Vars.push_back(EVar.get());
11465 }
11466 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11467 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11468}
11469
11470template <typename Derived>
11471OMPClause *
11474 Vars.reserve(C->varlist_size());
11475 for (auto *VE : C->varlist()) {
11476 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11477 if (EVar.isInvalid())
11478 return nullptr;
11479 Vars.push_back(EVar.get());
11480 }
11481 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11482 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11483}
11484
11485template <typename Derived>
11489 Vars.reserve(C->varlist_size());
11490 for (auto *VE : C->varlist()) {
11491 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11492 if (EVar.isInvalid())
11493 return nullptr;
11494 Vars.push_back(EVar.get());
11495 }
11496 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11497 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11498}
11499
11500template <typename Derived>
11501OMPClause *
11504 Vars.reserve(C->varlist_size());
11505 for (auto *VE : C->varlist()) {
11506 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11507 if (EVar.isInvalid())
11508 return nullptr;
11509 Vars.push_back(EVar.get());
11510 }
11511 return getDerived().RebuildOMPNontemporalClause(
11512 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11513}
11514
11515template <typename Derived>
11516OMPClause *
11519 Vars.reserve(C->varlist_size());
11520 for (auto *VE : C->varlist()) {
11521 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11522 if (EVar.isInvalid())
11523 return nullptr;
11524 Vars.push_back(EVar.get());
11525 }
11526 return getDerived().RebuildOMPInclusiveClause(
11527 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11528}
11529
11530template <typename Derived>
11531OMPClause *
11534 Vars.reserve(C->varlist_size());
11535 for (auto *VE : C->varlist()) {
11536 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11537 if (EVar.isInvalid())
11538 return nullptr;
11539 Vars.push_back(EVar.get());
11540 }
11541 return getDerived().RebuildOMPExclusiveClause(
11542 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11543}
11544
11545template <typename Derived>
11549 Data.reserve(C->getNumberOfAllocators());
11550 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11551 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11552 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11553 if (Allocator.isInvalid())
11554 continue;
11555 ExprResult AllocatorTraits;
11556 if (Expr *AT = D.AllocatorTraits) {
11557 AllocatorTraits = getDerived().TransformExpr(AT);
11558 if (AllocatorTraits.isInvalid())
11559 continue;
11560 }
11561 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11562 NewD.Allocator = Allocator.get();
11563 NewD.AllocatorTraits = AllocatorTraits.get();
11564 NewD.LParenLoc = D.LParenLoc;
11565 NewD.RParenLoc = D.RParenLoc;
11566 }
11567 return getDerived().RebuildOMPUsesAllocatorsClause(
11568 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11569}
11570
11571template <typename Derived>
11572OMPClause *
11574 SmallVector<Expr *, 4> Locators;
11575 Locators.reserve(C->varlist_size());
11576 ExprResult ModifierRes;
11577 if (Expr *Modifier = C->getModifier()) {
11578 ModifierRes = getDerived().TransformExpr(Modifier);
11579 if (ModifierRes.isInvalid())
11580 return nullptr;
11581 }
11582 for (Expr *E : C->varlist()) {
11583 ExprResult Locator = getDerived().TransformExpr(E);
11584 if (Locator.isInvalid())
11585 continue;
11586 Locators.push_back(Locator.get());
11587 }
11588 return getDerived().RebuildOMPAffinityClause(
11589 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11590 ModifierRes.get(), Locators);
11591}
11592
11593template <typename Derived>
11595 return getDerived().RebuildOMPOrderClause(
11596 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11597 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11598}
11599
11600template <typename Derived>
11602 return getDerived().RebuildOMPBindClause(
11603 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11604 C->getLParenLoc(), C->getEndLoc());
11605}
11606
11607template <typename Derived>
11610 ExprResult Size = getDerived().TransformExpr(C->getSize());
11611 if (Size.isInvalid())
11612 return nullptr;
11613 return getDerived().RebuildOMPXDynCGroupMemClause(
11614 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11615}
11616
11617template <typename Derived>
11618OMPClause *
11621 Vars.reserve(C->varlist_size());
11622 for (auto *VE : C->varlist()) {
11623 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11624 if (EVar.isInvalid())
11625 return nullptr;
11626 Vars.push_back(EVar.get());
11627 }
11628 return getDerived().RebuildOMPDoacrossClause(
11629 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11630 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11631}
11632
11633template <typename Derived>
11634OMPClause *
11637 for (auto *A : C->getAttrs())
11638 NewAttrs.push_back(getDerived().TransformAttr(A));
11639 return getDerived().RebuildOMPXAttributeClause(
11640 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11641}
11642
11643template <typename Derived>
11645 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11646}
11647
11648//===----------------------------------------------------------------------===//
11649// OpenACC transformation
11650//===----------------------------------------------------------------------===//
11651namespace {
11652template <typename Derived>
11653class OpenACCClauseTransform final
11654 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11655 TreeTransform<Derived> &Self;
11656 ArrayRef<const OpenACCClause *> ExistingClauses;
11657 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11658 OpenACCClause *NewClause = nullptr;
11659
11660 ExprResult VisitVar(Expr *VarRef) {
11661 ExprResult Res = Self.TransformExpr(VarRef);
11662
11663 if (!Res.isUsable())
11664 return Res;
11665
11666 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11667 ParsedClause.getClauseKind(),
11668 Res.get());
11669
11670 return Res;
11671 }
11672
11673 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11674 llvm::SmallVector<Expr *> InstantiatedVarList;
11675 for (Expr *CurVar : VarList) {
11676 ExprResult VarRef = VisitVar(CurVar);
11677
11678 if (VarRef.isUsable())
11679 InstantiatedVarList.push_back(VarRef.get());
11680 }
11681
11682 return InstantiatedVarList;
11683 }
11684
11685public:
11686 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11687 ArrayRef<const OpenACCClause *> ExistingClauses,
11688 SemaOpenACC::OpenACCParsedClause &PC)
11689 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11690
11691 OpenACCClause *CreatedClause() const { return NewClause; }
11692
11693#define VISIT_CLAUSE(CLAUSE_NAME) \
11694 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11695#include "clang/Basic/OpenACCClauses.def"
11696};
11697
11698template <typename Derived>
11699void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11700 const OpenACCDefaultClause &C) {
11701 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11702
11703 NewClause = OpenACCDefaultClause::Create(
11704 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11705 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11706 ParsedClause.getEndLoc());
11707}
11708
11709template <typename Derived>
11710void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11711 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11712 assert(Cond && "If constructed with invalid Condition");
11713 Sema::ConditionResult Res = Self.TransformCondition(
11714 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11715
11716 if (Res.isInvalid() || !Res.get().second)
11717 return;
11718
11719 ParsedClause.setConditionDetails(Res.get().second);
11720
11721 NewClause = OpenACCIfClause::Create(
11722 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11723 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11724 ParsedClause.getEndLoc());
11725}
11726
11727template <typename Derived>
11728void OpenACCClauseTransform<Derived>::VisitSelfClause(
11729 const OpenACCSelfClause &C) {
11730
11731 // If this is an 'update' 'self' clause, this is actually a var list instead.
11732 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11733 llvm::SmallVector<Expr *> InstantiatedVarList;
11734 for (Expr *CurVar : C.getVarList()) {
11735 ExprResult Res = Self.TransformExpr(CurVar);
11736
11737 if (!Res.isUsable())
11738 continue;
11739
11740 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11741 ParsedClause.getClauseKind(),
11742 Res.get());
11743
11744 if (Res.isUsable())
11745 InstantiatedVarList.push_back(Res.get());
11746 }
11747
11748 ParsedClause.setVarListDetails(InstantiatedVarList,
11750
11751 NewClause = OpenACCSelfClause::Create(
11752 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11753 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11754 ParsedClause.getEndLoc());
11755 } else {
11756
11757 if (C.hasConditionExpr()) {
11758 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11760 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11762
11763 if (Res.isInvalid() || !Res.get().second)
11764 return;
11765
11766 ParsedClause.setConditionDetails(Res.get().second);
11767 }
11768
11769 NewClause = OpenACCSelfClause::Create(
11770 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11771 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11772 ParsedClause.getEndLoc());
11773 }
11774}
11775
11776template <typename Derived>
11777void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11778 const OpenACCNumGangsClause &C) {
11779 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11780
11781 for (Expr *CurIntExpr : C.getIntExprs()) {
11782 ExprResult Res = Self.TransformExpr(CurIntExpr);
11783
11784 if (!Res.isUsable())
11785 return;
11786
11787 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11788 C.getClauseKind(),
11789 C.getBeginLoc(), Res.get());
11790 if (!Res.isUsable())
11791 return;
11792
11793 InstantiatedIntExprs.push_back(Res.get());
11794 }
11795
11796 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11798 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11799 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11800 ParsedClause.getEndLoc());
11801}
11802
11803template <typename Derived>
11804void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11805 const OpenACCPrivateClause &C) {
11806 llvm::SmallVector<Expr *> InstantiatedVarList;
11808
11809 for (const auto [RefExpr, InitRecipe] :
11810 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11811 ExprResult VarRef = VisitVar(RefExpr);
11812
11813 if (VarRef.isUsable()) {
11814 InstantiatedVarList.push_back(VarRef.get());
11815
11816 // We only have to create a new one if it is dependent, and Sema won't
11817 // make one of these unless the type is non-dependent.
11818 if (InitRecipe.isSet())
11819 InitRecipes.push_back(InitRecipe);
11820 else
11821 InitRecipes.push_back(
11822 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
11823 }
11824 }
11825 ParsedClause.setVarListDetails(InstantiatedVarList,
11827
11828 NewClause = OpenACCPrivateClause::Create(
11829 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11830 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11831 ParsedClause.getEndLoc());
11832}
11833
11834template <typename Derived>
11835void OpenACCClauseTransform<Derived>::VisitHostClause(
11836 const OpenACCHostClause &C) {
11837 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11839
11840 NewClause = OpenACCHostClause::Create(
11841 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11842 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11843 ParsedClause.getEndLoc());
11844}
11845
11846template <typename Derived>
11847void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11848 const OpenACCDeviceClause &C) {
11849 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11851
11852 NewClause = OpenACCDeviceClause::Create(
11853 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11854 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11855 ParsedClause.getEndLoc());
11856}
11857
11858template <typename Derived>
11859void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11861 llvm::SmallVector<Expr *> InstantiatedVarList;
11863
11864 for (const auto [RefExpr, InitRecipe] :
11865 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11866 ExprResult VarRef = VisitVar(RefExpr);
11867
11868 if (VarRef.isUsable()) {
11869 InstantiatedVarList.push_back(VarRef.get());
11870
11871 // We only have to create a new one if it is dependent, and Sema won't
11872 // make one of these unless the type is non-dependent.
11873 if (InitRecipe.isSet())
11874 InitRecipes.push_back(InitRecipe);
11875 else
11876 InitRecipes.push_back(
11877 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
11878 VarRef.get()));
11879 }
11880 }
11881 ParsedClause.setVarListDetails(InstantiatedVarList,
11883
11885 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11886 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11887 ParsedClause.getEndLoc());
11888}
11889
11890template <typename Derived>
11891void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11892 const OpenACCNoCreateClause &C) {
11893 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11895
11897 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11898 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11899 ParsedClause.getEndLoc());
11900}
11901
11902template <typename Derived>
11903void OpenACCClauseTransform<Derived>::VisitPresentClause(
11904 const OpenACCPresentClause &C) {
11905 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11907
11908 NewClause = OpenACCPresentClause::Create(
11909 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11910 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11911 ParsedClause.getEndLoc());
11912}
11913
11914template <typename Derived>
11915void OpenACCClauseTransform<Derived>::VisitCopyClause(
11916 const OpenACCCopyClause &C) {
11917 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11918 C.getModifierList());
11919
11920 NewClause = OpenACCCopyClause::Create(
11921 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11922 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11923 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11924 ParsedClause.getEndLoc());
11925}
11926
11927template <typename Derived>
11928void OpenACCClauseTransform<Derived>::VisitLinkClause(
11929 const OpenACCLinkClause &C) {
11930 llvm_unreachable("link clause not valid unless a decl transform");
11931}
11932
11933template <typename Derived>
11934void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
11936 llvm_unreachable("device_resident clause not valid unless a decl transform");
11937}
11938template <typename Derived>
11939void OpenACCClauseTransform<Derived>::VisitNoHostClause(
11940 const OpenACCNoHostClause &C) {
11941 llvm_unreachable("nohost clause not valid unless a decl transform");
11942}
11943template <typename Derived>
11944void OpenACCClauseTransform<Derived>::VisitBindClause(
11945 const OpenACCBindClause &C) {
11946 llvm_unreachable("bind clause not valid unless a decl transform");
11947}
11948
11949template <typename Derived>
11950void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11951 const OpenACCCopyInClause &C) {
11952 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11953 C.getModifierList());
11954
11955 NewClause = OpenACCCopyInClause::Create(
11956 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11957 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11958 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11959 ParsedClause.getEndLoc());
11960}
11961
11962template <typename Derived>
11963void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11964 const OpenACCCopyOutClause &C) {
11965 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11966 C.getModifierList());
11967
11968 NewClause = OpenACCCopyOutClause::Create(
11969 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11970 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11971 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11972 ParsedClause.getEndLoc());
11973}
11974
11975template <typename Derived>
11976void OpenACCClauseTransform<Derived>::VisitCreateClause(
11977 const OpenACCCreateClause &C) {
11978 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11979 C.getModifierList());
11980
11981 NewClause = OpenACCCreateClause::Create(
11982 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11983 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11984 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11985 ParsedClause.getEndLoc());
11986}
11987template <typename Derived>
11988void OpenACCClauseTransform<Derived>::VisitAttachClause(
11989 const OpenACCAttachClause &C) {
11990 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11991
11992 // Ensure each var is a pointer type.
11993 llvm::erase_if(VarList, [&](Expr *E) {
11994 return Self.getSema().OpenACC().CheckVarIsPointerType(
11996 });
11997
11998 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
11999 NewClause = OpenACCAttachClause::Create(
12000 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12001 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12002 ParsedClause.getEndLoc());
12003}
12004
12005template <typename Derived>
12006void OpenACCClauseTransform<Derived>::VisitDetachClause(
12007 const OpenACCDetachClause &C) {
12008 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12009
12010 // Ensure each var is a pointer type.
12011 llvm::erase_if(VarList, [&](Expr *E) {
12012 return Self.getSema().OpenACC().CheckVarIsPointerType(
12014 });
12015
12016 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12017 NewClause = OpenACCDetachClause::Create(
12018 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12019 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12020 ParsedClause.getEndLoc());
12021}
12022
12023template <typename Derived>
12024void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12025 const OpenACCDeleteClause &C) {
12026 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12028 NewClause = OpenACCDeleteClause::Create(
12029 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12030 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12031 ParsedClause.getEndLoc());
12032}
12033
12034template <typename Derived>
12035void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12036 const OpenACCUseDeviceClause &C) {
12037 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12040 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12041 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12042 ParsedClause.getEndLoc());
12043}
12044
12045template <typename Derived>
12046void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12047 const OpenACCDevicePtrClause &C) {
12048 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12049
12050 // Ensure each var is a pointer type.
12051 llvm::erase_if(VarList, [&](Expr *E) {
12052 return Self.getSema().OpenACC().CheckVarIsPointerType(
12054 });
12055
12056 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12058 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12059 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12060 ParsedClause.getEndLoc());
12061}
12062
12063template <typename Derived>
12064void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12065 const OpenACCNumWorkersClause &C) {
12066 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12067 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12068
12069 ExprResult Res = Self.TransformExpr(IntExpr);
12070 if (!Res.isUsable())
12071 return;
12072
12073 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12074 C.getClauseKind(),
12075 C.getBeginLoc(), Res.get());
12076 if (!Res.isUsable())
12077 return;
12078
12079 ParsedClause.setIntExprDetails(Res.get());
12081 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12082 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12083 ParsedClause.getEndLoc());
12084}
12085
12086template <typename Derived>
12087void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12088 const OpenACCDeviceNumClause &C) {
12089 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12090 assert(IntExpr && "device_num clause constructed with invalid int expr");
12091
12092 ExprResult Res = Self.TransformExpr(IntExpr);
12093 if (!Res.isUsable())
12094 return;
12095
12096 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12097 C.getClauseKind(),
12098 C.getBeginLoc(), Res.get());
12099 if (!Res.isUsable())
12100 return;
12101
12102 ParsedClause.setIntExprDetails(Res.get());
12104 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12105 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12106 ParsedClause.getEndLoc());
12107}
12108
12109template <typename Derived>
12110void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12112 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12113 assert(IntExpr && "default_async clause constructed with invalid int expr");
12114
12115 ExprResult Res = Self.TransformExpr(IntExpr);
12116 if (!Res.isUsable())
12117 return;
12118
12119 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12120 C.getClauseKind(),
12121 C.getBeginLoc(), Res.get());
12122 if (!Res.isUsable())
12123 return;
12124
12125 ParsedClause.setIntExprDetails(Res.get());
12127 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12128 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12129 ParsedClause.getEndLoc());
12130}
12131
12132template <typename Derived>
12133void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12135 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12136 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12137
12138 ExprResult Res = Self.TransformExpr(IntExpr);
12139 if (!Res.isUsable())
12140 return;
12141
12142 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12143 C.getClauseKind(),
12144 C.getBeginLoc(), Res.get());
12145 if (!Res.isUsable())
12146 return;
12147
12148 ParsedClause.setIntExprDetails(Res.get());
12150 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12151 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12152 ParsedClause.getEndLoc());
12153}
12154
12155template <typename Derived>
12156void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12157 const OpenACCAsyncClause &C) {
12158 if (C.hasIntExpr()) {
12159 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12160 if (!Res.isUsable())
12161 return;
12162
12163 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12164 C.getClauseKind(),
12165 C.getBeginLoc(), Res.get());
12166 if (!Res.isUsable())
12167 return;
12168 ParsedClause.setIntExprDetails(Res.get());
12169 }
12170
12171 NewClause = OpenACCAsyncClause::Create(
12172 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12173 ParsedClause.getLParenLoc(),
12174 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12175 : nullptr,
12176 ParsedClause.getEndLoc());
12177}
12178
12179template <typename Derived>
12180void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12181 const OpenACCWorkerClause &C) {
12182 if (C.hasIntExpr()) {
12183 // restrictions on this expression are all "does it exist in certain
12184 // situations" that are not possible to be dependent, so the only check we
12185 // have is that it transforms, and is an int expression.
12186 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12187 if (!Res.isUsable())
12188 return;
12189
12190 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12191 C.getClauseKind(),
12192 C.getBeginLoc(), Res.get());
12193 if (!Res.isUsable())
12194 return;
12195 ParsedClause.setIntExprDetails(Res.get());
12196 }
12197
12198 NewClause = OpenACCWorkerClause::Create(
12199 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12200 ParsedClause.getLParenLoc(),
12201 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12202 : nullptr,
12203 ParsedClause.getEndLoc());
12204}
12205
12206template <typename Derived>
12207void OpenACCClauseTransform<Derived>::VisitVectorClause(
12208 const OpenACCVectorClause &C) {
12209 if (C.hasIntExpr()) {
12210 // restrictions on this expression are all "does it exist in certain
12211 // situations" that are not possible to be dependent, so the only check we
12212 // have is that it transforms, and is an int expression.
12213 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12214 if (!Res.isUsable())
12215 return;
12216
12217 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12218 C.getClauseKind(),
12219 C.getBeginLoc(), Res.get());
12220 if (!Res.isUsable())
12221 return;
12222 ParsedClause.setIntExprDetails(Res.get());
12223 }
12224
12225 NewClause = OpenACCVectorClause::Create(
12226 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12227 ParsedClause.getLParenLoc(),
12228 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12229 : nullptr,
12230 ParsedClause.getEndLoc());
12231}
12232
12233template <typename Derived>
12234void OpenACCClauseTransform<Derived>::VisitWaitClause(
12235 const OpenACCWaitClause &C) {
12236 if (C.hasExprs()) {
12237 Expr *DevNumExpr = nullptr;
12238 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12239
12240 // Instantiate devnum expr if it exists.
12241 if (C.getDevNumExpr()) {
12242 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12243 if (!Res.isUsable())
12244 return;
12245 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12246 C.getClauseKind(),
12247 C.getBeginLoc(), Res.get());
12248 if (!Res.isUsable())
12249 return;
12250
12251 DevNumExpr = Res.get();
12252 }
12253
12254 // Instantiate queue ids.
12255 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12256 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12257 if (!Res.isUsable())
12258 return;
12259 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12260 C.getClauseKind(),
12261 C.getBeginLoc(), Res.get());
12262 if (!Res.isUsable())
12263 return;
12264
12265 InstantiatedQueueIdExprs.push_back(Res.get());
12266 }
12267
12268 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12269 std::move(InstantiatedQueueIdExprs));
12270 }
12271
12272 NewClause = OpenACCWaitClause::Create(
12273 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12274 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12275 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12276 ParsedClause.getEndLoc());
12277}
12278
12279template <typename Derived>
12280void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12281 const OpenACCDeviceTypeClause &C) {
12282 // Nothing to transform here, just create a new version of 'C'.
12284 Self.getSema().getASTContext(), C.getClauseKind(),
12285 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12286 C.getArchitectures(), ParsedClause.getEndLoc());
12287}
12288
12289template <typename Derived>
12290void OpenACCClauseTransform<Derived>::VisitAutoClause(
12291 const OpenACCAutoClause &C) {
12292 // Nothing to do, so just create a new node.
12293 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12294 ParsedClause.getBeginLoc(),
12295 ParsedClause.getEndLoc());
12296}
12297
12298template <typename Derived>
12299void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12300 const OpenACCIndependentClause &C) {
12301 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12302 ParsedClause.getBeginLoc(),
12303 ParsedClause.getEndLoc());
12304}
12305
12306template <typename Derived>
12307void OpenACCClauseTransform<Derived>::VisitSeqClause(
12308 const OpenACCSeqClause &C) {
12309 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12310 ParsedClause.getBeginLoc(),
12311 ParsedClause.getEndLoc());
12312}
12313template <typename Derived>
12314void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12315 const OpenACCFinalizeClause &C) {
12316 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12317 ParsedClause.getBeginLoc(),
12318 ParsedClause.getEndLoc());
12319}
12320
12321template <typename Derived>
12322void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12323 const OpenACCIfPresentClause &C) {
12324 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12325 ParsedClause.getBeginLoc(),
12326 ParsedClause.getEndLoc());
12327}
12328
12329template <typename Derived>
12330void OpenACCClauseTransform<Derived>::VisitReductionClause(
12331 const OpenACCReductionClause &C) {
12332 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12333 SmallVector<Expr *> ValidVars;
12335
12336 for (const auto [Var, OrigRecipe] :
12337 llvm::zip(TransformedVars, C.getRecipes())) {
12338 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12339 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12340 if (Res.isUsable()) {
12341 ValidVars.push_back(Res.get());
12342
12343 if (OrigRecipe.isSet())
12344 Recipes.push_back(OrigRecipe);
12345 else
12346 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12347 C.getReductionOp(), Res.get()));
12348 }
12349 }
12350
12351 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12352 ExistingClauses, ParsedClause.getDirectiveKind(),
12353 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12354 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12355}
12356
12357template <typename Derived>
12358void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12359 const OpenACCCollapseClause &C) {
12360 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12361 assert(LoopCount && "collapse clause constructed with invalid loop count");
12362
12363 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12364
12365 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12366 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12367 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12368
12369 NewLoopCount =
12370 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12371
12372 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12374 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12375 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12376 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12377}
12378
12379template <typename Derived>
12380void OpenACCClauseTransform<Derived>::VisitTileClause(
12381 const OpenACCTileClause &C) {
12382
12383 llvm::SmallVector<Expr *> TransformedExprs;
12384
12385 for (Expr *E : C.getSizeExprs()) {
12386 ExprResult NewSizeExpr = Self.TransformExpr(E);
12387
12388 if (!NewSizeExpr.isUsable())
12389 return;
12390
12391 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12392 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12393 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12394
12395 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12396
12397 if (!NewSizeExpr.isUsable())
12398 return;
12399 TransformedExprs.push_back(NewSizeExpr.get());
12400 }
12401
12402 ParsedClause.setIntExprDetails(TransformedExprs);
12403 NewClause = OpenACCTileClause::Create(
12404 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12405 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12406 ParsedClause.getEndLoc());
12407}
12408template <typename Derived>
12409void OpenACCClauseTransform<Derived>::VisitGangClause(
12410 const OpenACCGangClause &C) {
12411 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12412 llvm::SmallVector<Expr *> TransformedIntExprs;
12413
12414 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12415 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12416 if (!ER.isUsable())
12417 continue;
12418
12419 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12420 ParsedClause.getDirectiveKind(),
12421 C.getExpr(I).first, ER.get());
12422 if (!ER.isUsable())
12423 continue;
12424 TransformedGangKinds.push_back(C.getExpr(I).first);
12425 TransformedIntExprs.push_back(ER.get());
12426 }
12427
12428 NewClause = Self.getSema().OpenACC().CheckGangClause(
12429 ParsedClause.getDirectiveKind(), ExistingClauses,
12430 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12431 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12432}
12433} // namespace
12434template <typename Derived>
12435OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12436 ArrayRef<const OpenACCClause *> ExistingClauses,
12437 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12438
12440 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12441 ParsedClause.setEndLoc(OldClause->getEndLoc());
12442
12443 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12444 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12445
12446 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12447 ParsedClause};
12448 Transform.Visit(OldClause);
12449
12450 return Transform.CreatedClause();
12451}
12452
12453template <typename Derived>
12455TreeTransform<Derived>::TransformOpenACCClauseList(
12457 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12458 for (const auto *Clause : OldClauses) {
12459 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12460 TransformedClauses, DirKind, Clause))
12461 TransformedClauses.push_back(TransformedClause);
12462 }
12463 return TransformedClauses;
12464}
12465
12466template <typename Derived>
12469 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12470
12471 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12472 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12473 C->clauses());
12474
12475 if (getSema().OpenACC().ActOnStartStmtDirective(
12476 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12477 return StmtError();
12478
12479 // Transform Structured Block.
12480 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12481 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12482 C->clauses(), TransformedClauses);
12483 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12484 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12485 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12486
12487 return getDerived().RebuildOpenACCComputeConstruct(
12488 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12489 C->getEndLoc(), TransformedClauses, StrBlock);
12490}
12491
12492template <typename Derived>
12495
12496 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12497
12498 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12499 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12500 C->clauses());
12501
12502 if (getSema().OpenACC().ActOnStartStmtDirective(
12503 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12504 return StmtError();
12505
12506 // Transform Loop.
12507 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12508 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12509 C->clauses(), TransformedClauses);
12510 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12511 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12512 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12513
12514 return getDerived().RebuildOpenACCLoopConstruct(
12515 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12516 TransformedClauses, Loop);
12517}
12518
12519template <typename Derived>
12521 OpenACCCombinedConstruct *C) {
12522 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12523
12524 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12525 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12526 C->clauses());
12527
12528 if (getSema().OpenACC().ActOnStartStmtDirective(
12529 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12530 return StmtError();
12531
12532 // Transform Loop.
12533 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12534 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12535 C->clauses(), TransformedClauses);
12536 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12537 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12538 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12539
12540 return getDerived().RebuildOpenACCCombinedConstruct(
12541 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12542 C->getEndLoc(), TransformedClauses, Loop);
12543}
12544
12545template <typename Derived>
12548 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12549
12550 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12551 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12552 C->clauses());
12553 if (getSema().OpenACC().ActOnStartStmtDirective(
12554 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12555 return StmtError();
12556
12557 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12558 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12559 C->clauses(), TransformedClauses);
12560 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12561 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12562 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12563
12564 return getDerived().RebuildOpenACCDataConstruct(
12565 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12566 TransformedClauses, StrBlock);
12567}
12568
12569template <typename Derived>
12571 OpenACCEnterDataConstruct *C) {
12572 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12573
12574 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12575 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12576 C->clauses());
12577 if (getSema().OpenACC().ActOnStartStmtDirective(
12578 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12579 return StmtError();
12580
12581 return getDerived().RebuildOpenACCEnterDataConstruct(
12582 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12583 TransformedClauses);
12584}
12585
12586template <typename Derived>
12588 OpenACCExitDataConstruct *C) {
12589 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12590
12591 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12592 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12593 C->clauses());
12594 if (getSema().OpenACC().ActOnStartStmtDirective(
12595 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12596 return StmtError();
12597
12598 return getDerived().RebuildOpenACCExitDataConstruct(
12599 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12600 TransformedClauses);
12601}
12602
12603template <typename Derived>
12605 OpenACCHostDataConstruct *C) {
12606 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12607
12608 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12609 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12610 C->clauses());
12611 if (getSema().OpenACC().ActOnStartStmtDirective(
12612 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12613 return StmtError();
12614
12615 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12616 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12617 C->clauses(), TransformedClauses);
12618 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12619 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12620 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12621
12622 return getDerived().RebuildOpenACCHostDataConstruct(
12623 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12624 TransformedClauses, StrBlock);
12625}
12626
12627template <typename Derived>
12630 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12631
12632 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12633 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12634 C->clauses());
12635 if (getSema().OpenACC().ActOnStartStmtDirective(
12636 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12637 return StmtError();
12638
12639 return getDerived().RebuildOpenACCInitConstruct(
12640 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12641 TransformedClauses);
12642}
12643
12644template <typename Derived>
12646 OpenACCShutdownConstruct *C) {
12647 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12648
12649 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12650 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12651 C->clauses());
12652 if (getSema().OpenACC().ActOnStartStmtDirective(
12653 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12654 return StmtError();
12655
12656 return getDerived().RebuildOpenACCShutdownConstruct(
12657 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12658 TransformedClauses);
12659}
12660template <typename Derived>
12663 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12664
12665 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12666 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12667 C->clauses());
12668 if (getSema().OpenACC().ActOnStartStmtDirective(
12669 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12670 return StmtError();
12671
12672 return getDerived().RebuildOpenACCSetConstruct(
12673 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12674 TransformedClauses);
12675}
12676
12677template <typename Derived>
12679 OpenACCUpdateConstruct *C) {
12680 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12681
12682 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12683 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12684 C->clauses());
12685 if (getSema().OpenACC().ActOnStartStmtDirective(
12686 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12687 return StmtError();
12688
12689 return getDerived().RebuildOpenACCUpdateConstruct(
12690 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12691 TransformedClauses);
12692}
12693
12694template <typename Derived>
12697 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12698
12699 ExprResult DevNumExpr;
12700 if (C->hasDevNumExpr()) {
12701 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12702
12703 if (DevNumExpr.isUsable())
12704 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12706 C->getBeginLoc(), DevNumExpr.get());
12707 }
12708
12709 llvm::SmallVector<Expr *> QueueIdExprs;
12710
12711 for (Expr *QE : C->getQueueIdExprs()) {
12712 assert(QE && "Null queue id expr?");
12713 ExprResult NewEQ = getDerived().TransformExpr(QE);
12714
12715 if (!NewEQ.isUsable())
12716 break;
12717 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12719 C->getBeginLoc(), NewEQ.get());
12720 if (NewEQ.isUsable())
12721 QueueIdExprs.push_back(NewEQ.get());
12722 }
12723
12724 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12725 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12726 C->clauses());
12727
12728 if (getSema().OpenACC().ActOnStartStmtDirective(
12729 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12730 return StmtError();
12731
12732 return getDerived().RebuildOpenACCWaitConstruct(
12733 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12734 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12735 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12736}
12737template <typename Derived>
12739 OpenACCCacheConstruct *C) {
12740 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12741
12742 llvm::SmallVector<Expr *> TransformedVarList;
12743 for (Expr *Var : C->getVarList()) {
12744 assert(Var && "Null var listexpr?");
12745
12746 ExprResult NewVar = getDerived().TransformExpr(Var);
12747
12748 if (!NewVar.isUsable())
12749 break;
12750
12751 NewVar = getSema().OpenACC().ActOnVar(
12752 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
12753 if (!NewVar.isUsable())
12754 break;
12755
12756 TransformedVarList.push_back(NewVar.get());
12757 }
12758
12759 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12760 C->getBeginLoc(), {}))
12761 return StmtError();
12762
12763 return getDerived().RebuildOpenACCCacheConstruct(
12764 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12765 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
12766 C->getEndLoc());
12767}
12768
12769template <typename Derived>
12771 OpenACCAtomicConstruct *C) {
12772 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12773
12774 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12775 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12776 C->clauses());
12777
12778 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12779 C->getBeginLoc(), {}))
12780 return StmtError();
12781
12782 // Transform Associated Stmt.
12783 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12784 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
12785
12786 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
12787 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
12788 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
12789 AssocStmt);
12790
12791 return getDerived().RebuildOpenACCAtomicConstruct(
12792 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
12793 C->getEndLoc(), TransformedClauses, AssocStmt);
12794}
12795
12796template <typename Derived>
12799 if (getDerived().AlwaysRebuild())
12800 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12801 // Nothing can ever change, so there is never anything to transform.
12802 return E;
12803}
12804
12805//===----------------------------------------------------------------------===//
12806// Expression transformation
12807//===----------------------------------------------------------------------===//
12808template<typename Derived>
12811 return TransformExpr(E->getSubExpr());
12812}
12813
12814template <typename Derived>
12817 if (!E->isTypeDependent())
12818 return E;
12819
12820 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12821
12822 if (!NewT)
12823 return ExprError();
12824
12825 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12826 return E;
12827
12828 return getDerived().RebuildSYCLUniqueStableNameExpr(
12829 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12830}
12831
12832template<typename Derived>
12835 if (!E->isTypeDependent())
12836 return E;
12837
12838 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12839 E->getIdentKind());
12840}
12841
12842template<typename Derived>
12845 NestedNameSpecifierLoc QualifierLoc;
12846 if (E->getQualifierLoc()) {
12847 QualifierLoc
12848 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12849 if (!QualifierLoc)
12850 return ExprError();
12851 }
12852
12853 ValueDecl *ND
12854 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12855 E->getDecl()));
12856 if (!ND || ND->isInvalidDecl())
12857 return ExprError();
12858
12859 NamedDecl *Found = ND;
12860 if (E->getFoundDecl() != E->getDecl()) {
12861 Found = cast_or_null<NamedDecl>(
12862 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12863 if (!Found)
12864 return ExprError();
12865 }
12866
12867 DeclarationNameInfo NameInfo = E->getNameInfo();
12868 if (NameInfo.getName()) {
12869 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12870 if (!NameInfo.getName())
12871 return ExprError();
12872 }
12873
12874 if (!getDerived().AlwaysRebuild() &&
12875 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12876 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12877 Found == E->getFoundDecl() &&
12878 NameInfo.getName() == E->getDecl()->getDeclName() &&
12879 !E->hasExplicitTemplateArgs()) {
12880
12881 // Mark it referenced in the new context regardless.
12882 // FIXME: this is a bit instantiation-specific.
12883 SemaRef.MarkDeclRefReferenced(E);
12884
12885 return E;
12886 }
12887
12888 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12889 if (E->hasExplicitTemplateArgs()) {
12890 TemplateArgs = &TransArgs;
12891 TransArgs.setLAngleLoc(E->getLAngleLoc());
12892 TransArgs.setRAngleLoc(E->getRAngleLoc());
12893 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12894 E->getNumTemplateArgs(),
12895 TransArgs))
12896 return ExprError();
12897 }
12898
12899 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12900 Found, TemplateArgs);
12901}
12902
12903template<typename Derived>
12906 return E;
12907}
12908
12909template <typename Derived>
12911 FixedPointLiteral *E) {
12912 return E;
12913}
12914
12915template<typename Derived>
12918 return E;
12919}
12920
12921template<typename Derived>
12924 return E;
12925}
12926
12927template<typename Derived>
12930 return E;
12931}
12932
12933template<typename Derived>
12936 return E;
12937}
12938
12939template<typename Derived>
12942 return getDerived().TransformCallExpr(E);
12943}
12944
12945template<typename Derived>
12948 ExprResult ControllingExpr;
12949 TypeSourceInfo *ControllingType = nullptr;
12950 if (E->isExprPredicate())
12951 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12952 else
12953 ControllingType = getDerived().TransformType(E->getControllingType());
12954
12955 if (ControllingExpr.isInvalid() && !ControllingType)
12956 return ExprError();
12957
12958 SmallVector<Expr *, 4> AssocExprs;
12960 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
12961 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
12962 if (TSI) {
12963 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
12964 if (!AssocType)
12965 return ExprError();
12966 AssocTypes.push_back(AssocType);
12967 } else {
12968 AssocTypes.push_back(nullptr);
12969 }
12970
12971 ExprResult AssocExpr =
12972 getDerived().TransformExpr(Assoc.getAssociationExpr());
12973 if (AssocExpr.isInvalid())
12974 return ExprError();
12975 AssocExprs.push_back(AssocExpr.get());
12976 }
12977
12978 if (!ControllingType)
12979 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
12980 E->getDefaultLoc(),
12981 E->getRParenLoc(),
12982 ControllingExpr.get(),
12983 AssocTypes,
12984 AssocExprs);
12985 return getDerived().RebuildGenericSelectionExpr(
12986 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
12987 ControllingType, AssocTypes, AssocExprs);
12988}
12989
12990template<typename Derived>
12993 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12994 if (SubExpr.isInvalid())
12995 return ExprError();
12996
12997 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12998 return E;
12999
13000 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13001 E->getRParen());
13002}
13003
13004/// The operand of a unary address-of operator has special rules: it's
13005/// allowed to refer to a non-static member of a class even if there's no 'this'
13006/// object available.
13007template<typename Derived>
13010 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13011 return getDerived().TransformDependentScopeDeclRefExpr(
13012 DRE, /*IsAddressOfOperand=*/true, nullptr);
13013 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13014 return getDerived().TransformUnresolvedLookupExpr(
13015 ULE, /*IsAddressOfOperand=*/true);
13016 else
13017 return getDerived().TransformExpr(E);
13018}
13019
13020template<typename Derived>
13023 ExprResult SubExpr;
13024 if (E->getOpcode() == UO_AddrOf)
13025 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13026 else
13027 SubExpr = TransformExpr(E->getSubExpr());
13028 if (SubExpr.isInvalid())
13029 return ExprError();
13030
13031 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13032 return E;
13033
13034 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13035 E->getOpcode(),
13036 SubExpr.get());
13037}
13038
13039template<typename Derived>
13041TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13042 // Transform the type.
13043 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13044 if (!Type)
13045 return ExprError();
13046
13047 // Transform all of the components into components similar to what the
13048 // parser uses.
13049 // FIXME: It would be slightly more efficient in the non-dependent case to
13050 // just map FieldDecls, rather than requiring the rebuilder to look for
13051 // the fields again. However, __builtin_offsetof is rare enough in
13052 // template code that we don't care.
13053 bool ExprChanged = false;
13054 typedef Sema::OffsetOfComponent Component;
13055 SmallVector<Component, 4> Components;
13056 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13057 const OffsetOfNode &ON = E->getComponent(I);
13058 Component Comp;
13059 Comp.isBrackets = true;
13060 Comp.LocStart = ON.getSourceRange().getBegin();
13061 Comp.LocEnd = ON.getSourceRange().getEnd();
13062 switch (ON.getKind()) {
13063 case OffsetOfNode::Array: {
13064 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13065 ExprResult Index = getDerived().TransformExpr(FromIndex);
13066 if (Index.isInvalid())
13067 return ExprError();
13068
13069 ExprChanged = ExprChanged || Index.get() != FromIndex;
13070 Comp.isBrackets = true;
13071 Comp.U.E = Index.get();
13072 break;
13073 }
13074
13077 Comp.isBrackets = false;
13078 Comp.U.IdentInfo = ON.getFieldName();
13079 if (!Comp.U.IdentInfo)
13080 continue;
13081
13082 break;
13083
13084 case OffsetOfNode::Base:
13085 // Will be recomputed during the rebuild.
13086 continue;
13087 }
13088
13089 Components.push_back(Comp);
13090 }
13091
13092 // If nothing changed, retain the existing expression.
13093 if (!getDerived().AlwaysRebuild() &&
13094 Type == E->getTypeSourceInfo() &&
13095 !ExprChanged)
13096 return E;
13097
13098 // Build a new offsetof expression.
13099 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
13100 Components, E->getRParenLoc());
13101}
13102
13103template<typename Derived>
13106 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13107 "opaque value expression requires transformation");
13108 return E;
13109}
13110
13111template <typename Derived>
13114 bool Changed = false;
13115 for (Expr *C : E->subExpressions()) {
13116 ExprResult NewC = getDerived().TransformExpr(C);
13117 if (NewC.isInvalid())
13118 return ExprError();
13119 Children.push_back(NewC.get());
13120
13121 Changed |= NewC.get() != C;
13122 }
13123 if (!getDerived().AlwaysRebuild() && !Changed)
13124 return E;
13125 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13126 Children, E->getType());
13127}
13128
13129template<typename Derived>
13132 // Rebuild the syntactic form. The original syntactic form has
13133 // opaque-value expressions in it, so strip those away and rebuild
13134 // the result. This is a really awful way of doing this, but the
13135 // better solution (rebuilding the semantic expressions and
13136 // rebinding OVEs as necessary) doesn't work; we'd need
13137 // TreeTransform to not strip away implicit conversions.
13138 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13139 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13140 if (result.isInvalid()) return ExprError();
13141
13142 // If that gives us a pseudo-object result back, the pseudo-object
13143 // expression must have been an lvalue-to-rvalue conversion which we
13144 // should reapply.
13145 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13146 result = SemaRef.PseudoObject().checkRValue(result.get());
13147
13148 return result;
13149}
13150
13151template<typename Derived>
13155 if (E->isArgumentType()) {
13156 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13157
13158 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13159 if (!NewT)
13160 return ExprError();
13161
13162 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13163 return E;
13164
13165 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13166 E->getKind(),
13167 E->getSourceRange());
13168 }
13169
13170 // C++0x [expr.sizeof]p1:
13171 // The operand is either an expression, which is an unevaluated operand
13172 // [...]
13176
13177 // Try to recover if we have something like sizeof(T::X) where X is a type.
13178 // Notably, there must be *exactly* one set of parens if X is a type.
13179 TypeSourceInfo *RecoveryTSI = nullptr;
13180 ExprResult SubExpr;
13181 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13182 if (auto *DRE =
13183 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13184 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13185 PE, DRE, false, &RecoveryTSI);
13186 else
13187 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13188
13189 if (RecoveryTSI) {
13190 return getDerived().RebuildUnaryExprOrTypeTrait(
13191 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13192 } else if (SubExpr.isInvalid())
13193 return ExprError();
13194
13195 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13196 return E;
13197
13198 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13199 E->getOperatorLoc(),
13200 E->getKind(),
13201 E->getSourceRange());
13202}
13203
13204template<typename Derived>
13207 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13208 if (LHS.isInvalid())
13209 return ExprError();
13210
13211 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13212 if (RHS.isInvalid())
13213 return ExprError();
13214
13215
13216 if (!getDerived().AlwaysRebuild() &&
13217 LHS.get() == E->getLHS() &&
13218 RHS.get() == E->getRHS())
13219 return E;
13220
13221 return getDerived().RebuildArraySubscriptExpr(
13222 LHS.get(),
13223 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13224}
13225
13226template <typename Derived>
13229 ExprResult Base = getDerived().TransformExpr(E->getBase());
13230 if (Base.isInvalid())
13231 return ExprError();
13232
13233 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13234 if (RowIdx.isInvalid())
13235 return ExprError();
13236
13237 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13238 if (ColumnIdx.isInvalid())
13239 return ExprError();
13240
13241 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13242 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13243 return E;
13244
13245 return getDerived().RebuildMatrixSubscriptExpr(
13246 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13247}
13248
13249template <typename Derived>
13252 ExprResult Base = getDerived().TransformExpr(E->getBase());
13253 if (Base.isInvalid())
13254 return ExprError();
13255
13256 ExprResult LowerBound;
13257 if (E->getLowerBound()) {
13258 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13259 if (LowerBound.isInvalid())
13260 return ExprError();
13261 }
13262
13263 ExprResult Length;
13264 if (E->getLength()) {
13265 Length = getDerived().TransformExpr(E->getLength());
13266 if (Length.isInvalid())
13267 return ExprError();
13268 }
13269
13270 ExprResult Stride;
13271 if (E->isOMPArraySection()) {
13272 if (Expr *Str = E->getStride()) {
13273 Stride = getDerived().TransformExpr(Str);
13274 if (Stride.isInvalid())
13275 return ExprError();
13276 }
13277 }
13278
13279 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13280 LowerBound.get() == E->getLowerBound() &&
13281 Length.get() == E->getLength() &&
13282 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13283 return E;
13284
13285 return getDerived().RebuildArraySectionExpr(
13286 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13287 LowerBound.get(), E->getColonLocFirst(),
13288 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13289 Length.get(), Stride.get(), E->getRBracketLoc());
13290}
13291
13292template <typename Derived>
13295 ExprResult Base = getDerived().TransformExpr(E->getBase());
13296 if (Base.isInvalid())
13297 return ExprError();
13298
13300 bool ErrorFound = false;
13301 for (Expr *Dim : E->getDimensions()) {
13302 ExprResult DimRes = getDerived().TransformExpr(Dim);
13303 if (DimRes.isInvalid()) {
13304 ErrorFound = true;
13305 continue;
13306 }
13307 Dims.push_back(DimRes.get());
13308 }
13309
13310 if (ErrorFound)
13311 return ExprError();
13312 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13313 E->getRParenLoc(), Dims,
13314 E->getBracketsRanges());
13315}
13316
13317template <typename Derived>
13320 unsigned NumIterators = E->numOfIterators();
13322
13323 bool ErrorFound = false;
13324 bool NeedToRebuild = getDerived().AlwaysRebuild();
13325 for (unsigned I = 0; I < NumIterators; ++I) {
13326 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13327 Data[I].DeclIdent = D->getIdentifier();
13328 Data[I].DeclIdentLoc = D->getLocation();
13329 if (D->getLocation() == D->getBeginLoc()) {
13330 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13331 "Implicit type must be int.");
13332 } else {
13333 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13334 QualType DeclTy = getDerived().TransformType(D->getType());
13335 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13336 }
13337 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13338 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13339 ExprResult End = getDerived().TransformExpr(Range.End);
13340 ExprResult Step = getDerived().TransformExpr(Range.Step);
13341 ErrorFound = ErrorFound ||
13342 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13343 !Data[I].Type.get().isNull())) ||
13344 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13345 if (ErrorFound)
13346 continue;
13347 Data[I].Range.Begin = Begin.get();
13348 Data[I].Range.End = End.get();
13349 Data[I].Range.Step = Step.get();
13350 Data[I].AssignLoc = E->getAssignLoc(I);
13351 Data[I].ColonLoc = E->getColonLoc(I);
13352 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13353 NeedToRebuild =
13354 NeedToRebuild ||
13355 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13356 D->getType().getTypePtrOrNull()) ||
13357 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13358 Range.Step != Data[I].Range.Step;
13359 }
13360 if (ErrorFound)
13361 return ExprError();
13362 if (!NeedToRebuild)
13363 return E;
13364
13365 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13366 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13367 if (!Res.isUsable())
13368 return Res;
13369 auto *IE = cast<OMPIteratorExpr>(Res.get());
13370 for (unsigned I = 0; I < NumIterators; ++I)
13371 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13372 IE->getIteratorDecl(I));
13373 return Res;
13374}
13375
13376template<typename Derived>
13379 // Transform the callee.
13380 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13381 if (Callee.isInvalid())
13382 return ExprError();
13383
13384 // Transform arguments.
13385 bool ArgChanged = false;
13387 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13388 &ArgChanged))
13389 return ExprError();
13390
13391 if (!getDerived().AlwaysRebuild() &&
13392 Callee.get() == E->getCallee() &&
13393 !ArgChanged)
13394 return SemaRef.MaybeBindToTemporary(E);
13395
13396 // FIXME: Wrong source location information for the '('.
13397 SourceLocation FakeLParenLoc
13398 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13399
13400 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13401 if (E->hasStoredFPFeatures()) {
13402 FPOptionsOverride NewOverrides = E->getFPFeatures();
13403 getSema().CurFPFeatures =
13404 NewOverrides.applyOverrides(getSema().getLangOpts());
13405 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13406 }
13407
13408 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13409 Args,
13410 E->getRParenLoc());
13411}
13412
13413template<typename Derived>
13416 ExprResult Base = getDerived().TransformExpr(E->getBase());
13417 if (Base.isInvalid())
13418 return ExprError();
13419
13420 NestedNameSpecifierLoc QualifierLoc;
13421 if (E->hasQualifier()) {
13422 QualifierLoc
13423 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13424
13425 if (!QualifierLoc)
13426 return ExprError();
13427 }
13428 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13429
13431 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13432 E->getMemberDecl()));
13433 if (!Member)
13434 return ExprError();
13435
13436 NamedDecl *FoundDecl = E->getFoundDecl();
13437 if (FoundDecl == E->getMemberDecl()) {
13438 FoundDecl = Member;
13439 } else {
13440 FoundDecl = cast_or_null<NamedDecl>(
13441 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13442 if (!FoundDecl)
13443 return ExprError();
13444 }
13445
13446 if (!getDerived().AlwaysRebuild() &&
13447 Base.get() == E->getBase() &&
13448 QualifierLoc == E->getQualifierLoc() &&
13449 Member == E->getMemberDecl() &&
13450 FoundDecl == E->getFoundDecl() &&
13451 !E->hasExplicitTemplateArgs()) {
13452
13453 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13454 // for Openmp where the field need to be privatizized in the case.
13455 if (!(isa<CXXThisExpr>(E->getBase()) &&
13456 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13458 // Mark it referenced in the new context regardless.
13459 // FIXME: this is a bit instantiation-specific.
13460 SemaRef.MarkMemberReferenced(E);
13461 return E;
13462 }
13463 }
13464
13465 TemplateArgumentListInfo TransArgs;
13466 if (E->hasExplicitTemplateArgs()) {
13467 TransArgs.setLAngleLoc(E->getLAngleLoc());
13468 TransArgs.setRAngleLoc(E->getRAngleLoc());
13469 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13470 E->getNumTemplateArgs(),
13471 TransArgs))
13472 return ExprError();
13473 }
13474
13475 // FIXME: Bogus source location for the operator
13476 SourceLocation FakeOperatorLoc =
13477 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13478
13479 // FIXME: to do this check properly, we will need to preserve the
13480 // first-qualifier-in-scope here, just in case we had a dependent
13481 // base (and therefore couldn't do the check) and a
13482 // nested-name-qualifier (and therefore could do the lookup).
13483 NamedDecl *FirstQualifierInScope = nullptr;
13484 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13485 if (MemberNameInfo.getName()) {
13486 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13487 if (!MemberNameInfo.getName())
13488 return ExprError();
13489 }
13490
13491 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13492 E->isArrow(),
13493 QualifierLoc,
13494 TemplateKWLoc,
13495 MemberNameInfo,
13496 Member,
13497 FoundDecl,
13498 (E->hasExplicitTemplateArgs()
13499 ? &TransArgs : nullptr),
13500 FirstQualifierInScope);
13501}
13502
13503template<typename Derived>
13506 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13507 if (LHS.isInvalid())
13508 return ExprError();
13509
13510 ExprResult RHS =
13511 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13512 if (RHS.isInvalid())
13513 return ExprError();
13514
13515 if (!getDerived().AlwaysRebuild() &&
13516 LHS.get() == E->getLHS() &&
13517 RHS.get() == E->getRHS())
13518 return E;
13519
13520 if (E->isCompoundAssignmentOp())
13521 // FPFeatures has already been established from trailing storage
13522 return getDerived().RebuildBinaryOperator(
13523 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13524 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13525 FPOptionsOverride NewOverrides(E->getFPFeatures());
13526 getSema().CurFPFeatures =
13527 NewOverrides.applyOverrides(getSema().getLangOpts());
13528 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13529 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13530 LHS.get(), RHS.get());
13531}
13532
13533template <typename Derived>
13536 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13537
13538 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13539 if (LHS.isInvalid())
13540 return ExprError();
13541
13542 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13543 if (RHS.isInvalid())
13544 return ExprError();
13545
13546 // Extract the already-resolved callee declarations so that we can restrict
13547 // ourselves to using them as the unqualified lookup results when rebuilding.
13548 UnresolvedSet<2> UnqualLookups;
13549 bool ChangedAnyLookups = false;
13550 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13551 const_cast<Expr *>(Decomp.InnerBinOp)};
13552 for (Expr *PossibleBinOp : PossibleBinOps) {
13553 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13554 if (!Op)
13555 continue;
13556 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13557 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13558 continue;
13559
13560 // Transform the callee in case we built a call to a local extern
13561 // declaration.
13562 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13563 E->getOperatorLoc(), Callee->getFoundDecl()));
13564 if (!Found)
13565 return ExprError();
13566 if (Found != Callee->getFoundDecl())
13567 ChangedAnyLookups = true;
13568 UnqualLookups.addDecl(Found);
13569 }
13570
13571 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13572 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13573 // Mark all functions used in the rewrite as referenced. Note that when
13574 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13575 // function calls, and/or there might be a user-defined conversion sequence
13576 // applied to the operands of the <.
13577 // FIXME: this is a bit instantiation-specific.
13578 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13579 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13580 return E;
13581 }
13582
13583 return getDerived().RebuildCXXRewrittenBinaryOperator(
13584 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13585}
13586
13587template<typename Derived>
13591 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13592 FPOptionsOverride NewOverrides(E->getFPFeatures());
13593 getSema().CurFPFeatures =
13594 NewOverrides.applyOverrides(getSema().getLangOpts());
13595 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13596 return getDerived().TransformBinaryOperator(E);
13597}
13598
13599template<typename Derived>
13602 // Just rebuild the common and RHS expressions and see whether we
13603 // get any changes.
13604
13605 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13606 if (commonExpr.isInvalid())
13607 return ExprError();
13608
13609 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13610 if (rhs.isInvalid())
13611 return ExprError();
13612
13613 if (!getDerived().AlwaysRebuild() &&
13614 commonExpr.get() == e->getCommon() &&
13615 rhs.get() == e->getFalseExpr())
13616 return e;
13617
13618 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13619 e->getQuestionLoc(),
13620 nullptr,
13621 e->getColonLoc(),
13622 rhs.get());
13623}
13624
13625template<typename Derived>
13628 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13629 if (Cond.isInvalid())
13630 return ExprError();
13631
13632 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13633 if (LHS.isInvalid())
13634 return ExprError();
13635
13636 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13637 if (RHS.isInvalid())
13638 return ExprError();
13639
13640 if (!getDerived().AlwaysRebuild() &&
13641 Cond.get() == E->getCond() &&
13642 LHS.get() == E->getLHS() &&
13643 RHS.get() == E->getRHS())
13644 return E;
13645
13646 return getDerived().RebuildConditionalOperator(Cond.get(),
13647 E->getQuestionLoc(),
13648 LHS.get(),
13649 E->getColonLoc(),
13650 RHS.get());
13651}
13652
13653template<typename Derived>
13656 // Implicit casts are eliminated during transformation, since they
13657 // will be recomputed by semantic analysis after transformation.
13658 return getDerived().TransformExpr(E->getSubExprAsWritten());
13659}
13660
13661template<typename Derived>
13664 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13665 if (!Type)
13666 return ExprError();
13667
13668 ExprResult SubExpr
13669 = getDerived().TransformExpr(E->getSubExprAsWritten());
13670 if (SubExpr.isInvalid())
13671 return ExprError();
13672
13673 if (!getDerived().AlwaysRebuild() &&
13674 Type == E->getTypeInfoAsWritten() &&
13675 SubExpr.get() == E->getSubExpr())
13676 return E;
13677
13678 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13679 Type,
13680 E->getRParenLoc(),
13681 SubExpr.get());
13682}
13683
13684template<typename Derived>
13687 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13688 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13689 if (!NewT)
13690 return ExprError();
13691
13692 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13693 if (Init.isInvalid())
13694 return ExprError();
13695
13696 if (!getDerived().AlwaysRebuild() &&
13697 OldT == NewT &&
13698 Init.get() == E->getInitializer())
13699 return SemaRef.MaybeBindToTemporary(E);
13700
13701 // Note: the expression type doesn't necessarily match the
13702 // type-as-written, but that's okay, because it should always be
13703 // derivable from the initializer.
13704
13705 return getDerived().RebuildCompoundLiteralExpr(
13706 E->getLParenLoc(), NewT,
13707 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13708}
13709
13710template<typename Derived>
13713 ExprResult Base = getDerived().TransformExpr(E->getBase());
13714 if (Base.isInvalid())
13715 return ExprError();
13716
13717 if (!getDerived().AlwaysRebuild() &&
13718 Base.get() == E->getBase())
13719 return E;
13720
13721 // FIXME: Bad source location
13722 SourceLocation FakeOperatorLoc =
13723 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13724 return getDerived().RebuildExtVectorElementExpr(
13725 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13726 E->getAccessor());
13727}
13728
13729template<typename Derived>
13732 if (InitListExpr *Syntactic = E->getSyntacticForm())
13733 E = Syntactic;
13734
13735 bool InitChanged = false;
13736
13739
13741 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13742 Inits, &InitChanged))
13743 return ExprError();
13744
13745 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13746 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13747 // in some cases. We can't reuse it in general, because the syntactic and
13748 // semantic forms are linked, and we can't know that semantic form will
13749 // match even if the syntactic form does.
13750 }
13751
13752 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13753 E->getRBraceLoc());
13754}
13755
13756template<typename Derived>
13759 Designation Desig;
13760
13761 // transform the initializer value
13762 ExprResult Init = getDerived().TransformExpr(E->getInit());
13763 if (Init.isInvalid())
13764 return ExprError();
13765
13766 // transform the designators.
13767 SmallVector<Expr*, 4> ArrayExprs;
13768 bool ExprChanged = false;
13769 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13770 if (D.isFieldDesignator()) {
13771 if (D.getFieldDecl()) {
13772 FieldDecl *Field = cast_or_null<FieldDecl>(
13773 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13774 if (Field != D.getFieldDecl())
13775 // Rebuild the expression when the transformed FieldDecl is
13776 // different to the already assigned FieldDecl.
13777 ExprChanged = true;
13778 if (Field->isAnonymousStructOrUnion())
13779 continue;
13780 } else {
13781 // Ensure that the designator expression is rebuilt when there isn't
13782 // a resolved FieldDecl in the designator as we don't want to assign
13783 // a FieldDecl to a pattern designator that will be instantiated again.
13784 ExprChanged = true;
13785 }
13786 Desig.AddDesignator(Designator::CreateFieldDesignator(
13787 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13788 continue;
13789 }
13790
13791 if (D.isArrayDesignator()) {
13792 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13793 if (Index.isInvalid())
13794 return ExprError();
13795
13796 Desig.AddDesignator(
13797 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13798
13799 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
13800 ArrayExprs.push_back(Index.get());
13801 continue;
13802 }
13803
13804 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13805 ExprResult Start
13806 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13807 if (Start.isInvalid())
13808 return ExprError();
13809
13810 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13811 if (End.isInvalid())
13812 return ExprError();
13813
13814 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13815 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13816
13817 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13818 End.get() != E->getArrayRangeEnd(D);
13819
13820 ArrayExprs.push_back(Start.get());
13821 ArrayExprs.push_back(End.get());
13822 }
13823
13824 if (!getDerived().AlwaysRebuild() &&
13825 Init.get() == E->getInit() &&
13826 !ExprChanged)
13827 return E;
13828
13829 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13830 E->getEqualOrColonLoc(),
13831 E->usesGNUSyntax(), Init.get());
13832}
13833
13834// Seems that if TransformInitListExpr() only works on the syntactic form of an
13835// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13836template<typename Derived>
13840 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13841 "initializer");
13842 return ExprError();
13843}
13844
13845template<typename Derived>
13848 NoInitExpr *E) {
13849 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13850 return ExprError();
13851}
13852
13853template<typename Derived>
13856 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13857 return ExprError();
13858}
13859
13860template<typename Derived>
13863 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13864 return ExprError();
13865}
13866
13867template<typename Derived>
13871 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13872
13873 // FIXME: Will we ever have proper type location here? Will we actually
13874 // need to transform the type?
13875 QualType T = getDerived().TransformType(E->getType());
13876 if (T.isNull())
13877 return ExprError();
13878
13879 if (!getDerived().AlwaysRebuild() &&
13880 T == E->getType())
13881 return E;
13882
13883 return getDerived().RebuildImplicitValueInitExpr(T);
13884}
13885
13886template<typename Derived>
13889 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13890 if (!TInfo)
13891 return ExprError();
13892
13893 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13894 if (SubExpr.isInvalid())
13895 return ExprError();
13896
13897 if (!getDerived().AlwaysRebuild() &&
13898 TInfo == E->getWrittenTypeInfo() &&
13899 SubExpr.get() == E->getSubExpr())
13900 return E;
13901
13902 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13903 TInfo, E->getRParenLoc());
13904}
13905
13906template<typename Derived>
13909 bool ArgumentChanged = false;
13911 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13912 &ArgumentChanged))
13913 return ExprError();
13914
13915 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13916 Inits,
13917 E->getRParenLoc());
13918}
13919
13920/// Transform an address-of-label expression.
13921///
13922/// By default, the transformation of an address-of-label expression always
13923/// rebuilds the expression, so that the label identifier can be resolved to
13924/// the corresponding label statement by semantic analysis.
13925template<typename Derived>
13928 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13929 E->getLabel());
13930 if (!LD)
13931 return ExprError();
13932
13933 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13934 cast<LabelDecl>(LD));
13935}
13936
13937template<typename Derived>
13940 SemaRef.ActOnStartStmtExpr();
13941 StmtResult SubStmt
13942 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13943 if (SubStmt.isInvalid()) {
13944 SemaRef.ActOnStmtExprError();
13945 return ExprError();
13946 }
13947
13948 unsigned OldDepth = E->getTemplateDepth();
13949 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13950
13951 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13952 SubStmt.get() == E->getSubStmt()) {
13953 // Calling this an 'error' is unintuitive, but it does the right thing.
13954 SemaRef.ActOnStmtExprError();
13955 return SemaRef.MaybeBindToTemporary(E);
13956 }
13957
13958 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
13959 E->getRParenLoc(), NewDepth);
13960}
13961
13962template<typename Derived>
13965 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13966 if (Cond.isInvalid())
13967 return ExprError();
13968
13969 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13970 if (LHS.isInvalid())
13971 return ExprError();
13972
13973 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13974 if (RHS.isInvalid())
13975 return ExprError();
13976
13977 if (!getDerived().AlwaysRebuild() &&
13978 Cond.get() == E->getCond() &&
13979 LHS.get() == E->getLHS() &&
13980 RHS.get() == E->getRHS())
13981 return E;
13982
13983 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
13984 Cond.get(), LHS.get(), RHS.get(),
13985 E->getRParenLoc());
13986}
13987
13988template<typename Derived>
13991 return E;
13992}
13993
13994template<typename Derived>
13997 switch (E->getOperator()) {
13998 case OO_New:
13999 case OO_Delete:
14000 case OO_Array_New:
14001 case OO_Array_Delete:
14002 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14003
14004 case OO_Subscript:
14005 case OO_Call: {
14006 // This is a call to an object's operator().
14007 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14008
14009 // Transform the object itself.
14010 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14011 if (Object.isInvalid())
14012 return ExprError();
14013
14014 // FIXME: Poor location information. Also, if the location for the end of
14015 // the token is within a macro expansion, getLocForEndOfToken() will return
14016 // an invalid source location. If that happens and we have an otherwise
14017 // valid end location, use the valid one instead of the invalid one.
14018 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14019 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14020 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14021 FakeLParenLoc = EndLoc;
14022
14023 // Transform the call arguments.
14025 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14026 Args))
14027 return ExprError();
14028
14029 if (E->getOperator() == OO_Subscript)
14030 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14031 Args, E->getEndLoc());
14032
14033 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14034 E->getEndLoc());
14035 }
14036
14037#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14038 case OO_##Name: \
14039 break;
14040
14041#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14042#include "clang/Basic/OperatorKinds.def"
14043
14044 case OO_Conditional:
14045 llvm_unreachable("conditional operator is not actually overloadable");
14046
14047 case OO_None:
14049 llvm_unreachable("not an overloaded operator?");
14050 }
14051
14053 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14054 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14055 else
14056 First = getDerived().TransformExpr(E->getArg(0));
14057 if (First.isInvalid())
14058 return ExprError();
14059
14060 ExprResult Second;
14061 if (E->getNumArgs() == 2) {
14062 Second =
14063 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14064 if (Second.isInvalid())
14065 return ExprError();
14066 }
14067
14068 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14069 FPOptionsOverride NewOverrides(E->getFPFeatures());
14070 getSema().CurFPFeatures =
14071 NewOverrides.applyOverrides(getSema().getLangOpts());
14072 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14073
14074 Expr *Callee = E->getCallee();
14075 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14076 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14078 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14079 return ExprError();
14080
14081 return getDerived().RebuildCXXOperatorCallExpr(
14082 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14083 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14084 }
14085
14086 UnresolvedSet<1> Functions;
14087 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14088 Callee = ICE->getSubExprAsWritten();
14089 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14090 ValueDecl *VD = cast_or_null<ValueDecl>(
14091 getDerived().TransformDecl(DR->getLocation(), DR));
14092 if (!VD)
14093 return ExprError();
14094
14095 if (!isa<CXXMethodDecl>(VD))
14096 Functions.addDecl(VD);
14097
14098 return getDerived().RebuildCXXOperatorCallExpr(
14099 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14100 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14101}
14102
14103template<typename Derived>
14106 return getDerived().TransformCallExpr(E);
14107}
14108
14109template <typename Derived>
14111 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14112 getSema().CurContext != E->getParentContext();
14113
14114 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14115 return E;
14116
14117 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14118 E->getBeginLoc(), E->getEndLoc(),
14119 getSema().CurContext);
14120}
14121
14122template <typename Derived>
14124 return E;
14125}
14126
14127template<typename Derived>
14130 // Transform the callee.
14131 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14132 if (Callee.isInvalid())
14133 return ExprError();
14134
14135 // Transform exec config.
14136 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14137 if (EC.isInvalid())
14138 return ExprError();
14139
14140 // Transform arguments.
14141 bool ArgChanged = false;
14143 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14144 &ArgChanged))
14145 return ExprError();
14146
14147 if (!getDerived().AlwaysRebuild() &&
14148 Callee.get() == E->getCallee() &&
14149 !ArgChanged)
14150 return SemaRef.MaybeBindToTemporary(E);
14151
14152 // FIXME: Wrong source location information for the '('.
14153 SourceLocation FakeLParenLoc
14154 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14155 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14156 Args,
14157 E->getRParenLoc(), EC.get());
14158}
14159
14160template<typename Derived>
14163 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14164 if (!Type)
14165 return ExprError();
14166
14167 ExprResult SubExpr
14168 = getDerived().TransformExpr(E->getSubExprAsWritten());
14169 if (SubExpr.isInvalid())
14170 return ExprError();
14171
14172 if (!getDerived().AlwaysRebuild() &&
14173 Type == E->getTypeInfoAsWritten() &&
14174 SubExpr.get() == E->getSubExpr())
14175 return E;
14176 return getDerived().RebuildCXXNamedCastExpr(
14179 // FIXME. this should be '(' location
14180 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14181}
14182
14183template<typename Derived>
14186 TypeSourceInfo *TSI =
14187 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14188 if (!TSI)
14189 return ExprError();
14190
14191 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14192 if (Sub.isInvalid())
14193 return ExprError();
14194
14195 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14196 Sub.get(), BCE->getEndLoc());
14197}
14198
14199template<typename Derived>
14201TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14202 return getDerived().TransformCXXNamedCastExpr(E);
14203}
14204
14205template<typename Derived>
14208 return getDerived().TransformCXXNamedCastExpr(E);
14209}
14210
14211template<typename Derived>
14215 return getDerived().TransformCXXNamedCastExpr(E);
14216}
14217
14218template<typename Derived>
14221 return getDerived().TransformCXXNamedCastExpr(E);
14222}
14223
14224template<typename Derived>
14227 return getDerived().TransformCXXNamedCastExpr(E);
14228}
14229
14230template<typename Derived>
14235 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14236 if (!Type)
14237 return ExprError();
14238
14239 ExprResult SubExpr
14240 = getDerived().TransformExpr(E->getSubExprAsWritten());
14241 if (SubExpr.isInvalid())
14242 return ExprError();
14243
14244 if (!getDerived().AlwaysRebuild() &&
14245 Type == E->getTypeInfoAsWritten() &&
14246 SubExpr.get() == E->getSubExpr())
14247 return E;
14248
14249 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14250 E->getLParenLoc(),
14251 SubExpr.get(),
14252 E->getRParenLoc(),
14253 E->isListInitialization());
14254}
14255
14256template<typename Derived>
14259 if (E->isTypeOperand()) {
14260 TypeSourceInfo *TInfo
14261 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14262 if (!TInfo)
14263 return ExprError();
14264
14265 if (!getDerived().AlwaysRebuild() &&
14266 TInfo == E->getTypeOperandSourceInfo())
14267 return E;
14268
14269 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14270 TInfo, E->getEndLoc());
14271 }
14272
14273 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14274 // type. We must not unilaterally enter unevaluated context here, as then
14275 // semantic processing can re-transform an already transformed operand.
14276 Expr *Op = E->getExprOperand();
14278 if (E->isGLValue())
14279 if (auto *RD = Op->getType()->getAsCXXRecordDecl();
14280 RD && RD->isPolymorphic())
14281 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14282
14285
14286 ExprResult SubExpr = getDerived().TransformExpr(Op);
14287 if (SubExpr.isInvalid())
14288 return ExprError();
14289
14290 if (!getDerived().AlwaysRebuild() &&
14291 SubExpr.get() == E->getExprOperand())
14292 return E;
14293
14294 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14295 SubExpr.get(), E->getEndLoc());
14296}
14297
14298template<typename Derived>
14301 if (E->isTypeOperand()) {
14302 TypeSourceInfo *TInfo
14303 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14304 if (!TInfo)
14305 return ExprError();
14306
14307 if (!getDerived().AlwaysRebuild() &&
14308 TInfo == E->getTypeOperandSourceInfo())
14309 return E;
14310
14311 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14312 TInfo, E->getEndLoc());
14313 }
14314
14317
14318 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14319 if (SubExpr.isInvalid())
14320 return ExprError();
14321
14322 if (!getDerived().AlwaysRebuild() &&
14323 SubExpr.get() == E->getExprOperand())
14324 return E;
14325
14326 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14327 SubExpr.get(), E->getEndLoc());
14328}
14329
14330template<typename Derived>
14333 return E;
14334}
14335
14336template<typename Derived>
14340 return E;
14341}
14342
14343template<typename Derived>
14346
14347 // In lambdas, the qualifiers of the type depends of where in
14348 // the call operator `this` appear, and we do not have a good way to
14349 // rebuild this information, so we transform the type.
14350 //
14351 // In other contexts, the type of `this` may be overrided
14352 // for type deduction, so we need to recompute it.
14353 //
14354 // Always recompute the type if we're in the body of a lambda, and
14355 // 'this' is dependent on a lambda's explicit object parameter; we
14356 // also need to always rebuild the expression in this case to clear
14357 // the flag.
14358 QualType T = [&]() {
14359 auto &S = getSema();
14360 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14361 return S.getCurrentThisType();
14362 if (S.getCurLambda())
14363 return getDerived().TransformType(E->getType());
14364 return S.getCurrentThisType();
14365 }();
14366
14367 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14368 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14369 // Mark it referenced in the new context regardless.
14370 // FIXME: this is a bit instantiation-specific.
14371 getSema().MarkThisReferenced(E);
14372 return E;
14373 }
14374
14375 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14376}
14377
14378template<typename Derived>
14381 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14382 if (SubExpr.isInvalid())
14383 return ExprError();
14384
14385 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14386
14387 if (!getDerived().AlwaysRebuild() &&
14388 SubExpr.get() == E->getSubExpr())
14389 return E;
14390
14391 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14392 E->isThrownVariableInScope());
14393}
14394
14395template<typename Derived>
14398 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14399 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14400 if (!Param)
14401 return ExprError();
14402
14403 ExprResult InitRes;
14404 if (E->hasRewrittenInit()) {
14405 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14406 if (InitRes.isInvalid())
14407 return ExprError();
14408 }
14409
14410 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14411 E->getUsedContext() == SemaRef.CurContext &&
14412 InitRes.get() == E->getRewrittenExpr())
14413 return E;
14414
14415 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14416 InitRes.get());
14417}
14418
14419template<typename Derived>
14422 FieldDecl *Field = cast_or_null<FieldDecl>(
14423 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14424 if (!Field)
14425 return ExprError();
14426
14427 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14428 E->getUsedContext() == SemaRef.CurContext)
14429 return E;
14430
14431 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14432}
14433
14434template<typename Derived>
14438 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14439 if (!T)
14440 return ExprError();
14441
14442 if (!getDerived().AlwaysRebuild() &&
14443 T == E->getTypeSourceInfo())
14444 return E;
14445
14446 return getDerived().RebuildCXXScalarValueInitExpr(T,
14447 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14448 E->getRParenLoc());
14449}
14450
14451template<typename Derived>
14454 // Transform the type that we're allocating
14455 TypeSourceInfo *AllocTypeInfo =
14456 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14457 if (!AllocTypeInfo)
14458 return ExprError();
14459
14460 // Transform the size of the array we're allocating (if any).
14461 std::optional<Expr *> ArraySize;
14462 if (E->isArray()) {
14463 ExprResult NewArraySize;
14464 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14465 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14466 if (NewArraySize.isInvalid())
14467 return ExprError();
14468 }
14469 ArraySize = NewArraySize.get();
14470 }
14471
14472 // Transform the placement arguments (if any).
14473 bool ArgumentChanged = false;
14474 SmallVector<Expr*, 8> PlacementArgs;
14475 if (getDerived().TransformExprs(E->getPlacementArgs(),
14476 E->getNumPlacementArgs(), true,
14477 PlacementArgs, &ArgumentChanged))
14478 return ExprError();
14479
14480 // Transform the initializer (if any).
14481 Expr *OldInit = E->getInitializer();
14482 ExprResult NewInit;
14483 if (OldInit)
14484 NewInit = getDerived().TransformInitializer(OldInit, true);
14485 if (NewInit.isInvalid())
14486 return ExprError();
14487
14488 // Transform new operator and delete operator.
14489 FunctionDecl *OperatorNew = nullptr;
14490 if (E->getOperatorNew()) {
14491 OperatorNew = cast_or_null<FunctionDecl>(
14492 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14493 if (!OperatorNew)
14494 return ExprError();
14495 }
14496
14497 FunctionDecl *OperatorDelete = nullptr;
14498 if (E->getOperatorDelete()) {
14499 OperatorDelete = cast_or_null<FunctionDecl>(
14500 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14501 if (!OperatorDelete)
14502 return ExprError();
14503 }
14504
14505 if (!getDerived().AlwaysRebuild() &&
14506 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14507 ArraySize == E->getArraySize() &&
14508 NewInit.get() == OldInit &&
14509 OperatorNew == E->getOperatorNew() &&
14510 OperatorDelete == E->getOperatorDelete() &&
14511 !ArgumentChanged) {
14512 // Mark any declarations we need as referenced.
14513 // FIXME: instantiation-specific.
14514 if (OperatorNew)
14515 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14516 if (OperatorDelete)
14517 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14518
14519 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14520 QualType ElementType
14521 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14522 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
14524 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
14525 }
14526 }
14527
14528 return E;
14529 }
14530
14531 QualType AllocType = AllocTypeInfo->getType();
14532 if (!ArraySize) {
14533 // If no array size was specified, but the new expression was
14534 // instantiated with an array type (e.g., "new T" where T is
14535 // instantiated with "int[4]"), extract the outer bound from the
14536 // array type as our array size. We do this with constant and
14537 // dependently-sized array types.
14538 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14539 if (!ArrayT) {
14540 // Do nothing
14541 } else if (const ConstantArrayType *ConsArrayT
14542 = dyn_cast<ConstantArrayType>(ArrayT)) {
14543 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14544 SemaRef.Context.getSizeType(),
14545 /*FIXME:*/ E->getBeginLoc());
14546 AllocType = ConsArrayT->getElementType();
14547 } else if (const DependentSizedArrayType *DepArrayT
14548 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14549 if (DepArrayT->getSizeExpr()) {
14550 ArraySize = DepArrayT->getSizeExpr();
14551 AllocType = DepArrayT->getElementType();
14552 }
14553 }
14554 }
14555
14556 return getDerived().RebuildCXXNewExpr(
14557 E->getBeginLoc(), E->isGlobalNew(),
14558 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14559 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14560 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14561}
14562
14563template<typename Derived>
14566 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14567 if (Operand.isInvalid())
14568 return ExprError();
14569
14570 // Transform the delete operator, if known.
14571 FunctionDecl *OperatorDelete = nullptr;
14572 if (E->getOperatorDelete()) {
14573 OperatorDelete = cast_or_null<FunctionDecl>(
14574 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14575 if (!OperatorDelete)
14576 return ExprError();
14577 }
14578
14579 if (!getDerived().AlwaysRebuild() &&
14580 Operand.get() == E->getArgument() &&
14581 OperatorDelete == E->getOperatorDelete()) {
14582 // Mark any declarations we need as referenced.
14583 // FIXME: instantiation-specific.
14584 if (OperatorDelete)
14585 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14586
14587 if (!E->getArgument()->isTypeDependent()) {
14588 QualType Destroyed = SemaRef.Context.getBaseElementType(
14589 E->getDestroyedType());
14590 if (auto *Record = Destroyed->getAsCXXRecordDecl())
14591 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
14592 SemaRef.LookupDestructor(Record));
14593 }
14594
14595 return E;
14596 }
14597
14598 return getDerived().RebuildCXXDeleteExpr(
14599 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14600}
14601
14602template<typename Derived>
14606 ExprResult Base = getDerived().TransformExpr(E->getBase());
14607 if (Base.isInvalid())
14608 return ExprError();
14609
14610 ParsedType ObjectTypePtr;
14611 bool MayBePseudoDestructor = false;
14612 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14613 E->getOperatorLoc(),
14614 E->isArrow()? tok::arrow : tok::period,
14615 ObjectTypePtr,
14616 MayBePseudoDestructor);
14617 if (Base.isInvalid())
14618 return ExprError();
14619
14620 QualType ObjectType = ObjectTypePtr.get();
14621 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14622 if (QualifierLoc) {
14623 QualifierLoc
14624 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14625 if (!QualifierLoc)
14626 return ExprError();
14627 }
14628 CXXScopeSpec SS;
14629 SS.Adopt(QualifierLoc);
14630
14632 if (E->getDestroyedTypeInfo()) {
14633 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
14634 E->getDestroyedTypeInfo(), ObjectType,
14635 /*FirstQualifierInScope=*/nullptr);
14636 if (!DestroyedTypeInfo)
14637 return ExprError();
14638 Destroyed = DestroyedTypeInfo;
14639 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14640 // We aren't likely to be able to resolve the identifier down to a type
14641 // now anyway, so just retain the identifier.
14642 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14643 E->getDestroyedTypeLoc());
14644 } else {
14645 // Look for a destructor known with the given name.
14646 ParsedType T = SemaRef.getDestructorName(
14647 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14648 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14649 if (!T)
14650 return ExprError();
14651
14652 Destroyed
14654 E->getDestroyedTypeLoc());
14655 }
14656
14657 TypeSourceInfo *ScopeTypeInfo = nullptr;
14658 if (E->getScopeTypeInfo()) {
14659 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14660 E->getScopeTypeInfo(), ObjectType, nullptr);
14661 if (!ScopeTypeInfo)
14662 return ExprError();
14663 }
14664
14665 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14666 E->getOperatorLoc(),
14667 E->isArrow(),
14668 SS,
14669 ScopeTypeInfo,
14670 E->getColonColonLoc(),
14671 E->getTildeLoc(),
14672 Destroyed);
14673}
14674
14675template <typename Derived>
14677 bool RequiresADL,
14678 LookupResult &R) {
14679 // Transform all the decls.
14680 bool AllEmptyPacks = true;
14681 for (auto *OldD : Old->decls()) {
14682 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14683 if (!InstD) {
14684 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14685 // This can happen because of dependent hiding.
14686 if (isa<UsingShadowDecl>(OldD))
14687 continue;
14688 else {
14689 R.clear();
14690 return true;
14691 }
14692 }
14693
14694 // Expand using pack declarations.
14695 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14696 ArrayRef<NamedDecl*> Decls = SingleDecl;
14697 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14698 Decls = UPD->expansions();
14699
14700 // Expand using declarations.
14701 for (auto *D : Decls) {
14702 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14703 for (auto *SD : UD->shadows())
14704 R.addDecl(SD);
14705 } else {
14706 R.addDecl(D);
14707 }
14708 }
14709
14710 AllEmptyPacks &= Decls.empty();
14711 }
14712
14713 // C++ [temp.res]/8.4.2:
14714 // The program is ill-formed, no diagnostic required, if [...] lookup for
14715 // a name in the template definition found a using-declaration, but the
14716 // lookup in the corresponding scope in the instantiation odoes not find
14717 // any declarations because the using-declaration was a pack expansion and
14718 // the corresponding pack is empty
14719 if (AllEmptyPacks && !RequiresADL) {
14720 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14721 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14722 return true;
14723 }
14724
14725 // Resolve a kind, but don't do any further analysis. If it's
14726 // ambiguous, the callee needs to deal with it.
14727 R.resolveKind();
14728
14729 if (Old->hasTemplateKeyword() && !R.empty()) {
14731 getSema().FilterAcceptableTemplateNames(R,
14732 /*AllowFunctionTemplates=*/true,
14733 /*AllowDependent=*/true);
14734 if (R.empty()) {
14735 // If a 'template' keyword was used, a lookup that finds only non-template
14736 // names is an error.
14737 getSema().Diag(R.getNameLoc(),
14738 diag::err_template_kw_refers_to_non_template)
14740 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14741 getSema().Diag(FoundDecl->getLocation(),
14742 diag::note_template_kw_refers_to_non_template)
14743 << R.getLookupName();
14744 return true;
14745 }
14746 }
14747
14748 return false;
14749}
14750
14751template <typename Derived>
14756
14757template <typename Derived>
14760 bool IsAddressOfOperand) {
14761 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14763
14764 // Transform the declaration set.
14765 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14766 return ExprError();
14767
14768 // Rebuild the nested-name qualifier, if present.
14769 CXXScopeSpec SS;
14770 if (Old->getQualifierLoc()) {
14771 NestedNameSpecifierLoc QualifierLoc
14772 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14773 if (!QualifierLoc)
14774 return ExprError();
14775
14776 SS.Adopt(QualifierLoc);
14777 }
14778
14779 if (Old->getNamingClass()) {
14780 CXXRecordDecl *NamingClass
14781 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14782 Old->getNameLoc(),
14783 Old->getNamingClass()));
14784 if (!NamingClass) {
14785 R.clear();
14786 return ExprError();
14787 }
14788
14789 R.setNamingClass(NamingClass);
14790 }
14791
14792 // Rebuild the template arguments, if any.
14793 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14794 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14795 if (Old->hasExplicitTemplateArgs() &&
14796 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14797 Old->getNumTemplateArgs(),
14798 TransArgs)) {
14799 R.clear();
14800 return ExprError();
14801 }
14802
14803 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14804 // a non-static data member is named in an unevaluated operand, or when
14805 // a member is named in a dependent class scope function template explicit
14806 // specialization that is neither declared static nor with an explicit object
14807 // parameter.
14808 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14809 return SemaRef.BuildPossibleImplicitMemberExpr(
14810 SS, TemplateKWLoc, R,
14811 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14812 /*S=*/nullptr);
14813
14814 // If we have neither explicit template arguments, nor the template keyword,
14815 // it's a normal declaration name or member reference.
14816 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14817 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14818
14819 // If we have template arguments, then rebuild the template-id expression.
14820 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14821 Old->requiresADL(), &TransArgs);
14822}
14823
14824template<typename Derived>
14827 bool ArgChanged = false;
14829 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14830 TypeSourceInfo *From = E->getArg(I);
14831 TypeLoc FromTL = From->getTypeLoc();
14832 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14833 TypeLocBuilder TLB;
14834 TLB.reserve(FromTL.getFullDataSize());
14835 QualType To = getDerived().TransformType(TLB, FromTL);
14836 if (To.isNull())
14837 return ExprError();
14838
14839 if (To == From->getType())
14840 Args.push_back(From);
14841 else {
14842 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14843 ArgChanged = true;
14844 }
14845 continue;
14846 }
14847
14848 ArgChanged = true;
14849
14850 // We have a pack expansion. Instantiate it.
14851 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14852 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14854 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14855
14856 // Determine whether the set of unexpanded parameter packs can and should
14857 // be expanded.
14858 bool Expand = true;
14859 bool RetainExpansion = false;
14860 UnsignedOrNone OrigNumExpansions =
14861 ExpansionTL.getTypePtr()->getNumExpansions();
14862 UnsignedOrNone NumExpansions = OrigNumExpansions;
14863 if (getDerived().TryExpandParameterPacks(
14864 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
14865 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
14866 RetainExpansion, NumExpansions))
14867 return ExprError();
14868
14869 if (!Expand) {
14870 // The transform has determined that we should perform a simple
14871 // transformation on the pack expansion, producing another pack
14872 // expansion.
14873 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
14874
14875 TypeLocBuilder TLB;
14876 TLB.reserve(From->getTypeLoc().getFullDataSize());
14877
14878 QualType To = getDerived().TransformType(TLB, PatternTL);
14879 if (To.isNull())
14880 return ExprError();
14881
14882 To = getDerived().RebuildPackExpansionType(To,
14883 PatternTL.getSourceRange(),
14884 ExpansionTL.getEllipsisLoc(),
14885 NumExpansions);
14886 if (To.isNull())
14887 return ExprError();
14888
14889 PackExpansionTypeLoc ToExpansionTL
14890 = TLB.push<PackExpansionTypeLoc>(To);
14891 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14892 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14893 continue;
14894 }
14895
14896 // Expand the pack expansion by substituting for each argument in the
14897 // pack(s).
14898 for (unsigned I = 0; I != *NumExpansions; ++I) {
14899 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
14900 TypeLocBuilder TLB;
14901 TLB.reserve(PatternTL.getFullDataSize());
14902 QualType To = getDerived().TransformType(TLB, PatternTL);
14903 if (To.isNull())
14904 return ExprError();
14905
14906 if (To->containsUnexpandedParameterPack()) {
14907 To = getDerived().RebuildPackExpansionType(To,
14908 PatternTL.getSourceRange(),
14909 ExpansionTL.getEllipsisLoc(),
14910 NumExpansions);
14911 if (To.isNull())
14912 return ExprError();
14913
14914 PackExpansionTypeLoc ToExpansionTL
14915 = TLB.push<PackExpansionTypeLoc>(To);
14916 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14917 }
14918
14919 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14920 }
14921
14922 if (!RetainExpansion)
14923 continue;
14924
14925 // If we're supposed to retain a pack expansion, do so by temporarily
14926 // forgetting the partially-substituted parameter pack.
14927 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14928
14929 TypeLocBuilder TLB;
14930 TLB.reserve(From->getTypeLoc().getFullDataSize());
14931
14932 QualType To = getDerived().TransformType(TLB, PatternTL);
14933 if (To.isNull())
14934 return ExprError();
14935
14936 To = getDerived().RebuildPackExpansionType(To,
14937 PatternTL.getSourceRange(),
14938 ExpansionTL.getEllipsisLoc(),
14939 NumExpansions);
14940 if (To.isNull())
14941 return ExprError();
14942
14943 PackExpansionTypeLoc ToExpansionTL
14944 = TLB.push<PackExpansionTypeLoc>(To);
14945 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14946 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14947 }
14948
14949 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14950 return E;
14951
14952 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14953 E->getEndLoc());
14954}
14955
14956template<typename Derived>
14960 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
14961 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
14962 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14963 Old->NumTemplateArgs, TransArgs))
14964 return ExprError();
14965
14966 return getDerived().RebuildConceptSpecializationExpr(
14967 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
14968 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
14969 &TransArgs);
14970}
14971
14972template<typename Derived>
14975 SmallVector<ParmVarDecl*, 4> TransParams;
14976 SmallVector<QualType, 4> TransParamTypes;
14977 Sema::ExtParameterInfoBuilder ExtParamInfos;
14978
14979 // C++2a [expr.prim.req]p2
14980 // Expressions appearing within a requirement-body are unevaluated operands.
14984
14986 getSema().Context, getSema().CurContext,
14987 E->getBody()->getBeginLoc());
14988
14989 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
14990
14991 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
14992 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
14993 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
14994
14995 for (ParmVarDecl *Param : TransParams)
14996 if (Param)
14997 Param->setDeclContext(Body);
14998
14999 // On failure to transform, TransformRequiresTypeParams returns an expression
15000 // in the event that the transformation of the type params failed in some way.
15001 // It is expected that this will result in a 'not satisfied' Requires clause
15002 // when instantiating.
15003 if (!TypeParamResult.isUnset())
15004 return TypeParamResult;
15005
15007 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15008 TransReqs))
15009 return ExprError();
15010
15011 for (concepts::Requirement *Req : TransReqs) {
15012 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15013 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15014 ER->getReturnTypeRequirement()
15015 .getTypeConstraintTemplateParameterList()->getParam(0)
15016 ->setDeclContext(Body);
15017 }
15018 }
15019 }
15020
15021 return getDerived().RebuildRequiresExpr(
15022 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15023 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15024}
15025
15026template<typename Derived>
15030 for (concepts::Requirement *Req : Reqs) {
15031 concepts::Requirement *TransReq = nullptr;
15032 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15033 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15034 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15035 TransReq = getDerived().TransformExprRequirement(ExprReq);
15036 else
15037 TransReq = getDerived().TransformNestedRequirement(
15039 if (!TransReq)
15040 return true;
15041 Transformed.push_back(TransReq);
15042 }
15043 return false;
15044}
15045
15046template<typename Derived>
15050 if (Req->isSubstitutionFailure()) {
15051 if (getDerived().AlwaysRebuild())
15052 return getDerived().RebuildTypeRequirement(
15054 return Req;
15055 }
15056 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15057 if (!TransType)
15058 return nullptr;
15059 return getDerived().RebuildTypeRequirement(TransType);
15060}
15061
15062template<typename Derived>
15065 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15066 if (Req->isExprSubstitutionFailure())
15067 TransExpr = Req->getExprSubstitutionDiagnostic();
15068 else {
15069 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15070 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15071 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15072 if (TransExprRes.isInvalid())
15073 return nullptr;
15074 TransExpr = TransExprRes.get();
15075 }
15076
15077 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15078 const auto &RetReq = Req->getReturnTypeRequirement();
15079 if (RetReq.isEmpty())
15080 TransRetReq.emplace();
15081 else if (RetReq.isSubstitutionFailure())
15082 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15083 else if (RetReq.isTypeConstraint()) {
15084 TemplateParameterList *OrigTPL =
15085 RetReq.getTypeConstraintTemplateParameterList();
15087 getDerived().TransformTemplateParameterList(OrigTPL);
15088 if (!TPL)
15089 return nullptr;
15090 TransRetReq.emplace(TPL);
15091 }
15092 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15093 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15094 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15095 Req->getNoexceptLoc(),
15096 std::move(*TransRetReq));
15097 return getDerived().RebuildExprRequirement(
15099 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15100}
15101
15102template<typename Derived>
15106 if (Req->hasInvalidConstraint()) {
15107 if (getDerived().AlwaysRebuild())
15108 return getDerived().RebuildNestedRequirement(
15110 return Req;
15111 }
15112 ExprResult TransConstraint =
15113 getDerived().TransformExpr(Req->getConstraintExpr());
15114 if (TransConstraint.isInvalid())
15115 return nullptr;
15116 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15117}
15118
15119template<typename Derived>
15122 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15123 if (!T)
15124 return ExprError();
15125
15126 if (!getDerived().AlwaysRebuild() &&
15128 return E;
15129
15130 ExprResult SubExpr;
15131 {
15134 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15135 if (SubExpr.isInvalid())
15136 return ExprError();
15137 }
15138
15139 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15140 SubExpr.get(), E->getEndLoc());
15141}
15142
15143template<typename Derived>
15146 ExprResult SubExpr;
15147 {
15150 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15151 if (SubExpr.isInvalid())
15152 return ExprError();
15153
15154 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15155 return E;
15156 }
15157
15158 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15159 SubExpr.get(), E->getEndLoc());
15160}
15161
15162template <typename Derived>
15164 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15165 TypeSourceInfo **RecoveryTSI) {
15166 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15167 DRE, AddrTaken, RecoveryTSI);
15168
15169 // Propagate both errors and recovered types, which return ExprEmpty.
15170 if (!NewDRE.isUsable())
15171 return NewDRE;
15172
15173 // We got an expr, wrap it up in parens.
15174 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15175 return PE;
15176 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15177 PE->getRParen());
15178}
15179
15180template <typename Derived>
15186
15187template <typename Derived>
15189 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15190 TypeSourceInfo **RecoveryTSI) {
15191 assert(E->getQualifierLoc());
15192 NestedNameSpecifierLoc QualifierLoc =
15193 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15194 if (!QualifierLoc)
15195 return ExprError();
15196 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15197
15198 // TODO: If this is a conversion-function-id, verify that the
15199 // destination type name (if present) resolves the same way after
15200 // instantiation as it did in the local scope.
15201
15202 DeclarationNameInfo NameInfo =
15203 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15204 if (!NameInfo.getName())
15205 return ExprError();
15206
15207 if (!E->hasExplicitTemplateArgs()) {
15208 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15209 // Note: it is sufficient to compare the Name component of NameInfo:
15210 // if name has not changed, DNLoc has not changed either.
15211 NameInfo.getName() == E->getDeclName())
15212 return E;
15213
15214 return getDerived().RebuildDependentScopeDeclRefExpr(
15215 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15216 IsAddressOfOperand, RecoveryTSI);
15217 }
15218
15219 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15220 if (getDerived().TransformTemplateArguments(
15221 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15222 return ExprError();
15223
15224 return getDerived().RebuildDependentScopeDeclRefExpr(
15225 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15226 RecoveryTSI);
15227}
15228
15229template<typename Derived>
15232 // CXXConstructExprs other than for list-initialization and
15233 // CXXTemporaryObjectExpr are always implicit, so when we have
15234 // a 1-argument construction we just transform that argument.
15235 if (getDerived().AllowSkippingCXXConstructExpr() &&
15236 ((E->getNumArgs() == 1 ||
15237 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15238 (!getDerived().DropCallArgument(E->getArg(0))) &&
15239 !E->isListInitialization()))
15240 return getDerived().TransformInitializer(E->getArg(0),
15241 /*DirectInit*/ false);
15242
15243 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15244
15245 QualType T = getDerived().TransformType(E->getType());
15246 if (T.isNull())
15247 return ExprError();
15248
15249 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15250 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15251 if (!Constructor)
15252 return ExprError();
15253
15254 bool ArgumentChanged = false;
15256 {
15259 E->isListInitialization());
15260 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15261 &ArgumentChanged))
15262 return ExprError();
15263 }
15264
15265 if (!getDerived().AlwaysRebuild() &&
15266 T == E->getType() &&
15267 Constructor == E->getConstructor() &&
15268 !ArgumentChanged) {
15269 // Mark the constructor as referenced.
15270 // FIXME: Instantiation-specific
15271 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15272 return E;
15273 }
15274
15275 return getDerived().RebuildCXXConstructExpr(
15276 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15277 E->hadMultipleCandidates(), E->isListInitialization(),
15278 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15279 E->getConstructionKind(), E->getParenOrBraceRange());
15280}
15281
15282template<typename Derived>
15285 QualType T = getDerived().TransformType(E->getType());
15286 if (T.isNull())
15287 return ExprError();
15288
15289 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15290 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15291 if (!Constructor)
15292 return ExprError();
15293
15294 if (!getDerived().AlwaysRebuild() &&
15295 T == E->getType() &&
15296 Constructor == E->getConstructor()) {
15297 // Mark the constructor as referenced.
15298 // FIXME: Instantiation-specific
15299 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15300 return E;
15301 }
15302
15303 return getDerived().RebuildCXXInheritedCtorInitExpr(
15304 T, E->getLocation(), Constructor,
15305 E->constructsVBase(), E->inheritedFromVBase());
15306}
15307
15308/// Transform a C++ temporary-binding expression.
15309///
15310/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15311/// transform the subexpression and return that.
15312template<typename Derived>
15315 if (auto *Dtor = E->getTemporary()->getDestructor())
15316 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15317 const_cast<CXXDestructorDecl *>(Dtor));
15318 return getDerived().TransformExpr(E->getSubExpr());
15319}
15320
15321/// Transform a C++ expression that contains cleanups that should
15322/// be run after the expression is evaluated.
15323///
15324/// Since ExprWithCleanups nodes are implicitly generated, we
15325/// just transform the subexpression and return that.
15326template<typename Derived>
15329 return getDerived().TransformExpr(E->getSubExpr());
15330}
15331
15332template<typename Derived>
15336 TypeSourceInfo *T =
15337 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15338 if (!T)
15339 return ExprError();
15340
15341 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15342 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15343 if (!Constructor)
15344 return ExprError();
15345
15346 bool ArgumentChanged = false;
15348 Args.reserve(E->getNumArgs());
15349 {
15352 E->isListInitialization());
15353 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15354 &ArgumentChanged))
15355 return ExprError();
15356
15357 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15358 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15359 if (Res.isInvalid())
15360 return ExprError();
15361 Args = {Res.get()};
15362 }
15363 }
15364
15365 if (!getDerived().AlwaysRebuild() &&
15366 T == E->getTypeSourceInfo() &&
15367 Constructor == E->getConstructor() &&
15368 !ArgumentChanged) {
15369 // FIXME: Instantiation-specific
15370 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15371 return SemaRef.MaybeBindToTemporary(E);
15372 }
15373
15374 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15375 return getDerived().RebuildCXXTemporaryObjectExpr(
15376 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15377}
15378
15379template<typename Derived>
15382 // Transform any init-capture expressions before entering the scope of the
15383 // lambda body, because they are not semantically within that scope.
15384 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15385 struct TransformedInitCapture {
15386 // The location of the ... if the result is retaining a pack expansion.
15387 SourceLocation EllipsisLoc;
15388 // Zero or more expansions of the init-capture.
15389 SmallVector<InitCaptureInfoTy, 4> Expansions;
15390 };
15392 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15393 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15394 CEnd = E->capture_end();
15395 C != CEnd; ++C) {
15396 if (!E->isInitCapture(C))
15397 continue;
15398
15399 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15400 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15401
15402 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15403 UnsignedOrNone NumExpansions) {
15404 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15405 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15406
15407 if (NewExprInitResult.isInvalid()) {
15408 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15409 return;
15410 }
15411 Expr *NewExprInit = NewExprInitResult.get();
15412
15413 QualType NewInitCaptureType =
15414 getSema().buildLambdaInitCaptureInitialization(
15415 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15416 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15417 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15419 NewExprInit);
15420 Result.Expansions.push_back(
15421 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15422 };
15423
15424 // If this is an init-capture pack, consider expanding the pack now.
15425 if (OldVD->isParameterPack()) {
15426 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15427 ->getTypeLoc()
15430 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15431
15432 // Determine whether the set of unexpanded parameter packs can and should
15433 // be expanded.
15434 bool Expand = true;
15435 bool RetainExpansion = false;
15436 UnsignedOrNone OrigNumExpansions =
15437 ExpansionTL.getTypePtr()->getNumExpansions();
15438 UnsignedOrNone NumExpansions = OrigNumExpansions;
15439 if (getDerived().TryExpandParameterPacks(
15440 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
15441 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15442 RetainExpansion, NumExpansions))
15443 return ExprError();
15444 assert(!RetainExpansion && "Should not need to retain expansion after a "
15445 "capture since it cannot be extended");
15446 if (Expand) {
15447 for (unsigned I = 0; I != *NumExpansions; ++I) {
15448 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15449 SubstInitCapture(SourceLocation(), std::nullopt);
15450 }
15451 } else {
15452 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15453 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15454 }
15455 } else {
15456 SubstInitCapture(SourceLocation(), std::nullopt);
15457 }
15458 }
15459
15460 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15461 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15462
15463 // Create the local class that will describe the lambda.
15464
15465 // FIXME: DependencyKind below is wrong when substituting inside a templated
15466 // context that isn't a DeclContext (such as a variable template), or when
15467 // substituting an unevaluated lambda inside of a function's parameter's type
15468 // - as parameter types are not instantiated from within a function's DC. We
15469 // use evaluation contexts to distinguish the function parameter case.
15472 DeclContext *DC = getSema().CurContext;
15473 // A RequiresExprBodyDecl is not interesting for dependencies.
15474 // For the following case,
15475 //
15476 // template <typename>
15477 // concept C = requires { [] {}; };
15478 //
15479 // template <class F>
15480 // struct Widget;
15481 //
15482 // template <C F>
15483 // struct Widget<F> {};
15484 //
15485 // While we are substituting Widget<F>, the parent of DC would be
15486 // the template specialization itself. Thus, the lambda expression
15487 // will be deemed as dependent even if there are no dependent template
15488 // arguments.
15489 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15490 while (DC->isRequiresExprBody())
15491 DC = DC->getParent();
15492 if ((getSema().isUnevaluatedContext() ||
15493 getSema().isConstantEvaluatedContext()) &&
15494 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15495 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15496
15497 CXXRecordDecl *OldClass = E->getLambdaClass();
15498 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15499 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15500 E->getCaptureDefault());
15501 getDerived().transformedLocalDecl(OldClass, {Class});
15502
15503 CXXMethodDecl *NewCallOperator =
15504 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15505
15506 // Enter the scope of the lambda.
15507 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15508 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15509 E->hasExplicitParameters(), E->isMutable());
15510
15511 // Introduce the context of the call operator.
15512 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15513 /*NewThisContext*/false);
15514
15515 bool Invalid = false;
15516
15517 // Transform captures.
15518 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15519 CEnd = E->capture_end();
15520 C != CEnd; ++C) {
15521 // When we hit the first implicit capture, tell Sema that we've finished
15522 // the list of explicit captures.
15523 if (C->isImplicit())
15524 break;
15525
15526 // Capturing 'this' is trivial.
15527 if (C->capturesThis()) {
15528 // If this is a lambda that is part of a default member initialiser
15529 // and which we're instantiating outside the class that 'this' is
15530 // supposed to refer to, adjust the type of 'this' accordingly.
15531 //
15532 // Otherwise, leave the type of 'this' as-is.
15533 Sema::CXXThisScopeRAII ThisScope(
15534 getSema(),
15535 dyn_cast_if_present<CXXRecordDecl>(
15536 getSema().getFunctionLevelDeclContext()),
15537 Qualifiers());
15538 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15539 /*BuildAndDiagnose*/ true, nullptr,
15540 C->getCaptureKind() == LCK_StarThis);
15541 continue;
15542 }
15543 // Captured expression will be recaptured during captured variables
15544 // rebuilding.
15545 if (C->capturesVLAType())
15546 continue;
15547
15548 // Rebuild init-captures, including the implied field declaration.
15549 if (E->isInitCapture(C)) {
15550 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15551
15552 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15554
15555 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15556 ExprResult Init = Info.first;
15557 QualType InitQualType = Info.second;
15558 if (Init.isInvalid() || InitQualType.isNull()) {
15559 Invalid = true;
15560 break;
15561 }
15562 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15563 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15564 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15565 getSema().CurContext);
15566 if (!NewVD) {
15567 Invalid = true;
15568 break;
15569 }
15570 NewVDs.push_back(NewVD);
15571 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15572 // Cases we want to tackle:
15573 // ([C(Pack)] {}, ...)
15574 // But rule out cases e.g.
15575 // [...C = Pack()] {}
15576 if (NewC.EllipsisLoc.isInvalid())
15577 LSI->ContainsUnexpandedParameterPack |=
15578 Init.get()->containsUnexpandedParameterPack();
15579 }
15580
15581 if (Invalid)
15582 break;
15583
15584 getDerived().transformedLocalDecl(OldVD, NewVDs);
15585 continue;
15586 }
15587
15588 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15589
15590 // Determine the capture kind for Sema.
15592 : C->getCaptureKind() == LCK_ByCopy
15595 SourceLocation EllipsisLoc;
15596 if (C->isPackExpansion()) {
15597 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15598 bool ShouldExpand = false;
15599 bool RetainExpansion = false;
15600 UnsignedOrNone NumExpansions = std::nullopt;
15601 if (getDerived().TryExpandParameterPacks(
15602 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
15603 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
15604 RetainExpansion, NumExpansions)) {
15605 Invalid = true;
15606 continue;
15607 }
15608
15609 if (ShouldExpand) {
15610 // The transform has determined that we should perform an expansion;
15611 // transform and capture each of the arguments.
15612 // expansion of the pattern. Do so.
15613 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
15614 for (unsigned I = 0; I != *NumExpansions; ++I) {
15615 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15616 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
15617 getDerived().TransformDecl(C->getLocation(), Pack));
15618 if (!CapturedVar) {
15619 Invalid = true;
15620 continue;
15621 }
15622
15623 // Capture the transformed variable.
15624 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15625 }
15626
15627 // FIXME: Retain a pack expansion if RetainExpansion is true.
15628
15629 continue;
15630 }
15631
15632 EllipsisLoc = C->getEllipsisLoc();
15633 }
15634
15635 // Transform the captured variable.
15636 auto *CapturedVar = cast_or_null<ValueDecl>(
15637 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15638 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15639 Invalid = true;
15640 continue;
15641 }
15642
15643 // This is not an init-capture; however it contains an unexpanded pack e.g.
15644 // ([Pack] {}(), ...)
15645 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15646 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15647
15648 // Capture the transformed variable.
15649 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15650 EllipsisLoc);
15651 }
15652 getSema().finishLambdaExplicitCaptures(LSI);
15653
15654 // Transform the template parameters, and add them to the current
15655 // instantiation scope. The null case is handled correctly.
15656 auto TPL = getDerived().TransformTemplateParameterList(
15657 E->getTemplateParameterList());
15658 LSI->GLTemplateParameterList = TPL;
15659 if (TPL) {
15660 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15661 TPL);
15662 LSI->ContainsUnexpandedParameterPack |=
15663 TPL->containsUnexpandedParameterPack();
15664 }
15665
15666 TypeLocBuilder NewCallOpTLBuilder;
15667 TypeLoc OldCallOpTypeLoc =
15668 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15669 QualType NewCallOpType =
15670 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15671 if (NewCallOpType.isNull())
15672 return ExprError();
15673 LSI->ContainsUnexpandedParameterPack |=
15674 NewCallOpType->containsUnexpandedParameterPack();
15675 TypeSourceInfo *NewCallOpTSI =
15676 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15677
15678 // The type may be an AttributedType or some other kind of sugar;
15679 // get the actual underlying FunctionProtoType.
15680 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15681 assert(FPTL && "Not a FunctionProtoType?");
15682
15683 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
15684 if (!TRC.ArgPackSubstIndex)
15686
15687 getSema().CompleteLambdaCallOperator(
15688 NewCallOperator, E->getCallOperator()->getLocation(),
15689 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
15690 E->getCallOperator()->getConstexprKind(),
15691 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15692 E->hasExplicitResultType());
15693
15694 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15695 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15696
15697 {
15698 // Number the lambda for linkage purposes if necessary.
15699 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15700
15701 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15702 if (getDerived().ReplacingOriginal()) {
15703 Numbering = OldClass->getLambdaNumbering();
15704 }
15705
15706 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15707 }
15708
15709 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15710 // evaluation context even if we're not transforming the function body.
15711 getSema().PushExpressionEvaluationContextForFunction(
15713 E->getCallOperator());
15714
15717 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15718 getSema().pushCodeSynthesisContext(C);
15719
15720 // Instantiate the body of the lambda expression.
15721 StmtResult Body =
15722 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15723
15724 getSema().popCodeSynthesisContext();
15725
15726 // ActOnLambda* will pop the function scope for us.
15727 FuncScopeCleanup.disable();
15728
15729 if (Body.isInvalid()) {
15730 SavedContext.pop();
15731 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15732 /*IsInstantiation=*/true);
15733 return ExprError();
15734 }
15735
15736 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15737 /*IsInstantiation=*/true,
15738 /*RetainFunctionScopeInfo=*/true);
15739 SavedContext.pop();
15740
15741 // Recompute the dependency of the lambda so that we can defer the lambda call
15742 // construction until after we have all the necessary template arguments. For
15743 // example, given
15744 //
15745 // template <class> struct S {
15746 // template <class U>
15747 // using Type = decltype([](U){}(42.0));
15748 // };
15749 // void foo() {
15750 // using T = S<int>::Type<float>;
15751 // ^~~~~~
15752 // }
15753 //
15754 // We would end up here from instantiating S<int> when ensuring its
15755 // completeness. That would transform the lambda call expression regardless of
15756 // the absence of the corresponding argument for U.
15757 //
15758 // Going ahead with unsubstituted type U makes things worse: we would soon
15759 // compare the argument type (which is float) against the parameter U
15760 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15761 // error suggesting unmatched types 'U' and 'float'!
15762 //
15763 // That said, everything will be fine if we defer that semantic checking.
15764 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15765 // dependent. Since the CallExpr's dependency boils down to the lambda's
15766 // dependency in this case, we can harness that by recomputing the dependency
15767 // from the instantiation arguments.
15768 //
15769 // FIXME: Creating the type of a lambda requires us to have a dependency
15770 // value, which happens before its substitution. We update its dependency
15771 // *after* the substitution in case we can't decide the dependency
15772 // so early, e.g. because we want to see if any of the *substituted*
15773 // parameters are dependent.
15774 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15775 Class->setLambdaDependencyKind(DependencyKind);
15776
15777 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15778 Body.get()->getEndLoc(), LSI);
15779}
15780
15781template<typename Derived>
15786
15787template<typename Derived>
15790 // Transform captures.
15792 CEnd = E->capture_end();
15793 C != CEnd; ++C) {
15794 // When we hit the first implicit capture, tell Sema that we've finished
15795 // the list of explicit captures.
15796 if (!C->isImplicit())
15797 continue;
15798
15799 // Capturing 'this' is trivial.
15800 if (C->capturesThis()) {
15801 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15802 /*BuildAndDiagnose*/ true, nullptr,
15803 C->getCaptureKind() == LCK_StarThis);
15804 continue;
15805 }
15806 // Captured expression will be recaptured during captured variables
15807 // rebuilding.
15808 if (C->capturesVLAType())
15809 continue;
15810
15811 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15812 assert(!E->isInitCapture(C) && "implicit init-capture?");
15813
15814 // Transform the captured variable.
15815 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15816 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15817 if (!CapturedVar || CapturedVar->isInvalidDecl())
15818 return StmtError();
15819
15820 // Capture the transformed variable.
15821 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15822 }
15823
15824 return S;
15825}
15826
15827template<typename Derived>
15831 TypeSourceInfo *T =
15832 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15833 if (!T)
15834 return ExprError();
15835
15836 bool ArgumentChanged = false;
15838 Args.reserve(E->getNumArgs());
15839 {
15843 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15844 &ArgumentChanged))
15845 return ExprError();
15846 }
15847
15848 if (!getDerived().AlwaysRebuild() &&
15849 T == E->getTypeSourceInfo() &&
15850 !ArgumentChanged)
15851 return E;
15852
15853 // FIXME: we're faking the locations of the commas
15854 return getDerived().RebuildCXXUnresolvedConstructExpr(
15855 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15856}
15857
15858template<typename Derived>
15862 // Transform the base of the expression.
15863 ExprResult Base((Expr*) nullptr);
15864 Expr *OldBase;
15865 QualType BaseType;
15866 QualType ObjectType;
15867 if (!E->isImplicitAccess()) {
15868 OldBase = E->getBase();
15869 Base = getDerived().TransformExpr(OldBase);
15870 if (Base.isInvalid())
15871 return ExprError();
15872
15873 // Start the member reference and compute the object's type.
15874 ParsedType ObjectTy;
15875 bool MayBePseudoDestructor = false;
15876 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15877 E->getOperatorLoc(),
15878 E->isArrow()? tok::arrow : tok::period,
15879 ObjectTy,
15880 MayBePseudoDestructor);
15881 if (Base.isInvalid())
15882 return ExprError();
15883
15884 ObjectType = ObjectTy.get();
15885 BaseType = ((Expr*) Base.get())->getType();
15886 } else {
15887 OldBase = nullptr;
15888 BaseType = getDerived().TransformType(E->getBaseType());
15889 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15890 }
15891
15892 // Transform the first part of the nested-name-specifier that qualifies
15893 // the member name.
15894 NamedDecl *FirstQualifierInScope
15895 = getDerived().TransformFirstQualifierInScope(
15896 E->getFirstQualifierFoundInScope(),
15897 E->getQualifierLoc().getBeginLoc());
15898
15899 NestedNameSpecifierLoc QualifierLoc;
15900 if (E->getQualifier()) {
15901 QualifierLoc
15902 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15903 ObjectType,
15904 FirstQualifierInScope);
15905 if (!QualifierLoc)
15906 return ExprError();
15907 }
15908
15909 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15910
15911 // TODO: If this is a conversion-function-id, verify that the
15912 // destination type name (if present) resolves the same way after
15913 // instantiation as it did in the local scope.
15914
15915 DeclarationNameInfo NameInfo
15916 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15917 if (!NameInfo.getName())
15918 return ExprError();
15919
15920 if (!E->hasExplicitTemplateArgs()) {
15921 // This is a reference to a member without an explicitly-specified
15922 // template argument list. Optimize for this common case.
15923 if (!getDerived().AlwaysRebuild() &&
15924 Base.get() == OldBase &&
15925 BaseType == E->getBaseType() &&
15926 QualifierLoc == E->getQualifierLoc() &&
15927 NameInfo.getName() == E->getMember() &&
15928 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15929 return E;
15930
15931 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15932 BaseType,
15933 E->isArrow(),
15934 E->getOperatorLoc(),
15935 QualifierLoc,
15936 TemplateKWLoc,
15937 FirstQualifierInScope,
15938 NameInfo,
15939 /*TemplateArgs*/nullptr);
15940 }
15941
15942 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15943 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15944 E->getNumTemplateArgs(),
15945 TransArgs))
15946 return ExprError();
15947
15948 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15949 BaseType,
15950 E->isArrow(),
15951 E->getOperatorLoc(),
15952 QualifierLoc,
15953 TemplateKWLoc,
15954 FirstQualifierInScope,
15955 NameInfo,
15956 &TransArgs);
15957}
15958
15959template <typename Derived>
15961 UnresolvedMemberExpr *Old) {
15962 // Transform the base of the expression.
15963 ExprResult Base((Expr *)nullptr);
15964 QualType BaseType;
15965 if (!Old->isImplicitAccess()) {
15966 Base = getDerived().TransformExpr(Old->getBase());
15967 if (Base.isInvalid())
15968 return ExprError();
15969 Base =
15970 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
15971 if (Base.isInvalid())
15972 return ExprError();
15973 BaseType = Base.get()->getType();
15974 } else {
15975 BaseType = getDerived().TransformType(Old->getBaseType());
15976 }
15977
15978 NestedNameSpecifierLoc QualifierLoc;
15979 if (Old->getQualifierLoc()) {
15980 QualifierLoc =
15981 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15982 if (!QualifierLoc)
15983 return ExprError();
15984 }
15985
15986 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15987
15988 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
15989
15990 // Transform the declaration set.
15991 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
15992 return ExprError();
15993
15994 // Determine the naming class.
15995 if (Old->getNamingClass()) {
15996 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
15997 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
15998 if (!NamingClass)
15999 return ExprError();
16000
16001 R.setNamingClass(NamingClass);
16002 }
16003
16004 TemplateArgumentListInfo TransArgs;
16005 if (Old->hasExplicitTemplateArgs()) {
16006 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16007 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16008 if (getDerived().TransformTemplateArguments(
16009 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16010 return ExprError();
16011 }
16012
16013 // FIXME: to do this check properly, we will need to preserve the
16014 // first-qualifier-in-scope here, just in case we had a dependent
16015 // base (and therefore couldn't do the check) and a
16016 // nested-name-qualifier (and therefore could do the lookup).
16017 NamedDecl *FirstQualifierInScope = nullptr;
16018
16019 return getDerived().RebuildUnresolvedMemberExpr(
16020 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16021 TemplateKWLoc, FirstQualifierInScope, R,
16022 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16023}
16024
16025template<typename Derived>
16030 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16031 if (SubExpr.isInvalid())
16032 return ExprError();
16033
16034 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16035 return E;
16036
16037 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16038}
16039
16040template<typename Derived>
16043 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16044 if (Pattern.isInvalid())
16045 return ExprError();
16046
16047 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16048 return E;
16049
16050 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16051 E->getNumExpansions());
16052}
16053
16054template <typename Derived>
16056 ArrayRef<TemplateArgument> PackArgs) {
16058 for (const TemplateArgument &Arg : PackArgs) {
16059 if (!Arg.isPackExpansion()) {
16060 Result = *Result + 1;
16061 continue;
16062 }
16063
16064 TemplateArgumentLoc ArgLoc;
16065 InventTemplateArgumentLoc(Arg, ArgLoc);
16066
16067 // Find the pattern of the pack expansion.
16068 SourceLocation Ellipsis;
16069 UnsignedOrNone OrigNumExpansions = std::nullopt;
16070 TemplateArgumentLoc Pattern =
16071 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16072 OrigNumExpansions);
16073
16074 // Substitute under the pack expansion. Do not expand the pack (yet).
16075 TemplateArgumentLoc OutPattern;
16076 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16077 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16078 /*Uneval*/ true))
16079 return 1u;
16080
16081 // See if we can determine the number of arguments from the result.
16082 UnsignedOrNone NumExpansions =
16083 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16084 if (!NumExpansions) {
16085 // No: we must be in an alias template expansion, and we're going to
16086 // need to actually expand the packs.
16087 Result = std::nullopt;
16088 break;
16089 }
16090
16091 Result = *Result + *NumExpansions;
16092 }
16093 return Result;
16094}
16095
16096template<typename Derived>
16099 // If E is not value-dependent, then nothing will change when we transform it.
16100 // Note: This is an instantiation-centric view.
16101 if (!E->isValueDependent())
16102 return E;
16103
16106
16108 TemplateArgument ArgStorage;
16109
16110 // Find the argument list to transform.
16111 if (E->isPartiallySubstituted()) {
16112 PackArgs = E->getPartialArguments();
16113 } else if (E->isValueDependent()) {
16114 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16115 bool ShouldExpand = false;
16116 bool RetainExpansion = false;
16117 UnsignedOrNone NumExpansions = std::nullopt;
16118 if (getDerived().TryExpandParameterPacks(
16119 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16120 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16121 RetainExpansion, NumExpansions))
16122 return ExprError();
16123
16124 // If we need to expand the pack, build a template argument from it and
16125 // expand that.
16126 if (ShouldExpand) {
16127 auto *Pack = E->getPack();
16128 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16129 ArgStorage = getSema().Context.getPackExpansionType(
16130 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16131 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16132 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16133 } else {
16134 auto *VD = cast<ValueDecl>(Pack);
16135 ExprResult DRE = getSema().BuildDeclRefExpr(
16136 VD, VD->getType().getNonLValueExprType(getSema().Context),
16137 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16138 E->getPackLoc());
16139 if (DRE.isInvalid())
16140 return ExprError();
16141 ArgStorage = TemplateArgument(
16142 new (getSema().Context)
16143 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16144 /*IsCanonical=*/false);
16145 }
16146 PackArgs = ArgStorage;
16147 }
16148 }
16149
16150 // If we're not expanding the pack, just transform the decl.
16151 if (!PackArgs.size()) {
16152 auto *Pack = cast_or_null<NamedDecl>(
16153 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16154 if (!Pack)
16155 return ExprError();
16156 return getDerived().RebuildSizeOfPackExpr(
16157 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16158 std::nullopt, {});
16159 }
16160
16161 // Try to compute the result without performing a partial substitution.
16163 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16164
16165 // Common case: we could determine the number of expansions without
16166 // substituting.
16167 if (Result)
16168 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16169 E->getPackLoc(),
16170 E->getRParenLoc(), *Result, {});
16171
16172 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16173 E->getPackLoc());
16174 {
16175 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16177 Derived, const TemplateArgument*> PackLocIterator;
16178 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16179 PackLocIterator(*this, PackArgs.end()),
16180 TransformedPackArgs, /*Uneval*/true))
16181 return ExprError();
16182 }
16183
16184 // Check whether we managed to fully-expand the pack.
16185 // FIXME: Is it possible for us to do so and not hit the early exit path?
16187 bool PartialSubstitution = false;
16188 for (auto &Loc : TransformedPackArgs.arguments()) {
16189 Args.push_back(Loc.getArgument());
16190 if (Loc.getArgument().isPackExpansion())
16191 PartialSubstitution = true;
16192 }
16193
16194 if (PartialSubstitution)
16195 return getDerived().RebuildSizeOfPackExpr(
16196 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16197 std::nullopt, Args);
16198
16199 return getDerived().RebuildSizeOfPackExpr(
16200 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16201 /*Length=*/static_cast<unsigned>(Args.size()),
16202 /*PartialArgs=*/{});
16203}
16204
16205template <typename Derived>
16208 if (!E->isValueDependent())
16209 return E;
16210
16211 // Transform the index
16212 ExprResult IndexExpr;
16213 {
16214 EnterExpressionEvaluationContext ConstantContext(
16216 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16217 if (IndexExpr.isInvalid())
16218 return ExprError();
16219 }
16220
16221 SmallVector<Expr *, 5> ExpandedExprs;
16222 bool FullySubstituted = true;
16223 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16224 Expr *Pattern = E->getPackIdExpression();
16226 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16227 Unexpanded);
16228 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16229
16230 // Determine whether the set of unexpanded parameter packs can and should
16231 // be expanded.
16232 bool ShouldExpand = true;
16233 bool RetainExpansion = false;
16234 UnsignedOrNone OrigNumExpansions = std::nullopt,
16235 NumExpansions = std::nullopt;
16236 if (getDerived().TryExpandParameterPacks(
16237 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16238 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16239 RetainExpansion, NumExpansions))
16240 return true;
16241 if (!ShouldExpand) {
16242 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16243 ExprResult Pack = getDerived().TransformExpr(Pattern);
16244 if (Pack.isInvalid())
16245 return ExprError();
16246 return getDerived().RebuildPackIndexingExpr(
16247 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16248 {}, /*FullySubstituted=*/false);
16249 }
16250 for (unsigned I = 0; I != *NumExpansions; ++I) {
16251 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16252 ExprResult Out = getDerived().TransformExpr(Pattern);
16253 if (Out.isInvalid())
16254 return true;
16255 if (Out.get()->containsUnexpandedParameterPack()) {
16256 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16257 OrigNumExpansions);
16258 if (Out.isInvalid())
16259 return true;
16260 FullySubstituted = false;
16261 }
16262 ExpandedExprs.push_back(Out.get());
16263 }
16264 // If we're supposed to retain a pack expansion, do so by temporarily
16265 // forgetting the partially-substituted parameter pack.
16266 if (RetainExpansion) {
16267 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16268
16269 ExprResult Out = getDerived().TransformExpr(Pattern);
16270 if (Out.isInvalid())
16271 return true;
16272
16273 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16274 OrigNumExpansions);
16275 if (Out.isInvalid())
16276 return true;
16277 FullySubstituted = false;
16278 ExpandedExprs.push_back(Out.get());
16279 }
16280 } else if (!E->expandsToEmptyPack()) {
16281 if (getDerived().TransformExprs(E->getExpressions().data(),
16282 E->getExpressions().size(), false,
16283 ExpandedExprs))
16284 return ExprError();
16285 }
16286
16287 return getDerived().RebuildPackIndexingExpr(
16288 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16289 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16290}
16291
16292template<typename Derived>
16296 // Default behavior is to do nothing with this transformation.
16297 return E;
16298}
16299
16300template<typename Derived>
16304 // Default behavior is to do nothing with this transformation.
16305 return E;
16306}
16307
16308template<typename Derived>
16311 // Default behavior is to do nothing with this transformation.
16312 return E;
16313}
16314
16315template<typename Derived>
16319 return getDerived().TransformExpr(E->getSubExpr());
16320}
16321
16322template<typename Derived>
16325 UnresolvedLookupExpr *Callee = nullptr;
16326 if (Expr *OldCallee = E->getCallee()) {
16327 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16328 if (CalleeResult.isInvalid())
16329 return ExprError();
16330 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16331 }
16332
16333 Expr *Pattern = E->getPattern();
16334
16336 getSema().collectUnexpandedParameterPacks(Pattern, 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 Expand = true;
16342 bool RetainExpansion = false;
16343 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
16344 NumExpansions = OrigNumExpansions;
16345 if (getDerived().TryExpandParameterPacks(
16346 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16347 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16348 NumExpansions))
16349 return true;
16350
16351 if (!Expand) {
16352 // Do not expand any packs here, just transform and rebuild a fold
16353 // expression.
16354 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16355
16356 ExprResult LHS =
16357 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16358 if (LHS.isInvalid())
16359 return true;
16360
16361 ExprResult RHS =
16362 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16363 if (RHS.isInvalid())
16364 return true;
16365
16366 if (!getDerived().AlwaysRebuild() &&
16367 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16368 return E;
16369
16370 return getDerived().RebuildCXXFoldExpr(
16371 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16372 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16373 }
16374
16375 // Formally a fold expression expands to nested parenthesized expressions.
16376 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16377 // them.
16378 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
16379 SemaRef.Diag(E->getEllipsisLoc(),
16380 clang::diag::err_fold_expression_limit_exceeded)
16381 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16382 << E->getSourceRange();
16383 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16384 return ExprError();
16385 }
16386
16387 // The transform has determined that we should perform an elementwise
16388 // expansion of the pattern. Do so.
16389 ExprResult Result = getDerived().TransformExpr(E->getInit());
16390 if (Result.isInvalid())
16391 return true;
16392 bool LeftFold = E->isLeftFold();
16393
16394 // If we're retaining an expansion for a right fold, it is the innermost
16395 // component and takes the init (if any).
16396 if (!LeftFold && RetainExpansion) {
16397 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16398
16399 ExprResult Out = getDerived().TransformExpr(Pattern);
16400 if (Out.isInvalid())
16401 return true;
16402
16403 Result = getDerived().RebuildCXXFoldExpr(
16404 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16405 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16406 if (Result.isInvalid())
16407 return true;
16408 }
16409
16410 bool WarnedOnComparison = false;
16411 for (unsigned I = 0; I != *NumExpansions; ++I) {
16412 Sema::ArgPackSubstIndexRAII SubstIndex(
16413 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16414 ExprResult Out = getDerived().TransformExpr(Pattern);
16415 if (Out.isInvalid())
16416 return true;
16417
16418 if (Out.get()->containsUnexpandedParameterPack()) {
16419 // We still have a pack; retain a pack expansion for this slice.
16420 Result = getDerived().RebuildCXXFoldExpr(
16421 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16422 E->getOperator(), E->getEllipsisLoc(),
16423 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16424 OrigNumExpansions);
16425 } else if (Result.isUsable()) {
16426 // We've got down to a single element; build a binary operator.
16427 Expr *LHS = LeftFold ? Result.get() : Out.get();
16428 Expr *RHS = LeftFold ? Out.get() : Result.get();
16429 if (Callee) {
16430 UnresolvedSet<16> Functions;
16431 Functions.append(Callee->decls_begin(), Callee->decls_end());
16432 Result = getDerived().RebuildCXXOperatorCallExpr(
16433 BinaryOperator::getOverloadedOperator(E->getOperator()),
16434 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16435 Functions, LHS, RHS);
16436 } else {
16437 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16438 E->getOperator(), LHS, RHS,
16439 /*ForFoldExpresion=*/true);
16440 if (!WarnedOnComparison && Result.isUsable()) {
16441 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
16442 BO && BO->isComparisonOp()) {
16443 WarnedOnComparison = true;
16444 SemaRef.Diag(BO->getBeginLoc(),
16445 diag::warn_comparison_in_fold_expression)
16446 << BO->getOpcodeStr();
16447 }
16448 }
16449 }
16450 } else
16451 Result = Out;
16452
16453 if (Result.isInvalid())
16454 return true;
16455 }
16456
16457 // If we're retaining an expansion for a left fold, it is the outermost
16458 // component and takes the complete expansion so far as its init (if any).
16459 if (LeftFold && RetainExpansion) {
16460 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16461
16462 ExprResult Out = getDerived().TransformExpr(Pattern);
16463 if (Out.isInvalid())
16464 return true;
16465
16466 Result = getDerived().RebuildCXXFoldExpr(
16467 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16468 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16469 if (Result.isInvalid())
16470 return true;
16471 }
16472
16473 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16474 PE->setIsProducedByFoldExpansion();
16475
16476 // If we had no init and an empty pack, and we're not retaining an expansion,
16477 // then produce a fallback value or error.
16478 if (Result.isUnset())
16479 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16480 E->getOperator());
16481 return Result;
16482}
16483
16484template <typename Derived>
16487 SmallVector<Expr *, 4> TransformedInits;
16488 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16489
16490 QualType T = getDerived().TransformType(E->getType());
16491
16492 bool ArgChanged = false;
16493
16494 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
16495 TransformedInits, &ArgChanged))
16496 return ExprError();
16497
16498 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
16499 return E;
16500
16501 return getDerived().RebuildCXXParenListInitExpr(
16502 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
16503 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
16504}
16505
16506template<typename Derived>
16510 return getDerived().TransformExpr(E->getSubExpr());
16511}
16512
16513template<typename Derived>
16516 return SemaRef.MaybeBindToTemporary(E);
16517}
16518
16519template<typename Derived>
16522 return E;
16523}
16524
16525template<typename Derived>
16528 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16529 if (SubExpr.isInvalid())
16530 return ExprError();
16531
16532 if (!getDerived().AlwaysRebuild() &&
16533 SubExpr.get() == E->getSubExpr())
16534 return E;
16535
16536 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16537}
16538
16539template<typename Derived>
16542 // Transform each of the elements.
16543 SmallVector<Expr *, 8> Elements;
16544 bool ArgChanged = false;
16545 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16546 /*IsCall=*/false, Elements, &ArgChanged))
16547 return ExprError();
16548
16549 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16550 return SemaRef.MaybeBindToTemporary(E);
16551
16552 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16553 Elements.data(),
16554 Elements.size());
16555}
16556
16557template<typename Derived>
16561 // Transform each of the elements.
16563 bool ArgChanged = false;
16564 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16565 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16566
16567 if (OrigElement.isPackExpansion()) {
16568 // This key/value element is a pack expansion.
16570 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16571 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16572 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16573
16574 // Determine whether the set of unexpanded parameter packs can
16575 // and should be expanded.
16576 bool Expand = true;
16577 bool RetainExpansion = false;
16578 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
16579 UnsignedOrNone NumExpansions = OrigNumExpansions;
16580 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16581 OrigElement.Value->getEndLoc());
16582 if (getDerived().TryExpandParameterPacks(
16583 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
16584 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16585 NumExpansions))
16586 return ExprError();
16587
16588 if (!Expand) {
16589 // The transform has determined that we should perform a simple
16590 // transformation on the pack expansion, producing another pack
16591 // expansion.
16592 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16593 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16594 if (Key.isInvalid())
16595 return ExprError();
16596
16597 if (Key.get() != OrigElement.Key)
16598 ArgChanged = true;
16599
16600 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16601 if (Value.isInvalid())
16602 return ExprError();
16603
16604 if (Value.get() != OrigElement.Value)
16605 ArgChanged = true;
16606
16607 ObjCDictionaryElement Expansion = {
16608 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16609 };
16610 Elements.push_back(Expansion);
16611 continue;
16612 }
16613
16614 // Record right away that the argument was changed. This needs
16615 // to happen even if the array expands to nothing.
16616 ArgChanged = true;
16617
16618 // The transform has determined that we should perform an elementwise
16619 // expansion of the pattern. Do so.
16620 for (unsigned I = 0; I != *NumExpansions; ++I) {
16621 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16622 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16623 if (Key.isInvalid())
16624 return ExprError();
16625
16626 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16627 if (Value.isInvalid())
16628 return ExprError();
16629
16630 ObjCDictionaryElement Element = {
16631 Key.get(), Value.get(), SourceLocation(), NumExpansions
16632 };
16633
16634 // If any unexpanded parameter packs remain, we still have a
16635 // pack expansion.
16636 // FIXME: Can this really happen?
16637 if (Key.get()->containsUnexpandedParameterPack() ||
16638 Value.get()->containsUnexpandedParameterPack())
16639 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16640
16641 Elements.push_back(Element);
16642 }
16643
16644 // FIXME: Retain a pack expansion if RetainExpansion is true.
16645
16646 // We've finished with this pack expansion.
16647 continue;
16648 }
16649
16650 // Transform and check key.
16651 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16652 if (Key.isInvalid())
16653 return ExprError();
16654
16655 if (Key.get() != OrigElement.Key)
16656 ArgChanged = true;
16657
16658 // Transform and check value.
16660 = getDerived().TransformExpr(OrigElement.Value);
16661 if (Value.isInvalid())
16662 return ExprError();
16663
16664 if (Value.get() != OrigElement.Value)
16665 ArgChanged = true;
16666
16667 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16668 std::nullopt};
16669 Elements.push_back(Element);
16670 }
16671
16672 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16673 return SemaRef.MaybeBindToTemporary(E);
16674
16675 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16676 Elements);
16677}
16678
16679template<typename Derived>
16682 TypeSourceInfo *EncodedTypeInfo
16683 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16684 if (!EncodedTypeInfo)
16685 return ExprError();
16686
16687 if (!getDerived().AlwaysRebuild() &&
16688 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16689 return E;
16690
16691 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16692 EncodedTypeInfo,
16693 E->getRParenLoc());
16694}
16695
16696template<typename Derived>
16699 // This is a kind of implicit conversion, and it needs to get dropped
16700 // and recomputed for the same general reasons that ImplicitCastExprs
16701 // do, as well a more specific one: this expression is only valid when
16702 // it appears *immediately* as an argument expression.
16703 return getDerived().TransformExpr(E->getSubExpr());
16704}
16705
16706template<typename Derived>
16709 TypeSourceInfo *TSInfo
16710 = getDerived().TransformType(E->getTypeInfoAsWritten());
16711 if (!TSInfo)
16712 return ExprError();
16713
16714 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16715 if (Result.isInvalid())
16716 return ExprError();
16717
16718 if (!getDerived().AlwaysRebuild() &&
16719 TSInfo == E->getTypeInfoAsWritten() &&
16720 Result.get() == E->getSubExpr())
16721 return E;
16722
16723 return SemaRef.ObjC().BuildObjCBridgedCast(
16724 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16725 Result.get());
16726}
16727
16728template <typename Derived>
16731 return E;
16732}
16733
16734template<typename Derived>
16737 // Transform arguments.
16738 bool ArgChanged = false;
16740 Args.reserve(E->getNumArgs());
16741 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16742 &ArgChanged))
16743 return ExprError();
16744
16745 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16746 // Class message: transform the receiver type.
16747 TypeSourceInfo *ReceiverTypeInfo
16748 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16749 if (!ReceiverTypeInfo)
16750 return ExprError();
16751
16752 // If nothing changed, just retain the existing message send.
16753 if (!getDerived().AlwaysRebuild() &&
16754 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16755 return SemaRef.MaybeBindToTemporary(E);
16756
16757 // Build a new class message send.
16759 E->getSelectorLocs(SelLocs);
16760 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16761 E->getSelector(),
16762 SelLocs,
16763 E->getMethodDecl(),
16764 E->getLeftLoc(),
16765 Args,
16766 E->getRightLoc());
16767 }
16768 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16769 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16770 if (!E->getMethodDecl())
16771 return ExprError();
16772
16773 // Build a new class message send to 'super'.
16775 E->getSelectorLocs(SelLocs);
16776 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16777 E->getSelector(),
16778 SelLocs,
16779 E->getReceiverType(),
16780 E->getMethodDecl(),
16781 E->getLeftLoc(),
16782 Args,
16783 E->getRightLoc());
16784 }
16785
16786 // Instance message: transform the receiver
16787 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16788 "Only class and instance messages may be instantiated");
16789 ExprResult Receiver
16790 = getDerived().TransformExpr(E->getInstanceReceiver());
16791 if (Receiver.isInvalid())
16792 return ExprError();
16793
16794 // If nothing changed, just retain the existing message send.
16795 if (!getDerived().AlwaysRebuild() &&
16796 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16797 return SemaRef.MaybeBindToTemporary(E);
16798
16799 // Build a new instance message send.
16801 E->getSelectorLocs(SelLocs);
16802 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16803 E->getSelector(),
16804 SelLocs,
16805 E->getMethodDecl(),
16806 E->getLeftLoc(),
16807 Args,
16808 E->getRightLoc());
16809}
16810
16811template<typename Derived>
16814 return E;
16815}
16816
16817template<typename Derived>
16820 return E;
16821}
16822
16823template<typename Derived>
16826 // Transform the base expression.
16827 ExprResult Base = getDerived().TransformExpr(E->getBase());
16828 if (Base.isInvalid())
16829 return ExprError();
16830
16831 // We don't need to transform the ivar; it will never change.
16832
16833 // If nothing changed, just retain the existing expression.
16834 if (!getDerived().AlwaysRebuild() &&
16835 Base.get() == E->getBase())
16836 return E;
16837
16838 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16839 E->getLocation(),
16840 E->isArrow(), E->isFreeIvar());
16841}
16842
16843template<typename Derived>
16846 // 'super' and types never change. Property never changes. Just
16847 // retain the existing expression.
16848 if (!E->isObjectReceiver())
16849 return E;
16850
16851 // Transform the base expression.
16852 ExprResult Base = getDerived().TransformExpr(E->getBase());
16853 if (Base.isInvalid())
16854 return ExprError();
16855
16856 // We don't need to transform the property; it will never change.
16857
16858 // If nothing changed, just retain the existing expression.
16859 if (!getDerived().AlwaysRebuild() &&
16860 Base.get() == E->getBase())
16861 return E;
16862
16863 if (E->isExplicitProperty())
16864 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16865 E->getExplicitProperty(),
16866 E->getLocation());
16867
16868 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16869 SemaRef.Context.PseudoObjectTy,
16870 E->getImplicitPropertyGetter(),
16871 E->getImplicitPropertySetter(),
16872 E->getLocation());
16873}
16874
16875template<typename Derived>
16878 // Transform the base expression.
16879 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16880 if (Base.isInvalid())
16881 return ExprError();
16882
16883 // Transform the key expression.
16884 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16885 if (Key.isInvalid())
16886 return ExprError();
16887
16888 // If nothing changed, just retain the existing expression.
16889 if (!getDerived().AlwaysRebuild() &&
16890 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16891 return E;
16892
16893 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16894 Base.get(), Key.get(),
16895 E->getAtIndexMethodDecl(),
16896 E->setAtIndexMethodDecl());
16897}
16898
16899template<typename Derived>
16902 // Transform the base expression.
16903 ExprResult Base = getDerived().TransformExpr(E->getBase());
16904 if (Base.isInvalid())
16905 return ExprError();
16906
16907 // If nothing changed, just retain the existing expression.
16908 if (!getDerived().AlwaysRebuild() &&
16909 Base.get() == E->getBase())
16910 return E;
16911
16912 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
16913 E->getOpLoc(),
16914 E->isArrow());
16915}
16916
16917template<typename Derived>
16920 bool ArgumentChanged = false;
16921 SmallVector<Expr*, 8> SubExprs;
16922 SubExprs.reserve(E->getNumSubExprs());
16923 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16924 SubExprs, &ArgumentChanged))
16925 return ExprError();
16926
16927 if (!getDerived().AlwaysRebuild() &&
16928 !ArgumentChanged)
16929 return E;
16930
16931 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
16932 SubExprs,
16933 E->getRParenLoc());
16934}
16935
16936template<typename Derived>
16939 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16940 if (SrcExpr.isInvalid())
16941 return ExprError();
16942
16943 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
16944 if (!Type)
16945 return ExprError();
16946
16947 if (!getDerived().AlwaysRebuild() &&
16948 Type == E->getTypeSourceInfo() &&
16949 SrcExpr.get() == E->getSrcExpr())
16950 return E;
16951
16952 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
16953 SrcExpr.get(), Type,
16954 E->getRParenLoc());
16955}
16956
16957template<typename Derived>
16960 BlockDecl *oldBlock = E->getBlockDecl();
16961
16962 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
16963 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
16964
16965 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
16966 blockScope->TheDecl->setBlockMissingReturnType(
16967 oldBlock->blockMissingReturnType());
16968
16970 SmallVector<QualType, 4> paramTypes;
16971
16972 const FunctionProtoType *exprFunctionType = E->getFunctionType();
16973
16974 // Parameter substitution.
16975 Sema::ExtParameterInfoBuilder extParamInfos;
16976 if (getDerived().TransformFunctionTypeParams(
16977 E->getCaretLocation(), oldBlock->parameters(), nullptr,
16978 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
16979 extParamInfos)) {
16980 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16981 return ExprError();
16982 }
16983
16984 QualType exprResultType =
16985 getDerived().TransformType(exprFunctionType->getReturnType());
16986
16987 auto epi = exprFunctionType->getExtProtoInfo();
16988 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
16989
16991 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
16992 blockScope->FunctionType = functionType;
16993
16994 // Set the parameters on the block decl.
16995 if (!params.empty())
16996 blockScope->TheDecl->setParams(params);
16997
16998 if (!oldBlock->blockMissingReturnType()) {
16999 blockScope->HasImplicitReturnType = false;
17000 blockScope->ReturnType = exprResultType;
17001 }
17002
17003 // Transform the body
17004 StmtResult body = getDerived().TransformStmt(E->getBody());
17005 if (body.isInvalid()) {
17006 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17007 return ExprError();
17008 }
17009
17010#ifndef NDEBUG
17011 // In builds with assertions, make sure that we captured everything we
17012 // captured before.
17013 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17014 for (const auto &I : oldBlock->captures()) {
17015 VarDecl *oldCapture = I.getVariable();
17016
17017 // Ignore parameter packs.
17018 if (oldCapture->isParameterPack())
17019 continue;
17020
17021 VarDecl *newCapture =
17022 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17023 oldCapture));
17024 assert(blockScope->CaptureMap.count(newCapture));
17025 }
17026
17027 // The this pointer may not be captured by the instantiated block, even when
17028 // it's captured by the original block, if the expression causing the
17029 // capture is in the discarded branch of a constexpr if statement.
17030 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17031 "this pointer isn't captured in the old block");
17032 }
17033#endif
17034
17035 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17036 /*Scope=*/nullptr);
17037}
17038
17039template<typename Derived>
17042 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17043 if (SrcExpr.isInvalid())
17044 return ExprError();
17045
17046 QualType Type = getDerived().TransformType(E->getType());
17047
17048 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17049 E->getRParenLoc());
17050}
17051
17052template<typename Derived>
17055 bool ArgumentChanged = false;
17056 SmallVector<Expr*, 8> SubExprs;
17057 SubExprs.reserve(E->getNumSubExprs());
17058 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17059 SubExprs, &ArgumentChanged))
17060 return ExprError();
17061
17062 if (!getDerived().AlwaysRebuild() &&
17063 !ArgumentChanged)
17064 return E;
17065
17066 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17067 E->getOp(), E->getRParenLoc());
17068}
17069
17070//===----------------------------------------------------------------------===//
17071// Type reconstruction
17072//===----------------------------------------------------------------------===//
17073
17074template<typename Derived>
17077 return SemaRef.BuildPointerType(PointeeType, Star,
17079}
17080
17081template<typename Derived>
17084 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17086}
17087
17088template<typename Derived>
17091 bool WrittenAsLValue,
17092 SourceLocation Sigil) {
17093 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17094 Sigil, getDerived().getBaseEntity());
17095}
17096
17097template <typename Derived>
17099 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17100 SourceLocation Sigil) {
17101 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17103}
17104
17105template<typename Derived>
17107 const ObjCTypeParamDecl *Decl,
17108 SourceLocation ProtocolLAngleLoc,
17110 ArrayRef<SourceLocation> ProtocolLocs,
17111 SourceLocation ProtocolRAngleLoc) {
17112 return SemaRef.ObjC().BuildObjCTypeParamType(
17113 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17114 /*FailOnError=*/true);
17115}
17116
17117template<typename Derived>
17119 QualType BaseType,
17120 SourceLocation Loc,
17121 SourceLocation TypeArgsLAngleLoc,
17123 SourceLocation TypeArgsRAngleLoc,
17124 SourceLocation ProtocolLAngleLoc,
17126 ArrayRef<SourceLocation> ProtocolLocs,
17127 SourceLocation ProtocolRAngleLoc) {
17128 return SemaRef.ObjC().BuildObjCObjectType(
17129 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17130 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17131 /*FailOnError=*/true,
17132 /*Rebuilding=*/true);
17133}
17134
17135template<typename Derived>
17137 QualType PointeeType,
17139 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17140}
17141
17142template <typename Derived>
17144 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17145 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17146 if (SizeExpr || !Size)
17147 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17148 IndexTypeQuals, BracketsRange,
17150
17151 QualType Types[] = {
17152 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17153 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17154 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17155 };
17156 QualType SizeType;
17157 for (const auto &T : Types)
17158 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17159 SizeType = T;
17160 break;
17161 }
17162
17163 // Note that we can return a VariableArrayType here in the case where
17164 // the element type was a dependent VariableArrayType.
17165 IntegerLiteral *ArraySize
17166 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17167 /*FIXME*/BracketsRange.getBegin());
17168 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17169 IndexTypeQuals, BracketsRange,
17171}
17172
17173template <typename Derived>
17175 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17176 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17177 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17178 IndexTypeQuals, BracketsRange);
17179}
17180
17181template <typename Derived>
17183 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17184 SourceRange BracketsRange) {
17185 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17186 IndexTypeQuals, BracketsRange);
17187}
17188
17189template <typename Derived>
17191 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17192 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17193 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17194 SizeExpr,
17195 IndexTypeQuals, BracketsRange);
17196}
17197
17198template <typename Derived>
17200 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17201 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17202 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17203 SizeExpr,
17204 IndexTypeQuals, BracketsRange);
17205}
17206
17207template <typename Derived>
17209 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17210 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17211 AttributeLoc);
17212}
17213
17214template <typename Derived>
17216 unsigned NumElements,
17217 VectorKind VecKind) {
17218 // FIXME: semantic checking!
17219 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17220}
17221
17222template <typename Derived>
17224 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17225 VectorKind VecKind) {
17226 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17227}
17228
17229template<typename Derived>
17231 unsigned NumElements,
17232 SourceLocation AttributeLoc) {
17233 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17234 NumElements, true);
17235 IntegerLiteral *VectorSize
17236 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17237 AttributeLoc);
17238 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17239}
17240
17241template<typename Derived>
17244 Expr *SizeExpr,
17245 SourceLocation AttributeLoc) {
17246 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17247}
17248
17249template <typename Derived>
17251 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17252 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17253 NumColumns);
17254}
17255
17256template <typename Derived>
17258 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17259 SourceLocation AttributeLoc) {
17260 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17261 AttributeLoc);
17262}
17263
17264template <typename Derived>
17268 return SemaRef.BuildFunctionType(T, ParamTypes,
17271 EPI);
17272}
17273
17274template<typename Derived>
17276 return SemaRef.Context.getFunctionNoProtoType(T);
17277}
17278
17279template <typename Derived>
17282 SourceLocation NameLoc, Decl *D) {
17283 assert(D && "no decl found");
17284 if (D->isInvalidDecl()) return QualType();
17285
17286 // FIXME: Doesn't account for ObjCInterfaceDecl!
17287 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17288 // A valid resolved using typename pack expansion decl can have multiple
17289 // UsingDecls, but they must each have exactly one type, and it must be
17290 // the same type in every case. But we must have at least one expansion!
17291 if (UPD->expansions().empty()) {
17292 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17293 << UPD->isCXXClassMember() << UPD;
17294 return QualType();
17295 }
17296
17297 // We might still have some unresolved types. Try to pick a resolved type
17298 // if we can. The final instantiation will check that the remaining
17299 // unresolved types instantiate to the type we pick.
17300 QualType FallbackT;
17301 QualType T;
17302 for (auto *E : UPD->expansions()) {
17303 QualType ThisT =
17304 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17305 if (ThisT.isNull())
17306 continue;
17307 if (ThisT->getAs<UnresolvedUsingType>())
17308 FallbackT = ThisT;
17309 else if (T.isNull())
17310 T = ThisT;
17311 else
17312 assert(getSema().Context.hasSameType(ThisT, T) &&
17313 "mismatched resolved types in using pack expansion");
17314 }
17315 return T.isNull() ? FallbackT : T;
17316 }
17317 if (auto *Using = dyn_cast<UsingDecl>(D)) {
17318 assert(Using->hasTypename() &&
17319 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17320
17321 // A valid resolved using typename decl points to exactly one type decl.
17322 assert(++Using->shadow_begin() == Using->shadow_end());
17323
17324 UsingShadowDecl *Shadow = *Using->shadow_begin();
17325 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
17326 return QualType();
17327 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
17328 }
17330 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17331 return SemaRef.Context.getUnresolvedUsingType(
17333}
17334
17335template <typename Derived>
17337 TypeOfKind Kind) {
17338 return SemaRef.BuildTypeofExprType(E, Kind);
17339}
17340
17341template<typename Derived>
17343 TypeOfKind Kind) {
17344 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17345}
17346
17347template <typename Derived>
17349 return SemaRef.BuildDecltypeType(E);
17350}
17351
17352template <typename Derived>
17354 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17355 SourceLocation EllipsisLoc, bool FullySubstituted,
17356 ArrayRef<QualType> Expansions) {
17357 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17358 FullySubstituted, Expansions);
17359}
17360
17361template<typename Derived>
17363 UnaryTransformType::UTTKind UKind,
17364 SourceLocation Loc) {
17365 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17366}
17367
17368template <typename Derived>
17371 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
17372 return SemaRef.CheckTemplateIdType(
17373 Keyword, Template, TemplateNameLoc, TemplateArgs,
17374 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
17375}
17376
17377template<typename Derived>
17379 SourceLocation KWLoc) {
17380 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17381}
17382
17383template<typename Derived>
17385 SourceLocation KWLoc,
17386 bool isReadPipe) {
17387 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17388 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17389}
17390
17391template <typename Derived>
17393 unsigned NumBits,
17394 SourceLocation Loc) {
17395 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17396 NumBits, true);
17397 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17398 SemaRef.Context.IntTy, Loc);
17399 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17400}
17401
17402template <typename Derived>
17404 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17405 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17406}
17407
17408template <typename Derived>
17410 bool TemplateKW,
17411 TemplateName Name) {
17412 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17413 Name);
17414}
17415
17416template <typename Derived>
17418 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
17419 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
17421 TemplateName.setIdentifier(&Name, NameLoc);
17423 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17424 TemplateName, ParsedType::make(ObjectType),
17425 /*EnteringContext=*/false, Template,
17426 AllowInjectedClassName);
17427 return Template.get();
17428}
17429
17430template<typename Derived>
17433 SourceLocation TemplateKWLoc,
17434 OverloadedOperatorKind Operator,
17435 SourceLocation NameLoc,
17436 QualType ObjectType,
17437 bool AllowInjectedClassName) {
17438 UnqualifiedId Name;
17439 // FIXME: Bogus location information.
17440 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17441 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17443 getSema().ActOnTemplateName(
17444 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17445 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17446 return Template.get();
17447}
17448
17449template <typename Derived>
17452 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17453 Expr *Second) {
17454 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17455
17456 if (First->getObjectKind() == OK_ObjCProperty) {
17459 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17460 Opc, First, Second);
17461 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
17462 if (Result.isInvalid())
17463 return ExprError();
17464 First = Result.get();
17465 }
17466
17467 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17468 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17469 if (Result.isInvalid())
17470 return ExprError();
17471 Second = Result.get();
17472 }
17473
17474 // Determine whether this should be a builtin operation.
17475 if (Op == OO_Subscript) {
17476 if (!First->getType()->isOverloadableType() &&
17477 !Second->getType()->isOverloadableType())
17478 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17479 OpLoc);
17480 } else if (Op == OO_Arrow) {
17481 // It is possible that the type refers to a RecoveryExpr created earlier
17482 // in the tree transformation.
17483 if (First->getType()->isDependentType())
17484 return ExprError();
17485 // -> is never a builtin operation.
17486 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17487 } else if (Second == nullptr || isPostIncDec) {
17488 if (!First->getType()->isOverloadableType() ||
17489 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17490 // The argument is not of overloadable type, or this is an expression
17491 // of the form &Class::member, so try to create a built-in unary
17492 // operation.
17494 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17495
17496 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17497 }
17498 } else {
17499 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17500 !First->getType()->isOverloadableType() &&
17501 !Second->getType()->isOverloadableType()) {
17502 // Neither of the arguments is type-dependent or has an overloadable
17503 // type, so try to create a built-in binary operation.
17506 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17507 if (Result.isInvalid())
17508 return ExprError();
17509
17510 return Result;
17511 }
17512 }
17513
17514 // Create the overloaded operator invocation for unary operators.
17515 if (!Second || isPostIncDec) {
17517 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17518 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17519 RequiresADL);
17520 }
17521
17522 // Create the overloaded operator invocation for binary operators.
17524 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17525 First, Second, RequiresADL);
17526 if (Result.isInvalid())
17527 return ExprError();
17528
17529 return Result;
17530}
17531
17532template<typename Derived>
17535 SourceLocation OperatorLoc,
17536 bool isArrow,
17537 CXXScopeSpec &SS,
17538 TypeSourceInfo *ScopeType,
17539 SourceLocation CCLoc,
17540 SourceLocation TildeLoc,
17541 PseudoDestructorTypeStorage Destroyed) {
17542 QualType CanonicalBaseType = Base->getType().getCanonicalType();
17543 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17544 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
17545 (isArrow && isa<PointerType>(CanonicalBaseType) &&
17546 !cast<PointerType>(CanonicalBaseType)
17547 ->getPointeeType()
17548 ->getAsCanonical<RecordType>())) {
17549 // This pseudo-destructor expression is still a pseudo-destructor.
17550 return SemaRef.BuildPseudoDestructorExpr(
17551 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17552 CCLoc, TildeLoc, Destroyed);
17553 }
17554
17555 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17556 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
17557 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17558 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17559 NameInfo.setNamedTypeInfo(DestroyedType);
17560
17561 // The scope type is now known to be a valid nested name specifier
17562 // component. Tack it on to the nested name specifier.
17563 if (ScopeType) {
17564 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
17565 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17566 diag::err_expected_class_or_namespace)
17567 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17568 return ExprError();
17569 }
17570 SS.clear();
17571 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
17572 }
17573
17574 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17575 return getSema().BuildMemberReferenceExpr(
17576 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
17577 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
17578 /*TemplateArgs*/ nullptr,
17579 /*S*/ nullptr);
17580}
17581
17582template<typename Derived>
17585 SourceLocation Loc = S->getBeginLoc();
17586 CapturedDecl *CD = S->getCapturedDecl();
17587 unsigned NumParams = CD->getNumParams();
17588 unsigned ContextParamPos = CD->getContextParamPosition();
17590 for (unsigned I = 0; I < NumParams; ++I) {
17591 if (I != ContextParamPos) {
17592 Params.push_back(
17593 std::make_pair(
17594 CD->getParam(I)->getName(),
17595 getDerived().TransformType(CD->getParam(I)->getType())));
17596 } else {
17597 Params.push_back(std::make_pair(StringRef(), QualType()));
17598 }
17599 }
17600 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17601 S->getCapturedRegionKind(), Params);
17602 StmtResult Body;
17603 {
17604 Sema::CompoundScopeRAII CompoundScope(getSema());
17605 Body = getDerived().TransformStmt(S->getCapturedStmt());
17606 }
17607
17608 if (Body.isInvalid()) {
17609 getSema().ActOnCapturedRegionError();
17610 return StmtError();
17611 }
17612
17613 return getSema().ActOnCapturedRegionEnd(Body.get());
17614}
17615
17616template <typename Derived>
17619 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
17620 // function definition or instantiation of a function template specialization
17621 // and will therefore never appear in a dependent context.
17622 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
17623 "context");
17624}
17625
17626template <typename Derived>
17628 // We can transform the base expression and allow argument resolution to fill
17629 // in the rest.
17630 return getDerived().TransformExpr(E->getArgLValue());
17631}
17632
17633} // end namespace clang
17634
17635#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.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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.
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:4486
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:5957
Represents a loop initializing the elements of an array.
Definition Expr.h:5904
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1813
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7092
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2723
Wrapper for source info for arrays.
Definition TypeLoc.h:1757
void setLBracketLoc(SourceLocation Loc)
Definition TypeLoc.h:1763
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2990
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3028
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3030
Expr * getDimensionExpression() const
Definition ExprCXX.h:3040
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3036
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3027
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3720
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6621
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6816
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2653
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:1017
void setAttr(const Attr *A)
Definition TypeLoc.h:1043
Type source information for an btf_tag attributed type.
Definition TypeLoc.h:1067
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4389
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3974
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:4110
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:8137
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4634
void setIsVariadic(bool value)
Definition Decl.h:4710
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6560
Wrapper for source info for block pointers.
Definition TypeLoc.h:1506
BreakStmt - This represents a break.
Definition Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5470
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5489
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5488
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:3905
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:2620
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3864
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:5026
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:2349
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4303
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:5135
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2739
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:3738
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3782
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3793
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3776
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3787
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3796
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:2879
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:4906
unsigned getNumParams() const
Definition Decl.h:4944
unsigned getContextParamPosition() const
Definition Decl.h:4973
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:4946
This captures a statement into a function.
Definition Stmt.h:3886
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1451
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:1466
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:3662
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4784
Represents a 'co_await' expression.
Definition ExprCXX.h:5363
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4236
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3541
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:438
ConditionalOperator - The ?
Definition Expr.h:4327
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3758
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1084
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4371
ContinueStmt - This represents a continue.
Definition Stmt.h:3119
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4655
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:5444
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h:1454
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:1272
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:821
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:808
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1874
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2268
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2493
void setAttrOperandParensRange(SourceRange range)
Definition TypeLoc.h:1978
Represents an extended address space qualifier where the input address space value is dependent.
Definition TypeBase.h:4059
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5395
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2561
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3504
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3578
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3552
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3570
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3588
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3562
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3605
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3543
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3598
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3540
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4009
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2076
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4099
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4430
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2048
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4225
Represents a single C99 designator.
Definition Expr.h:5530
Represents a C99 designated initializer expression.
Definition Expr.h:5487
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:871
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:4984
Expr * getCondition() const
Definition TypeBase.h:4991
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:749
Represents a reference to emded data.
Definition Expr.h:5062
RAII object that enters a new expression evaluation context.
Wrapper for source info for enum types.
Definition TypeLoc.h:870
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3886
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3655
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
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3168
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:3063
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6500
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3157
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2888
Represents a function declaration or definition.
Definition Decl.h:1999
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2771
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5232
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:4877
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5529
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5515
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5098
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4842
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4835
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5264
param_type_iterator param_type_begin() const
Definition TypeBase.h:5708
unsigned getNumParams() const
Definition TypeLoc.h:1696
SourceLocation getLocalRangeEnd() const
Definition TypeLoc.h:1648
void setLocalRangeBegin(SourceLocation L)
Definition TypeLoc.h:1644
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1660
SourceRange getExceptionSpecRange() const
Definition TypeLoc.h:1676
void setParam(unsigned i, ParmVarDecl *VD)
Definition TypeLoc.h:1703
ArrayRef< ParmVarDecl * > getParams() const
Definition TypeLoc.h:1687
void setRParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1668
void setLocalRangeEnd(SourceLocation L)
Definition TypeLoc.h:1652
void setExceptionSpecRange(SourceRange R)
Definition TypeLoc.h:1682
TypeLoc getReturnLoc() const
Definition TypeLoc.h:1705
SourceLocation getLocalRangeBegin() const
Definition TypeLoc.h:1640
SourceLocation getLParenLoc() const
Definition TypeLoc.h:1656
SourceLocation getRParenLoc() const
Definition TypeLoc.h:1664
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4486
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:4859
Represents a C11 generic selection.
Definition Expr.h:6114
AssociationTy< false > Association
Definition Expr.h:6345
GotoStmt - This represents a direct goto.
Definition Stmt.h:2969
Type source information for HLSL attributed resource type.
Definition TypeLoc.h:1094
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7258
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:1733
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3789
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:5993
Represents a C array with an unspecified size.
Definition TypeBase.h:3907
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3008
const TypeClass * getTypePtr() const
Definition TypeLoc.h:531
Describes an C or C++ initializer list.
Definition Expr.h:5235
InitListExpr * getSyntacticForm() const
Definition Expr.h:5408
Wrapper for source info for injected class names of class templates.
Definition TypeLoc.h:879
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:523
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:4338
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:1363
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4914
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2801
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2105
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3300
Wrapper for source info for member pointers.
Definition TypeLoc.h:1524
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3651
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:273
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:486
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:294
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:300
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:339
Represents C++ namespaces and their aliases.
Definition Decl.h:572
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:5813
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 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:1283
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:1566
void setStarLoc(SourceLocation Loc)
Definition TypeLoc.h:1572
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition TypeLoc.h:1238
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:904
@ Array
An index into an array.
Definition Expr.h:2428
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2432
@ Field
A field.
Definition Expr.h:2430
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2435
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:1180
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1230
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2092
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:3122
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3274
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3256
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3235
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3248
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3244
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3318
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3221
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3324
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3232
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3264
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3271
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4357
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2613
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2609
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2625
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2296
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2184
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2209
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2213
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1391
Represents a parameter to a function.
Definition Decl.h:1789
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1849
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1822
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:1839
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2705
PipeType - OpenCL20.
Definition TypeBase.h:8103
bool isReadOnly() const
Definition TypeBase.h:8133
Pointer-authentication qualifiers.
Definition TypeBase.h:152
void setSigilLoc(SourceLocation Loc)
Definition TypeLoc.h:1470
TypeLoc getPointeeLoc() const
Definition TypeLoc.h:1474
SourceLocation getSigilLoc() const
Definition TypeLoc.h:1466
Wrapper for source info for pointers.
Definition TypeLoc.h:1493
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:2007
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2688
const IdentifierInfo * getIdentifier() const
Definition ExprCXX.h:2708
SourceLocation getLocation() const
Definition ExprCXX.h:2712
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2704
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6692
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:8285
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8325
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8379
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8317
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:305
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:7364
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3571
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3587
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:1319
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, bool DeferHint=false)
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 * 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 * 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:13501
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8400
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:3475
A helper class for building up ExtParameterInfos.
Definition Sema.h:12912
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:12931
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:12919
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:13886
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:9288
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9296
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9291
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:1505
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:7796
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7798
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7797
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:1530
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
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:1490
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 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 *.
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:1495
@ ReuseLambdaContextDecl
Definition Sema.h:6977
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)
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.
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2512
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1418
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:13495
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:6695
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6705
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6674
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6700
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:8269
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:11008
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs)
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:7782
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:436
SemaPseudoObject & PseudoObject()
Definition Sema.h:1515
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:8606
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:4579
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4435
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4497
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4520
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:4525
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4494
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4500
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4503
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4953
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5013
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:4531
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:358
@ 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:334
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1801
Wrapper for substituted template type parameters.
Definition TypeLoc.h:1007
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4658
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4748
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:1001
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2509
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
SourceLocation getNameLoc() const
Definition TypeLoc.h:827
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:806
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:814
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition TypeLoc.h:821
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:829
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:810
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:1887
SourceLocation getRAngleLoc() const
Definition TypeLoc.h:1902
SourceLocation getTemplateNameLoc() const
Definition TypeLoc.h:1885
SourceLocation getTemplateKeywordLoc() const
Definition TypeLoc.h:1881
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:1871
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:1867
Wrapper for template type parameters.
Definition TypeLoc.h:890
The top declaration context.
Definition Decl.h:104
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.
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)
Build a new Objective-C boxed expression.
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.
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.
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:354
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:2715
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:6175
A container of type source information.
Definition TypeBase.h:8256
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:272
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8267
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:556
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2890
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:9021
bool isObjCObjectPointerType() const
Definition TypeBase.h:8691
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9101
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3559
Wrapper for source info for typedefs.
Definition TypeLoc.h:782
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2180
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2627
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2246
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2291
Expr * getSubExpr() const
Definition Expr.h:2287
Opcode getOpcode() const
Definition Expr.h:2282
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:2324
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:3384
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3458
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3453
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:4120
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:787
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h:5980
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:3393
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3457
Wrapper for source info for types used via transparent aliases.
Definition TypeLoc.h:790
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4893
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:711
QualType getType() const
Definition Decl.h:722
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5461
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:925
@ CInit
C-style initialization with assignment.
Definition Decl.h:930
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:933
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1167
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3964
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2025
Represents a GCC generic vector type.
Definition TypeBase.h:4173
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:985
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:865
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:235
@ 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:3717
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:5888
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.
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:4940
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:5863
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5884
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5874
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:5881
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:1991
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:88
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:5001
Holds information about the various types of exception specification.
Definition TypeBase.h:5321
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5337
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5323
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5326
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5329
Extra information about a function prototype.
Definition TypeBase.h:5349
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5354
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:3276
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:12958
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:12989
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:3275
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions