Thanks to visit codestin.com
Credit goes to clang.llvm.org

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 OMPClause *
1788 SourceLocation LParenLoc, SourceLocation FirstLoc,
1789 SourceLocation CountLoc, SourceLocation EndLoc) {
1791 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1792 }
1793
1794 /// Build a new OpenMP 'allocator' clause.
1795 ///
1796 /// By default, performs semantic analysis to build the new OpenMP clause.
1797 /// Subclasses may override this routine to provide different behavior.
1799 SourceLocation LParenLoc,
1800 SourceLocation EndLoc) {
1801 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1802 EndLoc);
1803 }
1804
1805 /// Build a new OpenMP 'collapse' clause.
1806 ///
1807 /// By default, performs semantic analysis to build the new OpenMP clause.
1808 /// Subclasses may override this routine to provide different behavior.
1810 SourceLocation LParenLoc,
1811 SourceLocation EndLoc) {
1812 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1813 LParenLoc, EndLoc);
1814 }
1815
1816 /// Build a new OpenMP 'default' clause.
1817 ///
1818 /// By default, performs semantic analysis to build the new OpenMP clause.
1819 /// Subclasses may override this routine to provide different behavior.
1822 SourceLocation VCLoc,
1823 SourceLocation StartLoc,
1824 SourceLocation LParenLoc,
1825 SourceLocation EndLoc) {
1827 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1828 }
1829
1830 /// Build a new OpenMP 'proc_bind' clause.
1831 ///
1832 /// By default, performs semantic analysis to build the new OpenMP clause.
1833 /// Subclasses may override this routine to provide different behavior.
1835 SourceLocation KindKwLoc,
1836 SourceLocation StartLoc,
1837 SourceLocation LParenLoc,
1838 SourceLocation EndLoc) {
1840 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1841 }
1842
1843 /// Build a new OpenMP 'schedule' clause.
1844 ///
1845 /// By default, performs semantic analysis to build the new OpenMP clause.
1846 /// Subclasses may override this routine to provide different behavior.
1849 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1850 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1851 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1853 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1854 CommaLoc, EndLoc);
1855 }
1856
1857 /// Build a new OpenMP 'ordered' clause.
1858 ///
1859 /// By default, performs semantic analysis to build the new OpenMP clause.
1860 /// Subclasses may override this routine to provide different behavior.
1862 SourceLocation EndLoc,
1863 SourceLocation LParenLoc, Expr *Num) {
1864 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1865 LParenLoc, Num);
1866 }
1867
1868 /// Build a new OpenMP 'private' clause.
1869 ///
1870 /// By default, performs semantic analysis to build the new OpenMP clause.
1871 /// Subclasses may override this routine to provide different behavior.
1873 SourceLocation StartLoc,
1874 SourceLocation LParenLoc,
1875 SourceLocation EndLoc) {
1876 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1877 LParenLoc, EndLoc);
1878 }
1879
1880 /// Build a new OpenMP 'firstprivate' clause.
1881 ///
1882 /// By default, performs semantic analysis to build the new OpenMP clause.
1883 /// Subclasses may override this routine to provide different behavior.
1885 SourceLocation StartLoc,
1886 SourceLocation LParenLoc,
1887 SourceLocation EndLoc) {
1888 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1889 LParenLoc, EndLoc);
1890 }
1891
1892 /// Build a new OpenMP 'lastprivate' clause.
1893 ///
1894 /// By default, performs semantic analysis to build the new OpenMP clause.
1895 /// Subclasses may override this routine to provide different behavior.
1898 SourceLocation LPKindLoc,
1899 SourceLocation ColonLoc,
1900 SourceLocation StartLoc,
1901 SourceLocation LParenLoc,
1902 SourceLocation EndLoc) {
1904 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1905 }
1906
1907 /// Build a new OpenMP 'shared' clause.
1908 ///
1909 /// By default, performs semantic analysis to build the new OpenMP clause.
1910 /// Subclasses may override this routine to provide different behavior.
1912 SourceLocation StartLoc,
1913 SourceLocation LParenLoc,
1914 SourceLocation EndLoc) {
1915 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1916 LParenLoc, EndLoc);
1917 }
1918
1919 /// Build a new OpenMP 'reduction' clause.
1920 ///
1921 /// By default, performs semantic analysis to build the new statement.
1922 /// Subclasses may override this routine to provide different behavior.
1925 OpenMPOriginalSharingModifier OriginalSharingModifier,
1926 SourceLocation StartLoc, SourceLocation LParenLoc,
1927 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1928 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1929 const DeclarationNameInfo &ReductionId,
1930 ArrayRef<Expr *> UnresolvedReductions) {
1932 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1933 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1934 UnresolvedReductions);
1935 }
1936
1937 /// Build a new OpenMP 'task_reduction' clause.
1938 ///
1939 /// By default, performs semantic analysis to build the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
1942 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1943 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1944 CXXScopeSpec &ReductionIdScopeSpec,
1945 const DeclarationNameInfo &ReductionId,
1946 ArrayRef<Expr *> UnresolvedReductions) {
1948 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1949 ReductionId, UnresolvedReductions);
1950 }
1951
1952 /// Build a new OpenMP 'in_reduction' clause.
1953 ///
1954 /// By default, performs semantic analysis to build the new statement.
1955 /// Subclasses may override this routine to provide different behavior.
1956 OMPClause *
1958 SourceLocation LParenLoc, SourceLocation ColonLoc,
1959 SourceLocation EndLoc,
1960 CXXScopeSpec &ReductionIdScopeSpec,
1961 const DeclarationNameInfo &ReductionId,
1962 ArrayRef<Expr *> UnresolvedReductions) {
1964 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1965 ReductionId, UnresolvedReductions);
1966 }
1967
1968 /// Build a new OpenMP 'linear' clause.
1969 ///
1970 /// By default, performs semantic analysis to build the new OpenMP clause.
1971 /// Subclasses may override this routine to provide different behavior.
1973 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1974 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1975 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1976 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1978 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1979 StepModifierLoc, EndLoc);
1980 }
1981
1982 /// Build a new OpenMP 'aligned' clause.
1983 ///
1984 /// By default, performs semantic analysis to build the new OpenMP clause.
1985 /// Subclasses may override this routine to provide different behavior.
1987 SourceLocation StartLoc,
1988 SourceLocation LParenLoc,
1989 SourceLocation ColonLoc,
1990 SourceLocation EndLoc) {
1992 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1993 }
1994
1995 /// Build a new OpenMP 'copyin' clause.
1996 ///
1997 /// By default, performs semantic analysis to build the new OpenMP clause.
1998 /// Subclasses may override this routine to provide different behavior.
2000 SourceLocation StartLoc,
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'copyprivate' clause.
2008 ///
2009 /// By default, performs semantic analysis to build the new OpenMP clause.
2010 /// Subclasses may override this routine to provide different behavior.
2012 SourceLocation StartLoc,
2013 SourceLocation LParenLoc,
2014 SourceLocation EndLoc) {
2015 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2016 LParenLoc, EndLoc);
2017 }
2018
2019 /// Build a new OpenMP 'flush' pseudo clause.
2020 ///
2021 /// By default, performs semantic analysis to build the new OpenMP clause.
2022 /// Subclasses may override this routine to provide different behavior.
2024 SourceLocation StartLoc,
2025 SourceLocation LParenLoc,
2026 SourceLocation EndLoc) {
2027 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2028 LParenLoc, EndLoc);
2029 }
2030
2031 /// Build a new OpenMP 'depobj' pseudo clause.
2032 ///
2033 /// By default, performs semantic analysis to build the new OpenMP clause.
2034 /// Subclasses may override this routine to provide different behavior.
2036 SourceLocation LParenLoc,
2037 SourceLocation EndLoc) {
2038 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2039 LParenLoc, EndLoc);
2040 }
2041
2042 /// Build a new OpenMP 'depend' pseudo clause.
2043 ///
2044 /// By default, performs semantic analysis to build the new OpenMP clause.
2045 /// Subclasses may override this routine to provide different behavior.
2047 Expr *DepModifier, ArrayRef<Expr *> VarList,
2048 SourceLocation StartLoc,
2049 SourceLocation LParenLoc,
2050 SourceLocation EndLoc) {
2052 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2053 }
2054
2055 /// Build a new OpenMP 'device' clause.
2056 ///
2057 /// By default, performs semantic analysis to build the new statement.
2058 /// Subclasses may override this routine to provide different behavior.
2060 Expr *Device, SourceLocation StartLoc,
2061 SourceLocation LParenLoc,
2062 SourceLocation ModifierLoc,
2063 SourceLocation EndLoc) {
2065 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2066 }
2067
2068 /// Build a new OpenMP 'map' clause.
2069 ///
2070 /// By default, performs semantic analysis to build the new OpenMP clause.
2071 /// Subclasses may override this routine to provide different behavior.
2073 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2074 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2075 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2076 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2077 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2078 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2080 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2081 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2082 ColonLoc, VarList, Locs,
2083 /*NoDiagnose=*/false, UnresolvedMappers);
2084 }
2085
2086 /// Build a new OpenMP 'allocate' clause.
2087 ///
2088 /// By default, performs semantic analysis to build the new OpenMP clause.
2089 /// Subclasses may override this routine to provide different behavior.
2090 OMPClause *
2091 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2092 OpenMPAllocateClauseModifier FirstModifier,
2093 SourceLocation FirstModifierLoc,
2094 OpenMPAllocateClauseModifier SecondModifier,
2095 SourceLocation SecondModifierLoc,
2096 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2097 SourceLocation LParenLoc, SourceLocation ColonLoc,
2098 SourceLocation EndLoc) {
2100 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2101 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2102 }
2103
2104 /// Build a new OpenMP 'num_teams' clause.
2105 ///
2106 /// By default, performs semantic analysis to build the new statement.
2107 /// Subclasses may override this routine to provide different behavior.
2109 SourceLocation StartLoc,
2110 SourceLocation LParenLoc,
2111 SourceLocation EndLoc) {
2112 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2113 LParenLoc, EndLoc);
2114 }
2115
2116 /// Build a new OpenMP 'thread_limit' clause.
2117 ///
2118 /// By default, performs semantic analysis to build the new statement.
2119 /// Subclasses may override this routine to provide different behavior.
2121 SourceLocation StartLoc,
2122 SourceLocation LParenLoc,
2123 SourceLocation EndLoc) {
2124 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2125 LParenLoc, EndLoc);
2126 }
2127
2128 /// Build a new OpenMP 'priority' clause.
2129 ///
2130 /// By default, performs semantic analysis to build the new statement.
2131 /// Subclasses may override this routine to provide different behavior.
2133 SourceLocation LParenLoc,
2134 SourceLocation EndLoc) {
2135 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2136 LParenLoc, EndLoc);
2137 }
2138
2139 /// Build a new OpenMP 'grainsize' clause.
2140 ///
2141 /// By default, performs semantic analysis to build the new statement.
2142 /// Subclasses may override this routine to provide different behavior.
2144 Expr *Device, SourceLocation StartLoc,
2145 SourceLocation LParenLoc,
2146 SourceLocation ModifierLoc,
2147 SourceLocation EndLoc) {
2149 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2150 }
2151
2152 /// Build a new OpenMP 'num_tasks' clause.
2153 ///
2154 /// By default, performs semantic analysis to build the new statement.
2155 /// Subclasses may override this routine to provide different behavior.
2157 Expr *NumTasks, SourceLocation StartLoc,
2158 SourceLocation LParenLoc,
2159 SourceLocation ModifierLoc,
2160 SourceLocation EndLoc) {
2162 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2163 }
2164
2165 /// Build a new OpenMP 'hint' clause.
2166 ///
2167 /// By default, performs semantic analysis to build the new statement.
2168 /// Subclasses may override this routine to provide different behavior.
2170 SourceLocation LParenLoc,
2171 SourceLocation EndLoc) {
2172 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2173 EndLoc);
2174 }
2175
2176 /// Build a new OpenMP 'detach' clause.
2177 ///
2178 /// By default, performs semantic analysis to build the new statement.
2179 /// Subclasses may override this routine to provide different behavior.
2181 SourceLocation LParenLoc,
2182 SourceLocation EndLoc) {
2183 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2184 EndLoc);
2185 }
2186
2187 /// Build a new OpenMP 'dist_schedule' clause.
2188 ///
2189 /// By default, performs semantic analysis to build the new OpenMP clause.
2190 /// Subclasses may override this routine to provide different behavior.
2191 OMPClause *
2193 Expr *ChunkSize, SourceLocation StartLoc,
2194 SourceLocation LParenLoc, SourceLocation KindLoc,
2195 SourceLocation CommaLoc, SourceLocation EndLoc) {
2197 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2198 }
2199
2200 /// Build a new OpenMP 'to' clause.
2201 ///
2202 /// By default, performs semantic analysis to build the new statement.
2203 /// Subclasses may override this routine to provide different behavior.
2204 OMPClause *
2206 ArrayRef<SourceLocation> MotionModifiersLoc,
2207 CXXScopeSpec &MapperIdScopeSpec,
2208 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2209 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2210 ArrayRef<Expr *> UnresolvedMappers) {
2212 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2213 ColonLoc, VarList, Locs, UnresolvedMappers);
2214 }
2215
2216 /// Build a new OpenMP 'from' clause.
2217 ///
2218 /// By default, performs semantic analysis to build the new statement.
2219 /// Subclasses may override this routine to provide different behavior.
2220 OMPClause *
2222 ArrayRef<SourceLocation> MotionModifiersLoc,
2223 CXXScopeSpec &MapperIdScopeSpec,
2224 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2225 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2226 ArrayRef<Expr *> UnresolvedMappers) {
2228 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2229 ColonLoc, VarList, Locs, UnresolvedMappers);
2230 }
2231
2232 /// Build a new OpenMP 'use_device_ptr' clause.
2233 ///
2234 /// By default, performs semantic analysis to build the new OpenMP clause.
2235 /// Subclasses may override this routine to provide different behavior.
2237 const OMPVarListLocTy &Locs) {
2238 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2239 }
2240
2241 /// Build a new OpenMP 'use_device_addr' clause.
2242 ///
2243 /// By default, performs semantic analysis to build the new OpenMP clause.
2244 /// Subclasses may override this routine to provide different behavior.
2249
2250 /// Build a new OpenMP 'is_device_ptr' clause.
2251 ///
2252 /// By default, performs semantic analysis to build the new OpenMP clause.
2253 /// Subclasses may override this routine to provide different behavior.
2255 const OMPVarListLocTy &Locs) {
2256 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2257 }
2258
2259 /// Build a new OpenMP 'has_device_addr' clause.
2260 ///
2261 /// By default, performs semantic analysis to build the new OpenMP clause.
2262 /// Subclasses may override this routine to provide different behavior.
2267
2268 /// Build a new OpenMP 'defaultmap' clause.
2269 ///
2270 /// By default, performs semantic analysis to build the new OpenMP clause.
2271 /// Subclasses may override this routine to provide different behavior.
2274 SourceLocation StartLoc,
2275 SourceLocation LParenLoc,
2276 SourceLocation MLoc,
2277 SourceLocation KindLoc,
2278 SourceLocation EndLoc) {
2280 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2281 }
2282
2283 /// Build a new OpenMP 'nontemporal' clause.
2284 ///
2285 /// By default, performs semantic analysis to build the new OpenMP clause.
2286 /// Subclasses may override this routine to provide different behavior.
2288 SourceLocation StartLoc,
2289 SourceLocation LParenLoc,
2290 SourceLocation EndLoc) {
2291 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2292 LParenLoc, EndLoc);
2293 }
2294
2295 /// Build a new OpenMP 'inclusive' clause.
2296 ///
2297 /// By default, performs semantic analysis to build the new OpenMP clause.
2298 /// Subclasses may override this routine to provide different behavior.
2300 SourceLocation StartLoc,
2301 SourceLocation LParenLoc,
2302 SourceLocation EndLoc) {
2303 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2304 LParenLoc, EndLoc);
2305 }
2306
2307 /// Build a new OpenMP 'exclusive' clause.
2308 ///
2309 /// By default, performs semantic analysis to build the new OpenMP clause.
2310 /// Subclasses may override this routine to provide different behavior.
2312 SourceLocation StartLoc,
2313 SourceLocation LParenLoc,
2314 SourceLocation EndLoc) {
2315 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2316 LParenLoc, EndLoc);
2317 }
2318
2319 /// Build a new OpenMP 'uses_allocators' clause.
2320 ///
2321 /// By default, performs semantic analysis to build the new OpenMP clause.
2322 /// Subclasses may override this routine to provide different behavior.
2329
2330 /// Build a new OpenMP 'affinity' clause.
2331 ///
2332 /// By default, performs semantic analysis to build the new OpenMP clause.
2333 /// Subclasses may override this routine to provide different behavior.
2335 SourceLocation LParenLoc,
2336 SourceLocation ColonLoc,
2337 SourceLocation EndLoc, Expr *Modifier,
2338 ArrayRef<Expr *> Locators) {
2340 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2341 }
2342
2343 /// Build a new OpenMP 'order' clause.
2344 ///
2345 /// By default, performs semantic analysis to build the new OpenMP clause.
2346 /// Subclasses may override this routine to provide different behavior.
2348 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2349 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2350 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2352 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2353 }
2354
2355 /// Build a new OpenMP 'init' clause.
2356 ///
2357 /// By default, performs semantic analysis to build the new OpenMP clause.
2358 /// Subclasses may override this routine to provide different behavior.
2360 SourceLocation StartLoc,
2361 SourceLocation LParenLoc,
2362 SourceLocation VarLoc,
2363 SourceLocation EndLoc) {
2365 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2366 }
2367
2368 /// Build a new OpenMP 'use' clause.
2369 ///
2370 /// By default, performs semantic analysis to build the new OpenMP clause.
2371 /// Subclasses may override this routine to provide different behavior.
2373 SourceLocation LParenLoc,
2374 SourceLocation VarLoc, SourceLocation EndLoc) {
2375 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2376 LParenLoc, VarLoc, EndLoc);
2377 }
2378
2379 /// Build a new OpenMP 'destroy' clause.
2380 ///
2381 /// By default, performs semantic analysis to build the new OpenMP clause.
2382 /// Subclasses may override this routine to provide different behavior.
2384 SourceLocation LParenLoc,
2385 SourceLocation VarLoc,
2386 SourceLocation EndLoc) {
2388 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2389 }
2390
2391 /// Build a new OpenMP 'novariants' clause.
2392 ///
2393 /// By default, performs semantic analysis to build the new OpenMP clause.
2394 /// Subclasses may override this routine to provide different behavior.
2396 SourceLocation StartLoc,
2397 SourceLocation LParenLoc,
2398 SourceLocation EndLoc) {
2400 LParenLoc, EndLoc);
2401 }
2402
2403 /// Build a new OpenMP 'nocontext' clause.
2404 ///
2405 /// By default, performs semantic analysis to build the new OpenMP clause.
2406 /// Subclasses may override this routine to provide different behavior.
2408 SourceLocation LParenLoc,
2409 SourceLocation EndLoc) {
2411 LParenLoc, EndLoc);
2412 }
2413
2414 /// Build a new OpenMP 'filter' clause.
2415 ///
2416 /// By default, performs semantic analysis to build the new OpenMP clause.
2417 /// Subclasses may override this routine to provide different behavior.
2419 SourceLocation LParenLoc,
2420 SourceLocation EndLoc) {
2421 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2422 LParenLoc, EndLoc);
2423 }
2424
2425 /// Build a new OpenMP 'bind' clause.
2426 ///
2427 /// By default, performs semantic analysis to build the new OpenMP clause.
2428 /// Subclasses may override this routine to provide different behavior.
2430 SourceLocation KindLoc,
2431 SourceLocation StartLoc,
2432 SourceLocation LParenLoc,
2433 SourceLocation EndLoc) {
2434 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2435 LParenLoc, EndLoc);
2436 }
2437
2438 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2439 ///
2440 /// By default, performs semantic analysis to build the new OpenMP clause.
2441 /// Subclasses may override this routine to provide different behavior.
2443 SourceLocation LParenLoc,
2444 SourceLocation EndLoc) {
2445 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2446 LParenLoc, EndLoc);
2447 }
2448
2449 /// Build a new OpenMP 'ompx_attribute' clause.
2450 ///
2451 /// By default, performs semantic analysis to build the new OpenMP clause.
2452 /// Subclasses may override this routine to provide different behavior.
2454 SourceLocation StartLoc,
2455 SourceLocation LParenLoc,
2456 SourceLocation EndLoc) {
2457 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2458 LParenLoc, EndLoc);
2459 }
2460
2461 /// Build a new OpenMP 'ompx_bare' clause.
2462 ///
2463 /// By default, performs semantic analysis to build the new OpenMP clause.
2464 /// Subclasses may override this routine to provide different behavior.
2466 SourceLocation EndLoc) {
2467 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2468 }
2469
2470 /// Build a new OpenMP 'align' clause.
2471 ///
2472 /// By default, performs semantic analysis to build the new OpenMP clause.
2473 /// Subclasses may override this routine to provide different behavior.
2475 SourceLocation LParenLoc,
2476 SourceLocation EndLoc) {
2477 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2478 EndLoc);
2479 }
2480
2481 /// Build a new OpenMP 'at' clause.
2482 ///
2483 /// By default, performs semantic analysis to build the new OpenMP clause.
2484 /// Subclasses may override this routine to provide different behavior.
2486 SourceLocation StartLoc,
2487 SourceLocation LParenLoc,
2488 SourceLocation EndLoc) {
2489 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2490 LParenLoc, EndLoc);
2491 }
2492
2493 /// Build a new OpenMP 'severity' clause.
2494 ///
2495 /// By default, performs semantic analysis to build the new OpenMP clause.
2496 /// Subclasses may override this routine to provide different behavior.
2498 SourceLocation KwLoc,
2499 SourceLocation StartLoc,
2500 SourceLocation LParenLoc,
2501 SourceLocation EndLoc) {
2502 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2503 LParenLoc, EndLoc);
2504 }
2505
2506 /// Build a new OpenMP 'message' clause.
2507 ///
2508 /// By default, performs semantic analysis to build the new OpenMP clause.
2509 /// Subclasses may override this routine to provide different behavior.
2511 SourceLocation LParenLoc,
2512 SourceLocation EndLoc) {
2513 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2514 EndLoc);
2515 }
2516
2517 /// Build a new OpenMP 'doacross' clause.
2518 ///
2519 /// By default, performs semantic analysis to build the new OpenMP clause.
2520 /// Subclasses may override this routine to provide different behavior.
2521 OMPClause *
2523 SourceLocation DepLoc, SourceLocation ColonLoc,
2524 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2525 SourceLocation LParenLoc, SourceLocation EndLoc) {
2527 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2528 }
2529
2530 /// Build a new OpenMP 'holds' clause.
2532 SourceLocation LParenLoc,
2533 SourceLocation EndLoc) {
2534 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2535 EndLoc);
2536 }
2537
2538 /// Rebuild the operand to an Objective-C \@synchronized statement.
2539 ///
2540 /// By default, performs semantic analysis to build the new statement.
2541 /// Subclasses may override this routine to provide different behavior.
2546
2547 /// Build a new Objective-C \@synchronized statement.
2548 ///
2549 /// By default, performs semantic analysis to build the new statement.
2550 /// Subclasses may override this routine to provide different behavior.
2552 Expr *Object, Stmt *Body) {
2553 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2554 }
2555
2556 /// Build a new Objective-C \@autoreleasepool statement.
2557 ///
2558 /// By default, performs semantic analysis to build the new statement.
2559 /// Subclasses may override this routine to provide different behavior.
2564
2565 /// Build a new Objective-C fast enumeration statement.
2566 ///
2567 /// By default, performs semantic analysis to build the new statement.
2568 /// Subclasses may override this routine to provide different behavior.
2570 Stmt *Element,
2571 Expr *Collection,
2572 SourceLocation RParenLoc,
2573 Stmt *Body) {
2575 ForLoc, Element, Collection, RParenLoc);
2576 if (ForEachStmt.isInvalid())
2577 return StmtError();
2578
2579 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2580 Body);
2581 }
2582
2583 /// Build a new C++ exception declaration.
2584 ///
2585 /// By default, performs semantic analysis to build the new decaration.
2586 /// Subclasses may override this routine to provide different behavior.
2589 SourceLocation StartLoc,
2590 SourceLocation IdLoc,
2591 IdentifierInfo *Id) {
2593 StartLoc, IdLoc, Id);
2594 if (Var)
2595 getSema().CurContext->addDecl(Var);
2596 return Var;
2597 }
2598
2599 /// Build a new C++ catch statement.
2600 ///
2601 /// By default, performs semantic analysis to build the new statement.
2602 /// Subclasses may override this routine to provide different behavior.
2604 VarDecl *ExceptionDecl,
2605 Stmt *Handler) {
2606 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2607 Handler));
2608 }
2609
2610 /// Build a new C++ try statement.
2611 ///
2612 /// By default, performs semantic analysis to build the new statement.
2613 /// Subclasses may override this routine to provide different behavior.
2615 ArrayRef<Stmt *> Handlers) {
2616 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2617 }
2618
2619 /// Build a new C++0x range-based for statement.
2620 ///
2621 /// By default, performs semantic analysis to build the new statement.
2622 /// Subclasses may override this routine to provide different behavior.
2624 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2625 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2626 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2627 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2628 // If we've just learned that the range is actually an Objective-C
2629 // collection, treat this as an Objective-C fast enumeration loop.
2630 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2631 if (RangeStmt->isSingleDecl()) {
2632 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2633 if (RangeVar->isInvalidDecl())
2634 return StmtError();
2635
2636 Expr *RangeExpr = RangeVar->getInit();
2637 if (!RangeExpr->isTypeDependent() &&
2638 RangeExpr->getType()->isObjCObjectPointerType()) {
2639 // FIXME: Support init-statements in Objective-C++20 ranged for
2640 // statement.
2641 if (Init) {
2642 return SemaRef.Diag(Init->getBeginLoc(),
2643 diag::err_objc_for_range_init_stmt)
2644 << Init->getSourceRange();
2645 }
2647 ForLoc, LoopVar, RangeExpr, RParenLoc);
2648 }
2649 }
2650 }
2651 }
2652
2654 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2655 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2656 }
2657
2658 /// Build a new C++0x range-based for statement.
2659 ///
2660 /// By default, performs semantic analysis to build the new statement.
2661 /// Subclasses may override this routine to provide different behavior.
2663 bool IsIfExists,
2664 NestedNameSpecifierLoc QualifierLoc,
2665 DeclarationNameInfo NameInfo,
2666 Stmt *Nested) {
2667 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2668 QualifierLoc, NameInfo, Nested);
2669 }
2670
2671 /// Attach body to a C++0x range-based for statement.
2672 ///
2673 /// By default, performs semantic analysis to finish the new statement.
2674 /// Subclasses may override this routine to provide different behavior.
2676 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2677 }
2678
2680 Stmt *TryBlock, Stmt *Handler) {
2681 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2682 }
2683
2685 Stmt *Block) {
2686 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2687 }
2688
2690 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2691 }
2692
2694 SourceLocation LParen,
2695 SourceLocation RParen,
2696 TypeSourceInfo *TSI) {
2697 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2698 TSI);
2699 }
2700
2701 /// Build a new predefined expression.
2702 ///
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
2708
2709 /// Build a new expression that references a declaration.
2710 ///
2711 /// By default, performs semantic analysis to build the new expression.
2712 /// Subclasses may override this routine to provide different behavior.
2714 LookupResult &R,
2715 bool RequiresADL) {
2716 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2717 }
2718
2719
2720 /// Build a new expression that references a declaration.
2721 ///
2722 /// By default, performs semantic analysis to build the new expression.
2723 /// Subclasses may override this routine to provide different behavior.
2725 ValueDecl *VD,
2726 const DeclarationNameInfo &NameInfo,
2728 TemplateArgumentListInfo *TemplateArgs) {
2729 CXXScopeSpec SS;
2730 SS.Adopt(QualifierLoc);
2731 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2732 TemplateArgs);
2733 }
2734
2735 /// Build a new expression in parentheses.
2736 ///
2737 /// By default, performs semantic analysis to build the new expression.
2738 /// Subclasses may override this routine to provide different behavior.
2740 SourceLocation RParen) {
2741 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2742 }
2743
2744 /// Build a new pseudo-destructor expression.
2745 ///
2746 /// By default, performs semantic analysis to build the new expression.
2747 /// Subclasses may override this routine to provide different behavior.
2749 SourceLocation OperatorLoc,
2750 bool isArrow,
2751 CXXScopeSpec &SS,
2752 TypeSourceInfo *ScopeType,
2753 SourceLocation CCLoc,
2754 SourceLocation TildeLoc,
2755 PseudoDestructorTypeStorage Destroyed);
2756
2757 /// Build a new unary operator expression.
2758 ///
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2763 Expr *SubExpr) {
2764 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2765 }
2766
2767 /// Build a new builtin offsetof expression.
2768 ///
2769 /// By default, performs semantic analysis to build the new expression.
2770 /// Subclasses may override this routine to provide different behavior.
2774 SourceLocation RParenLoc) {
2775 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2776 RParenLoc);
2777 }
2778
2779 /// Build a new sizeof, alignof or vec_step expression with a
2780 /// type argument.
2781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
2785 SourceLocation OpLoc,
2786 UnaryExprOrTypeTrait ExprKind,
2787 SourceRange R) {
2788 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2789 }
2790
2791 /// Build a new sizeof, alignof or vec step expression with an
2792 /// expression argument.
2793 ///
2794 /// By default, performs semantic analysis to build the new expression.
2795 /// Subclasses may override this routine to provide different behavior.
2797 UnaryExprOrTypeTrait ExprKind,
2798 SourceRange R) {
2800 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2801 if (Result.isInvalid())
2802 return ExprError();
2803
2804 return Result;
2805 }
2806
2807 /// Build a new array subscript expression.
2808 ///
2809 /// By default, performs semantic analysis to build the new expression.
2810 /// Subclasses may override this routine to provide different behavior.
2812 SourceLocation LBracketLoc,
2813 Expr *RHS,
2814 SourceLocation RBracketLoc) {
2815 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2816 LBracketLoc, RHS,
2817 RBracketLoc);
2818 }
2819
2820 /// Build a new matrix subscript expression.
2821 ///
2822 /// By default, performs semantic analysis to build the new expression.
2823 /// Subclasses may override this routine to provide different behavior.
2825 Expr *ColumnIdx,
2826 SourceLocation RBracketLoc) {
2827 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2828 RBracketLoc);
2829 }
2830
2831 /// Build a new array section expression.
2832 ///
2833 /// By default, performs semantic analysis to build the new expression.
2834 /// Subclasses may override this routine to provide different behavior.
2836 SourceLocation LBracketLoc,
2837 Expr *LowerBound,
2838 SourceLocation ColonLocFirst,
2839 SourceLocation ColonLocSecond,
2840 Expr *Length, Expr *Stride,
2841 SourceLocation RBracketLoc) {
2842 if (IsOMPArraySection)
2844 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2845 Stride, RBracketLoc);
2846
2847 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2848 "Stride/second colon not allowed for OpenACC");
2849
2851 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2852 }
2853
2854 /// Build a new array shaping expression.
2855 ///
2856 /// By default, performs semantic analysis to build the new expression.
2857 /// Subclasses may override this routine to provide different behavior.
2859 SourceLocation RParenLoc,
2860 ArrayRef<Expr *> Dims,
2861 ArrayRef<SourceRange> BracketsRanges) {
2863 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2864 }
2865
2866 /// Build a new iterator expression.
2867 ///
2868 /// By default, performs semantic analysis to build the new expression.
2869 /// Subclasses may override this routine to provide different behavior.
2872 SourceLocation RLoc,
2875 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2876 }
2877
2878 /// Build a new call expression.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
2883 MultiExprArg Args,
2884 SourceLocation RParenLoc,
2885 Expr *ExecConfig = nullptr) {
2886 return getSema().ActOnCallExpr(
2887 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2888 }
2889
2891 MultiExprArg Args,
2892 SourceLocation RParenLoc) {
2894 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2895 }
2896
2897 /// Build a new member access expression.
2898 ///
2899 /// By default, performs semantic analysis to build the new expression.
2900 /// Subclasses may override this routine to provide different behavior.
2902 bool isArrow,
2903 NestedNameSpecifierLoc QualifierLoc,
2904 SourceLocation TemplateKWLoc,
2905 const DeclarationNameInfo &MemberNameInfo,
2907 NamedDecl *FoundDecl,
2908 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2909 NamedDecl *FirstQualifierInScope) {
2911 isArrow);
2912 if (!Member->getDeclName()) {
2913 // We have a reference to an unnamed field. This is always the
2914 // base of an anonymous struct/union member access, i.e. the
2915 // field is always of record type.
2916 assert(Member->getType()->isRecordType() &&
2917 "unnamed member not of record type?");
2918
2919 BaseResult =
2921 QualifierLoc.getNestedNameSpecifier(),
2922 FoundDecl, Member);
2923 if (BaseResult.isInvalid())
2924 return ExprError();
2925 Base = BaseResult.get();
2926
2927 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2928 // from the AST, so we need to re-insert them if needed (since
2929 // `BuildFieldRefereneExpr()` doesn't do this).
2930 if (!isArrow && Base->isPRValue()) {
2932 if (BaseResult.isInvalid())
2933 return ExprError();
2934 Base = BaseResult.get();
2935 }
2936
2937 CXXScopeSpec EmptySS;
2939 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2940 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2941 MemberNameInfo);
2942 }
2943
2944 CXXScopeSpec SS;
2945 SS.Adopt(QualifierLoc);
2946
2947 Base = BaseResult.get();
2948 if (Base->containsErrors())
2949 return ExprError();
2950
2951 QualType BaseType = Base->getType();
2952
2953 if (isArrow && !BaseType->isPointerType())
2954 return ExprError();
2955
2956 // FIXME: this involves duplicating earlier analysis in a lot of
2957 // cases; we should avoid this when possible.
2958 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2959 R.addDecl(FoundDecl);
2960 R.resolveKind();
2961
2962 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2964 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2965 ->getType()
2966 ->getPointeeType()
2967 ->getAsCXXRecordDecl()) {
2968 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2969 // In unevaluated contexts, an expression supposed to be a member access
2970 // might reference a member in an unrelated class.
2971 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2972 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2973 VK_LValue, Member->getLocation());
2974 }
2975 }
2976
2977 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2978 SS, TemplateKWLoc,
2979 FirstQualifierInScope,
2980 R, ExplicitTemplateArgs,
2981 /*S*/nullptr);
2982 }
2983
2984 /// Build a new binary operator expression.
2985 ///
2986 /// By default, performs semantic analysis to build the new expression.
2987 /// Subclasses may override this routine to provide different behavior.
2989 Expr *LHS, Expr *RHS,
2990 bool ForFoldExpression = false) {
2991 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
2992 ForFoldExpression);
2993 }
2994
2995 /// Build a new rewritten operator expression.
2996 ///
2997 /// By default, performs semantic analysis to build the new expression.
2998 /// Subclasses may override this routine to provide different behavior.
3000 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3001 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3002 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3003 RHS, /*RequiresADL*/false);
3004 }
3005
3006 /// Build a new conditional operator expression.
3007 ///
3008 /// By default, performs semantic analysis to build the new expression.
3009 /// Subclasses may override this routine to provide different behavior.
3011 SourceLocation QuestionLoc,
3012 Expr *LHS,
3013 SourceLocation ColonLoc,
3014 Expr *RHS) {
3015 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3016 LHS, RHS);
3017 }
3018
3019 /// Build a new C-style cast expression.
3020 ///
3021 /// By default, performs semantic analysis to build the new expression.
3022 /// Subclasses may override this routine to provide different behavior.
3024 TypeSourceInfo *TInfo,
3025 SourceLocation RParenLoc,
3026 Expr *SubExpr) {
3027 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3028 SubExpr);
3029 }
3030
3031 /// Build a new compound literal expression.
3032 ///
3033 /// By default, performs semantic analysis to build the new expression.
3034 /// Subclasses may override this routine to provide different behavior.
3036 TypeSourceInfo *TInfo,
3037 SourceLocation RParenLoc,
3038 Expr *Init) {
3039 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3040 Init);
3041 }
3042
3043 /// Build a new extended vector element access expression.
3044 ///
3045 /// By default, performs semantic analysis to build the new expression.
3046 /// Subclasses may override this routine to provide different behavior.
3048 bool IsArrow,
3049 SourceLocation AccessorLoc,
3050 IdentifierInfo &Accessor) {
3051
3052 CXXScopeSpec SS;
3053 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3055 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3056 /*FirstQualifierInScope*/ nullptr, NameInfo,
3057 /* TemplateArgs */ nullptr,
3058 /*S*/ nullptr);
3059 }
3060
3061 /// Build a new initializer list expression.
3062 ///
3063 /// By default, performs semantic analysis to build the new expression.
3064 /// Subclasses may override this routine to provide different behavior.
3066 MultiExprArg Inits,
3067 SourceLocation RBraceLoc) {
3068 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3069 }
3070
3071 /// Build a new designated initializer expression.
3072 ///
3073 /// By default, performs semantic analysis to build the new expression.
3074 /// Subclasses may override this routine to provide different behavior.
3076 MultiExprArg ArrayExprs,
3077 SourceLocation EqualOrColonLoc,
3078 bool GNUSyntax,
3079 Expr *Init) {
3081 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3082 Init);
3083 if (Result.isInvalid())
3084 return ExprError();
3085
3086 return Result;
3087 }
3088
3089 /// Build a new value-initialized expression.
3090 ///
3091 /// By default, builds the implicit value initialization without performing
3092 /// any semantic analysis. Subclasses may override this routine to provide
3093 /// different behavior.
3097
3098 /// Build a new \c va_arg expression.
3099 ///
3100 /// By default, performs semantic analysis to build the new expression.
3101 /// Subclasses may override this routine to provide different behavior.
3103 Expr *SubExpr, TypeSourceInfo *TInfo,
3104 SourceLocation RParenLoc) {
3105 return getSema().BuildVAArgExpr(BuiltinLoc,
3106 SubExpr, TInfo,
3107 RParenLoc);
3108 }
3109
3110 /// Build a new expression list in parentheses.
3111 ///
3112 /// By default, performs semantic analysis to build the new expression.
3113 /// Subclasses may override this routine to provide different behavior.
3115 MultiExprArg SubExprs,
3116 SourceLocation RParenLoc) {
3117 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3118 }
3119
3121 unsigned NumUserSpecifiedExprs,
3122 SourceLocation InitLoc,
3123 SourceLocation LParenLoc,
3124 SourceLocation RParenLoc) {
3125 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3126 InitLoc, LParenLoc, RParenLoc);
3127 }
3128
3129 /// Build a new address-of-label expression.
3130 ///
3131 /// By default, performs semantic analysis, using the name of the label
3132 /// rather than attempting to map the label statement itself.
3133 /// Subclasses may override this routine to provide different behavior.
3135 SourceLocation LabelLoc, LabelDecl *Label) {
3136 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3137 }
3138
3139 /// Build a new GNU statement expression.
3140 ///
3141 /// By default, performs semantic analysis to build the new expression.
3142 /// Subclasses may override this routine to provide different behavior.
3144 SourceLocation RParenLoc, unsigned TemplateDepth) {
3145 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3146 TemplateDepth);
3147 }
3148
3149 /// Build a new __builtin_choose_expr expression.
3150 ///
3151 /// By default, performs semantic analysis to build the new expression.
3152 /// Subclasses may override this routine to provide different behavior.
3154 Expr *Cond, Expr *LHS, Expr *RHS,
3155 SourceLocation RParenLoc) {
3156 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3157 Cond, LHS, RHS,
3158 RParenLoc);
3159 }
3160
3161 /// Build a new generic selection expression with an expression predicate.
3162 ///
3163 /// By default, performs semantic analysis to build the new expression.
3164 /// Subclasses may override this routine to provide different behavior.
3166 SourceLocation DefaultLoc,
3167 SourceLocation RParenLoc,
3168 Expr *ControllingExpr,
3170 ArrayRef<Expr *> Exprs) {
3171 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3172 /*PredicateIsExpr=*/true,
3173 ControllingExpr, Types, Exprs);
3174 }
3175
3176 /// Build a new generic selection expression with a type predicate.
3177 ///
3178 /// By default, performs semantic analysis to build the new expression.
3179 /// Subclasses may override this routine to provide different behavior.
3181 SourceLocation DefaultLoc,
3182 SourceLocation RParenLoc,
3183 TypeSourceInfo *ControllingType,
3185 ArrayRef<Expr *> Exprs) {
3186 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3187 /*PredicateIsExpr=*/false,
3188 ControllingType, Types, Exprs);
3189 }
3190
3191 /// Build a new overloaded operator call expression.
3192 ///
3193 /// By default, performs semantic analysis to build the new expression.
3194 /// The semantic analysis provides the behavior of template instantiation,
3195 /// copying with transformations that turn what looks like an overloaded
3196 /// operator call into a use of a builtin operator, performing
3197 /// argument-dependent lookup, etc. Subclasses may override this routine to
3198 /// provide different behavior.
3200 SourceLocation OpLoc,
3201 SourceLocation CalleeLoc,
3202 bool RequiresADL,
3203 const UnresolvedSetImpl &Functions,
3204 Expr *First, Expr *Second);
3205
3206 /// Build a new C++ "named" cast expression, such as static_cast or
3207 /// reinterpret_cast.
3208 ///
3209 /// By default, this routine dispatches to one of the more-specific routines
3210 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3211 /// Subclasses may override this routine to provide different behavior.
3214 SourceLocation LAngleLoc,
3215 TypeSourceInfo *TInfo,
3216 SourceLocation RAngleLoc,
3217 SourceLocation LParenLoc,
3218 Expr *SubExpr,
3219 SourceLocation RParenLoc) {
3220 switch (Class) {
3221 case Stmt::CXXStaticCastExprClass:
3222 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3223 RAngleLoc, LParenLoc,
3224 SubExpr, RParenLoc);
3225
3226 case Stmt::CXXDynamicCastExprClass:
3227 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3228 RAngleLoc, LParenLoc,
3229 SubExpr, RParenLoc);
3230
3231 case Stmt::CXXReinterpretCastExprClass:
3232 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3233 RAngleLoc, LParenLoc,
3234 SubExpr,
3235 RParenLoc);
3236
3237 case Stmt::CXXConstCastExprClass:
3238 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3239 RAngleLoc, LParenLoc,
3240 SubExpr, RParenLoc);
3241
3242 case Stmt::CXXAddrspaceCastExprClass:
3243 return getDerived().RebuildCXXAddrspaceCastExpr(
3244 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3245
3246 default:
3247 llvm_unreachable("Invalid C++ named cast");
3248 }
3249 }
3250
3251 /// Build a new C++ static_cast expression.
3252 ///
3253 /// By default, performs semantic analysis to build the new expression.
3254 /// Subclasses may override this routine to provide different behavior.
3256 SourceLocation LAngleLoc,
3257 TypeSourceInfo *TInfo,
3258 SourceLocation RAngleLoc,
3259 SourceLocation LParenLoc,
3260 Expr *SubExpr,
3261 SourceLocation RParenLoc) {
3262 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3263 TInfo, SubExpr,
3264 SourceRange(LAngleLoc, RAngleLoc),
3265 SourceRange(LParenLoc, RParenLoc));
3266 }
3267
3268 /// Build a new C++ dynamic_cast expression.
3269 ///
3270 /// By default, performs semantic analysis to build the new expression.
3271 /// Subclasses may override this routine to provide different behavior.
3273 SourceLocation LAngleLoc,
3274 TypeSourceInfo *TInfo,
3275 SourceLocation RAngleLoc,
3276 SourceLocation LParenLoc,
3277 Expr *SubExpr,
3278 SourceLocation RParenLoc) {
3279 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3280 TInfo, SubExpr,
3281 SourceRange(LAngleLoc, RAngleLoc),
3282 SourceRange(LParenLoc, RParenLoc));
3283 }
3284
3285 /// Build a new C++ reinterpret_cast expression.
3286 ///
3287 /// By default, performs semantic analysis to build the new expression.
3288 /// Subclasses may override this routine to provide different behavior.
3290 SourceLocation LAngleLoc,
3291 TypeSourceInfo *TInfo,
3292 SourceLocation RAngleLoc,
3293 SourceLocation LParenLoc,
3294 Expr *SubExpr,
3295 SourceLocation RParenLoc) {
3296 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3297 TInfo, SubExpr,
3298 SourceRange(LAngleLoc, RAngleLoc),
3299 SourceRange(LParenLoc, RParenLoc));
3300 }
3301
3302 /// Build a new C++ const_cast expression.
3303 ///
3304 /// By default, performs semantic analysis to build the new expression.
3305 /// Subclasses may override this routine to provide different behavior.
3307 SourceLocation LAngleLoc,
3308 TypeSourceInfo *TInfo,
3309 SourceLocation RAngleLoc,
3310 SourceLocation LParenLoc,
3311 Expr *SubExpr,
3312 SourceLocation RParenLoc) {
3313 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3314 TInfo, SubExpr,
3315 SourceRange(LAngleLoc, RAngleLoc),
3316 SourceRange(LParenLoc, RParenLoc));
3317 }
3318
3321 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3322 SourceLocation LParenLoc, Expr *SubExpr,
3323 SourceLocation RParenLoc) {
3324 return getSema().BuildCXXNamedCast(
3325 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3326 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3327 }
3328
3329 /// Build a new C++ functional-style cast expression.
3330 ///
3331 /// By default, performs semantic analysis to build the new expression.
3332 /// Subclasses may override this routine to provide different behavior.
3334 SourceLocation LParenLoc,
3335 Expr *Sub,
3336 SourceLocation RParenLoc,
3337 bool ListInitialization) {
3338 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3339 // CXXParenListInitExpr. Pass its expanded arguments so that the
3340 // CXXParenListInitExpr can be rebuilt.
3341 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3343 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3344 RParenLoc, ListInitialization);
3345
3346 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3348 TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
3349
3350 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3351 MultiExprArg(&Sub, 1), RParenLoc,
3352 ListInitialization);
3353 }
3354
3355 /// Build a new C++ __builtin_bit_cast expression.
3356 ///
3357 /// By default, performs semantic analysis to build the new expression.
3358 /// Subclasses may override this routine to provide different behavior.
3360 TypeSourceInfo *TSI, Expr *Sub,
3361 SourceLocation RParenLoc) {
3362 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3363 }
3364
3365 /// Build a new C++ typeid(type) expression.
3366 ///
3367 /// By default, performs semantic analysis to build the new expression.
3368 /// Subclasses may override this routine to provide different behavior.
3370 SourceLocation TypeidLoc,
3371 TypeSourceInfo *Operand,
3372 SourceLocation RParenLoc) {
3373 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3374 RParenLoc);
3375 }
3376
3377
3378 /// Build a new C++ typeid(expr) expression.
3379 ///
3380 /// By default, performs semantic analysis to build the new expression.
3381 /// Subclasses may override this routine to provide different behavior.
3383 SourceLocation TypeidLoc,
3384 Expr *Operand,
3385 SourceLocation RParenLoc) {
3386 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3387 RParenLoc);
3388 }
3389
3390 /// Build a new C++ __uuidof(type) expression.
3391 ///
3392 /// By default, performs semantic analysis to build the new expression.
3393 /// Subclasses may override this routine to provide different behavior.
3395 TypeSourceInfo *Operand,
3396 SourceLocation RParenLoc) {
3397 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3398 }
3399
3400 /// Build a new C++ __uuidof(expr) expression.
3401 ///
3402 /// By default, performs semantic analysis to build the new expression.
3403 /// Subclasses may override this routine to provide different behavior.
3405 Expr *Operand, SourceLocation RParenLoc) {
3406 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3407 }
3408
3409 /// Build a new C++ "this" expression.
3410 ///
3411 /// By default, performs semantic analysis to build a new "this" expression.
3412 /// Subclasses may override this routine to provide different behavior.
3414 QualType ThisType,
3415 bool isImplicit) {
3416 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3417 return ExprError();
3418 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3419 }
3420
3421 /// Build a new C++ throw expression.
3422 ///
3423 /// By default, performs semantic analysis to build the new expression.
3424 /// Subclasses may override this routine to provide different behavior.
3426 bool IsThrownVariableInScope) {
3427 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3428 }
3429
3430 /// Build a new C++ default-argument expression.
3431 ///
3432 /// By default, builds a new default-argument expression, which does not
3433 /// require any semantic analysis. Subclasses may override this routine to
3434 /// provide different behavior.
3436 Expr *RewrittenExpr) {
3437 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3438 RewrittenExpr, getSema().CurContext);
3439 }
3440
3441 /// Build a new C++11 default-initialization expression.
3442 ///
3443 /// By default, builds a new default field initialization expression, which
3444 /// does not require any semantic analysis. Subclasses may override this
3445 /// routine to provide different behavior.
3450
3451 /// Build a new C++ zero-initialization expression.
3452 ///
3453 /// By default, performs semantic analysis to build the new expression.
3454 /// Subclasses may override this routine to provide different behavior.
3456 SourceLocation LParenLoc,
3457 SourceLocation RParenLoc) {
3458 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3459 /*ListInitialization=*/false);
3460 }
3461
3462 /// Build a new C++ "new" expression.
3463 ///
3464 /// By default, performs semantic analysis to build the new expression.
3465 /// Subclasses may override this routine to provide different behavior.
3467 SourceLocation PlacementLParen,
3468 MultiExprArg PlacementArgs,
3469 SourceLocation PlacementRParen,
3470 SourceRange TypeIdParens, QualType AllocatedType,
3471 TypeSourceInfo *AllocatedTypeInfo,
3472 std::optional<Expr *> ArraySize,
3473 SourceRange DirectInitRange, Expr *Initializer) {
3474 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3475 PlacementLParen,
3476 PlacementArgs,
3477 PlacementRParen,
3478 TypeIdParens,
3479 AllocatedType,
3480 AllocatedTypeInfo,
3481 ArraySize,
3482 DirectInitRange,
3483 Initializer);
3484 }
3485
3486 /// Build a new C++ "delete" expression.
3487 ///
3488 /// By default, performs semantic analysis to build the new expression.
3489 /// Subclasses may override this routine to provide different behavior.
3491 bool IsGlobalDelete,
3492 bool IsArrayForm,
3493 Expr *Operand) {
3494 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3495 Operand);
3496 }
3497
3498 /// Build a new type trait expression.
3499 ///
3500 /// By default, performs semantic analysis to build the new expression.
3501 /// Subclasses may override this routine to provide different behavior.
3503 SourceLocation StartLoc,
3505 SourceLocation RParenLoc) {
3506 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3507 }
3508
3509 /// Build a new array type trait expression.
3510 ///
3511 /// By default, performs semantic analysis to build the new expression.
3512 /// Subclasses may override this routine to provide different behavior.
3514 SourceLocation StartLoc,
3515 TypeSourceInfo *TSInfo,
3516 Expr *DimExpr,
3517 SourceLocation RParenLoc) {
3518 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3519 }
3520
3521 /// Build a new expression trait expression.
3522 ///
3523 /// By default, performs semantic analysis to build the new expression.
3524 /// Subclasses may override this routine to provide different behavior.
3526 SourceLocation StartLoc,
3527 Expr *Queried,
3528 SourceLocation RParenLoc) {
3529 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3530 }
3531
3532 /// Build a new (previously unresolved) declaration reference
3533 /// expression.
3534 ///
3535 /// By default, performs semantic analysis to build the new expression.
3536 /// Subclasses may override this routine to provide different behavior.
3538 NestedNameSpecifierLoc QualifierLoc,
3539 SourceLocation TemplateKWLoc,
3540 const DeclarationNameInfo &NameInfo,
3541 const TemplateArgumentListInfo *TemplateArgs,
3542 bool IsAddressOfOperand,
3543 TypeSourceInfo **RecoveryTSI) {
3544 CXXScopeSpec SS;
3545 SS.Adopt(QualifierLoc);
3546
3547 if (TemplateArgs || TemplateKWLoc.isValid())
3549 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3550
3552 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3553 }
3554
3555 /// Build a new template-id expression.
3556 ///
3557 /// By default, performs semantic analysis to build the new expression.
3558 /// Subclasses may override this routine to provide different behavior.
3560 SourceLocation TemplateKWLoc,
3561 LookupResult &R,
3562 bool RequiresADL,
3563 const TemplateArgumentListInfo *TemplateArgs) {
3564 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3565 TemplateArgs);
3566 }
3567
3568 /// Build a new object-construction expression.
3569 ///
3570 /// By default, performs semantic analysis to build the new expression.
3571 /// Subclasses may override this routine to provide different behavior.
3574 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3575 bool ListInitialization, bool StdInitListInitialization,
3576 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3577 SourceRange ParenRange) {
3578 // Reconstruct the constructor we originally found, which might be
3579 // different if this is a call to an inherited constructor.
3580 CXXConstructorDecl *FoundCtor = Constructor;
3581 if (Constructor->isInheritingConstructor())
3582 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3583
3584 SmallVector<Expr *, 8> ConvertedArgs;
3585 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3586 ConvertedArgs))
3587 return ExprError();
3588
3590 IsElidable,
3591 ConvertedArgs,
3592 HadMultipleCandidates,
3593 ListInitialization,
3594 StdInitListInitialization,
3595 RequiresZeroInit, ConstructKind,
3596 ParenRange);
3597 }
3598
3599 /// Build a new implicit construction via inherited constructor
3600 /// expression.
3603 bool ConstructsVBase,
3604 bool InheritedFromVBase) {
3606 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3607 }
3608
3609 /// Build a new object-construction expression.
3610 ///
3611 /// By default, performs semantic analysis to build the new expression.
3612 /// Subclasses may override this routine to provide different behavior.
3614 SourceLocation LParenOrBraceLoc,
3615 MultiExprArg Args,
3616 SourceLocation RParenOrBraceLoc,
3617 bool ListInitialization) {
3619 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3620 }
3621
3622 /// Build a new object-construction expression.
3623 ///
3624 /// By default, performs semantic analysis to build the new expression.
3625 /// Subclasses may override this routine to provide different behavior.
3627 SourceLocation LParenLoc,
3628 MultiExprArg Args,
3629 SourceLocation RParenLoc,
3630 bool ListInitialization) {
3631 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3632 RParenLoc, ListInitialization);
3633 }
3634
3635 /// Build a new member reference expression.
3636 ///
3637 /// By default, performs semantic analysis to build the new expression.
3638 /// Subclasses may override this routine to provide different behavior.
3640 QualType BaseType,
3641 bool IsArrow,
3642 SourceLocation OperatorLoc,
3643 NestedNameSpecifierLoc QualifierLoc,
3644 SourceLocation TemplateKWLoc,
3645 NamedDecl *FirstQualifierInScope,
3646 const DeclarationNameInfo &MemberNameInfo,
3647 const TemplateArgumentListInfo *TemplateArgs) {
3648 CXXScopeSpec SS;
3649 SS.Adopt(QualifierLoc);
3650
3651 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3652 OperatorLoc, IsArrow,
3653 SS, TemplateKWLoc,
3654 FirstQualifierInScope,
3655 MemberNameInfo,
3656 TemplateArgs, /*S*/nullptr);
3657 }
3658
3659 /// Build a new member reference expression.
3660 ///
3661 /// By default, performs semantic analysis to build the new expression.
3662 /// Subclasses may override this routine to provide different behavior.
3664 SourceLocation OperatorLoc,
3665 bool IsArrow,
3666 NestedNameSpecifierLoc QualifierLoc,
3667 SourceLocation TemplateKWLoc,
3668 NamedDecl *FirstQualifierInScope,
3669 LookupResult &R,
3670 const TemplateArgumentListInfo *TemplateArgs) {
3671 CXXScopeSpec SS;
3672 SS.Adopt(QualifierLoc);
3673
3674 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3675 OperatorLoc, IsArrow,
3676 SS, TemplateKWLoc,
3677 FirstQualifierInScope,
3678 R, TemplateArgs, /*S*/nullptr);
3679 }
3680
3681 /// Build a new noexcept expression.
3682 ///
3683 /// By default, performs semantic analysis to build the new expression.
3684 /// Subclasses may override this routine to provide different behavior.
3686 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3687 }
3688
3691
3692 /// Build a new expression to compute the length of a parameter pack.
3694 SourceLocation PackLoc,
3695 SourceLocation RParenLoc,
3696 UnsignedOrNone Length,
3697 ArrayRef<TemplateArgument> PartialArgs) {
3698 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3699 RParenLoc, Length, PartialArgs);
3700 }
3701
3703 SourceLocation RSquareLoc,
3704 Expr *PackIdExpression, Expr *IndexExpr,
3705 ArrayRef<Expr *> ExpandedExprs,
3706 bool FullySubstituted = false) {
3707 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3708 IndexExpr, RSquareLoc, ExpandedExprs,
3709 FullySubstituted);
3710 }
3711
3712 /// Build a new expression representing a call to a source location
3713 /// builtin.
3714 ///
3715 /// By default, performs semantic analysis to build the new expression.
3716 /// Subclasses may override this routine to provide different behavior.
3718 SourceLocation BuiltinLoc,
3719 SourceLocation RPLoc,
3720 DeclContext *ParentContext) {
3721 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3722 ParentContext);
3723 }
3724
3726 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3727 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3729 CXXScopeSpec SS;
3730 SS.Adopt(NNS);
3731 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3732 ConceptNameInfo,
3733 FoundDecl,
3734 NamedConcept, TALI);
3735 if (Result.isInvalid())
3736 return ExprError();
3737 return Result;
3738 }
3739
3740 /// \brief Build a new requires expression.
3741 ///
3742 /// By default, performs semantic analysis to build the new expression.
3743 /// Subclasses may override this routine to provide different behavior.
3746 SourceLocation LParenLoc,
3747 ArrayRef<ParmVarDecl *> LocalParameters,
3748 SourceLocation RParenLoc,
3750 SourceLocation ClosingBraceLoc) {
3751 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3752 LocalParameters, RParenLoc, Requirements,
3753 ClosingBraceLoc);
3754 }
3755
3759 return SemaRef.BuildTypeRequirement(SubstDiag);
3760 }
3761
3763 return SemaRef.BuildTypeRequirement(T);
3764 }
3765
3768 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3769 SourceLocation NoexceptLoc,
3771 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3772 std::move(Ret));
3773 }
3774
3776 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3778 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3779 std::move(Ret));
3780 }
3781
3783 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3784 const ASTConstraintSatisfaction &Satisfaction) {
3785 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3786 Satisfaction);
3787 }
3788
3790 return SemaRef.BuildNestedRequirement(Constraint);
3791 }
3792
3793 /// \brief Build a new Objective-C boxed expression.
3794 ///
3795 /// By default, performs semantic analysis to build the new expression.
3796 /// Subclasses may override this routine to provide different behavior.
3798 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3799 }
3800
3801 /// Build a new Objective-C array literal.
3802 ///
3803 /// By default, performs semantic analysis to build the new expression.
3804 /// Subclasses may override this routine to provide different behavior.
3806 Expr **Elements, unsigned NumElements) {
3808 Range, MultiExprArg(Elements, NumElements));
3809 }
3810
3812 Expr *Base, Expr *Key,
3813 ObjCMethodDecl *getterMethod,
3814 ObjCMethodDecl *setterMethod) {
3816 RB, Base, Key, getterMethod, setterMethod);
3817 }
3818
3819 /// Build a new Objective-C dictionary literal.
3820 ///
3821 /// By default, performs semantic analysis to build the new expression.
3822 /// Subclasses may override this routine to provide different behavior.
3827
3828 /// Build a new Objective-C \@encode expression.
3829 ///
3830 /// By default, performs semantic analysis to build the new expression.
3831 /// Subclasses may override this routine to provide different behavior.
3833 TypeSourceInfo *EncodeTypeInfo,
3834 SourceLocation RParenLoc) {
3835 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3836 RParenLoc);
3837 }
3838
3839 /// Build a new Objective-C class message.
3841 Selector Sel,
3842 ArrayRef<SourceLocation> SelectorLocs,
3844 SourceLocation LBracLoc,
3845 MultiExprArg Args,
3846 SourceLocation RBracLoc) {
3847 return SemaRef.ObjC().BuildClassMessage(
3848 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3849 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3850 RBracLoc, Args);
3851 }
3852
3853 /// Build a new Objective-C instance message.
3855 Selector Sel,
3856 ArrayRef<SourceLocation> SelectorLocs,
3858 SourceLocation LBracLoc,
3859 MultiExprArg Args,
3860 SourceLocation RBracLoc) {
3861 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3862 /*SuperLoc=*/SourceLocation(),
3863 Sel, Method, LBracLoc,
3864 SelectorLocs, RBracLoc, Args);
3865 }
3866
3867 /// Build a new Objective-C instance/class message to 'super'.
3869 Selector Sel,
3870 ArrayRef<SourceLocation> SelectorLocs,
3871 QualType SuperType,
3873 SourceLocation LBracLoc,
3874 MultiExprArg Args,
3875 SourceLocation RBracLoc) {
3876 return Method->isInstanceMethod()
3877 ? SemaRef.ObjC().BuildInstanceMessage(
3878 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3879 SelectorLocs, RBracLoc, Args)
3880 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3881 Sel, Method, LBracLoc,
3882 SelectorLocs, RBracLoc, Args);
3883 }
3884
3885 /// Build a new Objective-C ivar reference expression.
3886 ///
3887 /// By default, performs semantic analysis to build the new expression.
3888 /// Subclasses may override this routine to provide different behavior.
3890 SourceLocation IvarLoc,
3891 bool IsArrow, bool IsFreeIvar) {
3892 CXXScopeSpec SS;
3893 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3895 BaseArg, BaseArg->getType(),
3896 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3897 /*FirstQualifierInScope=*/nullptr, NameInfo,
3898 /*TemplateArgs=*/nullptr,
3899 /*S=*/nullptr);
3900 if (IsFreeIvar && Result.isUsable())
3901 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3902 return Result;
3903 }
3904
3905 /// Build a new Objective-C property reference expression.
3906 ///
3907 /// By default, performs semantic analysis to build the new expression.
3908 /// Subclasses may override this routine to provide different behavior.
3911 SourceLocation PropertyLoc) {
3912 CXXScopeSpec SS;
3913 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3914 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3915 /*FIXME:*/PropertyLoc,
3916 /*IsArrow=*/false,
3917 SS, SourceLocation(),
3918 /*FirstQualifierInScope=*/nullptr,
3919 NameInfo,
3920 /*TemplateArgs=*/nullptr,
3921 /*S=*/nullptr);
3922 }
3923
3924 /// Build a new Objective-C property reference expression.
3925 ///
3926 /// By default, performs semantic analysis to build the new expression.
3927 /// Subclasses may override this routine to provide different behavior.
3929 ObjCMethodDecl *Getter,
3930 ObjCMethodDecl *Setter,
3931 SourceLocation PropertyLoc) {
3932 // Since these expressions can only be value-dependent, we do not
3933 // need to perform semantic analysis again.
3934 return Owned(
3935 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3937 PropertyLoc, Base));
3938 }
3939
3940 /// Build a new Objective-C "isa" expression.
3941 ///
3942 /// By default, performs semantic analysis to build the new expression.
3943 /// Subclasses may override this routine to provide different behavior.
3945 SourceLocation OpLoc, bool IsArrow) {
3946 CXXScopeSpec SS;
3947 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3948 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3949 OpLoc, IsArrow,
3950 SS, SourceLocation(),
3951 /*FirstQualifierInScope=*/nullptr,
3952 NameInfo,
3953 /*TemplateArgs=*/nullptr,
3954 /*S=*/nullptr);
3955 }
3956
3957 /// Build a new shuffle vector expression.
3958 ///
3959 /// By default, performs semantic analysis to build the new expression.
3960 /// Subclasses may override this routine to provide different behavior.
3962 MultiExprArg SubExprs,
3963 SourceLocation RParenLoc) {
3964 // Find the declaration for __builtin_shufflevector
3965 const IdentifierInfo &Name
3966 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3967 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3968 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3969 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3970
3971 // Build a reference to the __builtin_shufflevector builtin
3973 Expr *Callee = new (SemaRef.Context)
3974 DeclRefExpr(SemaRef.Context, Builtin, false,
3975 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3976 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3977 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3978 CK_BuiltinFnToFnPtr).get();
3979
3980 // Build the CallExpr
3981 ExprResult TheCall = CallExpr::Create(
3982 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3983 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3985
3986 // Type-check the __builtin_shufflevector expression.
3987 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3988 }
3989
3990 /// Build a new convert vector expression.
3992 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3993 SourceLocation RParenLoc) {
3994 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3995 }
3996
3997 /// Build a new template argument pack expansion.
3998 ///
3999 /// By default, performs semantic analysis to build a new pack expansion
4000 /// for a template argument. Subclasses may override this routine to provide
4001 /// different behavior.
4003 SourceLocation EllipsisLoc,
4004 UnsignedOrNone NumExpansions) {
4005 switch (Pattern.getArgument().getKind()) {
4009 EllipsisLoc, NumExpansions);
4010 if (Result.isInvalid())
4011 return TemplateArgumentLoc();
4012
4014 /*IsCanonical=*/false),
4015 Result.get());
4016 }
4017
4019 return TemplateArgumentLoc(
4020 SemaRef.Context,
4022 NumExpansions),
4023 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4024 Pattern.getTemplateNameLoc(), EllipsisLoc);
4025
4033 llvm_unreachable("Pack expansion pattern has no parameter packs");
4034
4036 if (TypeSourceInfo *Expansion
4037 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4038 EllipsisLoc,
4039 NumExpansions))
4040 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4041 Expansion);
4042 break;
4043 }
4044
4045 return TemplateArgumentLoc();
4046 }
4047
4048 /// Build a new expression pack expansion.
4049 ///
4050 /// By default, performs semantic analysis to build a new pack expansion
4051 /// for an expression. Subclasses may override this routine to provide
4052 /// different behavior.
4054 UnsignedOrNone NumExpansions) {
4055 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4056 }
4057
4058 /// Build a new C++1z fold-expression.
4059 ///
4060 /// By default, performs semantic analysis in order to build a new fold
4061 /// expression.
4063 SourceLocation LParenLoc, Expr *LHS,
4064 BinaryOperatorKind Operator,
4065 SourceLocation EllipsisLoc, Expr *RHS,
4066 SourceLocation RParenLoc,
4067 UnsignedOrNone NumExpansions) {
4068 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4069 EllipsisLoc, RHS, RParenLoc,
4070 NumExpansions);
4071 }
4072
4074 LambdaScopeInfo *LSI) {
4075 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4076 if (Expr *Init = PVD->getInit())
4078 Init->containsUnexpandedParameterPack();
4079 else if (PVD->hasUninstantiatedDefaultArg())
4081 PVD->getUninstantiatedDefaultArg()
4082 ->containsUnexpandedParameterPack();
4083 }
4084 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4085 }
4086
4087 /// Build an empty C++1z fold-expression with the given operator.
4088 ///
4089 /// By default, produces the fallback value for the fold-expression, or
4090 /// produce an error if there is no fallback value.
4092 BinaryOperatorKind Operator) {
4093 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4094 }
4095
4096 /// Build a new atomic operation expression.
4097 ///
4098 /// By default, performs semantic analysis to build the new expression.
4099 /// Subclasses may override this routine to provide different behavior.
4102 SourceLocation RParenLoc) {
4103 // Use this for all of the locations, since we don't know the difference
4104 // between the call and the expr at this point.
4105 SourceRange Range{BuiltinLoc, RParenLoc};
4106 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4108 }
4109
4111 ArrayRef<Expr *> SubExprs, QualType Type) {
4112 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4113 }
4114
4116 SourceLocation BeginLoc,
4117 SourceLocation DirLoc,
4118 SourceLocation EndLoc,
4120 StmtResult StrBlock) {
4122 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4123 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4124 }
4125
4136
4138 SourceLocation BeginLoc,
4139 SourceLocation DirLoc,
4140 SourceLocation EndLoc,
4142 StmtResult Loop) {
4144 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4145 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4146 }
4147
4149 SourceLocation DirLoc,
4150 SourceLocation EndLoc,
4152 StmtResult StrBlock) {
4154 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4156 Clauses, StrBlock);
4157 }
4158
4168
4178
4180 SourceLocation DirLoc,
4181 SourceLocation EndLoc,
4183 StmtResult StrBlock) {
4187 Clauses, StrBlock);
4188 }
4189
4191 SourceLocation DirLoc,
4192 SourceLocation EndLoc,
4193 ArrayRef<OpenACCClause *> Clauses) {
4195 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4197 Clauses, {});
4198 }
4199
4209
4211 SourceLocation DirLoc,
4212 SourceLocation EndLoc,
4213 ArrayRef<OpenACCClause *> Clauses) {
4215 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4217 Clauses, {});
4218 }
4219
4221 SourceLocation DirLoc,
4222 SourceLocation EndLoc,
4223 ArrayRef<OpenACCClause *> Clauses) {
4225 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4227 Clauses, {});
4228 }
4229
4231 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4232 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4233 SourceLocation RParenLoc, SourceLocation EndLoc,
4234 ArrayRef<OpenACCClause *> Clauses) {
4236 Exprs.push_back(DevNumExpr);
4237 llvm::append_range(Exprs, QueueIdExprs);
4239 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4240 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4241 }
4242
4244 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4245 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4246 SourceLocation RParenLoc, SourceLocation EndLoc) {
4248 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4249 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4250 }
4251
4253 SourceLocation DirLoc,
4254 OpenACCAtomicKind AtKind,
4255 SourceLocation EndLoc,
4257 StmtResult AssociatedStmt) {
4259 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4260 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4261 AssociatedStmt);
4262 }
4263
4267
4268private:
4269 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4270 QualType ObjectType,
4271 NamedDecl *FirstQualifierInScope);
4272
4273 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4274 QualType ObjectType,
4275 NamedDecl *FirstQualifierInScope) {
4276 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4277 return TSInfo;
4278
4279 TypeLocBuilder TLB;
4280 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4281 ObjectType, FirstQualifierInScope);
4282 if (T.isNull())
4283 return nullptr;
4284 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4285 }
4286
4287 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4288 DependentNameTypeLoc TL,
4289 bool DeducibleTSTContext,
4290 QualType ObjectType = QualType(),
4291 NamedDecl *UnqualLookup = nullptr);
4292
4294 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4296
4297 OpenACCClause *
4298 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4299 OpenACCDirectiveKind DirKind,
4300 const OpenACCClause *OldClause);
4301};
4302
4303template <typename Derived>
4305 if (!S)
4306 return S;
4307
4308 switch (S->getStmtClass()) {
4309 case Stmt::NoStmtClass: break;
4310
4311 // Transform individual statement nodes
4312 // Pass SDK into statements that can produce a value
4313#define STMT(Node, Parent) \
4314 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4315#define VALUESTMT(Node, Parent) \
4316 case Stmt::Node##Class: \
4317 return getDerived().Transform##Node(cast<Node>(S), SDK);
4318#define ABSTRACT_STMT(Node)
4319#define EXPR(Node, Parent)
4320#include "clang/AST/StmtNodes.inc"
4321
4322 // Transform expressions by calling TransformExpr.
4323#define STMT(Node, Parent)
4324#define ABSTRACT_STMT(Stmt)
4325#define EXPR(Node, Parent) case Stmt::Node##Class:
4326#include "clang/AST/StmtNodes.inc"
4327 {
4328 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4329
4331 E = getSema().ActOnStmtExprResult(E);
4332 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4333 }
4334 }
4335
4336 return S;
4337}
4338
4339template<typename Derived>
4341 if (!S)
4342 return S;
4343
4344 switch (S->getClauseKind()) {
4345 default: break;
4346 // Transform individual clause nodes
4347#define GEN_CLANG_CLAUSE_CLASS
4348#define CLAUSE_CLASS(Enum, Str, Class) \
4349 case Enum: \
4350 return getDerived().Transform##Class(cast<Class>(S));
4351#include "llvm/Frontend/OpenMP/OMP.inc"
4352 }
4353
4354 return S;
4355}
4356
4357
4358template<typename Derived>
4360 if (!E)
4361 return E;
4362
4363 switch (E->getStmtClass()) {
4364 case Stmt::NoStmtClass: break;
4365#define STMT(Node, Parent) case Stmt::Node##Class: break;
4366#define ABSTRACT_STMT(Stmt)
4367#define EXPR(Node, Parent) \
4368 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4369#include "clang/AST/StmtNodes.inc"
4370 }
4371
4372 return E;
4373}
4374
4375template<typename Derived>
4377 bool NotCopyInit) {
4378 // Initializers are instantiated like expressions, except that various outer
4379 // layers are stripped.
4380 if (!Init)
4381 return Init;
4382
4383 if (auto *FE = dyn_cast<FullExpr>(Init))
4384 Init = FE->getSubExpr();
4385
4386 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4387 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4388 Init = OVE->getSourceExpr();
4389 }
4390
4391 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4392 Init = MTE->getSubExpr();
4393
4394 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4395 Init = Binder->getSubExpr();
4396
4397 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4398 Init = ICE->getSubExprAsWritten();
4399
4400 if (CXXStdInitializerListExpr *ILE =
4401 dyn_cast<CXXStdInitializerListExpr>(Init))
4402 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4403
4404 // If this is copy-initialization, we only need to reconstruct
4405 // InitListExprs. Other forms of copy-initialization will be a no-op if
4406 // the initializer is already the right type.
4407 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4408 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4409 return getDerived().TransformExpr(Init);
4410
4411 // Revert value-initialization back to empty parens.
4412 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4413 SourceRange Parens = VIE->getSourceRange();
4414 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4415 Parens.getEnd());
4416 }
4417
4418 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4420 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4421 SourceLocation());
4422
4423 // Revert initialization by constructor back to a parenthesized or braced list
4424 // of expressions. Any other form of initializer can just be reused directly.
4425 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4426 return getDerived().TransformExpr(Init);
4427
4428 // If the initialization implicitly converted an initializer list to a
4429 // std::initializer_list object, unwrap the std::initializer_list too.
4430 if (Construct && Construct->isStdInitListInitialization())
4431 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4432
4433 // Enter a list-init context if this was list initialization.
4436 Construct->isListInitialization());
4437
4438 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4439 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4440 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4441 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4442 SmallVector<Expr*, 8> NewArgs;
4443 bool ArgChanged = false;
4444 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4445 /*IsCall*/true, NewArgs, &ArgChanged))
4446 return ExprError();
4447
4448 // If this was list initialization, revert to syntactic list form.
4449 if (Construct->isListInitialization())
4450 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4451 Construct->getEndLoc());
4452
4453 // Build a ParenListExpr to represent anything else.
4455 if (Parens.isInvalid()) {
4456 // This was a variable declaration's initialization for which no initializer
4457 // was specified.
4458 assert(NewArgs.empty() &&
4459 "no parens or braces but have direct init with arguments?");
4460 return ExprEmpty();
4461 }
4462 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4463 Parens.getEnd());
4464}
4465
4466template<typename Derived>
4468 unsigned NumInputs,
4469 bool IsCall,
4470 SmallVectorImpl<Expr *> &Outputs,
4471 bool *ArgChanged) {
4472 for (unsigned I = 0; I != NumInputs; ++I) {
4473 // If requested, drop call arguments that need to be dropped.
4474 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4475 if (ArgChanged)
4476 *ArgChanged = true;
4477
4478 break;
4479 }
4480
4481 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4482 Expr *Pattern = Expansion->getPattern();
4483
4485 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4486 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4487
4488 // Determine whether the set of unexpanded parameter packs can and should
4489 // be expanded.
4490 bool Expand = true;
4491 bool RetainExpansion = false;
4492 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4493 UnsignedOrNone NumExpansions = OrigNumExpansions;
4495 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4496 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4497 RetainExpansion, NumExpansions))
4498 return true;
4499
4500 if (!Expand) {
4501 // The transform has determined that we should perform a simple
4502 // transformation on the pack expansion, producing another pack
4503 // expansion.
4504 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4505 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4506 if (OutPattern.isInvalid())
4507 return true;
4508
4509 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4510 Expansion->getEllipsisLoc(),
4511 NumExpansions);
4512 if (Out.isInvalid())
4513 return true;
4514
4515 if (ArgChanged)
4516 *ArgChanged = true;
4517 Outputs.push_back(Out.get());
4518 continue;
4519 }
4520
4521 // Record right away that the argument was changed. This needs
4522 // to happen even if the array expands to nothing.
4523 if (ArgChanged) *ArgChanged = true;
4524
4525 // The transform has determined that we should perform an elementwise
4526 // expansion of the pattern. Do so.
4527 for (unsigned I = 0; I != *NumExpansions; ++I) {
4528 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4529 ExprResult Out = getDerived().TransformExpr(Pattern);
4530 if (Out.isInvalid())
4531 return true;
4532
4533 if (Out.get()->containsUnexpandedParameterPack()) {
4534 Out = getDerived().RebuildPackExpansion(
4535 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4536 if (Out.isInvalid())
4537 return true;
4538 }
4539
4540 Outputs.push_back(Out.get());
4541 }
4542
4543 // If we're supposed to retain a pack expansion, do so by temporarily
4544 // forgetting the partially-substituted parameter pack.
4545 if (RetainExpansion) {
4546 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4547
4548 ExprResult Out = getDerived().TransformExpr(Pattern);
4549 if (Out.isInvalid())
4550 return true;
4551
4552 Out = getDerived().RebuildPackExpansion(
4553 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4554 if (Out.isInvalid())
4555 return true;
4556
4557 Outputs.push_back(Out.get());
4558 }
4559
4560 continue;
4561 }
4562
4564 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4565 : getDerived().TransformExpr(Inputs[I]);
4566 if (Result.isInvalid())
4567 return true;
4568
4569 if (Result.get() != Inputs[I] && ArgChanged)
4570 *ArgChanged = true;
4571
4572 Outputs.push_back(Result.get());
4573 }
4574
4575 return false;
4576}
4577
4578template <typename Derived>
4581
4584 /*LambdaContextDecl=*/nullptr,
4586 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4587
4588 if (Var) {
4589 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4591
4592 if (!ConditionVar)
4593 return Sema::ConditionError();
4594
4595 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4596 }
4597
4598 if (Expr) {
4599 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4600
4601 if (CondExpr.isInvalid())
4602 return Sema::ConditionError();
4603
4604 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4605 /*MissingOK=*/true);
4606 }
4607
4608 return Sema::ConditionResult();
4609}
4610
4611template <typename Derived>
4613 NestedNameSpecifierLoc NNS, QualType ObjectType,
4614 NamedDecl *FirstQualifierInScope) {
4616
4617 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4618 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4619 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4620 Qualifiers.push_back(Qualifier);
4621 };
4622 insertNNS(NNS);
4623
4624 CXXScopeSpec SS;
4625 while (!Qualifiers.empty()) {
4626 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4628
4629 switch (QNNS.getKind()) {
4631 llvm_unreachable("unexpected null nested name specifier");
4632
4635 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4637 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4638 break;
4639 }
4640
4642 // There is no meaningful transformation that one could perform on the
4643 // global scope.
4644 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4645 break;
4646
4648 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4650 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4651 Q.getEndLoc());
4652 break;
4653 }
4654
4656 assert(SS.isEmpty());
4657 TypeLoc TL = Q.castAsTypeLoc();
4658
4659 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4660 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4661 if (QualifierLoc) {
4662 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4663 QualifierLoc, ObjectType, FirstQualifierInScope);
4664 if (!QualifierLoc)
4665 return NestedNameSpecifierLoc();
4666 ObjectType = QualType();
4667 FirstQualifierInScope = nullptr;
4668 }
4669 SS.Adopt(QualifierLoc);
4671 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4672 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4673 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4674 false, SS,
4675 FirstQualifierInScope, false))
4676 return NestedNameSpecifierLoc();
4677 return SS.getWithLocInContext(SemaRef.Context);
4678 }
4679
4680 QualType T = TL.getType();
4681 TypeLocBuilder TLB;
4683 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4684 FirstQualifierInScope);
4685 if (T.isNull())
4686 return NestedNameSpecifierLoc();
4687 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4688 }
4689
4690 if (T->isDependentType() || T->isRecordType() ||
4691 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4692 if (T->isEnumeralType())
4693 SemaRef.Diag(TL.getBeginLoc(),
4694 diag::warn_cxx98_compat_enum_nested_name_spec);
4695 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4696 break;
4697 }
4698 // If the nested-name-specifier is an invalid type def, don't emit an
4699 // error because a previous error should have already been emitted.
4701 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4702 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4703 << T << SS.getRange();
4704 }
4705 return NestedNameSpecifierLoc();
4706 }
4707 }
4708 }
4709
4710 // Don't rebuild the nested-name-specifier if we don't have to.
4711 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4713 return NNS;
4714
4715 // If we can re-use the source-location data from the original
4716 // nested-name-specifier, do so.
4717 if (SS.location_size() == NNS.getDataLength() &&
4718 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4720
4721 // Allocate new nested-name-specifier location information.
4722 return SS.getWithLocInContext(SemaRef.Context);
4723}
4724
4725template<typename Derived>
4729 DeclarationName Name = NameInfo.getName();
4730 if (!Name)
4731 return DeclarationNameInfo();
4732
4733 switch (Name.getNameKind()) {
4741 return NameInfo;
4742
4744 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4745 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4746 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4747 if (!NewTemplate)
4748 return DeclarationNameInfo();
4749
4750 DeclarationNameInfo NewNameInfo(NameInfo);
4751 NewNameInfo.setName(
4752 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4753 return NewNameInfo;
4754 }
4755
4759 TypeSourceInfo *NewTInfo;
4760 CanQualType NewCanTy;
4761 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4762 NewTInfo = getDerived().TransformType(OldTInfo);
4763 if (!NewTInfo)
4764 return DeclarationNameInfo();
4765 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4766 }
4767 else {
4768 NewTInfo = nullptr;
4769 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4770 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4771 if (NewT.isNull())
4772 return DeclarationNameInfo();
4773 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4774 }
4775
4776 DeclarationName NewName
4777 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4778 NewCanTy);
4779 DeclarationNameInfo NewNameInfo(NameInfo);
4780 NewNameInfo.setName(NewName);
4781 NewNameInfo.setNamedTypeInfo(NewTInfo);
4782 return NewNameInfo;
4783 }
4784 }
4785
4786 llvm_unreachable("Unknown name kind.");
4787}
4788
4789template <typename Derived>
4791 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4793 QualType ObjectType, bool AllowInjectedClassName) {
4794 if (const IdentifierInfo *II = IO.getIdentifier())
4795 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4796 ObjectType, AllowInjectedClassName);
4797 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4798 NameLoc, ObjectType,
4799 AllowInjectedClassName);
4800}
4801
4802template <typename Derived>
4804 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4805 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4806 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4808 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4809
4810 if (QualifierLoc) {
4811 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4812 QualifierLoc, ObjectType, FirstQualifierInScope);
4813 if (!QualifierLoc)
4814 return TemplateName();
4815 }
4816
4817 NestedNameSpecifierLoc UnderlyingQualifier;
4818 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4819 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4820 FirstQualifierInScope, AllowInjectedClassName);
4821 if (NewUnderlyingName.isNull())
4822 return TemplateName();
4823 assert(!UnderlyingQualifier && "unexpected qualifier");
4824
4825 if (!getDerived().AlwaysRebuild() &&
4826 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4827 NewUnderlyingName == UnderlyingName)
4828 return Name;
4829 CXXScopeSpec SS;
4830 SS.Adopt(QualifierLoc);
4831 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4832 NewUnderlyingName);
4833 }
4834
4836 if (QualifierLoc) {
4837 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4838 QualifierLoc, ObjectType, FirstQualifierInScope);
4839 if (!QualifierLoc)
4840 return TemplateName();
4841 // The qualifier-in-scope and object type only apply to the leftmost
4842 // entity.
4843 ObjectType = QualType();
4844 }
4845
4846 if (!getDerived().AlwaysRebuild() &&
4847 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4848 ObjectType.isNull())
4849 return Name;
4850
4851 CXXScopeSpec SS;
4852 SS.Adopt(QualifierLoc);
4853 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4854 NameLoc, ObjectType,
4855 AllowInjectedClassName);
4856 }
4857
4860 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4861
4862 NestedNameSpecifierLoc ReplacementQualifierLoc;
4863 TemplateName ReplacementName = S->getReplacement();
4864 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4866 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4867 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4868 }
4869
4870 TemplateName NewName = getDerived().TransformTemplateName(
4871 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4872 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4873 if (NewName.isNull())
4874 return TemplateName();
4875 Decl *AssociatedDecl =
4876 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4877 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4878 AssociatedDecl == S->getAssociatedDecl())
4879 return Name;
4880 return SemaRef.Context.getSubstTemplateTemplateParm(
4881 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4882 S->getFinal());
4883 }
4884
4885 assert(!Name.getAsDeducedTemplateName() &&
4886 "DeducedTemplateName should not escape partial ordering");
4887
4888 // FIXME: Preserve UsingTemplateName.
4889 if (auto *Template = Name.getAsTemplateDecl()) {
4890 assert(!QualifierLoc && "Unexpected qualifier");
4891 return TemplateName(cast_or_null<TemplateDecl>(
4892 getDerived().TransformDecl(NameLoc, Template)));
4893 }
4894
4897 assert(!QualifierLoc &&
4898 "Unexpected qualified SubstTemplateTemplateParmPack");
4899 return getDerived().RebuildTemplateName(
4900 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4901 SubstPack->getIndex(), SubstPack->getFinal());
4902 }
4903
4904 // These should be getting filtered out before they reach the AST.
4905 llvm_unreachable("overloaded function decl survived to here");
4906}
4907
4908template <typename Derived>
4910 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4911 TemplateName Name, SourceLocation NameLoc) {
4912 TemplateName TN = getDerived().TransformTemplateName(
4913 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
4914 if (TN.isNull())
4915 return TemplateArgument();
4916 return TemplateArgument(TN);
4917}
4918
4919template<typename Derived>
4921 const TemplateArgument &Arg,
4922 TemplateArgumentLoc &Output) {
4923 Output = getSema().getTrivialTemplateArgumentLoc(
4924 Arg, QualType(), getDerived().getBaseLocation());
4925}
4926
4927template <typename Derived>
4929 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4930 bool Uneval) {
4931 const TemplateArgument &Arg = Input.getArgument();
4932 switch (Arg.getKind()) {
4935 llvm_unreachable("Unexpected TemplateArgument");
4936
4941 // Transform a resolved template argument straight to a resolved template
4942 // argument. We get here when substituting into an already-substituted
4943 // template type argument during concept satisfaction checking.
4945 QualType NewT = getDerived().TransformType(T);
4946 if (NewT.isNull())
4947 return true;
4948
4950 ? Arg.getAsDecl()
4951 : nullptr;
4952 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4954 : nullptr;
4955 if (D && !NewD)
4956 return true;
4957
4958 if (NewT == T && D == NewD)
4959 Output = Input;
4960 else if (Arg.getKind() == TemplateArgument::Integral)
4961 Output = TemplateArgumentLoc(
4962 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4964 else if (Arg.getKind() == TemplateArgument::NullPtr)
4965 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4967 else if (Arg.getKind() == TemplateArgument::Declaration)
4968 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4971 Output = TemplateArgumentLoc(
4972 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4974 else
4975 llvm_unreachable("unexpected template argument kind");
4976
4977 return false;
4978 }
4979
4981 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4982 if (!DI)
4984
4985 DI = getDerived().TransformType(DI);
4986 if (!DI)
4987 return true;
4988
4989 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4990 return false;
4991 }
4992
4994 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4995
4996 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
4997 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
4998 Input.getTemplateNameLoc());
4999 if (Out.isNull())
5000 return true;
5001 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5002 QualifierLoc, Input.getTemplateNameLoc());
5003 return false;
5004 }
5005
5007 llvm_unreachable("Caller should expand pack expansions");
5008
5010 // Template argument expressions are constant expressions.
5012 getSema(),
5015 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5017
5018 Expr *InputExpr = Input.getSourceExpression();
5019 if (!InputExpr)
5020 InputExpr = Input.getArgument().getAsExpr();
5021
5022 ExprResult E = getDerived().TransformExpr(InputExpr);
5023 E = SemaRef.ActOnConstantExpression(E);
5024 if (E.isInvalid())
5025 return true;
5026 Output = TemplateArgumentLoc(
5027 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5028 return false;
5029 }
5030 }
5031
5032 // Work around bogus GCC warning
5033 return true;
5034}
5035
5036/// Iterator adaptor that invents template argument location information
5037/// for each of the template arguments in its underlying iterator.
5038template<typename Derived, typename InputIterator>
5041 InputIterator Iter;
5042
5043public:
5046 typedef typename std::iterator_traits<InputIterator>::difference_type
5048 typedef std::input_iterator_tag iterator_category;
5049
5050 class pointer {
5052
5053 public:
5054 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5055
5056 const TemplateArgumentLoc *operator->() const { return &Arg; }
5057 };
5058
5060 InputIterator Iter)
5061 : Self(Self), Iter(Iter) { }
5062
5064 ++Iter;
5065 return *this;
5066 }
5067
5070 ++(*this);
5071 return Old;
5072 }
5073
5076 Self.InventTemplateArgumentLoc(*Iter, Result);
5077 return Result;
5078 }
5079
5080 pointer operator->() const { return pointer(**this); }
5081
5084 return X.Iter == Y.Iter;
5085 }
5086
5089 return X.Iter != Y.Iter;
5090 }
5091};
5092
5093template<typename Derived>
5094template<typename InputIterator>
5096 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5097 bool Uneval) {
5098 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5100 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5101 // Unpack argument packs, which we translate them into separate
5102 // arguments.
5103 // FIXME: We could do much better if we could guarantee that the
5104 // TemplateArgumentLocInfo for the pack expansion would be usable for
5105 // all of the template arguments in the argument pack.
5106 typedef TemplateArgumentLocInventIterator<Derived,
5108 PackLocIterator;
5109
5110 TemplateArgumentListInfo *PackOutput = &Outputs;
5112
5114 PackLocIterator(*this, In.getArgument().pack_begin()),
5115 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5116 Uneval))
5117 return true;
5118
5119 continue;
5120 }
5121
5122 if (In.getArgument().isPackExpansion()) {
5123 UnexpandedInfo Info;
5124 TemplateArgumentLoc Prepared;
5125 if (PreparePackForExpansion(In, Uneval, Prepared, Info))
5126 return true;
5127 if (!Info.Expand) {
5128 Outputs.addArgument(Prepared);
5129 continue;
5130 }
5131
5132 // The transform has determined that we should perform an elementwise
5133 // expansion of the pattern. Do so.
5134 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5136 ForgetSubst.emplace(getDerived());
5137 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5138 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5139
5141 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5142 return true;
5143
5144 if (Out.getArgument().containsUnexpandedParameterPack()) {
5145 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5146 Info.OrigNumExpansions);
5147 if (Out.getArgument().isNull())
5148 return true;
5149 }
5150
5151 Outputs.addArgument(Out);
5152 }
5153
5154 // If we're supposed to retain a pack expansion, do so by temporarily
5155 // forgetting the partially-substituted parameter pack.
5156 if (Info.RetainExpansion) {
5157 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5158
5160 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5161 return true;
5162
5163 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5164 Info.OrigNumExpansions);
5165 if (Out.getArgument().isNull())
5166 return true;
5167
5168 Outputs.addArgument(Out);
5169 }
5170
5171 continue;
5172 }
5173
5174 // The simple case:
5175 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5176 return true;
5177
5178 Outputs.addArgument(Out);
5179 }
5180
5181 return false;
5182}
5183
5184// FIXME: Find ways to reduce code duplication for pack expansions.
5185template <typename Derived>
5187 bool Uneval,
5189 UnexpandedInfo &Info) {
5190 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5191 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5192 TemplateArgumentLoc &Pattern) {
5193 assert(Arg.getArgument().isPackExpansion());
5194 // We have a pack expansion, for which we will be substituting into the
5195 // pattern.
5196 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5197 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5199 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5200 if (IsLateExpansionAttempt) {
5201 // Request expansion only when there is an opportunity to expand a pack
5202 // that required a substituion first.
5203 bool SawPackTypes =
5204 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5205 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5206 });
5207 if (!SawPackTypes) {
5208 Info.Expand = false;
5209 return false;
5210 }
5211 }
5212 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5213
5214 // Determine whether the set of unexpanded parameter packs can and
5215 // should be expanded.
5216 Info.Expand = true;
5217 Info.RetainExpansion = false;
5218 Info.NumExpansions = Info.OrigNumExpansions;
5219 return getDerived().TryExpandParameterPacks(
5220 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5221 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5222 Info.RetainExpansion, Info.NumExpansions);
5223 };
5224
5225 TemplateArgumentLoc Pattern;
5226 if (ComputeInfo(In, false, Info, Pattern))
5227 return true;
5228
5229 if (Info.Expand) {
5230 Out = Pattern;
5231 return false;
5232 }
5233
5234 // The transform has determined that we should perform a simple
5235 // transformation on the pack expansion, producing another pack
5236 // expansion.
5237 TemplateArgumentLoc OutPattern;
5238 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5239 std::in_place, getSema(), std::nullopt);
5240 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5241 return true;
5242
5243 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5244 Info.NumExpansions);
5245 if (Out.getArgument().isNull())
5246 return true;
5247 SubstIndex.reset();
5248
5249 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5250 return false;
5251
5252 // Some packs will learn their length after substitution, e.g.
5253 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5254 // value of `T`.
5255 //
5256 // We only expand after we know sizes of all packs, check if this is the case
5257 // or not. However, we avoid a full template substitution and only do
5258 // expanstions after this point.
5259
5260 // E.g. when substituting template arguments of tuple with {T -> int} in the
5261 // following example:
5262 // template <class T>
5263 // struct TupleWithInt {
5264 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5265 // };
5266 // TupleWithInt<int>::type y;
5267 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5268 // lenght and run `ComputeInfo()` to provide the necessary information to our
5269 // caller.
5270 //
5271 // Note that we may still have situations where builtin is not going to be
5272 // expanded. For example:
5273 // template <class T>
5274 // struct Foo {
5275 // template <class U> using tuple_with_t =
5276 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5277 // tuple_with_t<short>;
5278 // }
5279 // Because the substitution into `type` happens in dependent context, `type`
5280 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5281 // and the caller will not be able to expand it.
5282 ForgetSubstitutionRAII ForgetSubst(getDerived());
5283 if (ComputeInfo(Out, true, Info, OutPattern))
5284 return true;
5285 if (!Info.Expand)
5286 return false;
5287 Out = OutPattern;
5288 Info.ExpandUnderForgetSubstitions = true;
5289 return false;
5290}
5291
5292//===----------------------------------------------------------------------===//
5293// Type transformation
5294//===----------------------------------------------------------------------===//
5295
5296template<typename Derived>
5299 return T;
5300
5301 // Temporary workaround. All of these transformations should
5302 // eventually turn into transformations on TypeLocs.
5303 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5305
5306 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5307
5308 if (!NewDI)
5309 return QualType();
5310
5311 return NewDI->getType();
5312}
5313
5314template<typename Derived>
5316 // Refine the base location to the type's location.
5317 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5320 return DI;
5321
5322 TypeLocBuilder TLB;
5323
5324 TypeLoc TL = DI->getTypeLoc();
5325 TLB.reserve(TL.getFullDataSize());
5326
5327 QualType Result = getDerived().TransformType(TLB, TL);
5328 if (Result.isNull())
5329 return nullptr;
5330
5331 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5332}
5333
5334template<typename Derived>
5337 switch (T.getTypeLocClass()) {
5338#define ABSTRACT_TYPELOC(CLASS, PARENT)
5339#define TYPELOC(CLASS, PARENT) \
5340 case TypeLoc::CLASS: \
5341 return getDerived().Transform##CLASS##Type(TLB, \
5342 T.castAs<CLASS##TypeLoc>());
5343#include "clang/AST/TypeLocNodes.def"
5344 }
5345
5346 llvm_unreachable("unhandled type loc!");
5347}
5348
5349template<typename Derived>
5352 return TransformType(T);
5353
5355 return T;
5356 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5358 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5359 return NewDI ? NewDI->getType() : QualType();
5360}
5361
5362template<typename Derived>
5365 if (!isa<DependentNameType>(DI->getType()))
5366 return TransformType(DI);
5367
5368 // Refine the base location to the type's location.
5369 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5372 return DI;
5373
5374 TypeLocBuilder TLB;
5375
5376 TypeLoc TL = DI->getTypeLoc();
5377 TLB.reserve(TL.getFullDataSize());
5378
5379 auto QTL = TL.getAs<QualifiedTypeLoc>();
5380 if (QTL)
5381 TL = QTL.getUnqualifiedLoc();
5382
5383 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5384
5385 QualType Result = getDerived().TransformDependentNameType(
5386 TLB, DNTL, /*DeducedTSTContext*/true);
5387 if (Result.isNull())
5388 return nullptr;
5389
5390 if (QTL) {
5391 Result = getDerived().RebuildQualifiedType(Result, QTL);
5392 if (Result.isNull())
5393 return nullptr;
5395 }
5396
5397 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5398}
5399
5400template<typename Derived>
5405 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5406 auto SuppressObjCLifetime =
5407 T.getType().getLocalQualifiers().hasObjCLifetime();
5408 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5409 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5410 SuppressObjCLifetime);
5411 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5412 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5413 TLB, STTP, SuppressObjCLifetime);
5414 } else {
5415 Result = getDerived().TransformType(TLB, UnqualTL);
5416 }
5417
5418 if (Result.isNull())
5419 return QualType();
5420
5421 Result = getDerived().RebuildQualifiedType(Result, T);
5422
5423 if (Result.isNull())
5424 return QualType();
5425
5426 // RebuildQualifiedType might have updated the type, but not in a way
5427 // that invalidates the TypeLoc. (There's no location information for
5428 // qualifiers.)
5430
5431 return Result;
5432}
5433
5434template <typename Derived>
5436 QualifiedTypeLoc TL) {
5437
5438 SourceLocation Loc = TL.getBeginLoc();
5439 Qualifiers Quals = TL.getType().getLocalQualifiers();
5440
5441 if ((T.getAddressSpace() != LangAS::Default &&
5442 Quals.getAddressSpace() != LangAS::Default) &&
5443 T.getAddressSpace() != Quals.getAddressSpace()) {
5444 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5445 << TL.getType() << T;
5446 return QualType();
5447 }
5448
5449 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5450 if (LocalPointerAuth.isPresent()) {
5451 if (T.getPointerAuth().isPresent()) {
5452 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5453 return QualType();
5454 }
5455 if (!T->isDependentType()) {
5456 if (!T->isSignableType(SemaRef.getASTContext())) {
5457 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5458 return QualType();
5459 }
5460 }
5461 }
5462 // C++ [dcl.fct]p7:
5463 // [When] adding cv-qualifications on top of the function type [...] the
5464 // cv-qualifiers are ignored.
5465 if (T->isFunctionType()) {
5466 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5467 Quals.getAddressSpace());
5468 return T;
5469 }
5470
5471 // C++ [dcl.ref]p1:
5472 // when the cv-qualifiers are introduced through the use of a typedef-name
5473 // or decltype-specifier [...] the cv-qualifiers are ignored.
5474 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5475 // applied to a reference type.
5476 if (T->isReferenceType()) {
5477 // The only qualifier that applies to a reference type is restrict.
5478 if (!Quals.hasRestrict())
5479 return T;
5481 }
5482
5483 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5484 // resulting type.
5485 if (Quals.hasObjCLifetime()) {
5486 if (!T->isObjCLifetimeType() && !T->isDependentType())
5487 Quals.removeObjCLifetime();
5488 else if (T.getObjCLifetime()) {
5489 // Objective-C ARC:
5490 // A lifetime qualifier applied to a substituted template parameter
5491 // overrides the lifetime qualifier from the template argument.
5492 const AutoType *AutoTy;
5493 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5494 // 'auto' types behave the same way as template parameters.
5495 QualType Deduced = AutoTy->getDeducedType();
5496 Qualifiers Qs = Deduced.getQualifiers();
5497 Qs.removeObjCLifetime();
5498 Deduced =
5499 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5500 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5501 AutoTy->isDependentType(),
5502 /*isPack=*/false,
5503 AutoTy->getTypeConstraintConcept(),
5504 AutoTy->getTypeConstraintArguments());
5505 } else {
5506 // Otherwise, complain about the addition of a qualifier to an
5507 // already-qualified type.
5508 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5509 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5510 Quals.removeObjCLifetime();
5511 }
5512 }
5513 }
5514
5515 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5516}
5517
5518template <typename Derived>
5519QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5520 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5521 NamedDecl *FirstQualifierInScope) {
5522 assert(!getDerived().AlreadyTransformed(TL.getType()));
5523
5524 switch (TL.getTypeLocClass()) {
5525 case TypeLoc::TemplateSpecialization:
5526 return getDerived().TransformTemplateSpecializationType(
5527 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5528 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5529 case TypeLoc::DependentName:
5530 return getDerived().TransformDependentNameType(
5531 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5532 ObjectType, FirstQualifierInScope);
5533 default:
5534 // Any dependent canonical type can appear here, through type alias
5535 // templates.
5536 return getDerived().TransformType(TLB, TL);
5537 }
5538}
5539
5540template <class TyLoc> static inline
5542 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5543 NewT.setNameLoc(T.getNameLoc());
5544 return T.getType();
5545}
5546
5547template<typename Derived>
5548QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5549 BuiltinTypeLoc T) {
5550 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5551 NewT.setBuiltinLoc(T.getBuiltinLoc());
5552 if (T.needsExtraLocalData())
5553 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5554 return T.getType();
5555}
5556
5557template<typename Derived>
5559 ComplexTypeLoc T) {
5560 // FIXME: recurse?
5561 return TransformTypeSpecType(TLB, T);
5562}
5563
5564template <typename Derived>
5566 AdjustedTypeLoc TL) {
5567 // Adjustments applied during transformation are handled elsewhere.
5568 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5569}
5570
5571template<typename Derived>
5573 DecayedTypeLoc TL) {
5574 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5575 if (OriginalType.isNull())
5576 return QualType();
5577
5578 QualType Result = TL.getType();
5579 if (getDerived().AlwaysRebuild() ||
5580 OriginalType != TL.getOriginalLoc().getType())
5581 Result = SemaRef.Context.getDecayedType(OriginalType);
5582 TLB.push<DecayedTypeLoc>(Result);
5583 // Nothing to set for DecayedTypeLoc.
5584 return Result;
5585}
5586
5587template <typename Derived>
5591 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5592 if (OriginalType.isNull())
5593 return QualType();
5594
5595 QualType Result = TL.getType();
5596 if (getDerived().AlwaysRebuild() ||
5597 OriginalType != TL.getElementLoc().getType())
5598 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5599 TLB.push<ArrayParameterTypeLoc>(Result);
5600 // Nothing to set for ArrayParameterTypeLoc.
5601 return Result;
5602}
5603
5604template<typename Derived>
5606 PointerTypeLoc TL) {
5607 QualType PointeeType
5608 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5609 if (PointeeType.isNull())
5610 return QualType();
5611
5612 QualType Result = TL.getType();
5613 if (PointeeType->getAs<ObjCObjectType>()) {
5614 // A dependent pointer type 'T *' has is being transformed such
5615 // that an Objective-C class type is being replaced for 'T'. The
5616 // resulting pointer type is an ObjCObjectPointerType, not a
5617 // PointerType.
5618 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5619
5621 NewT.setStarLoc(TL.getStarLoc());
5622 return Result;
5623 }
5624
5625 if (getDerived().AlwaysRebuild() ||
5626 PointeeType != TL.getPointeeLoc().getType()) {
5627 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5628 if (Result.isNull())
5629 return QualType();
5630 }
5631
5632 // Objective-C ARC can add lifetime qualifiers to the type that we're
5633 // pointing to.
5634 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5635
5636 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5637 NewT.setSigilLoc(TL.getSigilLoc());
5638 return Result;
5639}
5640
5641template<typename Derived>
5645 QualType PointeeType
5646 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5647 if (PointeeType.isNull())
5648 return QualType();
5649
5650 QualType Result = TL.getType();
5651 if (getDerived().AlwaysRebuild() ||
5652 PointeeType != TL.getPointeeLoc().getType()) {
5653 Result = getDerived().RebuildBlockPointerType(PointeeType,
5654 TL.getSigilLoc());
5655 if (Result.isNull())
5656 return QualType();
5657 }
5658
5660 NewT.setSigilLoc(TL.getSigilLoc());
5661 return Result;
5662}
5663
5664/// Transforms a reference type. Note that somewhat paradoxically we
5665/// don't care whether the type itself is an l-value type or an r-value
5666/// type; we only care if the type was *written* as an l-value type
5667/// or an r-value type.
5668template<typename Derived>
5671 ReferenceTypeLoc TL) {
5672 const ReferenceType *T = TL.getTypePtr();
5673
5674 // Note that this works with the pointee-as-written.
5675 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5676 if (PointeeType.isNull())
5677 return QualType();
5678
5679 QualType Result = TL.getType();
5680 if (getDerived().AlwaysRebuild() ||
5681 PointeeType != T->getPointeeTypeAsWritten()) {
5682 Result = getDerived().RebuildReferenceType(PointeeType,
5683 T->isSpelledAsLValue(),
5684 TL.getSigilLoc());
5685 if (Result.isNull())
5686 return QualType();
5687 }
5688
5689 // Objective-C ARC can add lifetime qualifiers to the type that we're
5690 // referring to.
5693
5694 // r-value references can be rebuilt as l-value references.
5695 ReferenceTypeLoc NewTL;
5697 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5698 else
5699 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5700 NewTL.setSigilLoc(TL.getSigilLoc());
5701
5702 return Result;
5703}
5704
5705template<typename Derived>
5709 return TransformReferenceType(TLB, TL);
5710}
5711
5712template<typename Derived>
5713QualType
5714TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5715 RValueReferenceTypeLoc TL) {
5716 return TransformReferenceType(TLB, TL);
5717}
5718
5719template<typename Derived>
5723 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5724 if (PointeeType.isNull())
5725 return QualType();
5726
5727 const MemberPointerType *T = TL.getTypePtr();
5728
5729 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5730 NestedNameSpecifierLoc NewQualifierLoc =
5731 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5732 if (!NewQualifierLoc)
5733 return QualType();
5734
5735 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5736 if (OldCls) {
5737 NewCls = cast_or_null<CXXRecordDecl>(
5738 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5739 if (!NewCls)
5740 return QualType();
5741 }
5742
5743 QualType Result = TL.getType();
5744 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5745 NewQualifierLoc.getNestedNameSpecifier() !=
5746 OldQualifierLoc.getNestedNameSpecifier() ||
5747 NewCls != OldCls) {
5748 CXXScopeSpec SS;
5749 SS.Adopt(NewQualifierLoc);
5750 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5751 TL.getStarLoc());
5752 if (Result.isNull())
5753 return QualType();
5754 }
5755
5756 // If we had to adjust the pointee type when building a member pointer, make
5757 // sure to push TypeLoc info for it.
5758 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5759 if (MPT && PointeeType != MPT->getPointeeType()) {
5760 assert(isa<AdjustedType>(MPT->getPointeeType()));
5761 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5762 }
5763
5765 NewTL.setSigilLoc(TL.getSigilLoc());
5766 NewTL.setQualifierLoc(NewQualifierLoc);
5767
5768 return Result;
5769}
5770
5771template<typename Derived>
5775 const ConstantArrayType *T = TL.getTypePtr();
5776 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5777 if (ElementType.isNull())
5778 return QualType();
5779
5780 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5781 Expr *OldSize = TL.getSizeExpr();
5782 if (!OldSize)
5783 OldSize = const_cast<Expr*>(T->getSizeExpr());
5784 Expr *NewSize = nullptr;
5785 if (OldSize) {
5788 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5789 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5790 }
5791
5792 QualType Result = TL.getType();
5793 if (getDerived().AlwaysRebuild() ||
5794 ElementType != T->getElementType() ||
5795 (T->getSizeExpr() && NewSize != OldSize)) {
5796 Result = getDerived().RebuildConstantArrayType(ElementType,
5797 T->getSizeModifier(),
5798 T->getSize(), NewSize,
5799 T->getIndexTypeCVRQualifiers(),
5800 TL.getBracketsRange());
5801 if (Result.isNull())
5802 return QualType();
5803 }
5804
5805 // We might have either a ConstantArrayType or a VariableArrayType now:
5806 // a ConstantArrayType is allowed to have an element type which is a
5807 // VariableArrayType if the type is dependent. Fortunately, all array
5808 // types have the same location layout.
5809 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5810 NewTL.setLBracketLoc(TL.getLBracketLoc());
5811 NewTL.setRBracketLoc(TL.getRBracketLoc());
5812 NewTL.setSizeExpr(NewSize);
5813
5814 return Result;
5815}
5816
5817template<typename Derived>
5819 TypeLocBuilder &TLB,
5821 const IncompleteArrayType *T = TL.getTypePtr();
5822 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5823 if (ElementType.isNull())
5824 return QualType();
5825
5826 QualType Result = TL.getType();
5827 if (getDerived().AlwaysRebuild() ||
5828 ElementType != T->getElementType()) {
5829 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5830 T->getSizeModifier(),
5831 T->getIndexTypeCVRQualifiers(),
5832 TL.getBracketsRange());
5833 if (Result.isNull())
5834 return QualType();
5835 }
5836
5838 NewTL.setLBracketLoc(TL.getLBracketLoc());
5839 NewTL.setRBracketLoc(TL.getRBracketLoc());
5840 NewTL.setSizeExpr(nullptr);
5841
5842 return Result;
5843}
5844
5845template<typename Derived>
5849 const VariableArrayType *T = TL.getTypePtr();
5850 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5851 if (ElementType.isNull())
5852 return QualType();
5853
5854 ExprResult SizeResult;
5855 {
5858 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5859 }
5860 if (SizeResult.isInvalid())
5861 return QualType();
5862 SizeResult =
5863 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5864 if (SizeResult.isInvalid())
5865 return QualType();
5866
5867 Expr *Size = SizeResult.get();
5868
5869 QualType Result = TL.getType();
5870 if (getDerived().AlwaysRebuild() ||
5871 ElementType != T->getElementType() ||
5872 Size != T->getSizeExpr()) {
5873 Result = getDerived().RebuildVariableArrayType(ElementType,
5874 T->getSizeModifier(),
5875 Size,
5876 T->getIndexTypeCVRQualifiers(),
5877 TL.getBracketsRange());
5878 if (Result.isNull())
5879 return QualType();
5880 }
5881
5882 // We might have constant size array now, but fortunately it has the same
5883 // location layout.
5884 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5885 NewTL.setLBracketLoc(TL.getLBracketLoc());
5886 NewTL.setRBracketLoc(TL.getRBracketLoc());
5887 NewTL.setSizeExpr(Size);
5888
5889 return Result;
5890}
5891
5892template<typename Derived>
5896 const DependentSizedArrayType *T = TL.getTypePtr();
5897 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5898 if (ElementType.isNull())
5899 return QualType();
5900
5901 // Array bounds are constant expressions.
5904
5905 // If we have a VLA then it won't be a constant.
5906 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5907
5908 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5909 Expr *origSize = TL.getSizeExpr();
5910 if (!origSize) origSize = T->getSizeExpr();
5911
5912 ExprResult sizeResult
5913 = getDerived().TransformExpr(origSize);
5914 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5915 if (sizeResult.isInvalid())
5916 return QualType();
5917
5918 Expr *size = sizeResult.get();
5919
5920 QualType Result = TL.getType();
5921 if (getDerived().AlwaysRebuild() ||
5922 ElementType != T->getElementType() ||
5923 size != origSize) {
5924 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5925 T->getSizeModifier(),
5926 size,
5927 T->getIndexTypeCVRQualifiers(),
5928 TL.getBracketsRange());
5929 if (Result.isNull())
5930 return QualType();
5931 }
5932
5933 // We might have any sort of array type now, but fortunately they
5934 // all have the same location layout.
5935 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5936 NewTL.setLBracketLoc(TL.getLBracketLoc());
5937 NewTL.setRBracketLoc(TL.getRBracketLoc());
5938 NewTL.setSizeExpr(size);
5939
5940 return Result;
5941}
5942
5943template <typename Derived>
5946 const DependentVectorType *T = TL.getTypePtr();
5947 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5948 if (ElementType.isNull())
5949 return QualType();
5950
5953
5954 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5955 Size = SemaRef.ActOnConstantExpression(Size);
5956 if (Size.isInvalid())
5957 return QualType();
5958
5959 QualType Result = TL.getType();
5960 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5961 Size.get() != T->getSizeExpr()) {
5962 Result = getDerived().RebuildDependentVectorType(
5963 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5964 if (Result.isNull())
5965 return QualType();
5966 }
5967
5968 // Result might be dependent or not.
5971 TLB.push<DependentVectorTypeLoc>(Result);
5972 NewTL.setNameLoc(TL.getNameLoc());
5973 } else {
5974 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5975 NewTL.setNameLoc(TL.getNameLoc());
5976 }
5977
5978 return Result;
5979}
5980
5981template<typename Derived>
5983 TypeLocBuilder &TLB,
5985 const DependentSizedExtVectorType *T = TL.getTypePtr();
5986
5987 // FIXME: ext vector locs should be nested
5988 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5989 if (ElementType.isNull())
5990 return QualType();
5991
5992 // Vector sizes are constant expressions.
5995
5996 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5997 Size = SemaRef.ActOnConstantExpression(Size);
5998 if (Size.isInvalid())
5999 return QualType();
6000
6001 QualType Result = TL.getType();
6002 if (getDerived().AlwaysRebuild() ||
6003 ElementType != T->getElementType() ||
6004 Size.get() != T->getSizeExpr()) {
6005 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6006 Size.get(),
6007 T->getAttributeLoc());
6008 if (Result.isNull())
6009 return QualType();
6010 }
6011
6012 // Result might be dependent or not.
6016 NewTL.setNameLoc(TL.getNameLoc());
6017 } else {
6018 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6019 NewTL.setNameLoc(TL.getNameLoc());
6020 }
6021
6022 return Result;
6023}
6024
6025template <typename Derived>
6029 const ConstantMatrixType *T = TL.getTypePtr();
6030 QualType ElementType = getDerived().TransformType(T->getElementType());
6031 if (ElementType.isNull())
6032 return QualType();
6033
6034 QualType Result = TL.getType();
6035 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6036 Result = getDerived().RebuildConstantMatrixType(
6037 ElementType, T->getNumRows(), T->getNumColumns());
6038 if (Result.isNull())
6039 return QualType();
6040 }
6041
6043 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6044 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6045 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6046 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6047
6048 return Result;
6049}
6050
6051template <typename Derived>
6054 const DependentSizedMatrixType *T = TL.getTypePtr();
6055
6056 QualType ElementType = getDerived().TransformType(T->getElementType());
6057 if (ElementType.isNull()) {
6058 return QualType();
6059 }
6060
6061 // Matrix dimensions are constant expressions.
6064
6065 Expr *origRows = TL.getAttrRowOperand();
6066 if (!origRows)
6067 origRows = T->getRowExpr();
6068 Expr *origColumns = TL.getAttrColumnOperand();
6069 if (!origColumns)
6070 origColumns = T->getColumnExpr();
6071
6072 ExprResult rowResult = getDerived().TransformExpr(origRows);
6073 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6074 if (rowResult.isInvalid())
6075 return QualType();
6076
6077 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6078 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6079 if (columnResult.isInvalid())
6080 return QualType();
6081
6082 Expr *rows = rowResult.get();
6083 Expr *columns = columnResult.get();
6084
6085 QualType Result = TL.getType();
6086 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6087 rows != origRows || columns != origColumns) {
6088 Result = getDerived().RebuildDependentSizedMatrixType(
6089 ElementType, rows, columns, T->getAttributeLoc());
6090
6091 if (Result.isNull())
6092 return QualType();
6093 }
6094
6095 // We might have any sort of matrix type now, but fortunately they
6096 // all have the same location layout.
6097 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6098 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6099 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6100 NewTL.setAttrRowOperand(rows);
6101 NewTL.setAttrColumnOperand(columns);
6102 return Result;
6103}
6104
6105template <typename Derived>
6108 const DependentAddressSpaceType *T = TL.getTypePtr();
6109
6110 QualType pointeeType =
6111 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6112
6113 if (pointeeType.isNull())
6114 return QualType();
6115
6116 // Address spaces are constant expressions.
6119
6120 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6121 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6122 if (AddrSpace.isInvalid())
6123 return QualType();
6124
6125 QualType Result = TL.getType();
6126 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6127 AddrSpace.get() != T->getAddrSpaceExpr()) {
6128 Result = getDerived().RebuildDependentAddressSpaceType(
6129 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6130 if (Result.isNull())
6131 return QualType();
6132 }
6133
6134 // Result might be dependent or not.
6138
6139 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6140 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6141 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6142
6143 } else {
6144 TLB.TypeWasModifiedSafely(Result);
6145 }
6146
6147 return Result;
6148}
6149
6150template <typename Derived>
6152 VectorTypeLoc TL) {
6153 const VectorType *T = TL.getTypePtr();
6154 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6155 if (ElementType.isNull())
6156 return QualType();
6157
6158 QualType Result = TL.getType();
6159 if (getDerived().AlwaysRebuild() ||
6160 ElementType != T->getElementType()) {
6161 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6162 T->getVectorKind());
6163 if (Result.isNull())
6164 return QualType();
6165 }
6166
6167 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6168 NewTL.setNameLoc(TL.getNameLoc());
6169
6170 return Result;
6171}
6172
6173template<typename Derived>
6175 ExtVectorTypeLoc TL) {
6176 const VectorType *T = TL.getTypePtr();
6177 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6178 if (ElementType.isNull())
6179 return QualType();
6180
6181 QualType Result = TL.getType();
6182 if (getDerived().AlwaysRebuild() ||
6183 ElementType != T->getElementType()) {
6184 Result = getDerived().RebuildExtVectorType(ElementType,
6185 T->getNumElements(),
6186 /*FIXME*/ SourceLocation());
6187 if (Result.isNull())
6188 return QualType();
6189 }
6190
6191 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6192 NewTL.setNameLoc(TL.getNameLoc());
6193
6194 return Result;
6195}
6196
6197template <typename Derived>
6199 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6200 bool ExpectParameterPack) {
6201 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6202 TypeSourceInfo *NewDI = nullptr;
6203
6204 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6205 // If we're substituting into a pack expansion type and we know the
6206 // length we want to expand to, just substitute for the pattern.
6207 TypeLoc OldTL = OldDI->getTypeLoc();
6208 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6209
6210 TypeLocBuilder TLB;
6211 TypeLoc NewTL = OldDI->getTypeLoc();
6212 TLB.reserve(NewTL.getFullDataSize());
6213
6214 QualType Result = getDerived().TransformType(TLB,
6215 OldExpansionTL.getPatternLoc());
6216 if (Result.isNull())
6217 return nullptr;
6218
6220 OldExpansionTL.getPatternLoc().getSourceRange(),
6221 OldExpansionTL.getEllipsisLoc(),
6222 NumExpansions);
6223 if (Result.isNull())
6224 return nullptr;
6225
6226 PackExpansionTypeLoc NewExpansionTL
6227 = TLB.push<PackExpansionTypeLoc>(Result);
6228 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6229 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6230 } else
6231 NewDI = getDerived().TransformType(OldDI);
6232 if (!NewDI)
6233 return nullptr;
6234
6235 if (NewDI == OldDI && indexAdjustment == 0)
6236 return OldParm;
6237
6238 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6239 OldParm->getDeclContext(),
6240 OldParm->getInnerLocStart(),
6241 OldParm->getLocation(),
6242 OldParm->getIdentifier(),
6243 NewDI->getType(),
6244 NewDI,
6245 OldParm->getStorageClass(),
6246 /* DefArg */ nullptr);
6247 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6248 OldParm->getFunctionScopeIndex() + indexAdjustment);
6249 getDerived().transformedLocalDecl(OldParm, {newParm});
6250 return newParm;
6251}
6252
6253template <typename Derived>
6256 const QualType *ParamTypes,
6257 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6258 SmallVectorImpl<QualType> &OutParamTypes,
6261 unsigned *LastParamTransformed) {
6262 int indexAdjustment = 0;
6263
6264 unsigned NumParams = Params.size();
6265 for (unsigned i = 0; i != NumParams; ++i) {
6266 if (LastParamTransformed)
6267 *LastParamTransformed = i;
6268 if (ParmVarDecl *OldParm = Params[i]) {
6269 assert(OldParm->getFunctionScopeIndex() == i);
6270
6271 UnsignedOrNone NumExpansions = std::nullopt;
6272 ParmVarDecl *NewParm = nullptr;
6273 if (OldParm->isParameterPack()) {
6274 // We have a function parameter pack that may need to be expanded.
6276
6277 // Find the parameter packs that could be expanded.
6278 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6280 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6281 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6282
6283 // Determine whether we should expand the parameter packs.
6284 bool ShouldExpand = false;
6285 bool RetainExpansion = false;
6286 UnsignedOrNone OrigNumExpansions = std::nullopt;
6287 if (Unexpanded.size() > 0) {
6288 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6289 NumExpansions = OrigNumExpansions;
6291 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6292 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6293 ShouldExpand, RetainExpansion, NumExpansions)) {
6294 return true;
6295 }
6296 } else {
6297#ifndef NDEBUG
6298 const AutoType *AT =
6299 Pattern.getType().getTypePtr()->getContainedAutoType();
6300 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6301 "Could not find parameter packs or undeduced auto type!");
6302#endif
6303 }
6304
6305 if (ShouldExpand) {
6306 // Expand the function parameter pack into multiple, separate
6307 // parameters.
6308 getDerived().ExpandingFunctionParameterPack(OldParm);
6309 for (unsigned I = 0; I != *NumExpansions; ++I) {
6310 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6311 ParmVarDecl *NewParm
6312 = getDerived().TransformFunctionTypeParam(OldParm,
6313 indexAdjustment++,
6314 OrigNumExpansions,
6315 /*ExpectParameterPack=*/false);
6316 if (!NewParm)
6317 return true;
6318
6319 if (ParamInfos)
6320 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6321 OutParamTypes.push_back(NewParm->getType());
6322 if (PVars)
6323 PVars->push_back(NewParm);
6324 }
6325
6326 // If we're supposed to retain a pack expansion, do so by temporarily
6327 // forgetting the partially-substituted parameter pack.
6328 if (RetainExpansion) {
6329 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6330 ParmVarDecl *NewParm
6331 = getDerived().TransformFunctionTypeParam(OldParm,
6332 indexAdjustment++,
6333 OrigNumExpansions,
6334 /*ExpectParameterPack=*/false);
6335 if (!NewParm)
6336 return true;
6337
6338 if (ParamInfos)
6339 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6340 OutParamTypes.push_back(NewParm->getType());
6341 if (PVars)
6342 PVars->push_back(NewParm);
6343 }
6344
6345 // The next parameter should have the same adjustment as the
6346 // last thing we pushed, but we post-incremented indexAdjustment
6347 // on every push. Also, if we push nothing, the adjustment should
6348 // go down by one.
6349 indexAdjustment--;
6350
6351 // We're done with the pack expansion.
6352 continue;
6353 }
6354
6355 // We'll substitute the parameter now without expanding the pack
6356 // expansion.
6357 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6358 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6359 indexAdjustment,
6360 NumExpansions,
6361 /*ExpectParameterPack=*/true);
6362 assert(NewParm->isParameterPack() &&
6363 "Parameter pack no longer a parameter pack after "
6364 "transformation.");
6365 } else {
6366 NewParm = getDerived().TransformFunctionTypeParam(
6367 OldParm, indexAdjustment, std::nullopt,
6368 /*ExpectParameterPack=*/false);
6369 }
6370
6371 if (!NewParm)
6372 return true;
6373
6374 if (ParamInfos)
6375 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6376 OutParamTypes.push_back(NewParm->getType());
6377 if (PVars)
6378 PVars->push_back(NewParm);
6379 continue;
6380 }
6381
6382 // Deal with the possibility that we don't have a parameter
6383 // declaration for this parameter.
6384 assert(ParamTypes);
6385 QualType OldType = ParamTypes[i];
6386 bool IsPackExpansion = false;
6387 UnsignedOrNone NumExpansions = std::nullopt;
6388 QualType NewType;
6389 if (const PackExpansionType *Expansion
6390 = dyn_cast<PackExpansionType>(OldType)) {
6391 // We have a function parameter pack that may need to be expanded.
6392 QualType Pattern = Expansion->getPattern();
6394 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6395
6396 // Determine whether we should expand the parameter packs.
6397 bool ShouldExpand = false;
6398 bool RetainExpansion = false;
6400 Loc, SourceRange(), Unexpanded,
6401 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6402 RetainExpansion, NumExpansions)) {
6403 return true;
6404 }
6405
6406 if (ShouldExpand) {
6407 // Expand the function parameter pack into multiple, separate
6408 // parameters.
6409 for (unsigned I = 0; I != *NumExpansions; ++I) {
6410 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6411 QualType NewType = getDerived().TransformType(Pattern);
6412 if (NewType.isNull())
6413 return true;
6414
6415 if (NewType->containsUnexpandedParameterPack()) {
6416 NewType = getSema().getASTContext().getPackExpansionType(
6417 NewType, std::nullopt);
6418
6419 if (NewType.isNull())
6420 return true;
6421 }
6422
6423 if (ParamInfos)
6424 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6425 OutParamTypes.push_back(NewType);
6426 if (PVars)
6427 PVars->push_back(nullptr);
6428 }
6429
6430 // We're done with the pack expansion.
6431 continue;
6432 }
6433
6434 // If we're supposed to retain a pack expansion, do so by temporarily
6435 // forgetting the partially-substituted parameter pack.
6436 if (RetainExpansion) {
6437 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6438 QualType NewType = getDerived().TransformType(Pattern);
6439 if (NewType.isNull())
6440 return true;
6441
6442 if (ParamInfos)
6443 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6444 OutParamTypes.push_back(NewType);
6445 if (PVars)
6446 PVars->push_back(nullptr);
6447 }
6448
6449 // We'll substitute the parameter now without expanding the pack
6450 // expansion.
6451 OldType = Expansion->getPattern();
6452 IsPackExpansion = true;
6453 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6454 NewType = getDerived().TransformType(OldType);
6455 } else {
6456 NewType = getDerived().TransformType(OldType);
6457 }
6458
6459 if (NewType.isNull())
6460 return true;
6461
6462 if (IsPackExpansion)
6463 NewType = getSema().Context.getPackExpansionType(NewType,
6464 NumExpansions);
6465
6466 if (ParamInfos)
6467 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6468 OutParamTypes.push_back(NewType);
6469 if (PVars)
6470 PVars->push_back(nullptr);
6471 }
6472
6473#ifndef NDEBUG
6474 if (PVars) {
6475 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6476 if (ParmVarDecl *parm = (*PVars)[i])
6477 assert(parm->getFunctionScopeIndex() == i);
6478 }
6479#endif
6480
6481 return false;
6482}
6483
6484template<typename Derived>
6488 SmallVector<QualType, 4> ExceptionStorage;
6489 return getDerived().TransformFunctionProtoType(
6490 TLB, TL, nullptr, Qualifiers(),
6491 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6492 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6493 ExceptionStorage, Changed);
6494 });
6495}
6496
6497template<typename Derived> template<typename Fn>
6499 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6500 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6501
6502 // Transform the parameters and return type.
6503 //
6504 // We are required to instantiate the params and return type in source order.
6505 // When the function has a trailing return type, we instantiate the
6506 // parameters before the return type, since the return type can then refer
6507 // to the parameters themselves (via decltype, sizeof, etc.).
6508 //
6509 SmallVector<QualType, 4> ParamTypes;
6511 Sema::ExtParameterInfoBuilder ExtParamInfos;
6512 const FunctionProtoType *T = TL.getTypePtr();
6513
6514 QualType ResultType;
6515
6516 if (T->hasTrailingReturn()) {
6518 TL.getBeginLoc(), TL.getParams(),
6520 T->getExtParameterInfosOrNull(),
6521 ParamTypes, &ParamDecls, ExtParamInfos))
6522 return QualType();
6523
6524 {
6525 // C++11 [expr.prim.general]p3:
6526 // If a declaration declares a member function or member function
6527 // template of a class X, the expression this is a prvalue of type
6528 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6529 // and the end of the function-definition, member-declarator, or
6530 // declarator.
6531 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6532 Sema::CXXThisScopeRAII ThisScope(
6533 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6534
6535 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6536 if (ResultType.isNull())
6537 return QualType();
6538 }
6539 }
6540 else {
6541 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6542 if (ResultType.isNull())
6543 return QualType();
6544
6546 TL.getBeginLoc(), TL.getParams(),
6548 T->getExtParameterInfosOrNull(),
6549 ParamTypes, &ParamDecls, ExtParamInfos))
6550 return QualType();
6551 }
6552
6553 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6554
6555 bool EPIChanged = false;
6556 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6557 return QualType();
6558
6559 // Handle extended parameter information.
6560 if (auto NewExtParamInfos =
6561 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6562 if (!EPI.ExtParameterInfos ||
6564 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6565 EPIChanged = true;
6566 }
6567 EPI.ExtParameterInfos = NewExtParamInfos;
6568 } else if (EPI.ExtParameterInfos) {
6569 EPIChanged = true;
6570 EPI.ExtParameterInfos = nullptr;
6571 }
6572
6573 // Transform any function effects with unevaluated conditions.
6574 // Hold this set in a local for the rest of this function, since EPI
6575 // may need to hold a FunctionEffectsRef pointing into it.
6576 std::optional<FunctionEffectSet> NewFX;
6577 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6578 NewFX.emplace();
6581
6582 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6583 FunctionEffectWithCondition NewEC = PrevEC;
6584 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6585 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6586 if (NewExpr.isInvalid())
6587 return QualType();
6588 std::optional<FunctionEffectMode> Mode =
6589 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6590 if (!Mode)
6591 return QualType();
6592
6593 // The condition expression has been transformed, and re-evaluated.
6594 // It may or may not have become constant.
6595 switch (*Mode) {
6597 NewEC.Cond = {};
6598 break;
6600 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6601 NewEC.Cond = {};
6602 break;
6604 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6605 break;
6607 llvm_unreachable(
6608 "FunctionEffectMode::None shouldn't be possible here");
6609 }
6610 }
6611 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6612 TL.getBeginLoc())) {
6614 NewFX->insert(NewEC, Errs);
6615 assert(Errs.empty());
6616 }
6617 }
6618 EPI.FunctionEffects = *NewFX;
6619 EPIChanged = true;
6620 }
6621
6622 QualType Result = TL.getType();
6623 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6624 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6625 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6626 if (Result.isNull())
6627 return QualType();
6628 }
6629
6632 NewTL.setLParenLoc(TL.getLParenLoc());
6633 NewTL.setRParenLoc(TL.getRParenLoc());
6636 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6637 NewTL.setParam(i, ParamDecls[i]);
6638
6639 return Result;
6640}
6641
6642template<typename Derived>
6645 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6646 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6647
6648 // Instantiate a dynamic noexcept expression, if any.
6649 if (isComputedNoexcept(ESI.Type)) {
6650 // Update this scrope because ContextDecl in Sema will be used in
6651 // TransformExpr.
6652 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6653 Sema::CXXThisScopeRAII ThisScope(
6654 SemaRef, Method ? Method->getParent() : nullptr,
6655 Method ? Method->getMethodQualifiers() : Qualifiers{},
6656 Method != nullptr);
6659 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6660 if (NoexceptExpr.isInvalid())
6661 return true;
6662
6664 NoexceptExpr =
6665 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6666 if (NoexceptExpr.isInvalid())
6667 return true;
6668
6669 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6670 Changed = true;
6671 ESI.NoexceptExpr = NoexceptExpr.get();
6672 ESI.Type = EST;
6673 }
6674
6675 if (ESI.Type != EST_Dynamic)
6676 return false;
6677
6678 // Instantiate a dynamic exception specification's type.
6679 for (QualType T : ESI.Exceptions) {
6680 if (const PackExpansionType *PackExpansion =
6681 T->getAs<PackExpansionType>()) {
6682 Changed = true;
6683
6684 // We have a pack expansion. Instantiate it.
6686 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6687 Unexpanded);
6688 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6689
6690 // Determine whether the set of unexpanded parameter packs can and
6691 // should
6692 // be expanded.
6693 bool Expand = false;
6694 bool RetainExpansion = false;
6695 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6696 // FIXME: Track the location of the ellipsis (and track source location
6697 // information for the types in the exception specification in general).
6699 Loc, SourceRange(), Unexpanded,
6700 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6701 NumExpansions))
6702 return true;
6703
6704 if (!Expand) {
6705 // We can't expand this pack expansion into separate arguments yet;
6706 // just substitute into the pattern and create a new pack expansion
6707 // type.
6708 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6709 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6710 if (U.isNull())
6711 return true;
6712
6713 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6714 Exceptions.push_back(U);
6715 continue;
6716 }
6717
6718 // Substitute into the pack expansion pattern for each slice of the
6719 // pack.
6720 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6721 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6722
6723 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6724 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6725 return true;
6726
6727 Exceptions.push_back(U);
6728 }
6729 } else {
6730 QualType U = getDerived().TransformType(T);
6731 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6732 return true;
6733 if (T != U)
6734 Changed = true;
6735
6736 Exceptions.push_back(U);
6737 }
6738 }
6739
6740 ESI.Exceptions = Exceptions;
6741 if (ESI.Exceptions.empty())
6742 ESI.Type = EST_DynamicNone;
6743 return false;
6744}
6745
6746template<typename Derived>
6748 TypeLocBuilder &TLB,
6750 const FunctionNoProtoType *T = TL.getTypePtr();
6751 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6752 if (ResultType.isNull())
6753 return QualType();
6754
6755 QualType Result = TL.getType();
6756 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6757 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6758
6761 NewTL.setLParenLoc(TL.getLParenLoc());
6762 NewTL.setRParenLoc(TL.getRParenLoc());
6764
6765 return Result;
6766}
6767
6768template <typename Derived>
6769QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6770 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6771
6772 const UnresolvedUsingType *T = TL.getTypePtr();
6773 bool Changed = false;
6774
6775 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6776 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6777 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6778 if (!QualifierLoc)
6779 return QualType();
6780 Changed |= QualifierLoc != OldQualifierLoc;
6781 }
6782
6783 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6784 if (!D)
6785 return QualType();
6786 Changed |= D != T->getDecl();
6787
6788 QualType Result = TL.getType();
6789 if (getDerived().AlwaysRebuild() || Changed) {
6790 Result = getDerived().RebuildUnresolvedUsingType(
6791 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6792 D);
6793 if (Result.isNull())
6794 return QualType();
6795 }
6796
6798 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6799 QualifierLoc, TL.getNameLoc());
6800 else
6801 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6802 QualifierLoc, TL.getNameLoc());
6803 return Result;
6804}
6805
6806template <typename Derived>
6808 UsingTypeLoc TL) {
6809 const UsingType *T = TL.getTypePtr();
6810 bool Changed = false;
6811
6812 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6813 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6814 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6815 if (!QualifierLoc)
6816 return QualType();
6817 Changed |= QualifierLoc != OldQualifierLoc;
6818 }
6819
6820 auto *D = cast_or_null<UsingShadowDecl>(
6821 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6822 if (!D)
6823 return QualType();
6824 Changed |= D != T->getDecl();
6825
6826 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6827 if (UnderlyingType.isNull())
6828 return QualType();
6829 Changed |= UnderlyingType != T->desugar();
6830
6831 QualType Result = TL.getType();
6832 if (getDerived().AlwaysRebuild() || Changed) {
6833 Result = getDerived().RebuildUsingType(
6834 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6835 UnderlyingType);
6836 if (Result.isNull())
6837 return QualType();
6838 }
6839 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6840 TL.getNameLoc());
6841 return Result;
6842}
6843
6844template<typename Derived>
6846 TypedefTypeLoc TL) {
6847 const TypedefType *T = TL.getTypePtr();
6848 bool Changed = false;
6849
6850 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6851 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6852 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6853 if (!QualifierLoc)
6854 return QualType();
6855 Changed |= QualifierLoc != OldQualifierLoc;
6856 }
6857
6858 auto *Typedef = cast_or_null<TypedefNameDecl>(
6859 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6860 if (!Typedef)
6861 return QualType();
6862 Changed |= Typedef != T->getDecl();
6863
6864 // FIXME: Transform the UnderlyingType if different from decl.
6865
6866 QualType Result = TL.getType();
6867 if (getDerived().AlwaysRebuild() || Changed) {
6868 Result = getDerived().RebuildTypedefType(
6869 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6870 if (Result.isNull())
6871 return QualType();
6872 }
6873
6874 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6875 QualifierLoc, TL.getNameLoc());
6876 return Result;
6877}
6878
6879template<typename Derived>
6881 TypeOfExprTypeLoc TL) {
6882 // typeof expressions are not potentially evaluated contexts
6886
6887 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6888 if (E.isInvalid())
6889 return QualType();
6890
6891 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6892 if (E.isInvalid())
6893 return QualType();
6894
6895 QualType Result = TL.getType();
6897 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6898 Result =
6899 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6900 if (Result.isNull())
6901 return QualType();
6902 }
6903
6904 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6905 NewTL.setTypeofLoc(TL.getTypeofLoc());
6906 NewTL.setLParenLoc(TL.getLParenLoc());
6907 NewTL.setRParenLoc(TL.getRParenLoc());
6908
6909 return Result;
6910}
6911
6912template<typename Derived>
6914 TypeOfTypeLoc TL) {
6915 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6916 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6917 if (!New_Under_TI)
6918 return QualType();
6919
6920 QualType Result = TL.getType();
6921 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6922 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6923 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6924 if (Result.isNull())
6925 return QualType();
6926 }
6927
6928 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6929 NewTL.setTypeofLoc(TL.getTypeofLoc());
6930 NewTL.setLParenLoc(TL.getLParenLoc());
6931 NewTL.setRParenLoc(TL.getRParenLoc());
6932 NewTL.setUnmodifiedTInfo(New_Under_TI);
6933
6934 return Result;
6935}
6936
6937template<typename Derived>
6939 DecltypeTypeLoc TL) {
6940 const DecltypeType *T = TL.getTypePtr();
6941
6942 // decltype expressions are not potentially evaluated contexts
6946
6947 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6948 if (E.isInvalid())
6949 return QualType();
6950
6951 E = getSema().ActOnDecltypeExpression(E.get());
6952 if (E.isInvalid())
6953 return QualType();
6954
6955 QualType Result = TL.getType();
6956 if (getDerived().AlwaysRebuild() ||
6957 E.get() != T->getUnderlyingExpr()) {
6958 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6959 if (Result.isNull())
6960 return QualType();
6961 }
6962 else E.get();
6963
6964 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6965 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6966 NewTL.setRParenLoc(TL.getRParenLoc());
6967 return Result;
6968}
6969
6970template <typename Derived>
6974 // Transform the index
6975 ExprResult IndexExpr;
6976 {
6977 EnterExpressionEvaluationContext ConstantContext(
6979
6980 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6981 if (IndexExpr.isInvalid())
6982 return QualType();
6983 }
6984 QualType Pattern = TL.getPattern();
6985
6986 const PackIndexingType *PIT = TL.getTypePtr();
6987 SmallVector<QualType, 5> SubtitutedTypes;
6988 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6989
6990 bool NotYetExpanded = Types.empty();
6991 bool FullySubstituted = true;
6992
6993 if (Types.empty() && !PIT->expandsToEmptyPack())
6994 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6995
6996 for (QualType T : Types) {
6997 if (!T->containsUnexpandedParameterPack()) {
6998 QualType Transformed = getDerived().TransformType(T);
6999 if (Transformed.isNull())
7000 return QualType();
7001 SubtitutedTypes.push_back(Transformed);
7002 continue;
7003 }
7004
7006 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7007 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7008 // Determine whether the set of unexpanded parameter packs can and should
7009 // be expanded.
7010 bool ShouldExpand = true;
7011 bool RetainExpansion = false;
7012 UnsignedOrNone NumExpansions = std::nullopt;
7013 if (getDerived().TryExpandParameterPacks(
7014 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7015 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7016 RetainExpansion, NumExpansions))
7017 return QualType();
7018 if (!ShouldExpand) {
7019 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7020 // FIXME: should we keep TypeLoc for individual expansions in
7021 // PackIndexingTypeLoc?
7022 TypeSourceInfo *TI =
7023 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7024 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7025 if (Pack.isNull())
7026 return QualType();
7027 if (NotYetExpanded) {
7028 FullySubstituted = false;
7029 QualType Out = getDerived().RebuildPackIndexingType(
7030 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7031 FullySubstituted);
7032 if (Out.isNull())
7033 return QualType();
7034
7036 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7037 return Out;
7038 }
7039 SubtitutedTypes.push_back(Pack);
7040 continue;
7041 }
7042 for (unsigned I = 0; I != *NumExpansions; ++I) {
7043 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7044 QualType Out = getDerived().TransformType(T);
7045 if (Out.isNull())
7046 return QualType();
7047 SubtitutedTypes.push_back(Out);
7048 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7049 }
7050 // If we're supposed to retain a pack expansion, do so by temporarily
7051 // forgetting the partially-substituted parameter pack.
7052 if (RetainExpansion) {
7053 FullySubstituted = false;
7054 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7055 QualType Out = getDerived().TransformType(T);
7056 if (Out.isNull())
7057 return QualType();
7058 SubtitutedTypes.push_back(Out);
7059 }
7060 }
7061
7062 // A pack indexing type can appear in a larger pack expansion,
7063 // e.g. `Pack...[pack_of_indexes]...`
7064 // so we need to temporarily disable substitution of pack elements
7065 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7066 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7067
7068 QualType Out = getDerived().RebuildPackIndexingType(
7069 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7070 FullySubstituted, SubtitutedTypes);
7071 if (Out.isNull())
7072 return Out;
7073
7075 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7076 return Out;
7077}
7078
7079template<typename Derived>
7081 TypeLocBuilder &TLB,
7083 QualType Result = TL.getType();
7084 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7085 if (Result->isDependentType()) {
7086 const UnaryTransformType *T = TL.getTypePtr();
7087
7088 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7089 if (!NewBaseTSI)
7090 return QualType();
7091 QualType NewBase = NewBaseTSI->getType();
7092
7093 Result = getDerived().RebuildUnaryTransformType(NewBase,
7094 T->getUTTKind(),
7095 TL.getKWLoc());
7096 if (Result.isNull())
7097 return QualType();
7098 }
7099
7101 NewTL.setKWLoc(TL.getKWLoc());
7102 NewTL.setParensRange(TL.getParensRange());
7103 NewTL.setUnderlyingTInfo(NewBaseTSI);
7104 return Result;
7105}
7106
7107template<typename Derived>
7110 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7111
7112 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7113 TemplateName TemplateName = getDerived().TransformTemplateName(
7114 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7115 TL.getTemplateNameLoc());
7116 if (TemplateName.isNull())
7117 return QualType();
7118
7119 QualType OldDeduced = T->getDeducedType();
7120 QualType NewDeduced;
7121 if (!OldDeduced.isNull()) {
7122 NewDeduced = getDerived().TransformType(OldDeduced);
7123 if (NewDeduced.isNull())
7124 return QualType();
7125 }
7126
7127 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7128 T->getKeyword(), TemplateName, NewDeduced);
7129 if (Result.isNull())
7130 return QualType();
7131
7132 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7133 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7134 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7135 NewTL.setQualifierLoc(QualifierLoc);
7136 return Result;
7137}
7138
7139template <typename Derived>
7141 TagTypeLoc TL) {
7142 const TagType *T = TL.getTypePtr();
7143
7144 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7145 if (QualifierLoc) {
7146 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7147 if (!QualifierLoc)
7148 return QualType();
7149 }
7150
7151 auto *TD = cast_or_null<TagDecl>(
7152 getDerived().TransformDecl(TL.getNameLoc(), T->getOriginalDecl()));
7153 if (!TD)
7154 return QualType();
7155
7156 QualType Result = TL.getType();
7157 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7158 TD != T->getOriginalDecl()) {
7159 if (T->isCanonicalUnqualified())
7160 Result = getDerived().RebuildCanonicalTagType(TD);
7161 else
7162 Result = getDerived().RebuildTagType(
7163 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7164 if (Result.isNull())
7165 return QualType();
7166 }
7167
7168 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7170 NewTL.setQualifierLoc(QualifierLoc);
7171 NewTL.setNameLoc(TL.getNameLoc());
7172
7173 return Result;
7174}
7175
7176template <typename Derived>
7178 EnumTypeLoc TL) {
7179 return getDerived().TransformTagType(TLB, TL);
7180}
7181
7182template <typename Derived>
7183QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7184 RecordTypeLoc TL) {
7185 return getDerived().TransformTagType(TLB, TL);
7186}
7187
7188template<typename Derived>
7190 TypeLocBuilder &TLB,
7192 return getDerived().TransformTagType(TLB, TL);
7193}
7194
7195template<typename Derived>
7197 TypeLocBuilder &TLB,
7199 return getDerived().TransformTemplateTypeParmType(
7200 TLB, TL,
7201 /*SuppressObjCLifetime=*/false);
7202}
7203
7204template <typename Derived>
7206 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7207 return TransformTypeSpecType(TLB, TL);
7208}
7209
7210template<typename Derived>
7211QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7212 TypeLocBuilder &TLB,
7213 SubstTemplateTypeParmTypeLoc TL) {
7214 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7215
7216 Decl *NewReplaced =
7217 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7218
7219 // Substitute into the replacement type, which itself might involve something
7220 // that needs to be transformed. This only tends to occur with default
7221 // template arguments of template template parameters.
7222 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7223 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7224 if (Replacement.isNull())
7225 return QualType();
7226
7227 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7228 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7229 T->getFinal());
7230
7231 // Propagate type-source information.
7232 SubstTemplateTypeParmTypeLoc NewTL
7233 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7234 NewTL.setNameLoc(TL.getNameLoc());
7235 return Result;
7236
7237}
7238template <typename Derived>
7241 return TransformTypeSpecType(TLB, TL);
7242}
7243
7244template<typename Derived>
7246 TypeLocBuilder &TLB,
7248 return getDerived().TransformSubstTemplateTypeParmPackType(
7249 TLB, TL, /*SuppressObjCLifetime=*/false);
7250}
7251
7252template <typename Derived>
7255 return TransformTypeSpecType(TLB, TL);
7256}
7257
7258template<typename Derived>
7259QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7260 AtomicTypeLoc TL) {
7261 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7262 if (ValueType.isNull())
7263 return QualType();
7264
7265 QualType Result = TL.getType();
7266 if (getDerived().AlwaysRebuild() ||
7267 ValueType != TL.getValueLoc().getType()) {
7268 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7269 if (Result.isNull())
7270 return QualType();
7271 }
7272
7273 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7274 NewTL.setKWLoc(TL.getKWLoc());
7275 NewTL.setLParenLoc(TL.getLParenLoc());
7276 NewTL.setRParenLoc(TL.getRParenLoc());
7277
7278 return Result;
7279}
7280
7281template <typename Derived>
7283 PipeTypeLoc TL) {
7284 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7285 if (ValueType.isNull())
7286 return QualType();
7287
7288 QualType Result = TL.getType();
7289 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7290 const PipeType *PT = Result->castAs<PipeType>();
7291 bool isReadPipe = PT->isReadOnly();
7292 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7293 if (Result.isNull())
7294 return QualType();
7295 }
7296
7297 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7298 NewTL.setKWLoc(TL.getKWLoc());
7299
7300 return Result;
7301}
7302
7303template <typename Derived>
7305 BitIntTypeLoc TL) {
7306 const BitIntType *EIT = TL.getTypePtr();
7307 QualType Result = TL.getType();
7308
7309 if (getDerived().AlwaysRebuild()) {
7310 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7311 EIT->getNumBits(), TL.getNameLoc());
7312 if (Result.isNull())
7313 return QualType();
7314 }
7315
7316 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7317 NewTL.setNameLoc(TL.getNameLoc());
7318 return Result;
7319}
7320
7321template <typename Derived>
7324 const DependentBitIntType *EIT = TL.getTypePtr();
7325
7328 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7329 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7330
7331 if (BitsExpr.isInvalid())
7332 return QualType();
7333
7334 QualType Result = TL.getType();
7335
7336 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7337 Result = getDerived().RebuildDependentBitIntType(
7338 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7339
7340 if (Result.isNull())
7341 return QualType();
7342 }
7343
7346 NewTL.setNameLoc(TL.getNameLoc());
7347 } else {
7348 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7349 NewTL.setNameLoc(TL.getNameLoc());
7350 }
7351 return Result;
7352}
7353
7354template <typename Derived>
7357 llvm_unreachable("This type does not need to be transformed.");
7358}
7359
7360 /// Simple iterator that traverses the template arguments in a
7361 /// container that provides a \c getArgLoc() member function.
7362 ///
7363 /// This iterator is intended to be used with the iterator form of
7364 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7365 template<typename ArgLocContainer>
7367 ArgLocContainer *Container;
7368 unsigned Index;
7369
7370 public:
7373 typedef int difference_type;
7374 typedef std::input_iterator_tag iterator_category;
7375
7376 class pointer {
7378
7379 public:
7380 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7381
7383 return &Arg;
7384 }
7385 };
7386
7387
7389
7390 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7391 unsigned Index)
7392 : Container(&Container), Index(Index) { }
7393
7395 ++Index;
7396 return *this;
7397 }
7398
7401 ++(*this);
7402 return Old;
7403 }
7404
7406 return Container->getArgLoc(Index);
7407 }
7408
7410 return pointer(Container->getArgLoc(Index));
7411 }
7412
7415 return X.Container == Y.Container && X.Index == Y.Index;
7416 }
7417
7420 return !(X == Y);
7421 }
7422 };
7423
7424template<typename Derived>
7425QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7426 AutoTypeLoc TL) {
7427 const AutoType *T = TL.getTypePtr();
7428 QualType OldDeduced = T->getDeducedType();
7429 QualType NewDeduced;
7430 if (!OldDeduced.isNull()) {
7431 NewDeduced = getDerived().TransformType(OldDeduced);
7432 if (NewDeduced.isNull())
7433 return QualType();
7434 }
7435
7436 ConceptDecl *NewCD = nullptr;
7437 TemplateArgumentListInfo NewTemplateArgs;
7438 NestedNameSpecifierLoc NewNestedNameSpec;
7439 if (T->isConstrained()) {
7440 assert(TL.getConceptReference());
7441 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7442 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7443
7444 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7445 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7447 if (getDerived().TransformTemplateArguments(
7448 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7449 NewTemplateArgs))
7450 return QualType();
7451
7452 if (TL.getNestedNameSpecifierLoc()) {
7453 NewNestedNameSpec
7454 = getDerived().TransformNestedNameSpecifierLoc(
7455 TL.getNestedNameSpecifierLoc());
7456 if (!NewNestedNameSpec)
7457 return QualType();
7458 }
7459 }
7460
7461 QualType Result = TL.getType();
7462 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7463 T->isDependentType() || T->isConstrained()) {
7464 // FIXME: Maybe don't rebuild if all template arguments are the same.
7466 NewArgList.reserve(NewTemplateArgs.size());
7467 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7468 NewArgList.push_back(ArgLoc.getArgument());
7469 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7470 NewArgList);
7471 if (Result.isNull())
7472 return QualType();
7473 }
7474
7475 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7476 NewTL.setNameLoc(TL.getNameLoc());
7477 NewTL.setRParenLoc(TL.getRParenLoc());
7478 NewTL.setConceptReference(nullptr);
7479
7480 if (T->isConstrained()) {
7482 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7483 TL.getConceptNameLoc(),
7484 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7485 auto *CR = ConceptReference::Create(
7486 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7487 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7488 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7489 NewTL.setConceptReference(CR);
7490 }
7491
7492 return Result;
7493}
7494
7495template <typename Derived>
7498 return getDerived().TransformTemplateSpecializationType(
7499 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7500 /*AllowInjectedClassName=*/false);
7501}
7502
7503template <typename Derived>
7506 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7507 const TemplateSpecializationType *T = TL.getTypePtr();
7508
7509 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7510 TemplateName Template = getDerived().TransformTemplateName(
7511 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7512 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7513 AllowInjectedClassName);
7514 if (Template.isNull())
7515 return QualType();
7516
7517 TemplateArgumentListInfo NewTemplateArgs;
7518 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7519 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7521 ArgIterator;
7522 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7523 ArgIterator(TL, TL.getNumArgs()),
7524 NewTemplateArgs))
7525 return QualType();
7526
7527 // This needs to be rebuilt if either the arguments changed, or if the
7528 // original template changed. If the template changed, and even if the
7529 // arguments didn't change, these arguments might not correspond to their
7530 // respective parameters, therefore needing conversions.
7531 QualType Result = getDerived().RebuildTemplateSpecializationType(
7532 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7533 NewTemplateArgs);
7534
7535 if (!Result.isNull()) {
7537 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7538 TL.getTemplateNameLoc(), NewTemplateArgs);
7539 }
7540
7541 return Result;
7542}
7543
7544template <typename Derived>
7546 AttributedTypeLoc TL) {
7547 const AttributedType *oldType = TL.getTypePtr();
7548 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7549 if (modifiedType.isNull())
7550 return QualType();
7551
7552 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7553 const Attr *oldAttr = TL.getAttr();
7554 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7555 if (oldAttr && !newAttr)
7556 return QualType();
7557
7558 QualType result = TL.getType();
7559
7560 // FIXME: dependent operand expressions?
7561 if (getDerived().AlwaysRebuild() ||
7562 modifiedType != oldType->getModifiedType()) {
7563 // If the equivalent type is equal to the modified type, we don't want to
7564 // transform it as well because:
7565 //
7566 // 1. The transformation would yield the same result and is therefore
7567 // superfluous, and
7568 //
7569 // 2. Transforming the same type twice can cause problems, e.g. if it
7570 // is a FunctionProtoType, we may end up instantiating the function
7571 // parameters twice, which causes an assertion since the parameters
7572 // are already bound to their counterparts in the template for this
7573 // instantiation.
7574 //
7575 QualType equivalentType = modifiedType;
7576 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7577 TypeLocBuilder AuxiliaryTLB;
7578 AuxiliaryTLB.reserve(TL.getFullDataSize());
7579 equivalentType =
7580 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7581 if (equivalentType.isNull())
7582 return QualType();
7583 }
7584
7585 // Check whether we can add nullability; it is only represented as
7586 // type sugar, and therefore cannot be diagnosed in any other way.
7587 if (auto nullability = oldType->getImmediateNullability()) {
7588 if (!modifiedType->canHaveNullability()) {
7589 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7590 : TL.getModifiedLoc().getBeginLoc()),
7591 diag::err_nullability_nonpointer)
7592 << DiagNullabilityKind(*nullability, false) << modifiedType;
7593 return QualType();
7594 }
7595 }
7596
7597 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7598 modifiedType,
7599 equivalentType,
7600 TL.getAttr());
7601 }
7602
7603 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7604 newTL.setAttr(newAttr);
7605 return result;
7606}
7607
7608template <typename Derived>
7611 const CountAttributedType *OldTy = TL.getTypePtr();
7612 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7613 if (InnerTy.isNull())
7614 return QualType();
7615
7616 Expr *OldCount = TL.getCountExpr();
7617 Expr *NewCount = nullptr;
7618 if (OldCount) {
7619 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7620 if (CountResult.isInvalid())
7621 return QualType();
7622 NewCount = CountResult.get();
7623 }
7624
7625 QualType Result = TL.getType();
7626 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7627 OldCount != NewCount) {
7628 // Currently, CountAttributedType can only wrap incomplete array types.
7630 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7631 }
7632
7633 TLB.push<CountAttributedTypeLoc>(Result);
7634 return Result;
7635}
7636
7637template <typename Derived>
7640 // The BTFTagAttributedType is available for C only.
7641 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7642}
7643
7644template <typename Derived>
7647
7648 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7649
7650 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7651 if (WrappedTy.isNull())
7652 return QualType();
7653
7654 QualType ContainedTy = QualType();
7655 QualType OldContainedTy = oldType->getContainedType();
7656 if (!OldContainedTy.isNull()) {
7657 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7658 if (!oldContainedTSI)
7659 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7660 OldContainedTy, SourceLocation());
7661 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7662 if (!ContainedTSI)
7663 return QualType();
7664 ContainedTy = ContainedTSI->getType();
7665 }
7666
7667 QualType Result = TL.getType();
7668 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7669 ContainedTy != oldType->getContainedType()) {
7671 WrappedTy, ContainedTy, oldType->getAttrs());
7672 }
7673
7675 return Result;
7676}
7677
7678template <typename Derived>
7681 // No transformations needed.
7682 return TL.getType();
7683}
7684
7685template<typename Derived>
7688 ParenTypeLoc TL) {
7689 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7690 if (Inner.isNull())
7691 return QualType();
7692
7693 QualType Result = TL.getType();
7694 if (getDerived().AlwaysRebuild() ||
7695 Inner != TL.getInnerLoc().getType()) {
7696 Result = getDerived().RebuildParenType(Inner);
7697 if (Result.isNull())
7698 return QualType();
7699 }
7700
7701 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7702 NewTL.setLParenLoc(TL.getLParenLoc());
7703 NewTL.setRParenLoc(TL.getRParenLoc());
7704 return Result;
7705}
7706
7707template <typename Derived>
7711 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7712 if (Inner.isNull())
7713 return QualType();
7714
7715 QualType Result = TL.getType();
7716 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7717 Result =
7718 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7719 if (Result.isNull())
7720 return QualType();
7721 }
7722
7724 NewTL.setExpansionLoc(TL.getExpansionLoc());
7725 return Result;
7726}
7727
7728template<typename Derived>
7729QualType TreeTransform<Derived>::TransformDependentNameType(
7731 return TransformDependentNameType(TLB, TL, false);
7732}
7733
7734template <typename Derived>
7735QualType TreeTransform<Derived>::TransformDependentNameType(
7736 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7737 QualType ObjectType, NamedDecl *UnqualLookup) {
7738 const DependentNameType *T = TL.getTypePtr();
7739
7740 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7741 if (QualifierLoc) {
7742 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7743 QualifierLoc, ObjectType, UnqualLookup);
7744 if (!QualifierLoc)
7745 return QualType();
7746 } else {
7747 assert((ObjectType.isNull() && !UnqualLookup) &&
7748 "must be transformed by TransformNestedNameSpecifierLoc");
7749 }
7750
7752 = getDerived().RebuildDependentNameType(T->getKeyword(),
7753 TL.getElaboratedKeywordLoc(),
7754 QualifierLoc,
7755 T->getIdentifier(),
7756 TL.getNameLoc(),
7757 DeducedTSTContext);
7758 if (Result.isNull())
7759 return QualType();
7760
7761 if (isa<TagType>(Result)) {
7762 auto NewTL = TLB.push<TagTypeLoc>(Result);
7763 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7764 NewTL.setQualifierLoc(QualifierLoc);
7765 NewTL.setNameLoc(TL.getNameLoc());
7767 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7768 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7769 NewTL.setTemplateNameLoc(TL.getNameLoc());
7770 NewTL.setQualifierLoc(QualifierLoc);
7771 } else if (isa<TypedefType>(Result)) {
7772 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7773 QualifierLoc, TL.getNameLoc());
7774 } else if (isa<UnresolvedUsingType>(Result)) {
7775 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7776 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7777 } else {
7778 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7779 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7780 NewTL.setQualifierLoc(QualifierLoc);
7781 NewTL.setNameLoc(TL.getNameLoc());
7782 }
7783 return Result;
7784}
7785
7786template<typename Derived>
7789 QualType Pattern
7790 = getDerived().TransformType(TLB, TL.getPatternLoc());
7791 if (Pattern.isNull())
7792 return QualType();
7793
7794 QualType Result = TL.getType();
7795 if (getDerived().AlwaysRebuild() ||
7796 Pattern != TL.getPatternLoc().getType()) {
7797 Result = getDerived().RebuildPackExpansionType(Pattern,
7798 TL.getPatternLoc().getSourceRange(),
7799 TL.getEllipsisLoc(),
7800 TL.getTypePtr()->getNumExpansions());
7801 if (Result.isNull())
7802 return QualType();
7803 }
7804
7806 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7807 return Result;
7808}
7809
7810template<typename Derived>
7814 // ObjCInterfaceType is never dependent.
7815 TLB.pushFullCopy(TL);
7816 return TL.getType();
7817}
7818
7819template<typename Derived>
7823 const ObjCTypeParamType *T = TL.getTypePtr();
7824 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7825 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7826 if (!OTP)
7827 return QualType();
7828
7829 QualType Result = TL.getType();
7830 if (getDerived().AlwaysRebuild() ||
7831 OTP != T->getDecl()) {
7832 Result = getDerived().RebuildObjCTypeParamType(
7833 OTP, TL.getProtocolLAngleLoc(),
7834 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7835 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7836 if (Result.isNull())
7837 return QualType();
7838 }
7839
7841 if (TL.getNumProtocols()) {
7842 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7843 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7844 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7845 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7846 }
7847 return Result;
7848}
7849
7850template<typename Derived>
7853 ObjCObjectTypeLoc TL) {
7854 // Transform base type.
7855 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7856 if (BaseType.isNull())
7857 return QualType();
7858
7859 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7860
7861 // Transform type arguments.
7862 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7863 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7864 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7865 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7866 QualType TypeArg = TypeArgInfo->getType();
7867 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7868 AnyChanged = true;
7869
7870 // We have a pack expansion. Instantiate it.
7871 const auto *PackExpansion = PackExpansionLoc.getType()
7872 ->castAs<PackExpansionType>();
7874 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7875 Unexpanded);
7876 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7877
7878 // Determine whether the set of unexpanded parameter packs can
7879 // and should be expanded.
7880 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7881 bool Expand = false;
7882 bool RetainExpansion = false;
7883 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7884 if (getDerived().TryExpandParameterPacks(
7885 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7886 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
7887 RetainExpansion, NumExpansions))
7888 return QualType();
7889
7890 if (!Expand) {
7891 // We can't expand this pack expansion into separate arguments yet;
7892 // just substitute into the pattern and create a new pack expansion
7893 // type.
7894 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7895
7896 TypeLocBuilder TypeArgBuilder;
7897 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7898 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7899 PatternLoc);
7900 if (NewPatternType.isNull())
7901 return QualType();
7902
7903 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7904 NewPatternType, NumExpansions);
7905 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7906 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7907 NewTypeArgInfos.push_back(
7908 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7909 continue;
7910 }
7911
7912 // Substitute into the pack expansion pattern for each slice of the
7913 // pack.
7914 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7915 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
7916
7917 TypeLocBuilder TypeArgBuilder;
7918 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7919
7920 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7921 PatternLoc);
7922 if (NewTypeArg.isNull())
7923 return QualType();
7924
7925 NewTypeArgInfos.push_back(
7926 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7927 }
7928
7929 continue;
7930 }
7931
7932 TypeLocBuilder TypeArgBuilder;
7933 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7934 QualType NewTypeArg =
7935 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7936 if (NewTypeArg.isNull())
7937 return QualType();
7938
7939 // If nothing changed, just keep the old TypeSourceInfo.
7940 if (NewTypeArg == TypeArg) {
7941 NewTypeArgInfos.push_back(TypeArgInfo);
7942 continue;
7943 }
7944
7945 NewTypeArgInfos.push_back(
7946 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7947 AnyChanged = true;
7948 }
7949
7950 QualType Result = TL.getType();
7951 if (getDerived().AlwaysRebuild() || AnyChanged) {
7952 // Rebuild the type.
7953 Result = getDerived().RebuildObjCObjectType(
7954 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7955 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7956 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7957 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7958
7959 if (Result.isNull())
7960 return QualType();
7961 }
7962
7963 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7964 NewT.setHasBaseTypeAsWritten(true);
7965 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7966 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7967 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7968 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7969 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7970 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7971 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7972 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7973 return Result;
7974}
7975
7976template<typename Derived>
7980 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7981 if (PointeeType.isNull())
7982 return QualType();
7983
7984 QualType Result = TL.getType();
7985 if (getDerived().AlwaysRebuild() ||
7986 PointeeType != TL.getPointeeLoc().getType()) {
7987 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7988 TL.getStarLoc());
7989 if (Result.isNull())
7990 return QualType();
7991 }
7992
7994 NewT.setStarLoc(TL.getStarLoc());
7995 return Result;
7996}
7997
7998//===----------------------------------------------------------------------===//
7999// Statement transformation
8000//===----------------------------------------------------------------------===//
8001template<typename Derived>
8004 return S;
8005}
8006
8007template<typename Derived>
8010 return getDerived().TransformCompoundStmt(S, false);
8011}
8012
8013template<typename Derived>
8016 bool IsStmtExpr) {
8017 Sema::CompoundScopeRAII CompoundScope(getSema());
8018 Sema::FPFeaturesStateRAII FPSave(getSema());
8019 if (S->hasStoredFPFeatures())
8020 getSema().resetFPOptions(
8021 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8022
8023 const Stmt *ExprResult = S->getStmtExprResult();
8024 bool SubStmtInvalid = false;
8025 bool SubStmtChanged = false;
8026 SmallVector<Stmt*, 8> Statements;
8027 for (auto *B : S->body()) {
8028 StmtResult Result = getDerived().TransformStmt(
8029 B, IsStmtExpr && B == ExprResult ? StmtDiscardKind::StmtExprResult
8030 : StmtDiscardKind::Discarded);
8031
8032 if (Result.isInvalid()) {
8033 // Immediately fail if this was a DeclStmt, since it's very
8034 // likely that this will cause problems for future statements.
8035 if (isa<DeclStmt>(B))
8036 return StmtError();
8037
8038 // Otherwise, just keep processing substatements and fail later.
8039 SubStmtInvalid = true;
8040 continue;
8041 }
8042
8043 SubStmtChanged = SubStmtChanged || Result.get() != B;
8044 Statements.push_back(Result.getAs<Stmt>());
8045 }
8046
8047 if (SubStmtInvalid)
8048 return StmtError();
8049
8050 if (!getDerived().AlwaysRebuild() &&
8051 !SubStmtChanged)
8052 return S;
8053
8054 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8055 Statements,
8056 S->getRBracLoc(),
8057 IsStmtExpr);
8058}
8059
8060template<typename Derived>
8063 ExprResult LHS, RHS;
8064 {
8067
8068 // Transform the left-hand case value.
8069 LHS = getDerived().TransformExpr(S->getLHS());
8070 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8071 if (LHS.isInvalid())
8072 return StmtError();
8073
8074 // Transform the right-hand case value (for the GNU case-range extension).
8075 RHS = getDerived().TransformExpr(S->getRHS());
8076 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8077 if (RHS.isInvalid())
8078 return StmtError();
8079 }
8080
8081 // Build the case statement.
8082 // Case statements are always rebuilt so that they will attached to their
8083 // transformed switch statement.
8084 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8085 LHS.get(),
8086 S->getEllipsisLoc(),
8087 RHS.get(),
8088 S->getColonLoc());
8089 if (Case.isInvalid())
8090 return StmtError();
8091
8092 // Transform the statement following the case
8093 StmtResult SubStmt =
8094 getDerived().TransformStmt(S->getSubStmt());
8095 if (SubStmt.isInvalid())
8096 return StmtError();
8097
8098 // Attach the body to the case statement
8099 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8100}
8101
8102template <typename Derived>
8104 // Transform the statement following the default case
8105 StmtResult SubStmt =
8106 getDerived().TransformStmt(S->getSubStmt());
8107 if (SubStmt.isInvalid())
8108 return StmtError();
8109
8110 // Default statements are always rebuilt
8111 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8112 SubStmt.get());
8113}
8114
8115template<typename Derived>
8118 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8119 if (SubStmt.isInvalid())
8120 return StmtError();
8121
8122 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8123 S->getDecl());
8124 if (!LD)
8125 return StmtError();
8126
8127 // If we're transforming "in-place" (we're not creating new local
8128 // declarations), assume we're replacing the old label statement
8129 // and clear out the reference to it.
8130 if (LD == S->getDecl())
8131 S->getDecl()->setStmt(nullptr);
8132
8133 // FIXME: Pass the real colon location in.
8134 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8136 SubStmt.get());
8137}
8138
8139template <typename Derived>
8141 if (!R)
8142 return R;
8143
8144 switch (R->getKind()) {
8145// Transform attributes by calling TransformXXXAttr.
8146#define ATTR(X) \
8147 case attr::X: \
8148 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8149#include "clang/Basic/AttrList.inc"
8150 }
8151 return R;
8152}
8153
8154template <typename Derived>
8156 const Stmt *InstS,
8157 const Attr *R) {
8158 if (!R)
8159 return R;
8160
8161 switch (R->getKind()) {
8162// Transform attributes by calling TransformStmtXXXAttr.
8163#define ATTR(X) \
8164 case attr::X: \
8165 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8166#include "clang/Basic/AttrList.inc"
8167 }
8168 return TransformAttr(R);
8169}
8170
8171template <typename Derived>
8174 StmtDiscardKind SDK) {
8175 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8176 if (SubStmt.isInvalid())
8177 return StmtError();
8178
8179 bool AttrsChanged = false;
8181
8182 // Visit attributes and keep track if any are transformed.
8183 for (const auto *I : S->getAttrs()) {
8184 const Attr *R =
8185 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8186 AttrsChanged |= (I != R);
8187 if (R)
8188 Attrs.push_back(R);
8189 }
8190
8191 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8192 return S;
8193
8194 // If transforming the attributes failed for all of the attributes in the
8195 // statement, don't make an AttributedStmt without attributes.
8196 if (Attrs.empty())
8197 return SubStmt;
8198
8199 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8200 SubStmt.get());
8201}
8202
8203template<typename Derived>
8206 // Transform the initialization statement
8207 StmtResult Init = getDerived().TransformStmt(S->getInit());
8208 if (Init.isInvalid())
8209 return StmtError();
8210
8212 if (!S->isConsteval()) {
8213 // Transform the condition
8214 Cond = getDerived().TransformCondition(
8215 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8216 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8218 if (Cond.isInvalid())
8219 return StmtError();
8220 }
8221
8222 // If this is a constexpr if, determine which arm we should instantiate.
8223 std::optional<bool> ConstexprConditionValue;
8224 if (S->isConstexpr())
8225 ConstexprConditionValue = Cond.getKnownValue();
8226
8227 // Transform the "then" branch.
8228 StmtResult Then;
8229 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8233 S->isNonNegatedConsteval());
8234
8235 Then = getDerived().TransformStmt(S->getThen());
8236 if (Then.isInvalid())
8237 return StmtError();
8238 } else {
8239 // Discarded branch is replaced with empty CompoundStmt so we can keep
8240 // proper source location for start and end of original branch, so
8241 // subsequent transformations like CoverageMapping work properly
8242 Then = new (getSema().Context)
8243 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8244 }
8245
8246 // Transform the "else" branch.
8247 StmtResult Else;
8248 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8252 S->isNegatedConsteval());
8253
8254 Else = getDerived().TransformStmt(S->getElse());
8255 if (Else.isInvalid())
8256 return StmtError();
8257 } else if (S->getElse() && ConstexprConditionValue &&
8258 *ConstexprConditionValue) {
8259 // Same thing here as with <then> branch, we are discarding it, we can't
8260 // replace it with NULL nor NullStmt as we need to keep for source location
8261 // range, for CoverageMapping
8262 Else = new (getSema().Context)
8263 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8264 }
8265
8266 if (!getDerived().AlwaysRebuild() &&
8267 Init.get() == S->getInit() &&
8268 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8269 Then.get() == S->getThen() &&
8270 Else.get() == S->getElse())
8271 return S;
8272
8273 return getDerived().RebuildIfStmt(
8274 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8275 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8276}
8277
8278template<typename Derived>
8281 // Transform the initialization statement
8282 StmtResult Init = getDerived().TransformStmt(S->getInit());
8283 if (Init.isInvalid())
8284 return StmtError();
8285
8286 // Transform the condition.
8287 Sema::ConditionResult Cond = getDerived().TransformCondition(
8288 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8290 if (Cond.isInvalid())
8291 return StmtError();
8292
8293 // Rebuild the switch statement.
8295 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8296 Init.get(), Cond, S->getRParenLoc());
8297 if (Switch.isInvalid())
8298 return StmtError();
8299
8300 // Transform the body of the switch statement.
8301 StmtResult Body = getDerived().TransformStmt(S->getBody());
8302 if (Body.isInvalid())
8303 return StmtError();
8304
8305 // Complete the switch statement.
8306 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8307 Body.get());
8308}
8309
8310template<typename Derived>
8313 // Transform the condition
8314 Sema::ConditionResult Cond = getDerived().TransformCondition(
8315 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8317 if (Cond.isInvalid())
8318 return StmtError();
8319
8320 // OpenACC Restricts a while-loop inside of certain construct/clause
8321 // combinations, so diagnose that here in OpenACC mode.
8323 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8324
8325 // Transform the body
8326 StmtResult Body = getDerived().TransformStmt(S->getBody());
8327 if (Body.isInvalid())
8328 return StmtError();
8329
8330 if (!getDerived().AlwaysRebuild() &&
8331 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8332 Body.get() == S->getBody())
8333 return Owned(S);
8334
8335 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8336 Cond, S->getRParenLoc(), Body.get());
8337}
8338
8339template<typename Derived>
8342 // OpenACC Restricts a do-loop inside of certain construct/clause
8343 // combinations, so diagnose that here in OpenACC mode.
8345 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8346
8347 // Transform the body
8348 StmtResult Body = getDerived().TransformStmt(S->getBody());
8349 if (Body.isInvalid())
8350 return StmtError();
8351
8352 // Transform the condition
8353 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8354 if (Cond.isInvalid())
8355 return StmtError();
8356
8357 if (!getDerived().AlwaysRebuild() &&
8358 Cond.get() == S->getCond() &&
8359 Body.get() == S->getBody())
8360 return S;
8361
8362 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8363 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8364 S->getRParenLoc());
8365}
8366
8367template<typename Derived>
8370 if (getSema().getLangOpts().OpenMP)
8371 getSema().OpenMP().startOpenMPLoop();
8372
8373 // Transform the initialization statement
8374 StmtResult Init = getDerived().TransformStmt(S->getInit());
8375 if (Init.isInvalid())
8376 return StmtError();
8377
8378 // In OpenMP loop region loop control variable must be captured and be
8379 // private. Perform analysis of first part (if any).
8380 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8381 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8382 Init.get());
8383
8384 // Transform the condition
8385 Sema::ConditionResult Cond = getDerived().TransformCondition(
8386 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8388 if (Cond.isInvalid())
8389 return StmtError();
8390
8391 // Transform the increment
8392 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8393 if (Inc.isInvalid())
8394 return StmtError();
8395
8396 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8397 if (S->getInc() && !FullInc.get())
8398 return StmtError();
8399
8400 // OpenACC Restricts a for-loop inside of certain construct/clause
8401 // combinations, so diagnose that here in OpenACC mode.
8403 SemaRef.OpenACC().ActOnForStmtBegin(
8404 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8405 Cond.get().second, S->getInc(), Inc.get());
8406
8407 // Transform the body
8408 StmtResult Body = getDerived().TransformStmt(S->getBody());
8409 if (Body.isInvalid())
8410 return StmtError();
8411
8412 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8413
8414 if (!getDerived().AlwaysRebuild() &&
8415 Init.get() == S->getInit() &&
8416 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8417 Inc.get() == S->getInc() &&
8418 Body.get() == S->getBody())
8419 return S;
8420
8421 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8422 Init.get(), Cond, FullInc,
8423 S->getRParenLoc(), Body.get());
8424}
8425
8426template<typename Derived>
8429 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8430 S->getLabel());
8431 if (!LD)
8432 return StmtError();
8433
8434 // Goto statements must always be rebuilt, to resolve the label.
8435 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8436 cast<LabelDecl>(LD));
8437}
8438
8439template<typename Derived>
8442 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8443 if (Target.isInvalid())
8444 return StmtError();
8445 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8446
8447 if (!getDerived().AlwaysRebuild() &&
8448 Target.get() == S->getTarget())
8449 return S;
8450
8451 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8452 Target.get());
8453}
8454
8455template<typename Derived>
8458 if (!S->hasLabelTarget())
8459 return S;
8460
8461 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8462 S->getLabelDecl());
8463 if (!LD)
8464 return StmtError();
8465
8466 return new (SemaRef.Context)
8467 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8468}
8469
8470template<typename Derived>
8473 if (!S->hasLabelTarget())
8474 return S;
8475
8476 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8477 S->getLabelDecl());
8478 if (!LD)
8479 return StmtError();
8480
8481 return new (SemaRef.Context)
8482 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8483}
8484
8485template<typename Derived>
8488 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8489 /*NotCopyInit*/false);
8490 if (Result.isInvalid())
8491 return StmtError();
8492
8493 // FIXME: We always rebuild the return statement because there is no way
8494 // to tell whether the return type of the function has changed.
8495 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8496}
8497
8498template<typename Derived>
8501 bool DeclChanged = false;
8503 LambdaScopeInfo *LSI = getSema().getCurLambda();
8504 for (auto *D : S->decls()) {
8505 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8506 if (!Transformed)
8507 return StmtError();
8508
8509 if (Transformed != D)
8510 DeclChanged = true;
8511
8512 if (LSI) {
8513 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8514 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8515 LSI->ContainsUnexpandedParameterPack |=
8516 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8517 } else {
8518 LSI->ContainsUnexpandedParameterPack |=
8519 getSema()
8520 .getASTContext()
8521 .getTypeDeclType(TD)
8522 ->containsUnexpandedParameterPack();
8523 }
8524 }
8525 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8526 LSI->ContainsUnexpandedParameterPack |=
8527 VD->getType()->containsUnexpandedParameterPack();
8528 }
8529
8530 Decls.push_back(Transformed);
8531 }
8532
8533 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8534 return S;
8535
8536 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8537}
8538
8539template<typename Derived>
8542
8543 SmallVector<Expr*, 8> Constraints;
8546
8547 SmallVector<Expr*, 8> Clobbers;
8548
8549 bool ExprsChanged = false;
8550
8551 auto RebuildString = [&](Expr *E) {
8552 ExprResult Result = getDerived().TransformExpr(E);
8553 if (!Result.isUsable())
8554 return Result;
8555 if (Result.get() != E) {
8556 ExprsChanged = true;
8557 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8558 }
8559 return Result;
8560 };
8561
8562 // Go through the outputs.
8563 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8564 Names.push_back(S->getOutputIdentifier(I));
8565
8566 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8567 if (Result.isInvalid())
8568 return StmtError();
8569
8570 Constraints.push_back(Result.get());
8571
8572 // Transform the output expr.
8573 Expr *OutputExpr = S->getOutputExpr(I);
8574 Result = getDerived().TransformExpr(OutputExpr);
8575 if (Result.isInvalid())
8576 return StmtError();
8577
8578 ExprsChanged |= Result.get() != OutputExpr;
8579
8580 Exprs.push_back(Result.get());
8581 }
8582
8583 // Go through the inputs.
8584 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8585 Names.push_back(S->getInputIdentifier(I));
8586
8587 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8588 if (Result.isInvalid())
8589 return StmtError();
8590
8591 Constraints.push_back(Result.get());
8592
8593 // Transform the input expr.
8594 Expr *InputExpr = S->getInputExpr(I);
8595 Result = getDerived().TransformExpr(InputExpr);
8596 if (Result.isInvalid())
8597 return StmtError();
8598
8599 ExprsChanged |= Result.get() != InputExpr;
8600
8601 Exprs.push_back(Result.get());
8602 }
8603
8604 // Go through the Labels.
8605 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8606 Names.push_back(S->getLabelIdentifier(I));
8607
8608 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8609 if (Result.isInvalid())
8610 return StmtError();
8611 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8612 Exprs.push_back(Result.get());
8613 }
8614
8615 // Go through the clobbers.
8616 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8617 ExprResult Result = RebuildString(S->getClobberExpr(I));
8618 if (Result.isInvalid())
8619 return StmtError();
8620 Clobbers.push_back(Result.get());
8621 }
8622
8623 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8624 if (AsmString.isInvalid())
8625 return StmtError();
8626
8627 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8628 return S;
8629
8630 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8631 S->isVolatile(), S->getNumOutputs(),
8632 S->getNumInputs(), Names.data(),
8633 Constraints, Exprs, AsmString.get(),
8634 Clobbers, S->getNumLabels(),
8635 S->getRParenLoc());
8636}
8637
8638template<typename Derived>
8641 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8642
8643 bool HadError = false, HadChange = false;
8644
8645 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8646 SmallVector<Expr*, 8> TransformedExprs;
8647 TransformedExprs.reserve(SrcExprs.size());
8648 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8649 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8650 if (!Result.isUsable()) {
8651 HadError = true;
8652 } else {
8653 HadChange |= (Result.get() != SrcExprs[i]);
8654 TransformedExprs.push_back(Result.get());
8655 }
8656 }
8657
8658 if (HadError) return StmtError();
8659 if (!HadChange && !getDerived().AlwaysRebuild())
8660 return Owned(S);
8661
8662 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8663 AsmToks, S->getAsmString(),
8664 S->getNumOutputs(), S->getNumInputs(),
8665 S->getAllConstraints(), S->getClobbers(),
8666 TransformedExprs, S->getEndLoc());
8667}
8668
8669// C++ Coroutines
8670template<typename Derived>
8673 auto *ScopeInfo = SemaRef.getCurFunction();
8674 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8675 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8676 ScopeInfo->NeedsCoroutineSuspends &&
8677 ScopeInfo->CoroutineSuspends.first == nullptr &&
8678 ScopeInfo->CoroutineSuspends.second == nullptr &&
8679 "expected clean scope info");
8680
8681 // Set that we have (possibly-invalid) suspend points before we do anything
8682 // that may fail.
8683 ScopeInfo->setNeedsCoroutineSuspends(false);
8684
8685 // We re-build the coroutine promise object (and the coroutine parameters its
8686 // type and constructor depend on) based on the types used in our current
8687 // function. We must do so, and set it on the current FunctionScopeInfo,
8688 // before attempting to transform the other parts of the coroutine body
8689 // statement, such as the implicit suspend statements (because those
8690 // statements reference the FunctionScopeInfo::CoroutinePromise).
8691 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8692 return StmtError();
8693 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8694 if (!Promise)
8695 return StmtError();
8696 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8697 ScopeInfo->CoroutinePromise = Promise;
8698
8699 // Transform the implicit coroutine statements constructed using dependent
8700 // types during the previous parse: initial and final suspensions, the return
8701 // object, and others. We also transform the coroutine function's body.
8702 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8703 if (InitSuspend.isInvalid())
8704 return StmtError();
8705 StmtResult FinalSuspend =
8706 getDerived().TransformStmt(S->getFinalSuspendStmt());
8707 if (FinalSuspend.isInvalid() ||
8708 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8709 return StmtError();
8710 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8711 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8712
8713 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8714 if (BodyRes.isInvalid())
8715 return StmtError();
8716
8717 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8718 if (Builder.isInvalid())
8719 return StmtError();
8720
8721 Expr *ReturnObject = S->getReturnValueInit();
8722 assert(ReturnObject && "the return object is expected to be valid");
8723 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8724 /*NoCopyInit*/ false);
8725 if (Res.isInvalid())
8726 return StmtError();
8727 Builder.ReturnValue = Res.get();
8728
8729 // If during the previous parse the coroutine still had a dependent promise
8730 // statement, we may need to build some implicit coroutine statements
8731 // (such as exception and fallthrough handlers) for the first time.
8732 if (S->hasDependentPromiseType()) {
8733 // We can only build these statements, however, if the current promise type
8734 // is not dependent.
8735 if (!Promise->getType()->isDependentType()) {
8736 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8737 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8738 "these nodes should not have been built yet");
8739 if (!Builder.buildDependentStatements())
8740 return StmtError();
8741 }
8742 } else {
8743 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8744 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8745 if (Res.isInvalid())
8746 return StmtError();
8747 Builder.OnFallthrough = Res.get();
8748 }
8749
8750 if (auto *OnException = S->getExceptionHandler()) {
8751 StmtResult Res = getDerived().TransformStmt(OnException);
8752 if (Res.isInvalid())
8753 return StmtError();
8754 Builder.OnException = Res.get();
8755 }
8756
8757 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8758 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8759 if (Res.isInvalid())
8760 return StmtError();
8761 Builder.ReturnStmtOnAllocFailure = Res.get();
8762 }
8763
8764 // Transform any additional statements we may have already built
8765 assert(S->getAllocate() && S->getDeallocate() &&
8766 "allocation and deallocation calls must already be built");
8767 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8768 if (AllocRes.isInvalid())
8769 return StmtError();
8770 Builder.Allocate = AllocRes.get();
8771
8772 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8773 if (DeallocRes.isInvalid())
8774 return StmtError();
8775 Builder.Deallocate = DeallocRes.get();
8776
8777 if (auto *ResultDecl = S->getResultDecl()) {
8778 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8779 if (Res.isInvalid())
8780 return StmtError();
8781 Builder.ResultDecl = Res.get();
8782 }
8783
8784 if (auto *ReturnStmt = S->getReturnStmt()) {
8785 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8786 if (Res.isInvalid())
8787 return StmtError();
8788 Builder.ReturnStmt = Res.get();
8789 }
8790 }
8791
8792 return getDerived().RebuildCoroutineBodyStmt(Builder);
8793}
8794
8795template<typename Derived>
8798 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8799 /*NotCopyInit*/false);
8800 if (Result.isInvalid())
8801 return StmtError();
8802
8803 // Always rebuild; we don't know if this needs to be injected into a new
8804 // context or if the promise type has changed.
8805 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8806 S->isImplicit());
8807}
8808
8809template <typename Derived>
8811 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8812 /*NotCopyInit*/ false);
8813 if (Operand.isInvalid())
8814 return ExprError();
8815
8816 // Rebuild the common-expr from the operand rather than transforming it
8817 // separately.
8818
8819 // FIXME: getCurScope() should not be used during template instantiation.
8820 // We should pick up the set of unqualified lookup results for operator
8821 // co_await during the initial parse.
8822 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8823 getSema().getCurScope(), E->getKeywordLoc());
8824
8825 // Always rebuild; we don't know if this needs to be injected into a new
8826 // context or if the promise type has changed.
8827 return getDerived().RebuildCoawaitExpr(
8828 E->getKeywordLoc(), Operand.get(),
8829 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8830}
8831
8832template <typename Derived>
8835 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8836 /*NotCopyInit*/ false);
8837 if (OperandResult.isInvalid())
8838 return ExprError();
8839
8840 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8841 E->getOperatorCoawaitLookup());
8842
8843 if (LookupResult.isInvalid())
8844 return ExprError();
8845
8846 // Always rebuild; we don't know if this needs to be injected into a new
8847 // context or if the promise type has changed.
8848 return getDerived().RebuildDependentCoawaitExpr(
8849 E->getKeywordLoc(), OperandResult.get(),
8851}
8852
8853template<typename Derived>
8856 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8857 /*NotCopyInit*/false);
8858 if (Result.isInvalid())
8859 return ExprError();
8860
8861 // Always rebuild; we don't know if this needs to be injected into a new
8862 // context or if the promise type has changed.
8863 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8864}
8865
8866// Objective-C Statements.
8867
8868template<typename Derived>
8871 // Transform the body of the @try.
8872 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8873 if (TryBody.isInvalid())
8874 return StmtError();
8875
8876 // Transform the @catch statements (if present).
8877 bool AnyCatchChanged = false;
8878 SmallVector<Stmt*, 8> CatchStmts;
8879 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8880 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8881 if (Catch.isInvalid())
8882 return StmtError();
8883 if (Catch.get() != S->getCatchStmt(I))
8884 AnyCatchChanged = true;
8885 CatchStmts.push_back(Catch.get());
8886 }
8887
8888 // Transform the @finally statement (if present).
8889 StmtResult Finally;
8890 if (S->getFinallyStmt()) {
8891 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8892 if (Finally.isInvalid())
8893 return StmtError();
8894 }
8895
8896 // If nothing changed, just retain this statement.
8897 if (!getDerived().AlwaysRebuild() &&
8898 TryBody.get() == S->getTryBody() &&
8899 !AnyCatchChanged &&
8900 Finally.get() == S->getFinallyStmt())
8901 return S;
8902
8903 // Build a new statement.
8904 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8905 CatchStmts, Finally.get());
8906}
8907
8908template<typename Derived>
8911 // Transform the @catch parameter, if there is one.
8912 VarDecl *Var = nullptr;
8913 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8914 TypeSourceInfo *TSInfo = nullptr;
8915 if (FromVar->getTypeSourceInfo()) {
8916 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8917 if (!TSInfo)
8918 return StmtError();
8919 }
8920
8921 QualType T;
8922 if (TSInfo)
8923 T = TSInfo->getType();
8924 else {
8925 T = getDerived().TransformType(FromVar->getType());
8926 if (T.isNull())
8927 return StmtError();
8928 }
8929
8930 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8931 if (!Var)
8932 return StmtError();
8933 }
8934
8935 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8936 if (Body.isInvalid())
8937 return StmtError();
8938
8939 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8940 S->getRParenLoc(),
8941 Var, Body.get());
8942}
8943
8944template<typename Derived>
8947 // Transform the body.
8948 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8949 if (Body.isInvalid())
8950 return StmtError();
8951
8952 // If nothing changed, just retain this statement.
8953 if (!getDerived().AlwaysRebuild() &&
8954 Body.get() == S->getFinallyBody())
8955 return S;
8956
8957 // Build a new statement.
8958 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8959 Body.get());
8960}
8961
8962template<typename Derived>
8966 if (S->getThrowExpr()) {
8967 Operand = getDerived().TransformExpr(S->getThrowExpr());
8968 if (Operand.isInvalid())
8969 return StmtError();
8970 }
8971
8972 if (!getDerived().AlwaysRebuild() &&
8973 Operand.get() == S->getThrowExpr())
8974 return S;
8975
8976 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8977}
8978
8979template<typename Derived>
8983 // Transform the object we are locking.
8984 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8985 if (Object.isInvalid())
8986 return StmtError();
8987 Object =
8988 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8989 Object.get());
8990 if (Object.isInvalid())
8991 return StmtError();
8992
8993 // Transform the body.
8994 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8995 if (Body.isInvalid())
8996 return StmtError();
8997
8998 // If nothing change, just retain the current statement.
8999 if (!getDerived().AlwaysRebuild() &&
9000 Object.get() == S->getSynchExpr() &&
9001 Body.get() == S->getSynchBody())
9002 return S;
9003
9004 // Build a new statement.
9005 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9006 Object.get(), Body.get());
9007}
9008
9009template<typename Derived>
9013 // Transform the body.
9014 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9015 if (Body.isInvalid())
9016 return StmtError();
9017
9018 // If nothing changed, just retain this statement.
9019 if (!getDerived().AlwaysRebuild() &&
9020 Body.get() == S->getSubStmt())
9021 return S;
9022
9023 // Build a new statement.
9024 return getDerived().RebuildObjCAutoreleasePoolStmt(
9025 S->getAtLoc(), Body.get());
9026}
9027
9028template<typename Derived>
9032 // Transform the element statement.
9033 StmtResult Element = getDerived().TransformStmt(
9034 S->getElement(), StmtDiscardKind::NotDiscarded);
9035 if (Element.isInvalid())
9036 return StmtError();
9037
9038 // Transform the collection expression.
9039 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9040 if (Collection.isInvalid())
9041 return StmtError();
9042
9043 // Transform the body.
9044 StmtResult Body = getDerived().TransformStmt(S->getBody());
9045 if (Body.isInvalid())
9046 return StmtError();
9047
9048 // If nothing changed, just retain this statement.
9049 if (!getDerived().AlwaysRebuild() &&
9050 Element.get() == S->getElement() &&
9051 Collection.get() == S->getCollection() &&
9052 Body.get() == S->getBody())
9053 return S;
9054
9055 // Build a new statement.
9056 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9057 Element.get(),
9058 Collection.get(),
9059 S->getRParenLoc(),
9060 Body.get());
9061}
9062
9063template <typename Derived>
9065 // Transform the exception declaration, if any.
9066 VarDecl *Var = nullptr;
9067 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9068 TypeSourceInfo *T =
9069 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9070 if (!T)
9071 return StmtError();
9072
9073 Var = getDerived().RebuildExceptionDecl(
9074 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9075 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9076 if (!Var || Var->isInvalidDecl())
9077 return StmtError();
9078 }
9079
9080 // Transform the actual exception handler.
9081 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9082 if (Handler.isInvalid())
9083 return StmtError();
9084
9085 if (!getDerived().AlwaysRebuild() && !Var &&
9086 Handler.get() == S->getHandlerBlock())
9087 return S;
9088
9089 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9090}
9091
9092template <typename Derived>
9094 // Transform the try block itself.
9095 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9096 if (TryBlock.isInvalid())
9097 return StmtError();
9098
9099 // Transform the handlers.
9100 bool HandlerChanged = false;
9101 SmallVector<Stmt *, 8> Handlers;
9102 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9103 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9104 if (Handler.isInvalid())
9105 return StmtError();
9106
9107 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9108 Handlers.push_back(Handler.getAs<Stmt>());
9109 }
9110
9111 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9112
9113 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9114 !HandlerChanged)
9115 return S;
9116
9117 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9118 Handlers);
9119}
9120
9121template<typename Derived>
9124 EnterExpressionEvaluationContext ForRangeInitContext(
9126 /*LambdaContextDecl=*/nullptr,
9128 getSema().getLangOpts().CPlusPlus23);
9129
9130 // P2718R0 - Lifetime extension in range-based for loops.
9131 if (getSema().getLangOpts().CPlusPlus23) {
9132 auto &LastRecord = getSema().currentEvaluationContext();
9133 LastRecord.InLifetimeExtendingContext = true;
9134 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9135 }
9137 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9138 if (Init.isInvalid())
9139 return StmtError();
9140
9141 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9142 if (Range.isInvalid())
9143 return StmtError();
9144
9145 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9146 assert(getSema().getLangOpts().CPlusPlus23 ||
9147 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9148 auto ForRangeLifetimeExtendTemps =
9149 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9150
9151 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9152 if (Begin.isInvalid())
9153 return StmtError();
9154 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9155 if (End.isInvalid())
9156 return StmtError();
9157
9158 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9159 if (Cond.isInvalid())
9160 return StmtError();
9161 if (Cond.get())
9162 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9163 if (Cond.isInvalid())
9164 return StmtError();
9165 if (Cond.get())
9166 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9167
9168 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9169 if (Inc.isInvalid())
9170 return StmtError();
9171 if (Inc.get())
9172 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9173
9174 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9175 if (LoopVar.isInvalid())
9176 return StmtError();
9177
9178 StmtResult NewStmt = S;
9179 if (getDerived().AlwaysRebuild() ||
9180 Init.get() != S->getInit() ||
9181 Range.get() != S->getRangeStmt() ||
9182 Begin.get() != S->getBeginStmt() ||
9183 End.get() != S->getEndStmt() ||
9184 Cond.get() != S->getCond() ||
9185 Inc.get() != S->getInc() ||
9186 LoopVar.get() != S->getLoopVarStmt()) {
9187 NewStmt = getDerived().RebuildCXXForRangeStmt(
9188 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9189 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9190 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9191 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9192 // Might not have attached any initializer to the loop variable.
9193 getSema().ActOnInitializerError(
9194 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9195 return StmtError();
9196 }
9197 }
9198
9199 // OpenACC Restricts a while-loop inside of certain construct/clause
9200 // combinations, so diagnose that here in OpenACC mode.
9202 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9203
9204 StmtResult Body = getDerived().TransformStmt(S->getBody());
9205 if (Body.isInvalid())
9206 return StmtError();
9207
9208 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9209
9210 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9211 // it now so we have a new statement to attach the body to.
9212 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9213 NewStmt = getDerived().RebuildCXXForRangeStmt(
9214 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9215 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9216 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9217 if (NewStmt.isInvalid())
9218 return StmtError();
9219 }
9220
9221 if (NewStmt.get() == S)
9222 return S;
9223
9224 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9225}
9226
9227template<typename Derived>
9231 // Transform the nested-name-specifier, if any.
9232 NestedNameSpecifierLoc QualifierLoc;
9233 if (S->getQualifierLoc()) {
9234 QualifierLoc
9235 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9236 if (!QualifierLoc)
9237 return StmtError();
9238 }
9239
9240 // Transform the declaration name.
9241 DeclarationNameInfo NameInfo = S->getNameInfo();
9242 if (NameInfo.getName()) {
9243 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9244 if (!NameInfo.getName())
9245 return StmtError();
9246 }
9247
9248 // Check whether anything changed.
9249 if (!getDerived().AlwaysRebuild() &&
9250 QualifierLoc == S->getQualifierLoc() &&
9251 NameInfo.getName() == S->getNameInfo().getName())
9252 return S;
9253
9254 // Determine whether this name exists, if we can.
9255 CXXScopeSpec SS;
9256 SS.Adopt(QualifierLoc);
9257 bool Dependent = false;
9258 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9260 if (S->isIfExists())
9261 break;
9262
9263 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9264
9266 if (S->isIfNotExists())
9267 break;
9268
9269 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9270
9272 Dependent = true;
9273 break;
9274
9276 return StmtError();
9277 }
9278
9279 // We need to continue with the instantiation, so do so now.
9280 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9281 if (SubStmt.isInvalid())
9282 return StmtError();
9283
9284 // If we have resolved the name, just transform to the substatement.
9285 if (!Dependent)
9286 return SubStmt;
9287
9288 // The name is still dependent, so build a dependent expression again.
9289 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9290 S->isIfExists(),
9291 QualifierLoc,
9292 NameInfo,
9293 SubStmt.get());
9294}
9295
9296template<typename Derived>
9299 NestedNameSpecifierLoc QualifierLoc;
9300 if (E->getQualifierLoc()) {
9301 QualifierLoc
9302 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9303 if (!QualifierLoc)
9304 return ExprError();
9305 }
9306
9307 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9308 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9309 if (!PD)
9310 return ExprError();
9311
9312 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9313 if (Base.isInvalid())
9314 return ExprError();
9315
9316 return new (SemaRef.getASTContext())
9317 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9319 QualifierLoc, E->getMemberLoc());
9320}
9321
9322template <typename Derived>
9325 auto BaseRes = getDerived().TransformExpr(E->getBase());
9326 if (BaseRes.isInvalid())
9327 return ExprError();
9328 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9329 if (IdxRes.isInvalid())
9330 return ExprError();
9331
9332 if (!getDerived().AlwaysRebuild() &&
9333 BaseRes.get() == E->getBase() &&
9334 IdxRes.get() == E->getIdx())
9335 return E;
9336
9337 return getDerived().RebuildArraySubscriptExpr(
9338 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9339}
9340
9341template <typename Derived>
9343 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9344 if (TryBlock.isInvalid())
9345 return StmtError();
9346
9347 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9348 if (Handler.isInvalid())
9349 return StmtError();
9350
9351 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9352 Handler.get() == S->getHandler())
9353 return S;
9354
9355 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9356 TryBlock.get(), Handler.get());
9357}
9358
9359template <typename Derived>
9361 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9362 if (Block.isInvalid())
9363 return StmtError();
9364
9365 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9366}
9367
9368template <typename Derived>
9370 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9371 if (FilterExpr.isInvalid())
9372 return StmtError();
9373
9374 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9375 if (Block.isInvalid())
9376 return StmtError();
9377
9378 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9379 Block.get());
9380}
9381
9382template <typename Derived>
9384 if (isa<SEHFinallyStmt>(Handler))
9385 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9386 else
9387 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9388}
9389
9390template<typename Derived>
9393 return S;
9394}
9395
9396//===----------------------------------------------------------------------===//
9397// OpenMP directive transformation
9398//===----------------------------------------------------------------------===//
9399
9400template <typename Derived>
9401StmtResult
9402TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9403 // OMPCanonicalLoops are eliminated during transformation, since they will be
9404 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9405 // after transformation.
9406 return getDerived().TransformStmt(L->getLoopStmt());
9407}
9408
9409template <typename Derived>
9412
9413 // Transform the clauses
9415 ArrayRef<OMPClause *> Clauses = D->clauses();
9416 TClauses.reserve(Clauses.size());
9417 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9418 I != E; ++I) {
9419 if (*I) {
9420 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9421 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9422 getDerived().getSema().OpenMP().EndOpenMPClause();
9423 if (Clause)
9424 TClauses.push_back(Clause);
9425 } else {
9426 TClauses.push_back(nullptr);
9427 }
9428 }
9429 StmtResult AssociatedStmt;
9430 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9431 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9432 D->getDirectiveKind(),
9433 /*CurScope=*/nullptr);
9434 StmtResult Body;
9435 {
9436 Sema::CompoundScopeRAII CompoundScope(getSema());
9437 Stmt *CS;
9438 if (D->getDirectiveKind() == OMPD_atomic ||
9439 D->getDirectiveKind() == OMPD_critical ||
9440 D->getDirectiveKind() == OMPD_section ||
9441 D->getDirectiveKind() == OMPD_master)
9442 CS = D->getAssociatedStmt();
9443 else
9444 CS = D->getRawStmt();
9445 Body = getDerived().TransformStmt(CS);
9446 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9447 getSema().getLangOpts().OpenMPIRBuilder)
9448 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9449 }
9450 AssociatedStmt =
9451 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9452 if (AssociatedStmt.isInvalid()) {
9453 return StmtError();
9454 }
9455 }
9456 if (TClauses.size() != Clauses.size()) {
9457 return StmtError();
9458 }
9459
9460 // Transform directive name for 'omp critical' directive.
9461 DeclarationNameInfo DirName;
9462 if (D->getDirectiveKind() == OMPD_critical) {
9463 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9464 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9465 }
9466 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9467 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9468 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9469 } else if (D->getDirectiveKind() == OMPD_cancel) {
9470 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9471 }
9472
9473 return getDerived().RebuildOMPExecutableDirective(
9474 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9475 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9476}
9477
9478/// This is mostly the same as above, but allows 'informational' class
9479/// directives when rebuilding the stmt. It still takes an
9480/// OMPExecutableDirective-type argument because we're reusing that as the
9481/// superclass for the 'assume' directive at present, instead of defining a
9482/// mostly-identical OMPInformationalDirective parent class.
9483template <typename Derived>
9486
9487 // Transform the clauses
9489 ArrayRef<OMPClause *> Clauses = D->clauses();
9490 TClauses.reserve(Clauses.size());
9491 for (OMPClause *C : Clauses) {
9492 if (C) {
9493 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9494 OMPClause *Clause = getDerived().TransformOMPClause(C);
9495 getDerived().getSema().OpenMP().EndOpenMPClause();
9496 if (Clause)
9497 TClauses.push_back(Clause);
9498 } else {
9499 TClauses.push_back(nullptr);
9500 }
9501 }
9502 StmtResult AssociatedStmt;
9503 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9504 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9505 D->getDirectiveKind(),
9506 /*CurScope=*/nullptr);
9507 StmtResult Body;
9508 {
9509 Sema::CompoundScopeRAII CompoundScope(getSema());
9510 assert(D->getDirectiveKind() == OMPD_assume &&
9511 "Unexpected informational directive");
9512 Stmt *CS = D->getAssociatedStmt();
9513 Body = getDerived().TransformStmt(CS);
9514 }
9515 AssociatedStmt =
9516 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9517 if (AssociatedStmt.isInvalid())
9518 return StmtError();
9519 }
9520 if (TClauses.size() != Clauses.size())
9521 return StmtError();
9522
9523 DeclarationNameInfo DirName;
9524
9525 return getDerived().RebuildOMPInformationalDirective(
9526 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9527 D->getBeginLoc(), D->getEndLoc());
9528}
9529
9530template <typename Derived>
9533 // TODO: Fix This
9534 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9535 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9536 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9537 return StmtError();
9538}
9539
9540template <typename Derived>
9541StmtResult
9542TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9543 DeclarationNameInfo DirName;
9544 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9545 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9546 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9547 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9548 return Res;
9549}
9550
9551template <typename Derived>
9554 DeclarationNameInfo DirName;
9555 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9556 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9557 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9558 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9559 return Res;
9560}
9561
9562template <typename Derived>
9565 DeclarationNameInfo DirName;
9566 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9567 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9568 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9569 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9570 return Res;
9571}
9572
9573template <typename Derived>
9576 DeclarationNameInfo DirName;
9577 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9578 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9579 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9580 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9581 return Res;
9582}
9583
9584template <typename Derived>
9587 DeclarationNameInfo DirName;
9588 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9589 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9590 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9591 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9592 return Res;
9593}
9594
9595template <typename Derived>
9598 DeclarationNameInfo DirName;
9599 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9600 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9601 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9602 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9603 return Res;
9604}
9605
9606template <typename Derived>
9608 OMPInterchangeDirective *D) {
9609 DeclarationNameInfo DirName;
9610 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9611 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9612 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9613 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9614 return Res;
9615}
9616
9617template <typename Derived>
9620 DeclarationNameInfo DirName;
9621 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9622 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9623 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9624 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9625 return Res;
9626}
9627
9628template <typename Derived>
9631 DeclarationNameInfo DirName;
9632 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9633 OMPD_for, DirName, nullptr, D->getBeginLoc());
9634 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9635 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9636 return Res;
9637}
9638
9639template <typename Derived>
9642 DeclarationNameInfo DirName;
9643 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9644 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9645 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9646 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9647 return Res;
9648}
9649
9650template <typename Derived>
9653 DeclarationNameInfo DirName;
9654 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9655 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9656 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9657 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9658 return Res;
9659}
9660
9661template <typename Derived>
9664 DeclarationNameInfo DirName;
9665 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9666 OMPD_section, DirName, nullptr, D->getBeginLoc());
9667 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9668 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9669 return Res;
9670}
9671
9672template <typename Derived>
9675 DeclarationNameInfo DirName;
9676 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9677 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9678 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9679 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9680 return Res;
9681}
9682
9683template <typename Derived>
9686 DeclarationNameInfo DirName;
9687 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9688 OMPD_single, DirName, nullptr, D->getBeginLoc());
9689 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9690 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9691 return Res;
9692}
9693
9694template <typename Derived>
9697 DeclarationNameInfo DirName;
9698 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9699 OMPD_master, DirName, nullptr, D->getBeginLoc());
9700 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9701 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9702 return Res;
9703}
9704
9705template <typename Derived>
9708 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9709 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9710 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9711 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9712 return Res;
9713}
9714
9715template <typename Derived>
9717 OMPParallelForDirective *D) {
9718 DeclarationNameInfo DirName;
9719 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9720 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9721 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9722 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9723 return Res;
9724}
9725
9726template <typename Derived>
9728 OMPParallelForSimdDirective *D) {
9729 DeclarationNameInfo DirName;
9730 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9731 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9732 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9733 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9734 return Res;
9735}
9736
9737template <typename Derived>
9739 OMPParallelMasterDirective *D) {
9740 DeclarationNameInfo DirName;
9741 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9742 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9743 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9744 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9745 return Res;
9746}
9747
9748template <typename Derived>
9750 OMPParallelMaskedDirective *D) {
9751 DeclarationNameInfo DirName;
9752 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9753 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9754 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9755 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9756 return Res;
9757}
9758
9759template <typename Derived>
9761 OMPParallelSectionsDirective *D) {
9762 DeclarationNameInfo DirName;
9763 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9764 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9765 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9766 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9767 return Res;
9768}
9769
9770template <typename Derived>
9773 DeclarationNameInfo DirName;
9774 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9775 OMPD_task, DirName, nullptr, D->getBeginLoc());
9776 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9777 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9778 return Res;
9779}
9780
9781template <typename Derived>
9783 OMPTaskyieldDirective *D) {
9784 DeclarationNameInfo DirName;
9785 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9786 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9787 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9788 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9789 return Res;
9790}
9791
9792template <typename Derived>
9795 DeclarationNameInfo DirName;
9796 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9797 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9798 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9799 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9800 return Res;
9801}
9802
9803template <typename Derived>
9806 DeclarationNameInfo DirName;
9807 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9808 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9809 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9810 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9811 return Res;
9812}
9813
9814template <typename Derived>
9817 DeclarationNameInfo DirName;
9818 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9819 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9820 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9821 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9822 return Res;
9823}
9824
9825template <typename Derived>
9828 DeclarationNameInfo DirName;
9829 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9830 OMPD_error, DirName, nullptr, D->getBeginLoc());
9831 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9832 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9833 return Res;
9834}
9835
9836template <typename Derived>
9838 OMPTaskgroupDirective *D) {
9839 DeclarationNameInfo DirName;
9840 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9841 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9842 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9843 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9844 return Res;
9845}
9846
9847template <typename Derived>
9850 DeclarationNameInfo DirName;
9851 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9852 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9853 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9854 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9855 return Res;
9856}
9857
9858template <typename Derived>
9861 DeclarationNameInfo DirName;
9862 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9863 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9864 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9865 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9866 return Res;
9867}
9868
9869template <typename Derived>
9872 DeclarationNameInfo DirName;
9873 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9874 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9875 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9876 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9877 return Res;
9878}
9879
9880template <typename Derived>
9883 DeclarationNameInfo DirName;
9884 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9885 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9886 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9887 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9888 return Res;
9889}
9890
9891template <typename Derived>
9894 DeclarationNameInfo DirName;
9895 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9896 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9897 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9898 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9899 return Res;
9900}
9901
9902template <typename Derived>
9905 DeclarationNameInfo DirName;
9906 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9907 OMPD_target, DirName, nullptr, D->getBeginLoc());
9908 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9909 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9910 return Res;
9911}
9912
9913template <typename Derived>
9915 OMPTargetDataDirective *D) {
9916 DeclarationNameInfo DirName;
9917 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9918 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9919 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9920 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9921 return Res;
9922}
9923
9924template <typename Derived>
9926 OMPTargetEnterDataDirective *D) {
9927 DeclarationNameInfo DirName;
9928 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9929 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9930 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9931 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9932 return Res;
9933}
9934
9935template <typename Derived>
9937 OMPTargetExitDataDirective *D) {
9938 DeclarationNameInfo DirName;
9939 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9940 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9941 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9942 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9943 return Res;
9944}
9945
9946template <typename Derived>
9948 OMPTargetParallelDirective *D) {
9949 DeclarationNameInfo DirName;
9950 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9951 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9952 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9953 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9954 return Res;
9955}
9956
9957template <typename Derived>
9959 OMPTargetParallelForDirective *D) {
9960 DeclarationNameInfo DirName;
9961 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9962 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9963 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9964 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9965 return Res;
9966}
9967
9968template <typename Derived>
9970 OMPTargetUpdateDirective *D) {
9971 DeclarationNameInfo DirName;
9972 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9973 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9974 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9975 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9976 return Res;
9977}
9978
9979template <typename Derived>
9982 DeclarationNameInfo DirName;
9983 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9984 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9985 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9986 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9987 return Res;
9988}
9989
9990template <typename Derived>
9992 OMPCancellationPointDirective *D) {
9993 DeclarationNameInfo DirName;
9994 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9995 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9996 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9997 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9998 return Res;
9999}
10000
10001template <typename Derived>
10004 DeclarationNameInfo DirName;
10005 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10006 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10007 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10008 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10009 return Res;
10010}
10011
10012template <typename Derived>
10015 DeclarationNameInfo DirName;
10016 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10017 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10018 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10019 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10020 return Res;
10021}
10022
10023template <typename Derived>
10025 OMPTaskLoopSimdDirective *D) {
10026 DeclarationNameInfo DirName;
10027 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10028 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10029 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10030 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10031 return Res;
10032}
10033
10034template <typename Derived>
10036 OMPMasterTaskLoopDirective *D) {
10037 DeclarationNameInfo DirName;
10038 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10039 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10040 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10041 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10042 return Res;
10043}
10044
10045template <typename Derived>
10047 OMPMaskedTaskLoopDirective *D) {
10048 DeclarationNameInfo DirName;
10049 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10050 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10051 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10052 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10053 return Res;
10054}
10055
10056template <typename Derived>
10058 OMPMasterTaskLoopSimdDirective *D) {
10059 DeclarationNameInfo DirName;
10060 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10061 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10062 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10063 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10064 return Res;
10065}
10066
10067template <typename Derived>
10069 OMPMaskedTaskLoopSimdDirective *D) {
10070 DeclarationNameInfo DirName;
10071 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10072 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10073 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10074 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10075 return Res;
10076}
10077
10078template <typename Derived>
10080 OMPParallelMasterTaskLoopDirective *D) {
10081 DeclarationNameInfo DirName;
10082 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10083 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10084 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10085 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10086 return Res;
10087}
10088
10089template <typename Derived>
10091 OMPParallelMaskedTaskLoopDirective *D) {
10092 DeclarationNameInfo DirName;
10093 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10094 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10095 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10096 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10097 return Res;
10098}
10099
10100template <typename Derived>
10103 OMPParallelMasterTaskLoopSimdDirective *D) {
10104 DeclarationNameInfo DirName;
10105 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10106 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10107 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10108 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10109 return Res;
10110}
10111
10112template <typename Derived>
10115 OMPParallelMaskedTaskLoopSimdDirective *D) {
10116 DeclarationNameInfo DirName;
10117 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10118 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10119 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10120 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10121 return Res;
10122}
10123
10124template <typename Derived>
10126 OMPDistributeDirective *D) {
10127 DeclarationNameInfo DirName;
10128 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10129 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10130 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10131 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10132 return Res;
10133}
10134
10135template <typename Derived>
10137 OMPDistributeParallelForDirective *D) {
10138 DeclarationNameInfo DirName;
10139 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10140 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10141 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10142 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10143 return Res;
10144}
10145
10146template <typename Derived>
10149 OMPDistributeParallelForSimdDirective *D) {
10150 DeclarationNameInfo DirName;
10151 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10152 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10154 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10155 return Res;
10156}
10157
10158template <typename Derived>
10160 OMPDistributeSimdDirective *D) {
10161 DeclarationNameInfo DirName;
10162 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10163 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10165 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10166 return Res;
10167}
10168
10169template <typename Derived>
10171 OMPTargetParallelForSimdDirective *D) {
10172 DeclarationNameInfo DirName;
10173 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10174 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10176 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10177 return Res;
10178}
10179
10180template <typename Derived>
10182 OMPTargetSimdDirective *D) {
10183 DeclarationNameInfo DirName;
10184 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10185 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10187 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10188 return Res;
10189}
10190
10191template <typename Derived>
10193 OMPTeamsDistributeDirective *D) {
10194 DeclarationNameInfo DirName;
10195 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10196 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10198 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10199 return Res;
10200}
10201
10202template <typename Derived>
10204 OMPTeamsDistributeSimdDirective *D) {
10205 DeclarationNameInfo DirName;
10206 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10207 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10209 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10210 return Res;
10211}
10212
10213template <typename Derived>
10215 OMPTeamsDistributeParallelForSimdDirective *D) {
10216 DeclarationNameInfo DirName;
10217 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10218 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10219 D->getBeginLoc());
10220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10221 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10222 return Res;
10223}
10224
10225template <typename Derived>
10227 OMPTeamsDistributeParallelForDirective *D) {
10228 DeclarationNameInfo DirName;
10229 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10230 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10231 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10232 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10233 return Res;
10234}
10235
10236template <typename Derived>
10238 OMPTargetTeamsDirective *D) {
10239 DeclarationNameInfo DirName;
10240 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10241 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10242 auto Res = getDerived().TransformOMPExecutableDirective(D);
10243 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10244 return Res;
10245}
10246
10247template <typename Derived>
10249 OMPTargetTeamsDistributeDirective *D) {
10250 DeclarationNameInfo DirName;
10251 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10252 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10253 auto Res = getDerived().TransformOMPExecutableDirective(D);
10254 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10255 return Res;
10256}
10257
10258template <typename Derived>
10261 OMPTargetTeamsDistributeParallelForDirective *D) {
10262 DeclarationNameInfo DirName;
10263 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10264 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10265 D->getBeginLoc());
10266 auto Res = getDerived().TransformOMPExecutableDirective(D);
10267 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10268 return Res;
10269}
10270
10271template <typename Derived>
10274 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10275 DeclarationNameInfo DirName;
10276 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10277 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10278 D->getBeginLoc());
10279 auto Res = getDerived().TransformOMPExecutableDirective(D);
10280 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10281 return Res;
10282}
10283
10284template <typename Derived>
10287 OMPTargetTeamsDistributeSimdDirective *D) {
10288 DeclarationNameInfo DirName;
10289 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10290 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10291 auto Res = getDerived().TransformOMPExecutableDirective(D);
10292 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10293 return Res;
10294}
10295
10296template <typename Derived>
10299 DeclarationNameInfo DirName;
10300 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10301 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10302 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10303 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10304 return Res;
10305}
10306
10307template <typename Derived>
10310 DeclarationNameInfo DirName;
10311 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10312 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10313 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10314 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10315 return Res;
10316}
10317
10318template <typename Derived>
10321 DeclarationNameInfo DirName;
10322 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10323 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10324 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10325 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10326 return Res;
10327}
10328
10329template <typename Derived>
10331 OMPGenericLoopDirective *D) {
10332 DeclarationNameInfo DirName;
10333 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10334 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10335 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10336 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10337 return Res;
10338}
10339
10340template <typename Derived>
10342 OMPTeamsGenericLoopDirective *D) {
10343 DeclarationNameInfo DirName;
10344 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10345 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10346 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10347 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10348 return Res;
10349}
10350
10351template <typename Derived>
10353 OMPTargetTeamsGenericLoopDirective *D) {
10354 DeclarationNameInfo DirName;
10355 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10356 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10357 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10358 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10359 return Res;
10360}
10361
10362template <typename Derived>
10364 OMPParallelGenericLoopDirective *D) {
10365 DeclarationNameInfo DirName;
10366 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10367 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10368 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10369 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10370 return Res;
10371}
10372
10373template <typename Derived>
10376 OMPTargetParallelGenericLoopDirective *D) {
10377 DeclarationNameInfo DirName;
10378 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10379 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10381 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10382 return Res;
10383}
10384
10385//===----------------------------------------------------------------------===//
10386// OpenMP clause transformation
10387//===----------------------------------------------------------------------===//
10388template <typename Derived>
10390 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10391 if (Cond.isInvalid())
10392 return nullptr;
10393 return getDerived().RebuildOMPIfClause(
10394 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10395 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10396}
10397
10398template <typename Derived>
10400 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10401 if (Cond.isInvalid())
10402 return nullptr;
10403 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10404 C->getLParenLoc(), C->getEndLoc());
10405}
10406
10407template <typename Derived>
10408OMPClause *
10410 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10411 if (NumThreads.isInvalid())
10412 return nullptr;
10413 return getDerived().RebuildOMPNumThreadsClause(
10414 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10415 C->getModifierLoc(), C->getEndLoc());
10416}
10417
10418template <typename Derived>
10419OMPClause *
10421 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10422 if (E.isInvalid())
10423 return nullptr;
10424 return getDerived().RebuildOMPSafelenClause(
10425 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10426}
10427
10428template <typename Derived>
10429OMPClause *
10431 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10432 if (E.isInvalid())
10433 return nullptr;
10434 return getDerived().RebuildOMPAllocatorClause(
10435 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10436}
10437
10438template <typename Derived>
10439OMPClause *
10441 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10442 if (E.isInvalid())
10443 return nullptr;
10444 return getDerived().RebuildOMPSimdlenClause(
10445 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10446}
10447
10448template <typename Derived>
10450 SmallVector<Expr *, 4> TransformedSizes;
10451 TransformedSizes.reserve(C->getNumSizes());
10452 bool Changed = false;
10453 for (Expr *E : C->getSizesRefs()) {
10454 if (!E) {
10455 TransformedSizes.push_back(nullptr);
10456 continue;
10457 }
10458
10459 ExprResult T = getDerived().TransformExpr(E);
10460 if (T.isInvalid())
10461 return nullptr;
10462 if (E != T.get())
10463 Changed = true;
10464 TransformedSizes.push_back(T.get());
10465 }
10466
10467 if (!Changed && !getDerived().AlwaysRebuild())
10468 return C;
10469 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10470 C->getLParenLoc(), C->getEndLoc());
10471}
10472
10473template <typename Derived>
10474OMPClause *
10476 SmallVector<Expr *> TransformedArgs;
10477 TransformedArgs.reserve(C->getNumLoops());
10478 bool Changed = false;
10479 for (Expr *E : C->getArgsRefs()) {
10480 if (!E) {
10481 TransformedArgs.push_back(nullptr);
10482 continue;
10483 }
10484
10485 ExprResult T = getDerived().TransformExpr(E);
10486 if (T.isInvalid())
10487 return nullptr;
10488 if (E != T.get())
10489 Changed = true;
10490 TransformedArgs.push_back(T.get());
10491 }
10492
10493 if (!Changed && !getDerived().AlwaysRebuild())
10494 return C;
10495 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10496 C->getLParenLoc(), C->getEndLoc());
10497}
10498
10499template <typename Derived>
10501 if (!getDerived().AlwaysRebuild())
10502 return C;
10503 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10504}
10505
10506template <typename Derived>
10507OMPClause *
10509 ExprResult T = getDerived().TransformExpr(C->getFactor());
10510 if (T.isInvalid())
10511 return nullptr;
10512 Expr *Factor = T.get();
10513 bool Changed = Factor != C->getFactor();
10514
10515 if (!Changed && !getDerived().AlwaysRebuild())
10516 return C;
10517 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10518 C->getEndLoc());
10519}
10520
10521template <typename Derived>
10522OMPClause *
10524 ExprResult F = getDerived().TransformExpr(C->getFirst());
10525 if (F.isInvalid())
10526 return nullptr;
10527
10528 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10529 if (Cn.isInvalid())
10530 return nullptr;
10531
10532 Expr *First = F.get();
10533 Expr *Count = Cn.get();
10534
10535 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10536
10537 // If no changes and AlwaysRebuild() is false, return the original clause
10538 if (!Changed && !getDerived().AlwaysRebuild())
10539 return C;
10540
10541 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10542 C->getLParenLoc(), C->getFirstLoc(),
10543 C->getCountLoc(), C->getEndLoc());
10544}
10545
10546template <typename Derived>
10547OMPClause *
10549 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10550 if (E.isInvalid())
10551 return nullptr;
10552 return getDerived().RebuildOMPCollapseClause(
10553 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10554}
10555
10556template <typename Derived>
10557OMPClause *
10559 return getDerived().RebuildOMPDefaultClause(
10560 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10561 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10562 C->getEndLoc());
10563}
10564
10565template <typename Derived>
10566OMPClause *
10568 return getDerived().RebuildOMPProcBindClause(
10569 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10570 C->getLParenLoc(), C->getEndLoc());
10571}
10572
10573template <typename Derived>
10574OMPClause *
10576 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10577 if (E.isInvalid())
10578 return nullptr;
10579 return getDerived().RebuildOMPScheduleClause(
10580 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10581 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10582 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10583 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10584}
10585
10586template <typename Derived>
10587OMPClause *
10589 ExprResult E;
10590 if (auto *Num = C->getNumForLoops()) {
10591 E = getDerived().TransformExpr(Num);
10592 if (E.isInvalid())
10593 return nullptr;
10594 }
10595 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10596 C->getLParenLoc(), E.get());
10597}
10598
10599template <typename Derived>
10600OMPClause *
10602 ExprResult E;
10603 if (Expr *Evt = C->getEventHandler()) {
10604 E = getDerived().TransformExpr(Evt);
10605 if (E.isInvalid())
10606 return nullptr;
10607 }
10608 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10609 C->getLParenLoc(), C->getEndLoc());
10610}
10611
10612template <typename Derived>
10613OMPClause *
10615 // No need to rebuild this clause, no template-dependent parameters.
10616 return C;
10617}
10618
10619template <typename Derived>
10620OMPClause *
10622 // No need to rebuild this clause, no template-dependent parameters.
10623 return C;
10624}
10625
10626template <typename Derived>
10627OMPClause *
10629 // No need to rebuild this clause, no template-dependent parameters.
10630 return C;
10631}
10632
10633template <typename Derived>
10635 // No need to rebuild this clause, no template-dependent parameters.
10636 return C;
10637}
10638
10639template <typename Derived>
10641 // No need to rebuild this clause, no template-dependent parameters.
10642 return C;
10643}
10644
10645template <typename Derived>
10646OMPClause *
10648 // No need to rebuild this clause, no template-dependent parameters.
10649 return C;
10650}
10651
10652template <typename Derived>
10653OMPClause *
10655 // No need to rebuild this clause, no template-dependent parameters.
10656 return C;
10657}
10658
10659template <typename Derived>
10660OMPClause *
10662 // No need to rebuild this clause, no template-dependent parameters.
10663 return C;
10664}
10665
10666template <typename Derived>
10668 // No need to rebuild this clause, no template-dependent parameters.
10669 return C;
10670}
10671
10672template <typename Derived>
10673OMPClause *
10675 return C;
10676}
10677
10678template <typename Derived>
10680 ExprResult E = getDerived().TransformExpr(C->getExpr());
10681 if (E.isInvalid())
10682 return nullptr;
10683 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10684 C->getLParenLoc(), C->getEndLoc());
10685}
10686
10687template <typename Derived>
10688OMPClause *
10690 return C;
10691}
10692
10693template <typename Derived>
10694OMPClause *
10696 return C;
10697}
10698template <typename Derived>
10701 return C;
10702}
10703template <typename Derived>
10706 return C;
10707}
10708template <typename Derived>
10711 return C;
10712}
10713
10714template <typename Derived>
10715OMPClause *
10717 // No need to rebuild this clause, no template-dependent parameters.
10718 return C;
10719}
10720
10721template <typename Derived>
10722OMPClause *
10724 // No need to rebuild this clause, no template-dependent parameters.
10725 return C;
10726}
10727
10728template <typename Derived>
10729OMPClause *
10731 // No need to rebuild this clause, no template-dependent parameters.
10732 return C;
10733}
10734
10735template <typename Derived>
10736OMPClause *
10738 // No need to rebuild this clause, no template-dependent parameters.
10739 return C;
10740}
10741
10742template <typename Derived>
10743OMPClause *
10745 // No need to rebuild this clause, no template-dependent parameters.
10746 return C;
10747}
10748
10749template <typename Derived>
10751 // No need to rebuild this clause, no template-dependent parameters.
10752 return C;
10753}
10754
10755template <typename Derived>
10756OMPClause *
10758 // No need to rebuild this clause, no template-dependent parameters.
10759 return C;
10760}
10761
10762template <typename Derived>
10764 // No need to rebuild this clause, no template-dependent parameters.
10765 return C;
10766}
10767
10768template <typename Derived>
10769OMPClause *
10771 // No need to rebuild this clause, no template-dependent parameters.
10772 return C;
10773}
10774
10775template <typename Derived>
10777 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10778 if (IVR.isInvalid())
10779 return nullptr;
10780
10781 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10782 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10783 for (Expr *E : llvm::drop_begin(C->varlist())) {
10784 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10785 if (ER.isInvalid())
10786 return nullptr;
10787 InteropInfo.PreferTypes.push_back(ER.get());
10788 }
10789 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10790 C->getBeginLoc(), C->getLParenLoc(),
10791 C->getVarLoc(), C->getEndLoc());
10792}
10793
10794template <typename Derived>
10796 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10797 if (ER.isInvalid())
10798 return nullptr;
10799 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10800 C->getLParenLoc(), C->getVarLoc(),
10801 C->getEndLoc());
10802}
10803
10804template <typename Derived>
10805OMPClause *
10807 ExprResult ER;
10808 if (Expr *IV = C->getInteropVar()) {
10809 ER = getDerived().TransformExpr(IV);
10810 if (ER.isInvalid())
10811 return nullptr;
10812 }
10813 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10814 C->getLParenLoc(), C->getVarLoc(),
10815 C->getEndLoc());
10816}
10817
10818template <typename Derived>
10819OMPClause *
10821 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10822 if (Cond.isInvalid())
10823 return nullptr;
10824 return getDerived().RebuildOMPNovariantsClause(
10825 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10826}
10827
10828template <typename Derived>
10829OMPClause *
10831 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10832 if (Cond.isInvalid())
10833 return nullptr;
10834 return getDerived().RebuildOMPNocontextClause(
10835 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10836}
10837
10838template <typename Derived>
10839OMPClause *
10841 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10842 if (ThreadID.isInvalid())
10843 return nullptr;
10844 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10845 C->getLParenLoc(), C->getEndLoc());
10846}
10847
10848template <typename Derived>
10850 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10851 if (E.isInvalid())
10852 return nullptr;
10853 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10854 C->getLParenLoc(), C->getEndLoc());
10855}
10856
10857template <typename Derived>
10860 llvm_unreachable("unified_address clause cannot appear in dependent context");
10861}
10862
10863template <typename Derived>
10866 llvm_unreachable(
10867 "unified_shared_memory clause cannot appear in dependent context");
10868}
10869
10870template <typename Derived>
10873 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10874}
10875
10876template <typename Derived>
10879 llvm_unreachable(
10880 "dynamic_allocators clause cannot appear in dependent context");
10881}
10882
10883template <typename Derived>
10886 llvm_unreachable(
10887 "atomic_default_mem_order clause cannot appear in dependent context");
10888}
10889
10890template <typename Derived>
10891OMPClause *
10893 llvm_unreachable("self_maps clause cannot appear in dependent context");
10894}
10895
10896template <typename Derived>
10898 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10899 C->getBeginLoc(), C->getLParenLoc(),
10900 C->getEndLoc());
10901}
10902
10903template <typename Derived>
10904OMPClause *
10906 return getDerived().RebuildOMPSeverityClause(
10907 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10908 C->getLParenLoc(), C->getEndLoc());
10909}
10910
10911template <typename Derived>
10912OMPClause *
10914 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10915 if (E.isInvalid())
10916 return nullptr;
10917 return getDerived().RebuildOMPMessageClause(
10918 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10919}
10920
10921template <typename Derived>
10922OMPClause *
10925 Vars.reserve(C->varlist_size());
10926 for (auto *VE : C->varlist()) {
10927 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10928 if (EVar.isInvalid())
10929 return nullptr;
10930 Vars.push_back(EVar.get());
10931 }
10932 return getDerived().RebuildOMPPrivateClause(
10933 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10934}
10935
10936template <typename Derived>
10940 Vars.reserve(C->varlist_size());
10941 for (auto *VE : C->varlist()) {
10942 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10943 if (EVar.isInvalid())
10944 return nullptr;
10945 Vars.push_back(EVar.get());
10946 }
10947 return getDerived().RebuildOMPFirstprivateClause(
10948 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10949}
10950
10951template <typename Derived>
10952OMPClause *
10955 Vars.reserve(C->varlist_size());
10956 for (auto *VE : C->varlist()) {
10957 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10958 if (EVar.isInvalid())
10959 return nullptr;
10960 Vars.push_back(EVar.get());
10961 }
10962 return getDerived().RebuildOMPLastprivateClause(
10963 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10964 C->getLParenLoc(), C->getEndLoc());
10965}
10966
10967template <typename Derived>
10968OMPClause *
10971 Vars.reserve(C->varlist_size());
10972 for (auto *VE : C->varlist()) {
10973 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10974 if (EVar.isInvalid())
10975 return nullptr;
10976 Vars.push_back(EVar.get());
10977 }
10978 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10979 C->getLParenLoc(), C->getEndLoc());
10980}
10981
10982template <typename Derived>
10983OMPClause *
10986 Vars.reserve(C->varlist_size());
10987 for (auto *VE : C->varlist()) {
10988 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10989 if (EVar.isInvalid())
10990 return nullptr;
10991 Vars.push_back(EVar.get());
10992 }
10993 CXXScopeSpec ReductionIdScopeSpec;
10994 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10995
10996 DeclarationNameInfo NameInfo = C->getNameInfo();
10997 if (NameInfo.getName()) {
10998 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10999 if (!NameInfo.getName())
11000 return nullptr;
11001 }
11002 // Build a list of all UDR decls with the same names ranged by the Scopes.
11003 // The Scope boundary is a duplication of the previous decl.
11004 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11005 for (auto *E : C->reduction_ops()) {
11006 // Transform all the decls.
11007 if (E) {
11008 auto *ULE = cast<UnresolvedLookupExpr>(E);
11009 UnresolvedSet<8> Decls;
11010 for (auto *D : ULE->decls()) {
11011 NamedDecl *InstD =
11012 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11013 Decls.addDecl(InstD, InstD->getAccess());
11014 }
11015 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11016 SemaRef.Context, /*NamingClass=*/nullptr,
11017 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11018 /*ADL=*/true, Decls.begin(), Decls.end(),
11019 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11020 } else
11021 UnresolvedReductions.push_back(nullptr);
11022 }
11023 return getDerived().RebuildOMPReductionClause(
11024 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11025 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11026 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11027}
11028
11029template <typename Derived>
11033 Vars.reserve(C->varlist_size());
11034 for (auto *VE : C->varlist()) {
11035 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11036 if (EVar.isInvalid())
11037 return nullptr;
11038 Vars.push_back(EVar.get());
11039 }
11040 CXXScopeSpec ReductionIdScopeSpec;
11041 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11042
11043 DeclarationNameInfo NameInfo = C->getNameInfo();
11044 if (NameInfo.getName()) {
11045 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11046 if (!NameInfo.getName())
11047 return nullptr;
11048 }
11049 // Build a list of all UDR decls with the same names ranged by the Scopes.
11050 // The Scope boundary is a duplication of the previous decl.
11051 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11052 for (auto *E : C->reduction_ops()) {
11053 // Transform all the decls.
11054 if (E) {
11055 auto *ULE = cast<UnresolvedLookupExpr>(E);
11056 UnresolvedSet<8> Decls;
11057 for (auto *D : ULE->decls()) {
11058 NamedDecl *InstD =
11059 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11060 Decls.addDecl(InstD, InstD->getAccess());
11061 }
11062 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11063 SemaRef.Context, /*NamingClass=*/nullptr,
11064 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11065 /*ADL=*/true, Decls.begin(), Decls.end(),
11066 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11067 } else
11068 UnresolvedReductions.push_back(nullptr);
11069 }
11070 return getDerived().RebuildOMPTaskReductionClause(
11071 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11072 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11073}
11074
11075template <typename Derived>
11076OMPClause *
11079 Vars.reserve(C->varlist_size());
11080 for (auto *VE : C->varlist()) {
11081 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11082 if (EVar.isInvalid())
11083 return nullptr;
11084 Vars.push_back(EVar.get());
11085 }
11086 CXXScopeSpec ReductionIdScopeSpec;
11087 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11088
11089 DeclarationNameInfo NameInfo = C->getNameInfo();
11090 if (NameInfo.getName()) {
11091 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11092 if (!NameInfo.getName())
11093 return nullptr;
11094 }
11095 // Build a list of all UDR decls with the same names ranged by the Scopes.
11096 // The Scope boundary is a duplication of the previous decl.
11097 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11098 for (auto *E : C->reduction_ops()) {
11099 // Transform all the decls.
11100 if (E) {
11101 auto *ULE = cast<UnresolvedLookupExpr>(E);
11102 UnresolvedSet<8> Decls;
11103 for (auto *D : ULE->decls()) {
11104 NamedDecl *InstD =
11105 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11106 Decls.addDecl(InstD, InstD->getAccess());
11107 }
11108 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11109 SemaRef.Context, /*NamingClass=*/nullptr,
11110 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11111 /*ADL=*/true, Decls.begin(), Decls.end(),
11112 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11113 } else
11114 UnresolvedReductions.push_back(nullptr);
11115 }
11116 return getDerived().RebuildOMPInReductionClause(
11117 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11118 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11119}
11120
11121template <typename Derived>
11122OMPClause *
11125 Vars.reserve(C->varlist_size());
11126 for (auto *VE : C->varlist()) {
11127 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11128 if (EVar.isInvalid())
11129 return nullptr;
11130 Vars.push_back(EVar.get());
11131 }
11132 ExprResult Step = getDerived().TransformExpr(C->getStep());
11133 if (Step.isInvalid())
11134 return nullptr;
11135 return getDerived().RebuildOMPLinearClause(
11136 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11137 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11138 C->getEndLoc());
11139}
11140
11141template <typename Derived>
11142OMPClause *
11145 Vars.reserve(C->varlist_size());
11146 for (auto *VE : C->varlist()) {
11147 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11148 if (EVar.isInvalid())
11149 return nullptr;
11150 Vars.push_back(EVar.get());
11151 }
11152 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11153 if (Alignment.isInvalid())
11154 return nullptr;
11155 return getDerived().RebuildOMPAlignedClause(
11156 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11157 C->getColonLoc(), C->getEndLoc());
11158}
11159
11160template <typename Derived>
11161OMPClause *
11164 Vars.reserve(C->varlist_size());
11165 for (auto *VE : C->varlist()) {
11166 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11167 if (EVar.isInvalid())
11168 return nullptr;
11169 Vars.push_back(EVar.get());
11170 }
11171 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11172 C->getLParenLoc(), C->getEndLoc());
11173}
11174
11175template <typename Derived>
11176OMPClause *
11179 Vars.reserve(C->varlist_size());
11180 for (auto *VE : C->varlist()) {
11181 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11182 if (EVar.isInvalid())
11183 return nullptr;
11184 Vars.push_back(EVar.get());
11185 }
11186 return getDerived().RebuildOMPCopyprivateClause(
11187 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11188}
11189
11190template <typename Derived>
11193 Vars.reserve(C->varlist_size());
11194 for (auto *VE : C->varlist()) {
11195 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11196 if (EVar.isInvalid())
11197 return nullptr;
11198 Vars.push_back(EVar.get());
11199 }
11200 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11201 C->getLParenLoc(), C->getEndLoc());
11202}
11203
11204template <typename Derived>
11205OMPClause *
11207 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11208 if (E.isInvalid())
11209 return nullptr;
11210 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11211 C->getLParenLoc(), C->getEndLoc());
11212}
11213
11214template <typename Derived>
11215OMPClause *
11218 Expr *DepModifier = C->getModifier();
11219 if (DepModifier) {
11220 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11221 if (DepModRes.isInvalid())
11222 return nullptr;
11223 DepModifier = DepModRes.get();
11224 }
11225 Vars.reserve(C->varlist_size());
11226 for (auto *VE : C->varlist()) {
11227 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11228 if (EVar.isInvalid())
11229 return nullptr;
11230 Vars.push_back(EVar.get());
11231 }
11232 return getDerived().RebuildOMPDependClause(
11233 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11234 C->getOmpAllMemoryLoc()},
11235 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11236}
11237
11238template <typename Derived>
11239OMPClause *
11241 ExprResult E = getDerived().TransformExpr(C->getDevice());
11242 if (E.isInvalid())
11243 return nullptr;
11244 return getDerived().RebuildOMPDeviceClause(
11245 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11246 C->getModifierLoc(), C->getEndLoc());
11247}
11248
11249template <typename Derived, class T>
11252 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11253 DeclarationNameInfo &MapperIdInfo,
11254 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11255 // Transform expressions in the list.
11256 Vars.reserve(C->varlist_size());
11257 for (auto *VE : C->varlist()) {
11258 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11259 if (EVar.isInvalid())
11260 return true;
11261 Vars.push_back(EVar.get());
11262 }
11263 // Transform mapper scope specifier and identifier.
11264 NestedNameSpecifierLoc QualifierLoc;
11265 if (C->getMapperQualifierLoc()) {
11266 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11267 C->getMapperQualifierLoc());
11268 if (!QualifierLoc)
11269 return true;
11270 }
11271 MapperIdScopeSpec.Adopt(QualifierLoc);
11272 MapperIdInfo = C->getMapperIdInfo();
11273 if (MapperIdInfo.getName()) {
11274 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11275 if (!MapperIdInfo.getName())
11276 return true;
11277 }
11278 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11279 // the previous user-defined mapper lookup in dependent environment.
11280 for (auto *E : C->mapperlists()) {
11281 // Transform all the decls.
11282 if (E) {
11283 auto *ULE = cast<UnresolvedLookupExpr>(E);
11284 UnresolvedSet<8> Decls;
11285 for (auto *D : ULE->decls()) {
11286 NamedDecl *InstD =
11287 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11288 Decls.addDecl(InstD, InstD->getAccess());
11289 }
11290 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11291 TT.getSema().Context, /*NamingClass=*/nullptr,
11292 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11293 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11294 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11295 } else {
11296 UnresolvedMappers.push_back(nullptr);
11297 }
11298 }
11299 return false;
11300}
11301
11302template <typename Derived>
11303OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11304 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11306 Expr *IteratorModifier = C->getIteratorModifier();
11307 if (IteratorModifier) {
11308 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11309 if (MapModRes.isInvalid())
11310 return nullptr;
11311 IteratorModifier = MapModRes.get();
11312 }
11313 CXXScopeSpec MapperIdScopeSpec;
11314 DeclarationNameInfo MapperIdInfo;
11315 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11317 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11318 return nullptr;
11319 return getDerived().RebuildOMPMapClause(
11320 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11321 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11322 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11323}
11324
11325template <typename Derived>
11326OMPClause *
11328 Expr *Allocator = C->getAllocator();
11329 if (Allocator) {
11330 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11331 if (AllocatorRes.isInvalid())
11332 return nullptr;
11333 Allocator = AllocatorRes.get();
11334 }
11335 Expr *Alignment = C->getAlignment();
11336 if (Alignment) {
11337 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11338 if (AlignmentRes.isInvalid())
11339 return nullptr;
11340 Alignment = AlignmentRes.get();
11341 }
11343 Vars.reserve(C->varlist_size());
11344 for (auto *VE : C->varlist()) {
11345 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11346 if (EVar.isInvalid())
11347 return nullptr;
11348 Vars.push_back(EVar.get());
11349 }
11350 return getDerived().RebuildOMPAllocateClause(
11351 Allocator, Alignment, C->getFirstAllocateModifier(),
11352 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11353 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11354 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11355}
11356
11357template <typename Derived>
11358OMPClause *
11361 Vars.reserve(C->varlist_size());
11362 for (auto *VE : C->varlist()) {
11363 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11364 if (EVar.isInvalid())
11365 return nullptr;
11366 Vars.push_back(EVar.get());
11367 }
11368 return getDerived().RebuildOMPNumTeamsClause(
11369 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11370}
11371
11372template <typename Derived>
11373OMPClause *
11376 Vars.reserve(C->varlist_size());
11377 for (auto *VE : C->varlist()) {
11378 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11379 if (EVar.isInvalid())
11380 return nullptr;
11381 Vars.push_back(EVar.get());
11382 }
11383 return getDerived().RebuildOMPThreadLimitClause(
11384 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11385}
11386
11387template <typename Derived>
11388OMPClause *
11390 ExprResult E = getDerived().TransformExpr(C->getPriority());
11391 if (E.isInvalid())
11392 return nullptr;
11393 return getDerived().RebuildOMPPriorityClause(
11394 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11395}
11396
11397template <typename Derived>
11398OMPClause *
11400 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11401 if (E.isInvalid())
11402 return nullptr;
11403 return getDerived().RebuildOMPGrainsizeClause(
11404 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11405 C->getModifierLoc(), C->getEndLoc());
11406}
11407
11408template <typename Derived>
11409OMPClause *
11411 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11412 if (E.isInvalid())
11413 return nullptr;
11414 return getDerived().RebuildOMPNumTasksClause(
11415 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11416 C->getModifierLoc(), C->getEndLoc());
11417}
11418
11419template <typename Derived>
11421 ExprResult E = getDerived().TransformExpr(C->getHint());
11422 if (E.isInvalid())
11423 return nullptr;
11424 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11425 C->getLParenLoc(), C->getEndLoc());
11426}
11427
11428template <typename Derived>
11431 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11432 if (E.isInvalid())
11433 return nullptr;
11434 return getDerived().RebuildOMPDistScheduleClause(
11435 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11436 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11437}
11438
11439template <typename Derived>
11440OMPClause *
11442 // Rebuild Defaultmap Clause since we need to invoke the checking of
11443 // defaultmap(none:variable-category) after template initialization.
11444 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11445 C->getDefaultmapKind(),
11446 C->getBeginLoc(),
11447 C->getLParenLoc(),
11448 C->getDefaultmapModifierLoc(),
11449 C->getDefaultmapKindLoc(),
11450 C->getEndLoc());
11451}
11452
11453template <typename Derived>
11455 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11457 CXXScopeSpec MapperIdScopeSpec;
11458 DeclarationNameInfo MapperIdInfo;
11459 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11461 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11462 return nullptr;
11463 return getDerived().RebuildOMPToClause(
11464 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11465 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11466}
11467
11468template <typename Derived>
11470 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11472 CXXScopeSpec MapperIdScopeSpec;
11473 DeclarationNameInfo MapperIdInfo;
11474 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11476 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11477 return nullptr;
11478 return getDerived().RebuildOMPFromClause(
11479 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11480 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11481}
11482
11483template <typename Derived>
11487 Vars.reserve(C->varlist_size());
11488 for (auto *VE : C->varlist()) {
11489 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11490 if (EVar.isInvalid())
11491 return nullptr;
11492 Vars.push_back(EVar.get());
11493 }
11494 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11495 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11496}
11497
11498template <typename Derived>
11502 Vars.reserve(C->varlist_size());
11503 for (auto *VE : C->varlist()) {
11504 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11505 if (EVar.isInvalid())
11506 return nullptr;
11507 Vars.push_back(EVar.get());
11508 }
11509 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11510 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11511}
11512
11513template <typename Derived>
11514OMPClause *
11517 Vars.reserve(C->varlist_size());
11518 for (auto *VE : C->varlist()) {
11519 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11520 if (EVar.isInvalid())
11521 return nullptr;
11522 Vars.push_back(EVar.get());
11523 }
11524 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11525 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11526}
11527
11528template <typename Derived>
11532 Vars.reserve(C->varlist_size());
11533 for (auto *VE : C->varlist()) {
11534 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11535 if (EVar.isInvalid())
11536 return nullptr;
11537 Vars.push_back(EVar.get());
11538 }
11539 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11540 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11541}
11542
11543template <typename Derived>
11544OMPClause *
11547 Vars.reserve(C->varlist_size());
11548 for (auto *VE : C->varlist()) {
11549 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11550 if (EVar.isInvalid())
11551 return nullptr;
11552 Vars.push_back(EVar.get());
11553 }
11554 return getDerived().RebuildOMPNontemporalClause(
11555 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11556}
11557
11558template <typename Derived>
11559OMPClause *
11562 Vars.reserve(C->varlist_size());
11563 for (auto *VE : C->varlist()) {
11564 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11565 if (EVar.isInvalid())
11566 return nullptr;
11567 Vars.push_back(EVar.get());
11568 }
11569 return getDerived().RebuildOMPInclusiveClause(
11570 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11571}
11572
11573template <typename Derived>
11574OMPClause *
11577 Vars.reserve(C->varlist_size());
11578 for (auto *VE : C->varlist()) {
11579 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11580 if (EVar.isInvalid())
11581 return nullptr;
11582 Vars.push_back(EVar.get());
11583 }
11584 return getDerived().RebuildOMPExclusiveClause(
11585 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11586}
11587
11588template <typename Derived>
11592 Data.reserve(C->getNumberOfAllocators());
11593 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11594 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11595 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11596 if (Allocator.isInvalid())
11597 continue;
11598 ExprResult AllocatorTraits;
11599 if (Expr *AT = D.AllocatorTraits) {
11600 AllocatorTraits = getDerived().TransformExpr(AT);
11601 if (AllocatorTraits.isInvalid())
11602 continue;
11603 }
11604 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11605 NewD.Allocator = Allocator.get();
11606 NewD.AllocatorTraits = AllocatorTraits.get();
11607 NewD.LParenLoc = D.LParenLoc;
11608 NewD.RParenLoc = D.RParenLoc;
11609 }
11610 return getDerived().RebuildOMPUsesAllocatorsClause(
11611 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11612}
11613
11614template <typename Derived>
11615OMPClause *
11617 SmallVector<Expr *, 4> Locators;
11618 Locators.reserve(C->varlist_size());
11619 ExprResult ModifierRes;
11620 if (Expr *Modifier = C->getModifier()) {
11621 ModifierRes = getDerived().TransformExpr(Modifier);
11622 if (ModifierRes.isInvalid())
11623 return nullptr;
11624 }
11625 for (Expr *E : C->varlist()) {
11626 ExprResult Locator = getDerived().TransformExpr(E);
11627 if (Locator.isInvalid())
11628 continue;
11629 Locators.push_back(Locator.get());
11630 }
11631 return getDerived().RebuildOMPAffinityClause(
11632 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11633 ModifierRes.get(), Locators);
11634}
11635
11636template <typename Derived>
11638 return getDerived().RebuildOMPOrderClause(
11639 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11640 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11641}
11642
11643template <typename Derived>
11645 return getDerived().RebuildOMPBindClause(
11646 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11647 C->getLParenLoc(), C->getEndLoc());
11648}
11649
11650template <typename Derived>
11653 ExprResult Size = getDerived().TransformExpr(C->getSize());
11654 if (Size.isInvalid())
11655 return nullptr;
11656 return getDerived().RebuildOMPXDynCGroupMemClause(
11657 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11658}
11659
11660template <typename Derived>
11661OMPClause *
11664 Vars.reserve(C->varlist_size());
11665 for (auto *VE : C->varlist()) {
11666 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11667 if (EVar.isInvalid())
11668 return nullptr;
11669 Vars.push_back(EVar.get());
11670 }
11671 return getDerived().RebuildOMPDoacrossClause(
11672 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11673 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11674}
11675
11676template <typename Derived>
11677OMPClause *
11680 for (auto *A : C->getAttrs())
11681 NewAttrs.push_back(getDerived().TransformAttr(A));
11682 return getDerived().RebuildOMPXAttributeClause(
11683 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11684}
11685
11686template <typename Derived>
11688 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11689}
11690
11691//===----------------------------------------------------------------------===//
11692// OpenACC transformation
11693//===----------------------------------------------------------------------===//
11694namespace {
11695template <typename Derived>
11696class OpenACCClauseTransform final
11697 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11698 TreeTransform<Derived> &Self;
11699 ArrayRef<const OpenACCClause *> ExistingClauses;
11700 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11701 OpenACCClause *NewClause = nullptr;
11702
11703 ExprResult VisitVar(Expr *VarRef) {
11704 ExprResult Res = Self.TransformExpr(VarRef);
11705
11706 if (!Res.isUsable())
11707 return Res;
11708
11709 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11710 ParsedClause.getClauseKind(),
11711 Res.get());
11712
11713 return Res;
11714 }
11715
11716 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11717 llvm::SmallVector<Expr *> InstantiatedVarList;
11718 for (Expr *CurVar : VarList) {
11719 ExprResult VarRef = VisitVar(CurVar);
11720
11721 if (VarRef.isUsable())
11722 InstantiatedVarList.push_back(VarRef.get());
11723 }
11724
11725 return InstantiatedVarList;
11726 }
11727
11728public:
11729 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11730 ArrayRef<const OpenACCClause *> ExistingClauses,
11731 SemaOpenACC::OpenACCParsedClause &PC)
11732 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11733
11734 OpenACCClause *CreatedClause() const { return NewClause; }
11735
11736#define VISIT_CLAUSE(CLAUSE_NAME) \
11737 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11738#include "clang/Basic/OpenACCClauses.def"
11739};
11740
11741template <typename Derived>
11742void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11743 const OpenACCDefaultClause &C) {
11744 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11745
11746 NewClause = OpenACCDefaultClause::Create(
11747 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11748 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11749 ParsedClause.getEndLoc());
11750}
11751
11752template <typename Derived>
11753void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11754 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11755 assert(Cond && "If constructed with invalid Condition");
11756 Sema::ConditionResult Res = Self.TransformCondition(
11757 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11758
11759 if (Res.isInvalid() || !Res.get().second)
11760 return;
11761
11762 ParsedClause.setConditionDetails(Res.get().second);
11763
11764 NewClause = OpenACCIfClause::Create(
11765 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11766 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11767 ParsedClause.getEndLoc());
11768}
11769
11770template <typename Derived>
11771void OpenACCClauseTransform<Derived>::VisitSelfClause(
11772 const OpenACCSelfClause &C) {
11773
11774 // If this is an 'update' 'self' clause, this is actually a var list instead.
11775 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11776 llvm::SmallVector<Expr *> InstantiatedVarList;
11777 for (Expr *CurVar : C.getVarList()) {
11778 ExprResult Res = Self.TransformExpr(CurVar);
11779
11780 if (!Res.isUsable())
11781 continue;
11782
11783 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11784 ParsedClause.getClauseKind(),
11785 Res.get());
11786
11787 if (Res.isUsable())
11788 InstantiatedVarList.push_back(Res.get());
11789 }
11790
11791 ParsedClause.setVarListDetails(InstantiatedVarList,
11793
11794 NewClause = OpenACCSelfClause::Create(
11795 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11796 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11797 ParsedClause.getEndLoc());
11798 } else {
11799
11800 if (C.hasConditionExpr()) {
11801 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11803 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11805
11806 if (Res.isInvalid() || !Res.get().second)
11807 return;
11808
11809 ParsedClause.setConditionDetails(Res.get().second);
11810 }
11811
11812 NewClause = OpenACCSelfClause::Create(
11813 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11814 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11815 ParsedClause.getEndLoc());
11816 }
11817}
11818
11819template <typename Derived>
11820void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11821 const OpenACCNumGangsClause &C) {
11822 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11823
11824 for (Expr *CurIntExpr : C.getIntExprs()) {
11825 ExprResult Res = Self.TransformExpr(CurIntExpr);
11826
11827 if (!Res.isUsable())
11828 return;
11829
11830 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11831 C.getClauseKind(),
11832 C.getBeginLoc(), Res.get());
11833 if (!Res.isUsable())
11834 return;
11835
11836 InstantiatedIntExprs.push_back(Res.get());
11837 }
11838
11839 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11841 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11842 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11843 ParsedClause.getEndLoc());
11844}
11845
11846template <typename Derived>
11847void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11848 const OpenACCPrivateClause &C) {
11849 llvm::SmallVector<Expr *> InstantiatedVarList;
11851
11852 for (const auto [RefExpr, InitRecipe] :
11853 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11854 ExprResult VarRef = VisitVar(RefExpr);
11855
11856 if (VarRef.isUsable()) {
11857 InstantiatedVarList.push_back(VarRef.get());
11858
11859 // We only have to create a new one if it is dependent, and Sema won't
11860 // make one of these unless the type is non-dependent.
11861 if (InitRecipe.isSet())
11862 InitRecipes.push_back(InitRecipe);
11863 else
11864 InitRecipes.push_back(
11865 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
11866 }
11867 }
11868 ParsedClause.setVarListDetails(InstantiatedVarList,
11870
11871 NewClause = OpenACCPrivateClause::Create(
11872 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11873 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11874 ParsedClause.getEndLoc());
11875}
11876
11877template <typename Derived>
11878void OpenACCClauseTransform<Derived>::VisitHostClause(
11879 const OpenACCHostClause &C) {
11880 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11882
11883 NewClause = OpenACCHostClause::Create(
11884 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11885 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11886 ParsedClause.getEndLoc());
11887}
11888
11889template <typename Derived>
11890void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11891 const OpenACCDeviceClause &C) {
11892 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11894
11895 NewClause = OpenACCDeviceClause::Create(
11896 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11897 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11898 ParsedClause.getEndLoc());
11899}
11900
11901template <typename Derived>
11902void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11904 llvm::SmallVector<Expr *> InstantiatedVarList;
11906
11907 for (const auto [RefExpr, InitRecipe] :
11908 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11909 ExprResult VarRef = VisitVar(RefExpr);
11910
11911 if (VarRef.isUsable()) {
11912 InstantiatedVarList.push_back(VarRef.get());
11913
11914 // We only have to create a new one if it is dependent, and Sema won't
11915 // make one of these unless the type is non-dependent.
11916 if (InitRecipe.isSet())
11917 InitRecipes.push_back(InitRecipe);
11918 else
11919 InitRecipes.push_back(
11920 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
11921 VarRef.get()));
11922 }
11923 }
11924 ParsedClause.setVarListDetails(InstantiatedVarList,
11926
11928 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11929 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11930 ParsedClause.getEndLoc());
11931}
11932
11933template <typename Derived>
11934void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11935 const OpenACCNoCreateClause &C) {
11936 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11938
11940 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11941 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11942 ParsedClause.getEndLoc());
11943}
11944
11945template <typename Derived>
11946void OpenACCClauseTransform<Derived>::VisitPresentClause(
11947 const OpenACCPresentClause &C) {
11948 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11950
11951 NewClause = OpenACCPresentClause::Create(
11952 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11953 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11954 ParsedClause.getEndLoc());
11955}
11956
11957template <typename Derived>
11958void OpenACCClauseTransform<Derived>::VisitCopyClause(
11959 const OpenACCCopyClause &C) {
11960 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11961 C.getModifierList());
11962
11963 NewClause = OpenACCCopyClause::Create(
11964 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11965 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11966 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11967 ParsedClause.getEndLoc());
11968}
11969
11970template <typename Derived>
11971void OpenACCClauseTransform<Derived>::VisitLinkClause(
11972 const OpenACCLinkClause &C) {
11973 llvm_unreachable("link clause not valid unless a decl transform");
11974}
11975
11976template <typename Derived>
11977void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
11979 llvm_unreachable("device_resident clause not valid unless a decl transform");
11980}
11981template <typename Derived>
11982void OpenACCClauseTransform<Derived>::VisitNoHostClause(
11983 const OpenACCNoHostClause &C) {
11984 llvm_unreachable("nohost clause not valid unless a decl transform");
11985}
11986template <typename Derived>
11987void OpenACCClauseTransform<Derived>::VisitBindClause(
11988 const OpenACCBindClause &C) {
11989 llvm_unreachable("bind clause not valid unless a decl transform");
11990}
11991
11992template <typename Derived>
11993void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11994 const OpenACCCopyInClause &C) {
11995 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11996 C.getModifierList());
11997
11998 NewClause = OpenACCCopyInClause::Create(
11999 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12000 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12001 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12002 ParsedClause.getEndLoc());
12003}
12004
12005template <typename Derived>
12006void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12007 const OpenACCCopyOutClause &C) {
12008 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12009 C.getModifierList());
12010
12011 NewClause = OpenACCCopyOutClause::Create(
12012 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12013 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12014 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12015 ParsedClause.getEndLoc());
12016}
12017
12018template <typename Derived>
12019void OpenACCClauseTransform<Derived>::VisitCreateClause(
12020 const OpenACCCreateClause &C) {
12021 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12022 C.getModifierList());
12023
12024 NewClause = OpenACCCreateClause::Create(
12025 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12026 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12027 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12028 ParsedClause.getEndLoc());
12029}
12030template <typename Derived>
12031void OpenACCClauseTransform<Derived>::VisitAttachClause(
12032 const OpenACCAttachClause &C) {
12033 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12034
12035 // Ensure each var is a pointer type.
12036 llvm::erase_if(VarList, [&](Expr *E) {
12037 return Self.getSema().OpenACC().CheckVarIsPointerType(
12039 });
12040
12041 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12042 NewClause = OpenACCAttachClause::Create(
12043 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12044 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12045 ParsedClause.getEndLoc());
12046}
12047
12048template <typename Derived>
12049void OpenACCClauseTransform<Derived>::VisitDetachClause(
12050 const OpenACCDetachClause &C) {
12051 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12052
12053 // Ensure each var is a pointer type.
12054 llvm::erase_if(VarList, [&](Expr *E) {
12055 return Self.getSema().OpenACC().CheckVarIsPointerType(
12057 });
12058
12059 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12060 NewClause = OpenACCDetachClause::Create(
12061 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12062 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12063 ParsedClause.getEndLoc());
12064}
12065
12066template <typename Derived>
12067void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12068 const OpenACCDeleteClause &C) {
12069 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12071 NewClause = OpenACCDeleteClause::Create(
12072 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12073 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12074 ParsedClause.getEndLoc());
12075}
12076
12077template <typename Derived>
12078void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12079 const OpenACCUseDeviceClause &C) {
12080 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12083 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12084 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12085 ParsedClause.getEndLoc());
12086}
12087
12088template <typename Derived>
12089void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12090 const OpenACCDevicePtrClause &C) {
12091 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12092
12093 // Ensure each var is a pointer type.
12094 llvm::erase_if(VarList, [&](Expr *E) {
12095 return Self.getSema().OpenACC().CheckVarIsPointerType(
12097 });
12098
12099 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12101 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12102 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12103 ParsedClause.getEndLoc());
12104}
12105
12106template <typename Derived>
12107void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12108 const OpenACCNumWorkersClause &C) {
12109 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12110 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12111
12112 ExprResult Res = Self.TransformExpr(IntExpr);
12113 if (!Res.isUsable())
12114 return;
12115
12116 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12117 C.getClauseKind(),
12118 C.getBeginLoc(), Res.get());
12119 if (!Res.isUsable())
12120 return;
12121
12122 ParsedClause.setIntExprDetails(Res.get());
12124 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12125 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12126 ParsedClause.getEndLoc());
12127}
12128
12129template <typename Derived>
12130void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12131 const OpenACCDeviceNumClause &C) {
12132 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12133 assert(IntExpr && "device_num clause constructed with invalid int expr");
12134
12135 ExprResult Res = Self.TransformExpr(IntExpr);
12136 if (!Res.isUsable())
12137 return;
12138
12139 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12140 C.getClauseKind(),
12141 C.getBeginLoc(), Res.get());
12142 if (!Res.isUsable())
12143 return;
12144
12145 ParsedClause.setIntExprDetails(Res.get());
12147 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12148 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12149 ParsedClause.getEndLoc());
12150}
12151
12152template <typename Derived>
12153void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12155 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12156 assert(IntExpr && "default_async clause constructed with invalid int expr");
12157
12158 ExprResult Res = Self.TransformExpr(IntExpr);
12159 if (!Res.isUsable())
12160 return;
12161
12162 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12163 C.getClauseKind(),
12164 C.getBeginLoc(), Res.get());
12165 if (!Res.isUsable())
12166 return;
12167
12168 ParsedClause.setIntExprDetails(Res.get());
12170 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12171 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12172 ParsedClause.getEndLoc());
12173}
12174
12175template <typename Derived>
12176void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12178 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12179 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12180
12181 ExprResult Res = Self.TransformExpr(IntExpr);
12182 if (!Res.isUsable())
12183 return;
12184
12185 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12186 C.getClauseKind(),
12187 C.getBeginLoc(), Res.get());
12188 if (!Res.isUsable())
12189 return;
12190
12191 ParsedClause.setIntExprDetails(Res.get());
12193 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12194 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12195 ParsedClause.getEndLoc());
12196}
12197
12198template <typename Derived>
12199void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12200 const OpenACCAsyncClause &C) {
12201 if (C.hasIntExpr()) {
12202 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12203 if (!Res.isUsable())
12204 return;
12205
12206 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12207 C.getClauseKind(),
12208 C.getBeginLoc(), Res.get());
12209 if (!Res.isUsable())
12210 return;
12211 ParsedClause.setIntExprDetails(Res.get());
12212 }
12213
12214 NewClause = OpenACCAsyncClause::Create(
12215 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12216 ParsedClause.getLParenLoc(),
12217 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12218 : nullptr,
12219 ParsedClause.getEndLoc());
12220}
12221
12222template <typename Derived>
12223void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12224 const OpenACCWorkerClause &C) {
12225 if (C.hasIntExpr()) {
12226 // restrictions on this expression are all "does it exist in certain
12227 // situations" that are not possible to be dependent, so the only check we
12228 // have is that it transforms, and is an int expression.
12229 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12230 if (!Res.isUsable())
12231 return;
12232
12233 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12234 C.getClauseKind(),
12235 C.getBeginLoc(), Res.get());
12236 if (!Res.isUsable())
12237 return;
12238 ParsedClause.setIntExprDetails(Res.get());
12239 }
12240
12241 NewClause = OpenACCWorkerClause::Create(
12242 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12243 ParsedClause.getLParenLoc(),
12244 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12245 : nullptr,
12246 ParsedClause.getEndLoc());
12247}
12248
12249template <typename Derived>
12250void OpenACCClauseTransform<Derived>::VisitVectorClause(
12251 const OpenACCVectorClause &C) {
12252 if (C.hasIntExpr()) {
12253 // restrictions on this expression are all "does it exist in certain
12254 // situations" that are not possible to be dependent, so the only check we
12255 // have is that it transforms, and is an int expression.
12256 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12257 if (!Res.isUsable())
12258 return;
12259
12260 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12261 C.getClauseKind(),
12262 C.getBeginLoc(), Res.get());
12263 if (!Res.isUsable())
12264 return;
12265 ParsedClause.setIntExprDetails(Res.get());
12266 }
12267
12268 NewClause = OpenACCVectorClause::Create(
12269 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12270 ParsedClause.getLParenLoc(),
12271 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12272 : nullptr,
12273 ParsedClause.getEndLoc());
12274}
12275
12276template <typename Derived>
12277void OpenACCClauseTransform<Derived>::VisitWaitClause(
12278 const OpenACCWaitClause &C) {
12279 if (C.hasExprs()) {
12280 Expr *DevNumExpr = nullptr;
12281 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12282
12283 // Instantiate devnum expr if it exists.
12284 if (C.getDevNumExpr()) {
12285 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12286 if (!Res.isUsable())
12287 return;
12288 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12289 C.getClauseKind(),
12290 C.getBeginLoc(), Res.get());
12291 if (!Res.isUsable())
12292 return;
12293
12294 DevNumExpr = Res.get();
12295 }
12296
12297 // Instantiate queue ids.
12298 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12299 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12300 if (!Res.isUsable())
12301 return;
12302 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12303 C.getClauseKind(),
12304 C.getBeginLoc(), Res.get());
12305 if (!Res.isUsable())
12306 return;
12307
12308 InstantiatedQueueIdExprs.push_back(Res.get());
12309 }
12310
12311 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12312 std::move(InstantiatedQueueIdExprs));
12313 }
12314
12315 NewClause = OpenACCWaitClause::Create(
12316 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12317 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12318 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12319 ParsedClause.getEndLoc());
12320}
12321
12322template <typename Derived>
12323void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12324 const OpenACCDeviceTypeClause &C) {
12325 // Nothing to transform here, just create a new version of 'C'.
12327 Self.getSema().getASTContext(), C.getClauseKind(),
12328 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12329 C.getArchitectures(), ParsedClause.getEndLoc());
12330}
12331
12332template <typename Derived>
12333void OpenACCClauseTransform<Derived>::VisitAutoClause(
12334 const OpenACCAutoClause &C) {
12335 // Nothing to do, so just create a new node.
12336 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12337 ParsedClause.getBeginLoc(),
12338 ParsedClause.getEndLoc());
12339}
12340
12341template <typename Derived>
12342void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12343 const OpenACCIndependentClause &C) {
12344 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12345 ParsedClause.getBeginLoc(),
12346 ParsedClause.getEndLoc());
12347}
12348
12349template <typename Derived>
12350void OpenACCClauseTransform<Derived>::VisitSeqClause(
12351 const OpenACCSeqClause &C) {
12352 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12353 ParsedClause.getBeginLoc(),
12354 ParsedClause.getEndLoc());
12355}
12356template <typename Derived>
12357void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12358 const OpenACCFinalizeClause &C) {
12359 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12360 ParsedClause.getBeginLoc(),
12361 ParsedClause.getEndLoc());
12362}
12363
12364template <typename Derived>
12365void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12366 const OpenACCIfPresentClause &C) {
12367 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12368 ParsedClause.getBeginLoc(),
12369 ParsedClause.getEndLoc());
12370}
12371
12372template <typename Derived>
12373void OpenACCClauseTransform<Derived>::VisitReductionClause(
12374 const OpenACCReductionClause &C) {
12375 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12376 SmallVector<Expr *> ValidVars;
12378
12379 for (const auto [Var, OrigRecipe] :
12380 llvm::zip(TransformedVars, C.getRecipes())) {
12381 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12382 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12383 if (Res.isUsable()) {
12384 ValidVars.push_back(Res.get());
12385
12386 if (OrigRecipe.isSet())
12387 Recipes.push_back(OrigRecipe);
12388 else
12389 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12390 C.getReductionOp(), Res.get()));
12391 }
12392 }
12393
12394 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12395 ExistingClauses, ParsedClause.getDirectiveKind(),
12396 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12397 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12398}
12399
12400template <typename Derived>
12401void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12402 const OpenACCCollapseClause &C) {
12403 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12404 assert(LoopCount && "collapse clause constructed with invalid loop count");
12405
12406 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12407
12408 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12409 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12410 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12411
12412 NewLoopCount =
12413 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12414
12415 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12417 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12418 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12419 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12420}
12421
12422template <typename Derived>
12423void OpenACCClauseTransform<Derived>::VisitTileClause(
12424 const OpenACCTileClause &C) {
12425
12426 llvm::SmallVector<Expr *> TransformedExprs;
12427
12428 for (Expr *E : C.getSizeExprs()) {
12429 ExprResult NewSizeExpr = Self.TransformExpr(E);
12430
12431 if (!NewSizeExpr.isUsable())
12432 return;
12433
12434 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12435 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12436 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12437
12438 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12439
12440 if (!NewSizeExpr.isUsable())
12441 return;
12442 TransformedExprs.push_back(NewSizeExpr.get());
12443 }
12444
12445 ParsedClause.setIntExprDetails(TransformedExprs);
12446 NewClause = OpenACCTileClause::Create(
12447 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12448 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12449 ParsedClause.getEndLoc());
12450}
12451template <typename Derived>
12452void OpenACCClauseTransform<Derived>::VisitGangClause(
12453 const OpenACCGangClause &C) {
12454 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12455 llvm::SmallVector<Expr *> TransformedIntExprs;
12456
12457 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12458 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12459 if (!ER.isUsable())
12460 continue;
12461
12462 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12463 ParsedClause.getDirectiveKind(),
12464 C.getExpr(I).first, ER.get());
12465 if (!ER.isUsable())
12466 continue;
12467 TransformedGangKinds.push_back(C.getExpr(I).first);
12468 TransformedIntExprs.push_back(ER.get());
12469 }
12470
12471 NewClause = Self.getSema().OpenACC().CheckGangClause(
12472 ParsedClause.getDirectiveKind(), ExistingClauses,
12473 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12474 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12475}
12476} // namespace
12477template <typename Derived>
12478OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12479 ArrayRef<const OpenACCClause *> ExistingClauses,
12480 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12481
12483 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12484 ParsedClause.setEndLoc(OldClause->getEndLoc());
12485
12486 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12487 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12488
12489 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12490 ParsedClause};
12491 Transform.Visit(OldClause);
12492
12493 return Transform.CreatedClause();
12494}
12495
12496template <typename Derived>
12498TreeTransform<Derived>::TransformOpenACCClauseList(
12500 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12501 for (const auto *Clause : OldClauses) {
12502 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12503 TransformedClauses, DirKind, Clause))
12504 TransformedClauses.push_back(TransformedClause);
12505 }
12506 return TransformedClauses;
12507}
12508
12509template <typename Derived>
12512 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12513
12514 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12515 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12516 C->clauses());
12517
12518 if (getSema().OpenACC().ActOnStartStmtDirective(
12519 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12520 return StmtError();
12521
12522 // Transform Structured Block.
12523 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12524 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12525 C->clauses(), TransformedClauses);
12526 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12527 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12528 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12529
12530 return getDerived().RebuildOpenACCComputeConstruct(
12531 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12532 C->getEndLoc(), TransformedClauses, StrBlock);
12533}
12534
12535template <typename Derived>
12538
12539 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12540
12541 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12542 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12543 C->clauses());
12544
12545 if (getSema().OpenACC().ActOnStartStmtDirective(
12546 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12547 return StmtError();
12548
12549 // Transform Loop.
12550 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12551 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12552 C->clauses(), TransformedClauses);
12553 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12554 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12555 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12556
12557 return getDerived().RebuildOpenACCLoopConstruct(
12558 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12559 TransformedClauses, Loop);
12560}
12561
12562template <typename Derived>
12564 OpenACCCombinedConstruct *C) {
12565 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12566
12567 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12568 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12569 C->clauses());
12570
12571 if (getSema().OpenACC().ActOnStartStmtDirective(
12572 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12573 return StmtError();
12574
12575 // Transform Loop.
12576 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12577 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12578 C->clauses(), TransformedClauses);
12579 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12580 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12581 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12582
12583 return getDerived().RebuildOpenACCCombinedConstruct(
12584 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12585 C->getEndLoc(), TransformedClauses, Loop);
12586}
12587
12588template <typename Derived>
12591 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12592
12593 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12594 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12595 C->clauses());
12596 if (getSema().OpenACC().ActOnStartStmtDirective(
12597 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12598 return StmtError();
12599
12600 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12601 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12602 C->clauses(), TransformedClauses);
12603 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12604 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12605 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12606
12607 return getDerived().RebuildOpenACCDataConstruct(
12608 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12609 TransformedClauses, StrBlock);
12610}
12611
12612template <typename Derived>
12614 OpenACCEnterDataConstruct *C) {
12615 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12616
12617 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12618 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12619 C->clauses());
12620 if (getSema().OpenACC().ActOnStartStmtDirective(
12621 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12622 return StmtError();
12623
12624 return getDerived().RebuildOpenACCEnterDataConstruct(
12625 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12626 TransformedClauses);
12627}
12628
12629template <typename Derived>
12631 OpenACCExitDataConstruct *C) {
12632 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12633
12634 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12635 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12636 C->clauses());
12637 if (getSema().OpenACC().ActOnStartStmtDirective(
12638 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12639 return StmtError();
12640
12641 return getDerived().RebuildOpenACCExitDataConstruct(
12642 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12643 TransformedClauses);
12644}
12645
12646template <typename Derived>
12648 OpenACCHostDataConstruct *C) {
12649 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12650
12651 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12652 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12653 C->clauses());
12654 if (getSema().OpenACC().ActOnStartStmtDirective(
12655 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12656 return StmtError();
12657
12658 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12659 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12660 C->clauses(), TransformedClauses);
12661 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12662 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12663 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12664
12665 return getDerived().RebuildOpenACCHostDataConstruct(
12666 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12667 TransformedClauses, StrBlock);
12668}
12669
12670template <typename Derived>
12673 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12674
12675 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12676 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12677 C->clauses());
12678 if (getSema().OpenACC().ActOnStartStmtDirective(
12679 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12680 return StmtError();
12681
12682 return getDerived().RebuildOpenACCInitConstruct(
12683 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12684 TransformedClauses);
12685}
12686
12687template <typename Derived>
12689 OpenACCShutdownConstruct *C) {
12690 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12691
12692 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12693 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12694 C->clauses());
12695 if (getSema().OpenACC().ActOnStartStmtDirective(
12696 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12697 return StmtError();
12698
12699 return getDerived().RebuildOpenACCShutdownConstruct(
12700 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12701 TransformedClauses);
12702}
12703template <typename Derived>
12706 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12707
12708 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12709 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12710 C->clauses());
12711 if (getSema().OpenACC().ActOnStartStmtDirective(
12712 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12713 return StmtError();
12714
12715 return getDerived().RebuildOpenACCSetConstruct(
12716 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12717 TransformedClauses);
12718}
12719
12720template <typename Derived>
12722 OpenACCUpdateConstruct *C) {
12723 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12724
12725 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12726 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12727 C->clauses());
12728 if (getSema().OpenACC().ActOnStartStmtDirective(
12729 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12730 return StmtError();
12731
12732 return getDerived().RebuildOpenACCUpdateConstruct(
12733 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12734 TransformedClauses);
12735}
12736
12737template <typename Derived>
12740 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12741
12742 ExprResult DevNumExpr;
12743 if (C->hasDevNumExpr()) {
12744 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12745
12746 if (DevNumExpr.isUsable())
12747 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12749 C->getBeginLoc(), DevNumExpr.get());
12750 }
12751
12752 llvm::SmallVector<Expr *> QueueIdExprs;
12753
12754 for (Expr *QE : C->getQueueIdExprs()) {
12755 assert(QE && "Null queue id expr?");
12756 ExprResult NewEQ = getDerived().TransformExpr(QE);
12757
12758 if (!NewEQ.isUsable())
12759 break;
12760 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12762 C->getBeginLoc(), NewEQ.get());
12763 if (NewEQ.isUsable())
12764 QueueIdExprs.push_back(NewEQ.get());
12765 }
12766
12767 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12768 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12769 C->clauses());
12770
12771 if (getSema().OpenACC().ActOnStartStmtDirective(
12772 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12773 return StmtError();
12774
12775 return getDerived().RebuildOpenACCWaitConstruct(
12776 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12777 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12778 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12779}
12780template <typename Derived>
12782 OpenACCCacheConstruct *C) {
12783 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12784
12785 llvm::SmallVector<Expr *> TransformedVarList;
12786 for (Expr *Var : C->getVarList()) {
12787 assert(Var && "Null var listexpr?");
12788
12789 ExprResult NewVar = getDerived().TransformExpr(Var);
12790
12791 if (!NewVar.isUsable())
12792 break;
12793
12794 NewVar = getSema().OpenACC().ActOnVar(
12795 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
12796 if (!NewVar.isUsable())
12797 break;
12798
12799 TransformedVarList.push_back(NewVar.get());
12800 }
12801
12802 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12803 C->getBeginLoc(), {}))
12804 return StmtError();
12805
12806 return getDerived().RebuildOpenACCCacheConstruct(
12807 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12808 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
12809 C->getEndLoc());
12810}
12811
12812template <typename Derived>
12814 OpenACCAtomicConstruct *C) {
12815 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12816
12817 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12818 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12819 C->clauses());
12820
12821 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12822 C->getBeginLoc(), {}))
12823 return StmtError();
12824
12825 // Transform Associated Stmt.
12826 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12827 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
12828
12829 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
12830 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
12831 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
12832 AssocStmt);
12833
12834 return getDerived().RebuildOpenACCAtomicConstruct(
12835 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
12836 C->getEndLoc(), TransformedClauses, AssocStmt);
12837}
12838
12839template <typename Derived>
12842 if (getDerived().AlwaysRebuild())
12843 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12844 // Nothing can ever change, so there is never anything to transform.
12845 return E;
12846}
12847
12848//===----------------------------------------------------------------------===//
12849// Expression transformation
12850//===----------------------------------------------------------------------===//
12851template<typename Derived>
12854 return TransformExpr(E->getSubExpr());
12855}
12856
12857template <typename Derived>
12860 if (!E->isTypeDependent())
12861 return E;
12862
12863 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12864
12865 if (!NewT)
12866 return ExprError();
12867
12868 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12869 return E;
12870
12871 return getDerived().RebuildSYCLUniqueStableNameExpr(
12872 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12873}
12874
12875template<typename Derived>
12878 if (!E->isTypeDependent())
12879 return E;
12880
12881 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12882 E->getIdentKind());
12883}
12884
12885template<typename Derived>
12888 NestedNameSpecifierLoc QualifierLoc;
12889 if (E->getQualifierLoc()) {
12890 QualifierLoc
12891 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12892 if (!QualifierLoc)
12893 return ExprError();
12894 }
12895
12896 ValueDecl *ND
12897 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12898 E->getDecl()));
12899 if (!ND || ND->isInvalidDecl())
12900 return ExprError();
12901
12902 NamedDecl *Found = ND;
12903 if (E->getFoundDecl() != E->getDecl()) {
12904 Found = cast_or_null<NamedDecl>(
12905 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12906 if (!Found)
12907 return ExprError();
12908 }
12909
12910 DeclarationNameInfo NameInfo = E->getNameInfo();
12911 if (NameInfo.getName()) {
12912 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12913 if (!NameInfo.getName())
12914 return ExprError();
12915 }
12916
12917 if (!getDerived().AlwaysRebuild() &&
12918 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12919 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12920 Found == E->getFoundDecl() &&
12921 NameInfo.getName() == E->getDecl()->getDeclName() &&
12922 !E->hasExplicitTemplateArgs()) {
12923
12924 // Mark it referenced in the new context regardless.
12925 // FIXME: this is a bit instantiation-specific.
12926 SemaRef.MarkDeclRefReferenced(E);
12927
12928 return E;
12929 }
12930
12931 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12932 if (E->hasExplicitTemplateArgs()) {
12933 TemplateArgs = &TransArgs;
12934 TransArgs.setLAngleLoc(E->getLAngleLoc());
12935 TransArgs.setRAngleLoc(E->getRAngleLoc());
12936 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12937 E->getNumTemplateArgs(),
12938 TransArgs))
12939 return ExprError();
12940 }
12941
12942 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12943 Found, TemplateArgs);
12944}
12945
12946template<typename Derived>
12949 return E;
12950}
12951
12952template <typename Derived>
12954 FixedPointLiteral *E) {
12955 return E;
12956}
12957
12958template<typename Derived>
12961 return E;
12962}
12963
12964template<typename Derived>
12967 return E;
12968}
12969
12970template<typename Derived>
12973 return E;
12974}
12975
12976template<typename Derived>
12979 return E;
12980}
12981
12982template<typename Derived>
12985 return getDerived().TransformCallExpr(E);
12986}
12987
12988template<typename Derived>
12991 ExprResult ControllingExpr;
12992 TypeSourceInfo *ControllingType = nullptr;
12993 if (E->isExprPredicate())
12994 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12995 else
12996 ControllingType = getDerived().TransformType(E->getControllingType());
12997
12998 if (ControllingExpr.isInvalid() && !ControllingType)
12999 return ExprError();
13000
13001 SmallVector<Expr *, 4> AssocExprs;
13003 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13004 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13005 if (TSI) {
13006 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13007 if (!AssocType)
13008 return ExprError();
13009 AssocTypes.push_back(AssocType);
13010 } else {
13011 AssocTypes.push_back(nullptr);
13012 }
13013
13014 ExprResult AssocExpr =
13015 getDerived().TransformExpr(Assoc.getAssociationExpr());
13016 if (AssocExpr.isInvalid())
13017 return ExprError();
13018 AssocExprs.push_back(AssocExpr.get());
13019 }
13020
13021 if (!ControllingType)
13022 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13023 E->getDefaultLoc(),
13024 E->getRParenLoc(),
13025 ControllingExpr.get(),
13026 AssocTypes,
13027 AssocExprs);
13028 return getDerived().RebuildGenericSelectionExpr(
13029 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13030 ControllingType, AssocTypes, AssocExprs);
13031}
13032
13033template<typename Derived>
13036 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13037 if (SubExpr.isInvalid())
13038 return ExprError();
13039
13040 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13041 return E;
13042
13043 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13044 E->getRParen());
13045}
13046
13047/// The operand of a unary address-of operator has special rules: it's
13048/// allowed to refer to a non-static member of a class even if there's no 'this'
13049/// object available.
13050template<typename Derived>
13053 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13054 return getDerived().TransformDependentScopeDeclRefExpr(
13055 DRE, /*IsAddressOfOperand=*/true, nullptr);
13056 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13057 return getDerived().TransformUnresolvedLookupExpr(
13058 ULE, /*IsAddressOfOperand=*/true);
13059 else
13060 return getDerived().TransformExpr(E);
13061}
13062
13063template<typename Derived>
13066 ExprResult SubExpr;
13067 if (E->getOpcode() == UO_AddrOf)
13068 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13069 else
13070 SubExpr = TransformExpr(E->getSubExpr());
13071 if (SubExpr.isInvalid())
13072 return ExprError();
13073
13074 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13075 return E;
13076
13077 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13078 E->getOpcode(),
13079 SubExpr.get());
13080}
13081
13082template<typename Derived>
13084TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13085 // Transform the type.
13086 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13087 if (!Type)
13088 return ExprError();
13089
13090 // Transform all of the components into components similar to what the
13091 // parser uses.
13092 // FIXME: It would be slightly more efficient in the non-dependent case to
13093 // just map FieldDecls, rather than requiring the rebuilder to look for
13094 // the fields again. However, __builtin_offsetof is rare enough in
13095 // template code that we don't care.
13096 bool ExprChanged = false;
13097 typedef Sema::OffsetOfComponent Component;
13098 SmallVector<Component, 4> Components;
13099 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13100 const OffsetOfNode &ON = E->getComponent(I);
13101 Component Comp;
13102 Comp.isBrackets = true;
13103 Comp.LocStart = ON.getSourceRange().getBegin();
13104 Comp.LocEnd = ON.getSourceRange().getEnd();
13105 switch (ON.getKind()) {
13106 case OffsetOfNode::Array: {
13107 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13108 ExprResult Index = getDerived().TransformExpr(FromIndex);
13109 if (Index.isInvalid())
13110 return ExprError();
13111
13112 ExprChanged = ExprChanged || Index.get() != FromIndex;
13113 Comp.isBrackets = true;
13114 Comp.U.E = Index.get();
13115 break;
13116 }
13117
13120 Comp.isBrackets = false;
13121 Comp.U.IdentInfo = ON.getFieldName();
13122 if (!Comp.U.IdentInfo)
13123 continue;
13124
13125 break;
13126
13127 case OffsetOfNode::Base:
13128 // Will be recomputed during the rebuild.
13129 continue;
13130 }
13131
13132 Components.push_back(Comp);
13133 }
13134
13135 // If nothing changed, retain the existing expression.
13136 if (!getDerived().AlwaysRebuild() &&
13137 Type == E->getTypeSourceInfo() &&
13138 !ExprChanged)
13139 return E;
13140
13141 // Build a new offsetof expression.
13142 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
13143 Components, E->getRParenLoc());
13144}
13145
13146template<typename Derived>
13149 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13150 "opaque value expression requires transformation");
13151 return E;
13152}
13153
13154template <typename Derived>
13157 bool Changed = false;
13158 for (Expr *C : E->subExpressions()) {
13159 ExprResult NewC = getDerived().TransformExpr(C);
13160 if (NewC.isInvalid())
13161 return ExprError();
13162 Children.push_back(NewC.get());
13163
13164 Changed |= NewC.get() != C;
13165 }
13166 if (!getDerived().AlwaysRebuild() && !Changed)
13167 return E;
13168 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13169 Children, E->getType());
13170}
13171
13172template<typename Derived>
13175 // Rebuild the syntactic form. The original syntactic form has
13176 // opaque-value expressions in it, so strip those away and rebuild
13177 // the result. This is a really awful way of doing this, but the
13178 // better solution (rebuilding the semantic expressions and
13179 // rebinding OVEs as necessary) doesn't work; we'd need
13180 // TreeTransform to not strip away implicit conversions.
13181 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13182 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13183 if (result.isInvalid()) return ExprError();
13184
13185 // If that gives us a pseudo-object result back, the pseudo-object
13186 // expression must have been an lvalue-to-rvalue conversion which we
13187 // should reapply.
13188 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13189 result = SemaRef.PseudoObject().checkRValue(result.get());
13190
13191 return result;
13192}
13193
13194template<typename Derived>
13198 if (E->isArgumentType()) {
13199 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13200
13201 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13202 if (!NewT)
13203 return ExprError();
13204
13205 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13206 return E;
13207
13208 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13209 E->getKind(),
13210 E->getSourceRange());
13211 }
13212
13213 // C++0x [expr.sizeof]p1:
13214 // The operand is either an expression, which is an unevaluated operand
13215 // [...]
13219
13220 // Try to recover if we have something like sizeof(T::X) where X is a type.
13221 // Notably, there must be *exactly* one set of parens if X is a type.
13222 TypeSourceInfo *RecoveryTSI = nullptr;
13223 ExprResult SubExpr;
13224 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13225 if (auto *DRE =
13226 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13227 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13228 PE, DRE, false, &RecoveryTSI);
13229 else
13230 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13231
13232 if (RecoveryTSI) {
13233 return getDerived().RebuildUnaryExprOrTypeTrait(
13234 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13235 } else if (SubExpr.isInvalid())
13236 return ExprError();
13237
13238 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13239 return E;
13240
13241 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13242 E->getOperatorLoc(),
13243 E->getKind(),
13244 E->getSourceRange());
13245}
13246
13247template<typename Derived>
13250 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13251 if (LHS.isInvalid())
13252 return ExprError();
13253
13254 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13255 if (RHS.isInvalid())
13256 return ExprError();
13257
13258
13259 if (!getDerived().AlwaysRebuild() &&
13260 LHS.get() == E->getLHS() &&
13261 RHS.get() == E->getRHS())
13262 return E;
13263
13264 return getDerived().RebuildArraySubscriptExpr(
13265 LHS.get(),
13266 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13267}
13268
13269template <typename Derived>
13272 ExprResult Base = getDerived().TransformExpr(E->getBase());
13273 if (Base.isInvalid())
13274 return ExprError();
13275
13276 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13277 if (RowIdx.isInvalid())
13278 return ExprError();
13279
13280 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13281 if (ColumnIdx.isInvalid())
13282 return ExprError();
13283
13284 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13285 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13286 return E;
13287
13288 return getDerived().RebuildMatrixSubscriptExpr(
13289 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13290}
13291
13292template <typename Derived>
13295 ExprResult Base = getDerived().TransformExpr(E->getBase());
13296 if (Base.isInvalid())
13297 return ExprError();
13298
13299 ExprResult LowerBound;
13300 if (E->getLowerBound()) {
13301 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13302 if (LowerBound.isInvalid())
13303 return ExprError();
13304 }
13305
13306 ExprResult Length;
13307 if (E->getLength()) {
13308 Length = getDerived().TransformExpr(E->getLength());
13309 if (Length.isInvalid())
13310 return ExprError();
13311 }
13312
13313 ExprResult Stride;
13314 if (E->isOMPArraySection()) {
13315 if (Expr *Str = E->getStride()) {
13316 Stride = getDerived().TransformExpr(Str);
13317 if (Stride.isInvalid())
13318 return ExprError();
13319 }
13320 }
13321
13322 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13323 LowerBound.get() == E->getLowerBound() &&
13324 Length.get() == E->getLength() &&
13325 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13326 return E;
13327
13328 return getDerived().RebuildArraySectionExpr(
13329 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13330 LowerBound.get(), E->getColonLocFirst(),
13331 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13332 Length.get(), Stride.get(), E->getRBracketLoc());
13333}
13334
13335template <typename Derived>
13338 ExprResult Base = getDerived().TransformExpr(E->getBase());
13339 if (Base.isInvalid())
13340 return ExprError();
13341
13343 bool ErrorFound = false;
13344 for (Expr *Dim : E->getDimensions()) {
13345 ExprResult DimRes = getDerived().TransformExpr(Dim);
13346 if (DimRes.isInvalid()) {
13347 ErrorFound = true;
13348 continue;
13349 }
13350 Dims.push_back(DimRes.get());
13351 }
13352
13353 if (ErrorFound)
13354 return ExprError();
13355 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13356 E->getRParenLoc(), Dims,
13357 E->getBracketsRanges());
13358}
13359
13360template <typename Derived>
13363 unsigned NumIterators = E->numOfIterators();
13365
13366 bool ErrorFound = false;
13367 bool NeedToRebuild = getDerived().AlwaysRebuild();
13368 for (unsigned I = 0; I < NumIterators; ++I) {
13369 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13370 Data[I].DeclIdent = D->getIdentifier();
13371 Data[I].DeclIdentLoc = D->getLocation();
13372 if (D->getLocation() == D->getBeginLoc()) {
13373 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13374 "Implicit type must be int.");
13375 } else {
13376 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13377 QualType DeclTy = getDerived().TransformType(D->getType());
13378 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13379 }
13380 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13381 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13382 ExprResult End = getDerived().TransformExpr(Range.End);
13383 ExprResult Step = getDerived().TransformExpr(Range.Step);
13384 ErrorFound = ErrorFound ||
13385 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13386 !Data[I].Type.get().isNull())) ||
13387 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13388 if (ErrorFound)
13389 continue;
13390 Data[I].Range.Begin = Begin.get();
13391 Data[I].Range.End = End.get();
13392 Data[I].Range.Step = Step.get();
13393 Data[I].AssignLoc = E->getAssignLoc(I);
13394 Data[I].ColonLoc = E->getColonLoc(I);
13395 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13396 NeedToRebuild =
13397 NeedToRebuild ||
13398 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13399 D->getType().getTypePtrOrNull()) ||
13400 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13401 Range.Step != Data[I].Range.Step;
13402 }
13403 if (ErrorFound)
13404 return ExprError();
13405 if (!NeedToRebuild)
13406 return E;
13407
13408 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13409 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13410 if (!Res.isUsable())
13411 return Res;
13412 auto *IE = cast<OMPIteratorExpr>(Res.get());
13413 for (unsigned I = 0; I < NumIterators; ++I)
13414 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13415 IE->getIteratorDecl(I));
13416 return Res;
13417}
13418
13419template<typename Derived>
13422 // Transform the callee.
13423 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13424 if (Callee.isInvalid())
13425 return ExprError();
13426
13427 // Transform arguments.
13428 bool ArgChanged = false;
13430 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13431 &ArgChanged))
13432 return ExprError();
13433
13434 if (!getDerived().AlwaysRebuild() &&
13435 Callee.get() == E->getCallee() &&
13436 !ArgChanged)
13437 return SemaRef.MaybeBindToTemporary(E);
13438
13439 // FIXME: Wrong source location information for the '('.
13440 SourceLocation FakeLParenLoc
13441 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13442
13443 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13444 if (E->hasStoredFPFeatures()) {
13445 FPOptionsOverride NewOverrides = E->getFPFeatures();
13446 getSema().CurFPFeatures =
13447 NewOverrides.applyOverrides(getSema().getLangOpts());
13448 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13449 }
13450
13451 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13452 Args,
13453 E->getRParenLoc());
13454}
13455
13456template<typename Derived>
13459 ExprResult Base = getDerived().TransformExpr(E->getBase());
13460 if (Base.isInvalid())
13461 return ExprError();
13462
13463 NestedNameSpecifierLoc QualifierLoc;
13464 if (E->hasQualifier()) {
13465 QualifierLoc
13466 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13467
13468 if (!QualifierLoc)
13469 return ExprError();
13470 }
13471 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13472
13474 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13475 E->getMemberDecl()));
13476 if (!Member)
13477 return ExprError();
13478
13479 NamedDecl *FoundDecl = E->getFoundDecl();
13480 if (FoundDecl == E->getMemberDecl()) {
13481 FoundDecl = Member;
13482 } else {
13483 FoundDecl = cast_or_null<NamedDecl>(
13484 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13485 if (!FoundDecl)
13486 return ExprError();
13487 }
13488
13489 if (!getDerived().AlwaysRebuild() &&
13490 Base.get() == E->getBase() &&
13491 QualifierLoc == E->getQualifierLoc() &&
13492 Member == E->getMemberDecl() &&
13493 FoundDecl == E->getFoundDecl() &&
13494 !E->hasExplicitTemplateArgs()) {
13495
13496 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13497 // for Openmp where the field need to be privatizized in the case.
13498 if (!(isa<CXXThisExpr>(E->getBase()) &&
13499 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13501 // Mark it referenced in the new context regardless.
13502 // FIXME: this is a bit instantiation-specific.
13503 SemaRef.MarkMemberReferenced(E);
13504 return E;
13505 }
13506 }
13507
13508 TemplateArgumentListInfo TransArgs;
13509 if (E->hasExplicitTemplateArgs()) {
13510 TransArgs.setLAngleLoc(E->getLAngleLoc());
13511 TransArgs.setRAngleLoc(E->getRAngleLoc());
13512 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13513 E->getNumTemplateArgs(),
13514 TransArgs))
13515 return ExprError();
13516 }
13517
13518 // FIXME: Bogus source location for the operator
13519 SourceLocation FakeOperatorLoc =
13520 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13521
13522 // FIXME: to do this check properly, we will need to preserve the
13523 // first-qualifier-in-scope here, just in case we had a dependent
13524 // base (and therefore couldn't do the check) and a
13525 // nested-name-qualifier (and therefore could do the lookup).
13526 NamedDecl *FirstQualifierInScope = nullptr;
13527 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13528 if (MemberNameInfo.getName()) {
13529 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13530 if (!MemberNameInfo.getName())
13531 return ExprError();
13532 }
13533
13534 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13535 E->isArrow(),
13536 QualifierLoc,
13537 TemplateKWLoc,
13538 MemberNameInfo,
13539 Member,
13540 FoundDecl,
13541 (E->hasExplicitTemplateArgs()
13542 ? &TransArgs : nullptr),
13543 FirstQualifierInScope);
13544}
13545
13546template<typename Derived>
13549 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13550 if (LHS.isInvalid())
13551 return ExprError();
13552
13553 ExprResult RHS =
13554 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13555 if (RHS.isInvalid())
13556 return ExprError();
13557
13558 if (!getDerived().AlwaysRebuild() &&
13559 LHS.get() == E->getLHS() &&
13560 RHS.get() == E->getRHS())
13561 return E;
13562
13563 if (E->isCompoundAssignmentOp())
13564 // FPFeatures has already been established from trailing storage
13565 return getDerived().RebuildBinaryOperator(
13566 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13567 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13568 FPOptionsOverride NewOverrides(E->getFPFeatures());
13569 getSema().CurFPFeatures =
13570 NewOverrides.applyOverrides(getSema().getLangOpts());
13571 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13572 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13573 LHS.get(), RHS.get());
13574}
13575
13576template <typename Derived>
13579 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13580
13581 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13582 if (LHS.isInvalid())
13583 return ExprError();
13584
13585 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13586 if (RHS.isInvalid())
13587 return ExprError();
13588
13589 // Extract the already-resolved callee declarations so that we can restrict
13590 // ourselves to using them as the unqualified lookup results when rebuilding.
13591 UnresolvedSet<2> UnqualLookups;
13592 bool ChangedAnyLookups = false;
13593 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13594 const_cast<Expr *>(Decomp.InnerBinOp)};
13595 for (Expr *PossibleBinOp : PossibleBinOps) {
13596 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13597 if (!Op)
13598 continue;
13599 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13600 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13601 continue;
13602
13603 // Transform the callee in case we built a call to a local extern
13604 // declaration.
13605 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13606 E->getOperatorLoc(), Callee->getFoundDecl()));
13607 if (!Found)
13608 return ExprError();
13609 if (Found != Callee->getFoundDecl())
13610 ChangedAnyLookups = true;
13611 UnqualLookups.addDecl(Found);
13612 }
13613
13614 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13615 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13616 // Mark all functions used in the rewrite as referenced. Note that when
13617 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13618 // function calls, and/or there might be a user-defined conversion sequence
13619 // applied to the operands of the <.
13620 // FIXME: this is a bit instantiation-specific.
13621 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13622 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13623 return E;
13624 }
13625
13626 return getDerived().RebuildCXXRewrittenBinaryOperator(
13627 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13628}
13629
13630template<typename Derived>
13634 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13635 FPOptionsOverride NewOverrides(E->getFPFeatures());
13636 getSema().CurFPFeatures =
13637 NewOverrides.applyOverrides(getSema().getLangOpts());
13638 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13639 return getDerived().TransformBinaryOperator(E);
13640}
13641
13642template<typename Derived>
13645 // Just rebuild the common and RHS expressions and see whether we
13646 // get any changes.
13647
13648 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13649 if (commonExpr.isInvalid())
13650 return ExprError();
13651
13652 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13653 if (rhs.isInvalid())
13654 return ExprError();
13655
13656 if (!getDerived().AlwaysRebuild() &&
13657 commonExpr.get() == e->getCommon() &&
13658 rhs.get() == e->getFalseExpr())
13659 return e;
13660
13661 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13662 e->getQuestionLoc(),
13663 nullptr,
13664 e->getColonLoc(),
13665 rhs.get());
13666}
13667
13668template<typename Derived>
13671 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13672 if (Cond.isInvalid())
13673 return ExprError();
13674
13675 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13676 if (LHS.isInvalid())
13677 return ExprError();
13678
13679 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13680 if (RHS.isInvalid())
13681 return ExprError();
13682
13683 if (!getDerived().AlwaysRebuild() &&
13684 Cond.get() == E->getCond() &&
13685 LHS.get() == E->getLHS() &&
13686 RHS.get() == E->getRHS())
13687 return E;
13688
13689 return getDerived().RebuildConditionalOperator(Cond.get(),
13690 E->getQuestionLoc(),
13691 LHS.get(),
13692 E->getColonLoc(),
13693 RHS.get());
13694}
13695
13696template<typename Derived>
13699 // Implicit casts are eliminated during transformation, since they
13700 // will be recomputed by semantic analysis after transformation.
13701 return getDerived().TransformExpr(E->getSubExprAsWritten());
13702}
13703
13704template<typename Derived>
13707 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13708 if (!Type)
13709 return ExprError();
13710
13711 ExprResult SubExpr
13712 = getDerived().TransformExpr(E->getSubExprAsWritten());
13713 if (SubExpr.isInvalid())
13714 return ExprError();
13715
13716 if (!getDerived().AlwaysRebuild() &&
13717 Type == E->getTypeInfoAsWritten() &&
13718 SubExpr.get() == E->getSubExpr())
13719 return E;
13720
13721 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13722 Type,
13723 E->getRParenLoc(),
13724 SubExpr.get());
13725}
13726
13727template<typename Derived>
13730 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13731 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13732 if (!NewT)
13733 return ExprError();
13734
13735 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13736 if (Init.isInvalid())
13737 return ExprError();
13738
13739 if (!getDerived().AlwaysRebuild() &&
13740 OldT == NewT &&
13741 Init.get() == E->getInitializer())
13742 return SemaRef.MaybeBindToTemporary(E);
13743
13744 // Note: the expression type doesn't necessarily match the
13745 // type-as-written, but that's okay, because it should always be
13746 // derivable from the initializer.
13747
13748 return getDerived().RebuildCompoundLiteralExpr(
13749 E->getLParenLoc(), NewT,
13750 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13751}
13752
13753template<typename Derived>
13756 ExprResult Base = getDerived().TransformExpr(E->getBase());
13757 if (Base.isInvalid())
13758 return ExprError();
13759
13760 if (!getDerived().AlwaysRebuild() &&
13761 Base.get() == E->getBase())
13762 return E;
13763
13764 // FIXME: Bad source location
13765 SourceLocation FakeOperatorLoc =
13766 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13767 return getDerived().RebuildExtVectorElementExpr(
13768 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13769 E->getAccessor());
13770}
13771
13772template<typename Derived>
13775 if (InitListExpr *Syntactic = E->getSyntacticForm())
13776 E = Syntactic;
13777
13778 bool InitChanged = false;
13779
13782
13784 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13785 Inits, &InitChanged))
13786 return ExprError();
13787
13788 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13789 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13790 // in some cases. We can't reuse it in general, because the syntactic and
13791 // semantic forms are linked, and we can't know that semantic form will
13792 // match even if the syntactic form does.
13793 }
13794
13795 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13796 E->getRBraceLoc());
13797}
13798
13799template<typename Derived>
13802 Designation Desig;
13803
13804 // transform the initializer value
13805 ExprResult Init = getDerived().TransformExpr(E->getInit());
13806 if (Init.isInvalid())
13807 return ExprError();
13808
13809 // transform the designators.
13810 SmallVector<Expr*, 4> ArrayExprs;
13811 bool ExprChanged = false;
13812 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13813 if (D.isFieldDesignator()) {
13814 if (D.getFieldDecl()) {
13815 FieldDecl *Field = cast_or_null<FieldDecl>(
13816 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13817 if (Field != D.getFieldDecl())
13818 // Rebuild the expression when the transformed FieldDecl is
13819 // different to the already assigned FieldDecl.
13820 ExprChanged = true;
13821 if (Field->isAnonymousStructOrUnion())
13822 continue;
13823 } else {
13824 // Ensure that the designator expression is rebuilt when there isn't
13825 // a resolved FieldDecl in the designator as we don't want to assign
13826 // a FieldDecl to a pattern designator that will be instantiated again.
13827 ExprChanged = true;
13828 }
13829 Desig.AddDesignator(Designator::CreateFieldDesignator(
13830 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13831 continue;
13832 }
13833
13834 if (D.isArrayDesignator()) {
13835 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13836 if (Index.isInvalid())
13837 return ExprError();
13838
13839 Desig.AddDesignator(
13840 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13841
13842 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
13843 ArrayExprs.push_back(Index.get());
13844 continue;
13845 }
13846
13847 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13848 ExprResult Start
13849 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13850 if (Start.isInvalid())
13851 return ExprError();
13852
13853 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13854 if (End.isInvalid())
13855 return ExprError();
13856
13857 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13858 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13859
13860 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13861 End.get() != E->getArrayRangeEnd(D);
13862
13863 ArrayExprs.push_back(Start.get());
13864 ArrayExprs.push_back(End.get());
13865 }
13866
13867 if (!getDerived().AlwaysRebuild() &&
13868 Init.get() == E->getInit() &&
13869 !ExprChanged)
13870 return E;
13871
13872 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13873 E->getEqualOrColonLoc(),
13874 E->usesGNUSyntax(), Init.get());
13875}
13876
13877// Seems that if TransformInitListExpr() only works on the syntactic form of an
13878// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13879template<typename Derived>
13883 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13884 "initializer");
13885 return ExprError();
13886}
13887
13888template<typename Derived>
13891 NoInitExpr *E) {
13892 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13893 return ExprError();
13894}
13895
13896template<typename Derived>
13899 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13900 return ExprError();
13901}
13902
13903template<typename Derived>
13906 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13907 return ExprError();
13908}
13909
13910template<typename Derived>
13914 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13915
13916 // FIXME: Will we ever have proper type location here? Will we actually
13917 // need to transform the type?
13918 QualType T = getDerived().TransformType(E->getType());
13919 if (T.isNull())
13920 return ExprError();
13921
13922 if (!getDerived().AlwaysRebuild() &&
13923 T == E->getType())
13924 return E;
13925
13926 return getDerived().RebuildImplicitValueInitExpr(T);
13927}
13928
13929template<typename Derived>
13932 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13933 if (!TInfo)
13934 return ExprError();
13935
13936 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13937 if (SubExpr.isInvalid())
13938 return ExprError();
13939
13940 if (!getDerived().AlwaysRebuild() &&
13941 TInfo == E->getWrittenTypeInfo() &&
13942 SubExpr.get() == E->getSubExpr())
13943 return E;
13944
13945 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13946 TInfo, E->getRParenLoc());
13947}
13948
13949template<typename Derived>
13952 bool ArgumentChanged = false;
13954 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13955 &ArgumentChanged))
13956 return ExprError();
13957
13958 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13959 Inits,
13960 E->getRParenLoc());
13961}
13962
13963/// Transform an address-of-label expression.
13964///
13965/// By default, the transformation of an address-of-label expression always
13966/// rebuilds the expression, so that the label identifier can be resolved to
13967/// the corresponding label statement by semantic analysis.
13968template<typename Derived>
13971 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13972 E->getLabel());
13973 if (!LD)
13974 return ExprError();
13975
13976 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13977 cast<LabelDecl>(LD));
13978}
13979
13980template<typename Derived>
13983 SemaRef.ActOnStartStmtExpr();
13984 StmtResult SubStmt
13985 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13986 if (SubStmt.isInvalid()) {
13987 SemaRef.ActOnStmtExprError();
13988 return ExprError();
13989 }
13990
13991 unsigned OldDepth = E->getTemplateDepth();
13992 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13993
13994 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13995 SubStmt.get() == E->getSubStmt()) {
13996 // Calling this an 'error' is unintuitive, but it does the right thing.
13997 SemaRef.ActOnStmtExprError();
13998 return SemaRef.MaybeBindToTemporary(E);
13999 }
14000
14001 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14002 E->getRParenLoc(), NewDepth);
14003}
14004
14005template<typename Derived>
14008 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14009 if (Cond.isInvalid())
14010 return ExprError();
14011
14012 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14013 if (LHS.isInvalid())
14014 return ExprError();
14015
14016 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14017 if (RHS.isInvalid())
14018 return ExprError();
14019
14020 if (!getDerived().AlwaysRebuild() &&
14021 Cond.get() == E->getCond() &&
14022 LHS.get() == E->getLHS() &&
14023 RHS.get() == E->getRHS())
14024 return E;
14025
14026 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14027 Cond.get(), LHS.get(), RHS.get(),
14028 E->getRParenLoc());
14029}
14030
14031template<typename Derived>
14034 return E;
14035}
14036
14037template<typename Derived>
14040 switch (E->getOperator()) {
14041 case OO_New:
14042 case OO_Delete:
14043 case OO_Array_New:
14044 case OO_Array_Delete:
14045 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14046
14047 case OO_Subscript:
14048 case OO_Call: {
14049 // This is a call to an object's operator().
14050 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14051
14052 // Transform the object itself.
14053 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14054 if (Object.isInvalid())
14055 return ExprError();
14056
14057 // FIXME: Poor location information. Also, if the location for the end of
14058 // the token is within a macro expansion, getLocForEndOfToken() will return
14059 // an invalid source location. If that happens and we have an otherwise
14060 // valid end location, use the valid one instead of the invalid one.
14061 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14062 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14063 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14064 FakeLParenLoc = EndLoc;
14065
14066 // Transform the call arguments.
14068 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14069 Args))
14070 return ExprError();
14071
14072 if (E->getOperator() == OO_Subscript)
14073 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14074 Args, E->getEndLoc());
14075
14076 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14077 E->getEndLoc());
14078 }
14079
14080#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14081 case OO_##Name: \
14082 break;
14083
14084#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14085#include "clang/Basic/OperatorKinds.def"
14086
14087 case OO_Conditional:
14088 llvm_unreachable("conditional operator is not actually overloadable");
14089
14090 case OO_None:
14092 llvm_unreachable("not an overloaded operator?");
14093 }
14094
14096 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14097 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14098 else
14099 First = getDerived().TransformExpr(E->getArg(0));
14100 if (First.isInvalid())
14101 return ExprError();
14102
14103 ExprResult Second;
14104 if (E->getNumArgs() == 2) {
14105 Second =
14106 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14107 if (Second.isInvalid())
14108 return ExprError();
14109 }
14110
14111 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14112 FPOptionsOverride NewOverrides(E->getFPFeatures());
14113 getSema().CurFPFeatures =
14114 NewOverrides.applyOverrides(getSema().getLangOpts());
14115 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14116
14117 Expr *Callee = E->getCallee();
14118 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14119 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14121 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14122 return ExprError();
14123
14124 return getDerived().RebuildCXXOperatorCallExpr(
14125 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14126 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14127 }
14128
14129 UnresolvedSet<1> Functions;
14130 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14131 Callee = ICE->getSubExprAsWritten();
14132 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14133 ValueDecl *VD = cast_or_null<ValueDecl>(
14134 getDerived().TransformDecl(DR->getLocation(), DR));
14135 if (!VD)
14136 return ExprError();
14137
14138 if (!isa<CXXMethodDecl>(VD))
14139 Functions.addDecl(VD);
14140
14141 return getDerived().RebuildCXXOperatorCallExpr(
14142 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14143 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14144}
14145
14146template<typename Derived>
14149 return getDerived().TransformCallExpr(E);
14150}
14151
14152template <typename Derived>
14154 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14155 getSema().CurContext != E->getParentContext();
14156
14157 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14158 return E;
14159
14160 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14161 E->getBeginLoc(), E->getEndLoc(),
14162 getSema().CurContext);
14163}
14164
14165template <typename Derived>
14167 return E;
14168}
14169
14170template<typename Derived>
14173 // Transform the callee.
14174 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14175 if (Callee.isInvalid())
14176 return ExprError();
14177
14178 // Transform exec config.
14179 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14180 if (EC.isInvalid())
14181 return ExprError();
14182
14183 // Transform arguments.
14184 bool ArgChanged = false;
14186 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14187 &ArgChanged))
14188 return ExprError();
14189
14190 if (!getDerived().AlwaysRebuild() &&
14191 Callee.get() == E->getCallee() &&
14192 !ArgChanged)
14193 return SemaRef.MaybeBindToTemporary(E);
14194
14195 // FIXME: Wrong source location information for the '('.
14196 SourceLocation FakeLParenLoc
14197 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14198 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14199 Args,
14200 E->getRParenLoc(), EC.get());
14201}
14202
14203template<typename Derived>
14206 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14207 if (!Type)
14208 return ExprError();
14209
14210 ExprResult SubExpr
14211 = getDerived().TransformExpr(E->getSubExprAsWritten());
14212 if (SubExpr.isInvalid())
14213 return ExprError();
14214
14215 if (!getDerived().AlwaysRebuild() &&
14216 Type == E->getTypeInfoAsWritten() &&
14217 SubExpr.get() == E->getSubExpr())
14218 return E;
14219 return getDerived().RebuildCXXNamedCastExpr(
14222 // FIXME. this should be '(' location
14223 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14224}
14225
14226template<typename Derived>
14229 TypeSourceInfo *TSI =
14230 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14231 if (!TSI)
14232 return ExprError();
14233
14234 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14235 if (Sub.isInvalid())
14236 return ExprError();
14237
14238 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14239 Sub.get(), BCE->getEndLoc());
14240}
14241
14242template<typename Derived>
14244TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14245 return getDerived().TransformCXXNamedCastExpr(E);
14246}
14247
14248template<typename Derived>
14251 return getDerived().TransformCXXNamedCastExpr(E);
14252}
14253
14254template<typename Derived>
14258 return getDerived().TransformCXXNamedCastExpr(E);
14259}
14260
14261template<typename Derived>
14264 return getDerived().TransformCXXNamedCastExpr(E);
14265}
14266
14267template<typename Derived>
14270 return getDerived().TransformCXXNamedCastExpr(E);
14271}
14272
14273template<typename Derived>
14278 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14279 if (!Type)
14280 return ExprError();
14281
14282 ExprResult SubExpr
14283 = getDerived().TransformExpr(E->getSubExprAsWritten());
14284 if (SubExpr.isInvalid())
14285 return ExprError();
14286
14287 if (!getDerived().AlwaysRebuild() &&
14288 Type == E->getTypeInfoAsWritten() &&
14289 SubExpr.get() == E->getSubExpr())
14290 return E;
14291
14292 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14293 E->getLParenLoc(),
14294 SubExpr.get(),
14295 E->getRParenLoc(),
14296 E->isListInitialization());
14297}
14298
14299template<typename Derived>
14302 if (E->isTypeOperand()) {
14303 TypeSourceInfo *TInfo
14304 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14305 if (!TInfo)
14306 return ExprError();
14307
14308 if (!getDerived().AlwaysRebuild() &&
14309 TInfo == E->getTypeOperandSourceInfo())
14310 return E;
14311
14312 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14313 TInfo, E->getEndLoc());
14314 }
14315
14316 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14317 // type. We must not unilaterally enter unevaluated context here, as then
14318 // semantic processing can re-transform an already transformed operand.
14319 Expr *Op = E->getExprOperand();
14321 if (E->isGLValue())
14322 if (auto *RD = Op->getType()->getAsCXXRecordDecl();
14323 RD && RD->isPolymorphic())
14324 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14325
14328
14329 ExprResult SubExpr = getDerived().TransformExpr(Op);
14330 if (SubExpr.isInvalid())
14331 return ExprError();
14332
14333 if (!getDerived().AlwaysRebuild() &&
14334 SubExpr.get() == E->getExprOperand())
14335 return E;
14336
14337 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14338 SubExpr.get(), E->getEndLoc());
14339}
14340
14341template<typename Derived>
14344 if (E->isTypeOperand()) {
14345 TypeSourceInfo *TInfo
14346 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14347 if (!TInfo)
14348 return ExprError();
14349
14350 if (!getDerived().AlwaysRebuild() &&
14351 TInfo == E->getTypeOperandSourceInfo())
14352 return E;
14353
14354 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14355 TInfo, E->getEndLoc());
14356 }
14357
14360
14361 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14362 if (SubExpr.isInvalid())
14363 return ExprError();
14364
14365 if (!getDerived().AlwaysRebuild() &&
14366 SubExpr.get() == E->getExprOperand())
14367 return E;
14368
14369 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14370 SubExpr.get(), E->getEndLoc());
14371}
14372
14373template<typename Derived>
14376 return E;
14377}
14378
14379template<typename Derived>
14383 return E;
14384}
14385
14386template<typename Derived>
14389
14390 // In lambdas, the qualifiers of the type depends of where in
14391 // the call operator `this` appear, and we do not have a good way to
14392 // rebuild this information, so we transform the type.
14393 //
14394 // In other contexts, the type of `this` may be overrided
14395 // for type deduction, so we need to recompute it.
14396 //
14397 // Always recompute the type if we're in the body of a lambda, and
14398 // 'this' is dependent on a lambda's explicit object parameter; we
14399 // also need to always rebuild the expression in this case to clear
14400 // the flag.
14401 QualType T = [&]() {
14402 auto &S = getSema();
14403 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14404 return S.getCurrentThisType();
14405 if (S.getCurLambda())
14406 return getDerived().TransformType(E->getType());
14407 return S.getCurrentThisType();
14408 }();
14409
14410 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14411 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14412 // Mark it referenced in the new context regardless.
14413 // FIXME: this is a bit instantiation-specific.
14414 getSema().MarkThisReferenced(E);
14415 return E;
14416 }
14417
14418 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14419}
14420
14421template<typename Derived>
14424 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14425 if (SubExpr.isInvalid())
14426 return ExprError();
14427
14428 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14429
14430 if (!getDerived().AlwaysRebuild() &&
14431 SubExpr.get() == E->getSubExpr())
14432 return E;
14433
14434 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14435 E->isThrownVariableInScope());
14436}
14437
14438template<typename Derived>
14441 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14442 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14443 if (!Param)
14444 return ExprError();
14445
14446 ExprResult InitRes;
14447 if (E->hasRewrittenInit()) {
14448 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14449 if (InitRes.isInvalid())
14450 return ExprError();
14451 }
14452
14453 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14454 E->getUsedContext() == SemaRef.CurContext &&
14455 InitRes.get() == E->getRewrittenExpr())
14456 return E;
14457
14458 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14459 InitRes.get());
14460}
14461
14462template<typename Derived>
14465 FieldDecl *Field = cast_or_null<FieldDecl>(
14466 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14467 if (!Field)
14468 return ExprError();
14469
14470 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14471 E->getUsedContext() == SemaRef.CurContext)
14472 return E;
14473
14474 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14475}
14476
14477template<typename Derived>
14481 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14482 if (!T)
14483 return ExprError();
14484
14485 if (!getDerived().AlwaysRebuild() &&
14486 T == E->getTypeSourceInfo())
14487 return E;
14488
14489 return getDerived().RebuildCXXScalarValueInitExpr(T,
14490 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14491 E->getRParenLoc());
14492}
14493
14494template<typename Derived>
14497 // Transform the type that we're allocating
14498 TypeSourceInfo *AllocTypeInfo =
14499 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14500 if (!AllocTypeInfo)
14501 return ExprError();
14502
14503 // Transform the size of the array we're allocating (if any).
14504 std::optional<Expr *> ArraySize;
14505 if (E->isArray()) {
14506 ExprResult NewArraySize;
14507 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14508 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14509 if (NewArraySize.isInvalid())
14510 return ExprError();
14511 }
14512 ArraySize = NewArraySize.get();
14513 }
14514
14515 // Transform the placement arguments (if any).
14516 bool ArgumentChanged = false;
14517 SmallVector<Expr*, 8> PlacementArgs;
14518 if (getDerived().TransformExprs(E->getPlacementArgs(),
14519 E->getNumPlacementArgs(), true,
14520 PlacementArgs, &ArgumentChanged))
14521 return ExprError();
14522
14523 // Transform the initializer (if any).
14524 Expr *OldInit = E->getInitializer();
14525 ExprResult NewInit;
14526 if (OldInit)
14527 NewInit = getDerived().TransformInitializer(OldInit, true);
14528 if (NewInit.isInvalid())
14529 return ExprError();
14530
14531 // Transform new operator and delete operator.
14532 FunctionDecl *OperatorNew = nullptr;
14533 if (E->getOperatorNew()) {
14534 OperatorNew = cast_or_null<FunctionDecl>(
14535 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14536 if (!OperatorNew)
14537 return ExprError();
14538 }
14539
14540 FunctionDecl *OperatorDelete = nullptr;
14541 if (E->getOperatorDelete()) {
14542 OperatorDelete = cast_or_null<FunctionDecl>(
14543 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14544 if (!OperatorDelete)
14545 return ExprError();
14546 }
14547
14548 if (!getDerived().AlwaysRebuild() &&
14549 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14550 ArraySize == E->getArraySize() &&
14551 NewInit.get() == OldInit &&
14552 OperatorNew == E->getOperatorNew() &&
14553 OperatorDelete == E->getOperatorDelete() &&
14554 !ArgumentChanged) {
14555 // Mark any declarations we need as referenced.
14556 // FIXME: instantiation-specific.
14557 if (OperatorNew)
14558 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14559 if (OperatorDelete)
14560 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14561
14562 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14563 QualType ElementType
14564 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14565 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
14567 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
14568 }
14569 }
14570
14571 return E;
14572 }
14573
14574 QualType AllocType = AllocTypeInfo->getType();
14575 if (!ArraySize) {
14576 // If no array size was specified, but the new expression was
14577 // instantiated with an array type (e.g., "new T" where T is
14578 // instantiated with "int[4]"), extract the outer bound from the
14579 // array type as our array size. We do this with constant and
14580 // dependently-sized array types.
14581 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14582 if (!ArrayT) {
14583 // Do nothing
14584 } else if (const ConstantArrayType *ConsArrayT
14585 = dyn_cast<ConstantArrayType>(ArrayT)) {
14586 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14587 SemaRef.Context.getSizeType(),
14588 /*FIXME:*/ E->getBeginLoc());
14589 AllocType = ConsArrayT->getElementType();
14590 } else if (const DependentSizedArrayType *DepArrayT
14591 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14592 if (DepArrayT->getSizeExpr()) {
14593 ArraySize = DepArrayT->getSizeExpr();
14594 AllocType = DepArrayT->getElementType();
14595 }
14596 }
14597 }
14598
14599 return getDerived().RebuildCXXNewExpr(
14600 E->getBeginLoc(), E->isGlobalNew(),
14601 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14602 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14603 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14604}
14605
14606template<typename Derived>
14609 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14610 if (Operand.isInvalid())
14611 return ExprError();
14612
14613 // Transform the delete operator, if known.
14614 FunctionDecl *OperatorDelete = nullptr;
14615 if (E->getOperatorDelete()) {
14616 OperatorDelete = cast_or_null<FunctionDecl>(
14617 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14618 if (!OperatorDelete)
14619 return ExprError();
14620 }
14621
14622 if (!getDerived().AlwaysRebuild() &&
14623 Operand.get() == E->getArgument() &&
14624 OperatorDelete == E->getOperatorDelete()) {
14625 // Mark any declarations we need as referenced.
14626 // FIXME: instantiation-specific.
14627 if (OperatorDelete)
14628 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14629
14630 if (!E->getArgument()->isTypeDependent()) {
14631 QualType Destroyed = SemaRef.Context.getBaseElementType(
14632 E->getDestroyedType());
14633 if (auto *Record = Destroyed->getAsCXXRecordDecl())
14634 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
14635 SemaRef.LookupDestructor(Record));
14636 }
14637
14638 return E;
14639 }
14640
14641 return getDerived().RebuildCXXDeleteExpr(
14642 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14643}
14644
14645template<typename Derived>
14649 ExprResult Base = getDerived().TransformExpr(E->getBase());
14650 if (Base.isInvalid())
14651 return ExprError();
14652
14653 ParsedType ObjectTypePtr;
14654 bool MayBePseudoDestructor = false;
14655 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14656 E->getOperatorLoc(),
14657 E->isArrow()? tok::arrow : tok::period,
14658 ObjectTypePtr,
14659 MayBePseudoDestructor);
14660 if (Base.isInvalid())
14661 return ExprError();
14662
14663 QualType ObjectType = ObjectTypePtr.get();
14664 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14665 if (QualifierLoc) {
14666 QualifierLoc
14667 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14668 if (!QualifierLoc)
14669 return ExprError();
14670 }
14671 CXXScopeSpec SS;
14672 SS.Adopt(QualifierLoc);
14673
14675 if (E->getDestroyedTypeInfo()) {
14676 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
14677 E->getDestroyedTypeInfo(), ObjectType,
14678 /*FirstQualifierInScope=*/nullptr);
14679 if (!DestroyedTypeInfo)
14680 return ExprError();
14681 Destroyed = DestroyedTypeInfo;
14682 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14683 // We aren't likely to be able to resolve the identifier down to a type
14684 // now anyway, so just retain the identifier.
14685 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14686 E->getDestroyedTypeLoc());
14687 } else {
14688 // Look for a destructor known with the given name.
14689 ParsedType T = SemaRef.getDestructorName(
14690 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14691 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14692 if (!T)
14693 return ExprError();
14694
14695 Destroyed
14697 E->getDestroyedTypeLoc());
14698 }
14699
14700 TypeSourceInfo *ScopeTypeInfo = nullptr;
14701 if (E->getScopeTypeInfo()) {
14702 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14703 E->getScopeTypeInfo(), ObjectType, nullptr);
14704 if (!ScopeTypeInfo)
14705 return ExprError();
14706 }
14707
14708 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14709 E->getOperatorLoc(),
14710 E->isArrow(),
14711 SS,
14712 ScopeTypeInfo,
14713 E->getColonColonLoc(),
14714 E->getTildeLoc(),
14715 Destroyed);
14716}
14717
14718template <typename Derived>
14720 bool RequiresADL,
14721 LookupResult &R) {
14722 // Transform all the decls.
14723 bool AllEmptyPacks = true;
14724 for (auto *OldD : Old->decls()) {
14725 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14726 if (!InstD) {
14727 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14728 // This can happen because of dependent hiding.
14729 if (isa<UsingShadowDecl>(OldD))
14730 continue;
14731 else {
14732 R.clear();
14733 return true;
14734 }
14735 }
14736
14737 // Expand using pack declarations.
14738 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14739 ArrayRef<NamedDecl*> Decls = SingleDecl;
14740 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14741 Decls = UPD->expansions();
14742
14743 // Expand using declarations.
14744 for (auto *D : Decls) {
14745 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14746 for (auto *SD : UD->shadows())
14747 R.addDecl(SD);
14748 } else {
14749 R.addDecl(D);
14750 }
14751 }
14752
14753 AllEmptyPacks &= Decls.empty();
14754 }
14755
14756 // C++ [temp.res]/8.4.2:
14757 // The program is ill-formed, no diagnostic required, if [...] lookup for
14758 // a name in the template definition found a using-declaration, but the
14759 // lookup in the corresponding scope in the instantiation odoes not find
14760 // any declarations because the using-declaration was a pack expansion and
14761 // the corresponding pack is empty
14762 if (AllEmptyPacks && !RequiresADL) {
14763 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14764 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14765 return true;
14766 }
14767
14768 // Resolve a kind, but don't do any further analysis. If it's
14769 // ambiguous, the callee needs to deal with it.
14770 R.resolveKind();
14771
14772 if (Old->hasTemplateKeyword() && !R.empty()) {
14774 getSema().FilterAcceptableTemplateNames(R,
14775 /*AllowFunctionTemplates=*/true,
14776 /*AllowDependent=*/true);
14777 if (R.empty()) {
14778 // If a 'template' keyword was used, a lookup that finds only non-template
14779 // names is an error.
14780 getSema().Diag(R.getNameLoc(),
14781 diag::err_template_kw_refers_to_non_template)
14783 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14784 getSema().Diag(FoundDecl->getLocation(),
14785 diag::note_template_kw_refers_to_non_template)
14786 << R.getLookupName();
14787 return true;
14788 }
14789 }
14790
14791 return false;
14792}
14793
14794template <typename Derived>
14799
14800template <typename Derived>
14803 bool IsAddressOfOperand) {
14804 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14806
14807 // Transform the declaration set.
14808 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14809 return ExprError();
14810
14811 // Rebuild the nested-name qualifier, if present.
14812 CXXScopeSpec SS;
14813 if (Old->getQualifierLoc()) {
14814 NestedNameSpecifierLoc QualifierLoc
14815 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14816 if (!QualifierLoc)
14817 return ExprError();
14818
14819 SS.Adopt(QualifierLoc);
14820 }
14821
14822 if (Old->getNamingClass()) {
14823 CXXRecordDecl *NamingClass
14824 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14825 Old->getNameLoc(),
14826 Old->getNamingClass()));
14827 if (!NamingClass) {
14828 R.clear();
14829 return ExprError();
14830 }
14831
14832 R.setNamingClass(NamingClass);
14833 }
14834
14835 // Rebuild the template arguments, if any.
14836 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14837 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14838 if (Old->hasExplicitTemplateArgs() &&
14839 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14840 Old->getNumTemplateArgs(),
14841 TransArgs)) {
14842 R.clear();
14843 return ExprError();
14844 }
14845
14846 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14847 // a non-static data member is named in an unevaluated operand, or when
14848 // a member is named in a dependent class scope function template explicit
14849 // specialization that is neither declared static nor with an explicit object
14850 // parameter.
14851 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14852 return SemaRef.BuildPossibleImplicitMemberExpr(
14853 SS, TemplateKWLoc, R,
14854 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14855 /*S=*/nullptr);
14856
14857 // If we have neither explicit template arguments, nor the template keyword,
14858 // it's a normal declaration name or member reference.
14859 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14860 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14861
14862 // If we have template arguments, then rebuild the template-id expression.
14863 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14864 Old->requiresADL(), &TransArgs);
14865}
14866
14867template<typename Derived>
14870 bool ArgChanged = false;
14872 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14873 TypeSourceInfo *From = E->getArg(I);
14874 TypeLoc FromTL = From->getTypeLoc();
14875 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14876 TypeLocBuilder TLB;
14877 TLB.reserve(FromTL.getFullDataSize());
14878 QualType To = getDerived().TransformType(TLB, FromTL);
14879 if (To.isNull())
14880 return ExprError();
14881
14882 if (To == From->getType())
14883 Args.push_back(From);
14884 else {
14885 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14886 ArgChanged = true;
14887 }
14888 continue;
14889 }
14890
14891 ArgChanged = true;
14892
14893 // We have a pack expansion. Instantiate it.
14894 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14895 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14897 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14898
14899 // Determine whether the set of unexpanded parameter packs can and should
14900 // be expanded.
14901 bool Expand = true;
14902 bool RetainExpansion = false;
14903 UnsignedOrNone OrigNumExpansions =
14904 ExpansionTL.getTypePtr()->getNumExpansions();
14905 UnsignedOrNone NumExpansions = OrigNumExpansions;
14906 if (getDerived().TryExpandParameterPacks(
14907 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
14908 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
14909 RetainExpansion, NumExpansions))
14910 return ExprError();
14911
14912 if (!Expand) {
14913 // The transform has determined that we should perform a simple
14914 // transformation on the pack expansion, producing another pack
14915 // expansion.
14916 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
14917
14918 TypeLocBuilder TLB;
14919 TLB.reserve(From->getTypeLoc().getFullDataSize());
14920
14921 QualType To = getDerived().TransformType(TLB, PatternTL);
14922 if (To.isNull())
14923 return ExprError();
14924
14925 To = getDerived().RebuildPackExpansionType(To,
14926 PatternTL.getSourceRange(),
14927 ExpansionTL.getEllipsisLoc(),
14928 NumExpansions);
14929 if (To.isNull())
14930 return ExprError();
14931
14932 PackExpansionTypeLoc ToExpansionTL
14933 = TLB.push<PackExpansionTypeLoc>(To);
14934 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14935 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14936 continue;
14937 }
14938
14939 // Expand the pack expansion by substituting for each argument in the
14940 // pack(s).
14941 for (unsigned I = 0; I != *NumExpansions; ++I) {
14942 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
14943 TypeLocBuilder TLB;
14944 TLB.reserve(PatternTL.getFullDataSize());
14945 QualType To = getDerived().TransformType(TLB, PatternTL);
14946 if (To.isNull())
14947 return ExprError();
14948
14949 if (To->containsUnexpandedParameterPack()) {
14950 To = getDerived().RebuildPackExpansionType(To,
14951 PatternTL.getSourceRange(),
14952 ExpansionTL.getEllipsisLoc(),
14953 NumExpansions);
14954 if (To.isNull())
14955 return ExprError();
14956
14957 PackExpansionTypeLoc ToExpansionTL
14958 = TLB.push<PackExpansionTypeLoc>(To);
14959 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14960 }
14961
14962 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14963 }
14964
14965 if (!RetainExpansion)
14966 continue;
14967
14968 // If we're supposed to retain a pack expansion, do so by temporarily
14969 // forgetting the partially-substituted parameter pack.
14970 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14971
14972 TypeLocBuilder TLB;
14973 TLB.reserve(From->getTypeLoc().getFullDataSize());
14974
14975 QualType To = getDerived().TransformType(TLB, PatternTL);
14976 if (To.isNull())
14977 return ExprError();
14978
14979 To = getDerived().RebuildPackExpansionType(To,
14980 PatternTL.getSourceRange(),
14981 ExpansionTL.getEllipsisLoc(),
14982 NumExpansions);
14983 if (To.isNull())
14984 return ExprError();
14985
14986 PackExpansionTypeLoc ToExpansionTL
14987 = TLB.push<PackExpansionTypeLoc>(To);
14988 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14989 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14990 }
14991
14992 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14993 return E;
14994
14995 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14996 E->getEndLoc());
14997}
14998
14999template<typename Derived>
15003 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15004 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15005 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15006 Old->NumTemplateArgs, TransArgs))
15007 return ExprError();
15008
15009 return getDerived().RebuildConceptSpecializationExpr(
15010 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15011 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15012 &TransArgs);
15013}
15014
15015template<typename Derived>
15018 SmallVector<ParmVarDecl*, 4> TransParams;
15019 SmallVector<QualType, 4> TransParamTypes;
15020 Sema::ExtParameterInfoBuilder ExtParamInfos;
15021
15022 // C++2a [expr.prim.req]p2
15023 // Expressions appearing within a requirement-body are unevaluated operands.
15027
15029 getSema().Context, getSema().CurContext,
15030 E->getBody()->getBeginLoc());
15031
15032 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15033
15034 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15035 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15036 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15037
15038 for (ParmVarDecl *Param : TransParams)
15039 if (Param)
15040 Param->setDeclContext(Body);
15041
15042 // On failure to transform, TransformRequiresTypeParams returns an expression
15043 // in the event that the transformation of the type params failed in some way.
15044 // It is expected that this will result in a 'not satisfied' Requires clause
15045 // when instantiating.
15046 if (!TypeParamResult.isUnset())
15047 return TypeParamResult;
15048
15050 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15051 TransReqs))
15052 return ExprError();
15053
15054 for (concepts::Requirement *Req : TransReqs) {
15055 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15056 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15057 ER->getReturnTypeRequirement()
15058 .getTypeConstraintTemplateParameterList()->getParam(0)
15059 ->setDeclContext(Body);
15060 }
15061 }
15062 }
15063
15064 return getDerived().RebuildRequiresExpr(
15065 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15066 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15067}
15068
15069template<typename Derived>
15073 for (concepts::Requirement *Req : Reqs) {
15074 concepts::Requirement *TransReq = nullptr;
15075 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15076 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15077 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15078 TransReq = getDerived().TransformExprRequirement(ExprReq);
15079 else
15080 TransReq = getDerived().TransformNestedRequirement(
15082 if (!TransReq)
15083 return true;
15084 Transformed.push_back(TransReq);
15085 }
15086 return false;
15087}
15088
15089template<typename Derived>
15093 if (Req->isSubstitutionFailure()) {
15094 if (getDerived().AlwaysRebuild())
15095 return getDerived().RebuildTypeRequirement(
15097 return Req;
15098 }
15099 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15100 if (!TransType)
15101 return nullptr;
15102 return getDerived().RebuildTypeRequirement(TransType);
15103}
15104
15105template<typename Derived>
15108 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15109 if (Req->isExprSubstitutionFailure())
15110 TransExpr = Req->getExprSubstitutionDiagnostic();
15111 else {
15112 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15113 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15114 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15115 if (TransExprRes.isInvalid())
15116 return nullptr;
15117 TransExpr = TransExprRes.get();
15118 }
15119
15120 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15121 const auto &RetReq = Req->getReturnTypeRequirement();
15122 if (RetReq.isEmpty())
15123 TransRetReq.emplace();
15124 else if (RetReq.isSubstitutionFailure())
15125 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15126 else if (RetReq.isTypeConstraint()) {
15127 TemplateParameterList *OrigTPL =
15128 RetReq.getTypeConstraintTemplateParameterList();
15130 getDerived().TransformTemplateParameterList(OrigTPL);
15131 if (!TPL)
15132 return nullptr;
15133 TransRetReq.emplace(TPL);
15134 }
15135 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15136 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15137 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15138 Req->getNoexceptLoc(),
15139 std::move(*TransRetReq));
15140 return getDerived().RebuildExprRequirement(
15142 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15143}
15144
15145template<typename Derived>
15149 if (Req->hasInvalidConstraint()) {
15150 if (getDerived().AlwaysRebuild())
15151 return getDerived().RebuildNestedRequirement(
15153 return Req;
15154 }
15155 ExprResult TransConstraint =
15156 getDerived().TransformExpr(Req->getConstraintExpr());
15157 if (TransConstraint.isInvalid())
15158 return nullptr;
15159 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15160}
15161
15162template<typename Derived>
15165 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15166 if (!T)
15167 return ExprError();
15168
15169 if (!getDerived().AlwaysRebuild() &&
15171 return E;
15172
15173 ExprResult SubExpr;
15174 {
15177 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15178 if (SubExpr.isInvalid())
15179 return ExprError();
15180 }
15181
15182 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15183 SubExpr.get(), E->getEndLoc());
15184}
15185
15186template<typename Derived>
15189 ExprResult SubExpr;
15190 {
15193 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15194 if (SubExpr.isInvalid())
15195 return ExprError();
15196
15197 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15198 return E;
15199 }
15200
15201 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15202 SubExpr.get(), E->getEndLoc());
15203}
15204
15205template <typename Derived>
15207 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15208 TypeSourceInfo **RecoveryTSI) {
15209 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15210 DRE, AddrTaken, RecoveryTSI);
15211
15212 // Propagate both errors and recovered types, which return ExprEmpty.
15213 if (!NewDRE.isUsable())
15214 return NewDRE;
15215
15216 // We got an expr, wrap it up in parens.
15217 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15218 return PE;
15219 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15220 PE->getRParen());
15221}
15222
15223template <typename Derived>
15229
15230template <typename Derived>
15232 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15233 TypeSourceInfo **RecoveryTSI) {
15234 assert(E->getQualifierLoc());
15235 NestedNameSpecifierLoc QualifierLoc =
15236 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15237 if (!QualifierLoc)
15238 return ExprError();
15239 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15240
15241 // TODO: If this is a conversion-function-id, verify that the
15242 // destination type name (if present) resolves the same way after
15243 // instantiation as it did in the local scope.
15244
15245 DeclarationNameInfo NameInfo =
15246 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15247 if (!NameInfo.getName())
15248 return ExprError();
15249
15250 if (!E->hasExplicitTemplateArgs()) {
15251 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15252 // Note: it is sufficient to compare the Name component of NameInfo:
15253 // if name has not changed, DNLoc has not changed either.
15254 NameInfo.getName() == E->getDeclName())
15255 return E;
15256
15257 return getDerived().RebuildDependentScopeDeclRefExpr(
15258 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15259 IsAddressOfOperand, RecoveryTSI);
15260 }
15261
15262 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15263 if (getDerived().TransformTemplateArguments(
15264 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15265 return ExprError();
15266
15267 return getDerived().RebuildDependentScopeDeclRefExpr(
15268 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15269 RecoveryTSI);
15270}
15271
15272template<typename Derived>
15275 // CXXConstructExprs other than for list-initialization and
15276 // CXXTemporaryObjectExpr are always implicit, so when we have
15277 // a 1-argument construction we just transform that argument.
15278 if (getDerived().AllowSkippingCXXConstructExpr() &&
15279 ((E->getNumArgs() == 1 ||
15280 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15281 (!getDerived().DropCallArgument(E->getArg(0))) &&
15282 !E->isListInitialization()))
15283 return getDerived().TransformInitializer(E->getArg(0),
15284 /*DirectInit*/ false);
15285
15286 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15287
15288 QualType T = getDerived().TransformType(E->getType());
15289 if (T.isNull())
15290 return ExprError();
15291
15292 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15293 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15294 if (!Constructor)
15295 return ExprError();
15296
15297 bool ArgumentChanged = false;
15299 {
15302 E->isListInitialization());
15303 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15304 &ArgumentChanged))
15305 return ExprError();
15306 }
15307
15308 if (!getDerived().AlwaysRebuild() &&
15309 T == E->getType() &&
15310 Constructor == E->getConstructor() &&
15311 !ArgumentChanged) {
15312 // Mark the constructor as referenced.
15313 // FIXME: Instantiation-specific
15314 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15315 return E;
15316 }
15317
15318 return getDerived().RebuildCXXConstructExpr(
15319 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15320 E->hadMultipleCandidates(), E->isListInitialization(),
15321 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15322 E->getConstructionKind(), E->getParenOrBraceRange());
15323}
15324
15325template<typename Derived>
15328 QualType T = getDerived().TransformType(E->getType());
15329 if (T.isNull())
15330 return ExprError();
15331
15332 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15333 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15334 if (!Constructor)
15335 return ExprError();
15336
15337 if (!getDerived().AlwaysRebuild() &&
15338 T == E->getType() &&
15339 Constructor == E->getConstructor()) {
15340 // Mark the constructor as referenced.
15341 // FIXME: Instantiation-specific
15342 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15343 return E;
15344 }
15345
15346 return getDerived().RebuildCXXInheritedCtorInitExpr(
15347 T, E->getLocation(), Constructor,
15348 E->constructsVBase(), E->inheritedFromVBase());
15349}
15350
15351/// Transform a C++ temporary-binding expression.
15352///
15353/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15354/// transform the subexpression and return that.
15355template<typename Derived>
15358 if (auto *Dtor = E->getTemporary()->getDestructor())
15359 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15360 const_cast<CXXDestructorDecl *>(Dtor));
15361 return getDerived().TransformExpr(E->getSubExpr());
15362}
15363
15364/// Transform a C++ expression that contains cleanups that should
15365/// be run after the expression is evaluated.
15366///
15367/// Since ExprWithCleanups nodes are implicitly generated, we
15368/// just transform the subexpression and return that.
15369template<typename Derived>
15372 return getDerived().TransformExpr(E->getSubExpr());
15373}
15374
15375template<typename Derived>
15379 TypeSourceInfo *T =
15380 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15381 if (!T)
15382 return ExprError();
15383
15384 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15385 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15386 if (!Constructor)
15387 return ExprError();
15388
15389 bool ArgumentChanged = false;
15391 Args.reserve(E->getNumArgs());
15392 {
15395 E->isListInitialization());
15396 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15397 &ArgumentChanged))
15398 return ExprError();
15399
15400 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15401 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15402 if (Res.isInvalid())
15403 return ExprError();
15404 Args = {Res.get()};
15405 }
15406 }
15407
15408 if (!getDerived().AlwaysRebuild() &&
15409 T == E->getTypeSourceInfo() &&
15410 Constructor == E->getConstructor() &&
15411 !ArgumentChanged) {
15412 // FIXME: Instantiation-specific
15413 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15414 return SemaRef.MaybeBindToTemporary(E);
15415 }
15416
15417 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15418 return getDerived().RebuildCXXTemporaryObjectExpr(
15419 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15420}
15421
15422template<typename Derived>
15425 // Transform any init-capture expressions before entering the scope of the
15426 // lambda body, because they are not semantically within that scope.
15427 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15428 struct TransformedInitCapture {
15429 // The location of the ... if the result is retaining a pack expansion.
15430 SourceLocation EllipsisLoc;
15431 // Zero or more expansions of the init-capture.
15432 SmallVector<InitCaptureInfoTy, 4> Expansions;
15433 };
15435 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15436 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15437 CEnd = E->capture_end();
15438 C != CEnd; ++C) {
15439 if (!E->isInitCapture(C))
15440 continue;
15441
15442 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15443 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15444
15445 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15446 UnsignedOrNone NumExpansions) {
15447 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15448 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15449
15450 if (NewExprInitResult.isInvalid()) {
15451 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15452 return;
15453 }
15454 Expr *NewExprInit = NewExprInitResult.get();
15455
15456 QualType NewInitCaptureType =
15457 getSema().buildLambdaInitCaptureInitialization(
15458 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15459 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15460 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15462 NewExprInit);
15463 Result.Expansions.push_back(
15464 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15465 };
15466
15467 // If this is an init-capture pack, consider expanding the pack now.
15468 if (OldVD->isParameterPack()) {
15469 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15470 ->getTypeLoc()
15473 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15474
15475 // Determine whether the set of unexpanded parameter packs can and should
15476 // be expanded.
15477 bool Expand = true;
15478 bool RetainExpansion = false;
15479 UnsignedOrNone OrigNumExpansions =
15480 ExpansionTL.getTypePtr()->getNumExpansions();
15481 UnsignedOrNone NumExpansions = OrigNumExpansions;
15482 if (getDerived().TryExpandParameterPacks(
15483 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
15484 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15485 RetainExpansion, NumExpansions))
15486 return ExprError();
15487 assert(!RetainExpansion && "Should not need to retain expansion after a "
15488 "capture since it cannot be extended");
15489 if (Expand) {
15490 for (unsigned I = 0; I != *NumExpansions; ++I) {
15491 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15492 SubstInitCapture(SourceLocation(), std::nullopt);
15493 }
15494 } else {
15495 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15496 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15497 }
15498 } else {
15499 SubstInitCapture(SourceLocation(), std::nullopt);
15500 }
15501 }
15502
15503 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15504 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15505
15506 // Create the local class that will describe the lambda.
15507
15508 // FIXME: DependencyKind below is wrong when substituting inside a templated
15509 // context that isn't a DeclContext (such as a variable template), or when
15510 // substituting an unevaluated lambda inside of a function's parameter's type
15511 // - as parameter types are not instantiated from within a function's DC. We
15512 // use evaluation contexts to distinguish the function parameter case.
15515 DeclContext *DC = getSema().CurContext;
15516 // A RequiresExprBodyDecl is not interesting for dependencies.
15517 // For the following case,
15518 //
15519 // template <typename>
15520 // concept C = requires { [] {}; };
15521 //
15522 // template <class F>
15523 // struct Widget;
15524 //
15525 // template <C F>
15526 // struct Widget<F> {};
15527 //
15528 // While we are substituting Widget<F>, the parent of DC would be
15529 // the template specialization itself. Thus, the lambda expression
15530 // will be deemed as dependent even if there are no dependent template
15531 // arguments.
15532 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15533 while (DC->isRequiresExprBody())
15534 DC = DC->getParent();
15535 if ((getSema().isUnevaluatedContext() ||
15536 getSema().isConstantEvaluatedContext()) &&
15537 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15538 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15539
15540 CXXRecordDecl *OldClass = E->getLambdaClass();
15541 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15542 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15543 E->getCaptureDefault());
15544 getDerived().transformedLocalDecl(OldClass, {Class});
15545
15546 CXXMethodDecl *NewCallOperator =
15547 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15548
15549 // Enter the scope of the lambda.
15550 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15551 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15552 E->hasExplicitParameters(), E->isMutable());
15553
15554 // Introduce the context of the call operator.
15555 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15556 /*NewThisContext*/false);
15557
15558 bool Invalid = false;
15559
15560 // Transform captures.
15561 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15562 CEnd = E->capture_end();
15563 C != CEnd; ++C) {
15564 // When we hit the first implicit capture, tell Sema that we've finished
15565 // the list of explicit captures.
15566 if (C->isImplicit())
15567 break;
15568
15569 // Capturing 'this' is trivial.
15570 if (C->capturesThis()) {
15571 // If this is a lambda that is part of a default member initialiser
15572 // and which we're instantiating outside the class that 'this' is
15573 // supposed to refer to, adjust the type of 'this' accordingly.
15574 //
15575 // Otherwise, leave the type of 'this' as-is.
15576 Sema::CXXThisScopeRAII ThisScope(
15577 getSema(),
15578 dyn_cast_if_present<CXXRecordDecl>(
15579 getSema().getFunctionLevelDeclContext()),
15580 Qualifiers());
15581 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15582 /*BuildAndDiagnose*/ true, nullptr,
15583 C->getCaptureKind() == LCK_StarThis);
15584 continue;
15585 }
15586 // Captured expression will be recaptured during captured variables
15587 // rebuilding.
15588 if (C->capturesVLAType())
15589 continue;
15590
15591 // Rebuild init-captures, including the implied field declaration.
15592 if (E->isInitCapture(C)) {
15593 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15594
15595 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15597
15598 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15599 ExprResult Init = Info.first;
15600 QualType InitQualType = Info.second;
15601 if (Init.isInvalid() || InitQualType.isNull()) {
15602 Invalid = true;
15603 break;
15604 }
15605 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15606 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15607 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15608 getSema().CurContext);
15609 if (!NewVD) {
15610 Invalid = true;
15611 break;
15612 }
15613 NewVDs.push_back(NewVD);
15614 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15615 // Cases we want to tackle:
15616 // ([C(Pack)] {}, ...)
15617 // But rule out cases e.g.
15618 // [...C = Pack()] {}
15619 if (NewC.EllipsisLoc.isInvalid())
15620 LSI->ContainsUnexpandedParameterPack |=
15621 Init.get()->containsUnexpandedParameterPack();
15622 }
15623
15624 if (Invalid)
15625 break;
15626
15627 getDerived().transformedLocalDecl(OldVD, NewVDs);
15628 continue;
15629 }
15630
15631 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15632
15633 // Determine the capture kind for Sema.
15635 : C->getCaptureKind() == LCK_ByCopy
15638 SourceLocation EllipsisLoc;
15639 if (C->isPackExpansion()) {
15640 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15641 bool ShouldExpand = false;
15642 bool RetainExpansion = false;
15643 UnsignedOrNone NumExpansions = std::nullopt;
15644 if (getDerived().TryExpandParameterPacks(
15645 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
15646 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
15647 RetainExpansion, NumExpansions)) {
15648 Invalid = true;
15649 continue;
15650 }
15651
15652 if (ShouldExpand) {
15653 // The transform has determined that we should perform an expansion;
15654 // transform and capture each of the arguments.
15655 // expansion of the pattern. Do so.
15656 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
15657 for (unsigned I = 0; I != *NumExpansions; ++I) {
15658 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15659 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
15660 getDerived().TransformDecl(C->getLocation(), Pack));
15661 if (!CapturedVar) {
15662 Invalid = true;
15663 continue;
15664 }
15665
15666 // Capture the transformed variable.
15667 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15668 }
15669
15670 // FIXME: Retain a pack expansion if RetainExpansion is true.
15671
15672 continue;
15673 }
15674
15675 EllipsisLoc = C->getEllipsisLoc();
15676 }
15677
15678 // Transform the captured variable.
15679 auto *CapturedVar = cast_or_null<ValueDecl>(
15680 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15681 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15682 Invalid = true;
15683 continue;
15684 }
15685
15686 // This is not an init-capture; however it contains an unexpanded pack e.g.
15687 // ([Pack] {}(), ...)
15688 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15689 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15690
15691 // Capture the transformed variable.
15692 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15693 EllipsisLoc);
15694 }
15695 getSema().finishLambdaExplicitCaptures(LSI);
15696
15697 // Transform the template parameters, and add them to the current
15698 // instantiation scope. The null case is handled correctly.
15699 auto TPL = getDerived().TransformTemplateParameterList(
15700 E->getTemplateParameterList());
15701 LSI->GLTemplateParameterList = TPL;
15702 if (TPL) {
15703 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15704 TPL);
15705 LSI->ContainsUnexpandedParameterPack |=
15706 TPL->containsUnexpandedParameterPack();
15707 }
15708
15709 TypeLocBuilder NewCallOpTLBuilder;
15710 TypeLoc OldCallOpTypeLoc =
15711 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15712 QualType NewCallOpType =
15713 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15714 if (NewCallOpType.isNull())
15715 return ExprError();
15716 LSI->ContainsUnexpandedParameterPack |=
15717 NewCallOpType->containsUnexpandedParameterPack();
15718 TypeSourceInfo *NewCallOpTSI =
15719 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15720
15721 // The type may be an AttributedType or some other kind of sugar;
15722 // get the actual underlying FunctionProtoType.
15723 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15724 assert(FPTL && "Not a FunctionProtoType?");
15725
15726 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
15727 if (!TRC.ArgPackSubstIndex)
15729
15730 getSema().CompleteLambdaCallOperator(
15731 NewCallOperator, E->getCallOperator()->getLocation(),
15732 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
15733 E->getCallOperator()->getConstexprKind(),
15734 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15735 E->hasExplicitResultType());
15736
15737 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15738 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15739
15740 {
15741 // Number the lambda for linkage purposes if necessary.
15742 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15743
15744 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15745 if (getDerived().ReplacingOriginal()) {
15746 Numbering = OldClass->getLambdaNumbering();
15747 }
15748
15749 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15750 }
15751
15752 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15753 // evaluation context even if we're not transforming the function body.
15754 getSema().PushExpressionEvaluationContextForFunction(
15756 E->getCallOperator());
15757
15760 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15761 getSema().pushCodeSynthesisContext(C);
15762
15763 // Instantiate the body of the lambda expression.
15764 StmtResult Body =
15765 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15766
15767 getSema().popCodeSynthesisContext();
15768
15769 // ActOnLambda* will pop the function scope for us.
15770 FuncScopeCleanup.disable();
15771
15772 if (Body.isInvalid()) {
15773 SavedContext.pop();
15774 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15775 /*IsInstantiation=*/true);
15776 return ExprError();
15777 }
15778
15779 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15780 /*IsInstantiation=*/true,
15781 /*RetainFunctionScopeInfo=*/true);
15782 SavedContext.pop();
15783
15784 // Recompute the dependency of the lambda so that we can defer the lambda call
15785 // construction until after we have all the necessary template arguments. For
15786 // example, given
15787 //
15788 // template <class> struct S {
15789 // template <class U>
15790 // using Type = decltype([](U){}(42.0));
15791 // };
15792 // void foo() {
15793 // using T = S<int>::Type<float>;
15794 // ^~~~~~
15795 // }
15796 //
15797 // We would end up here from instantiating S<int> when ensuring its
15798 // completeness. That would transform the lambda call expression regardless of
15799 // the absence of the corresponding argument for U.
15800 //
15801 // Going ahead with unsubstituted type U makes things worse: we would soon
15802 // compare the argument type (which is float) against the parameter U
15803 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15804 // error suggesting unmatched types 'U' and 'float'!
15805 //
15806 // That said, everything will be fine if we defer that semantic checking.
15807 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15808 // dependent. Since the CallExpr's dependency boils down to the lambda's
15809 // dependency in this case, we can harness that by recomputing the dependency
15810 // from the instantiation arguments.
15811 //
15812 // FIXME: Creating the type of a lambda requires us to have a dependency
15813 // value, which happens before its substitution. We update its dependency
15814 // *after* the substitution in case we can't decide the dependency
15815 // so early, e.g. because we want to see if any of the *substituted*
15816 // parameters are dependent.
15817 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15818 Class->setLambdaDependencyKind(DependencyKind);
15819
15820 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15821 Body.get()->getEndLoc(), LSI);
15822}
15823
15824template<typename Derived>
15829
15830template<typename Derived>
15833 // Transform captures.
15835 CEnd = E->capture_end();
15836 C != CEnd; ++C) {
15837 // When we hit the first implicit capture, tell Sema that we've finished
15838 // the list of explicit captures.
15839 if (!C->isImplicit())
15840 continue;
15841
15842 // Capturing 'this' is trivial.
15843 if (C->capturesThis()) {
15844 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15845 /*BuildAndDiagnose*/ true, nullptr,
15846 C->getCaptureKind() == LCK_StarThis);
15847 continue;
15848 }
15849 // Captured expression will be recaptured during captured variables
15850 // rebuilding.
15851 if (C->capturesVLAType())
15852 continue;
15853
15854 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15855 assert(!E->isInitCapture(C) && "implicit init-capture?");
15856
15857 // Transform the captured variable.
15858 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15859 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15860 if (!CapturedVar || CapturedVar->isInvalidDecl())
15861 return StmtError();
15862
15863 // Capture the transformed variable.
15864 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15865 }
15866
15867 return S;
15868}
15869
15870template<typename Derived>
15874 TypeSourceInfo *T =
15875 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15876 if (!T)
15877 return ExprError();
15878
15879 bool ArgumentChanged = false;
15881 Args.reserve(E->getNumArgs());
15882 {
15886 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15887 &ArgumentChanged))
15888 return ExprError();
15889 }
15890
15891 if (!getDerived().AlwaysRebuild() &&
15892 T == E->getTypeSourceInfo() &&
15893 !ArgumentChanged)
15894 return E;
15895
15896 // FIXME: we're faking the locations of the commas
15897 return getDerived().RebuildCXXUnresolvedConstructExpr(
15898 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15899}
15900
15901template<typename Derived>
15905 // Transform the base of the expression.
15906 ExprResult Base((Expr*) nullptr);
15907 Expr *OldBase;
15908 QualType BaseType;
15909 QualType ObjectType;
15910 if (!E->isImplicitAccess()) {
15911 OldBase = E->getBase();
15912 Base = getDerived().TransformExpr(OldBase);
15913 if (Base.isInvalid())
15914 return ExprError();
15915
15916 // Start the member reference and compute the object's type.
15917 ParsedType ObjectTy;
15918 bool MayBePseudoDestructor = false;
15919 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15920 E->getOperatorLoc(),
15921 E->isArrow()? tok::arrow : tok::period,
15922 ObjectTy,
15923 MayBePseudoDestructor);
15924 if (Base.isInvalid())
15925 return ExprError();
15926
15927 ObjectType = ObjectTy.get();
15928 BaseType = ((Expr*) Base.get())->getType();
15929 } else {
15930 OldBase = nullptr;
15931 BaseType = getDerived().TransformType(E->getBaseType());
15932 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15933 }
15934
15935 // Transform the first part of the nested-name-specifier that qualifies
15936 // the member name.
15937 NamedDecl *FirstQualifierInScope
15938 = getDerived().TransformFirstQualifierInScope(
15939 E->getFirstQualifierFoundInScope(),
15940 E->getQualifierLoc().getBeginLoc());
15941
15942 NestedNameSpecifierLoc QualifierLoc;
15943 if (E->getQualifier()) {
15944 QualifierLoc
15945 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15946 ObjectType,
15947 FirstQualifierInScope);
15948 if (!QualifierLoc)
15949 return ExprError();
15950 }
15951
15952 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15953
15954 // TODO: If this is a conversion-function-id, verify that the
15955 // destination type name (if present) resolves the same way after
15956 // instantiation as it did in the local scope.
15957
15958 DeclarationNameInfo NameInfo
15959 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15960 if (!NameInfo.getName())
15961 return ExprError();
15962
15963 if (!E->hasExplicitTemplateArgs()) {
15964 // This is a reference to a member without an explicitly-specified
15965 // template argument list. Optimize for this common case.
15966 if (!getDerived().AlwaysRebuild() &&
15967 Base.get() == OldBase &&
15968 BaseType == E->getBaseType() &&
15969 QualifierLoc == E->getQualifierLoc() &&
15970 NameInfo.getName() == E->getMember() &&
15971 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15972 return E;
15973
15974 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15975 BaseType,
15976 E->isArrow(),
15977 E->getOperatorLoc(),
15978 QualifierLoc,
15979 TemplateKWLoc,
15980 FirstQualifierInScope,
15981 NameInfo,
15982 /*TemplateArgs*/nullptr);
15983 }
15984
15985 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15986 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15987 E->getNumTemplateArgs(),
15988 TransArgs))
15989 return ExprError();
15990
15991 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15992 BaseType,
15993 E->isArrow(),
15994 E->getOperatorLoc(),
15995 QualifierLoc,
15996 TemplateKWLoc,
15997 FirstQualifierInScope,
15998 NameInfo,
15999 &TransArgs);
16000}
16001
16002template <typename Derived>
16004 UnresolvedMemberExpr *Old) {
16005 // Transform the base of the expression.
16006 ExprResult Base((Expr *)nullptr);
16007 QualType BaseType;
16008 if (!Old->isImplicitAccess()) {
16009 Base = getDerived().TransformExpr(Old->getBase());
16010 if (Base.isInvalid())
16011 return ExprError();
16012 Base =
16013 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16014 if (Base.isInvalid())
16015 return ExprError();
16016 BaseType = Base.get()->getType();
16017 } else {
16018 BaseType = getDerived().TransformType(Old->getBaseType());
16019 }
16020
16021 NestedNameSpecifierLoc QualifierLoc;
16022 if (Old->getQualifierLoc()) {
16023 QualifierLoc =
16024 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16025 if (!QualifierLoc)
16026 return ExprError();
16027 }
16028
16029 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16030
16031 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16032
16033 // Transform the declaration set.
16034 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16035 return ExprError();
16036
16037 // Determine the naming class.
16038 if (Old->getNamingClass()) {
16039 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16040 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16041 if (!NamingClass)
16042 return ExprError();
16043
16044 R.setNamingClass(NamingClass);
16045 }
16046
16047 TemplateArgumentListInfo TransArgs;
16048 if (Old->hasExplicitTemplateArgs()) {
16049 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16050 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16051 if (getDerived().TransformTemplateArguments(
16052 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16053 return ExprError();
16054 }
16055
16056 // FIXME: to do this check properly, we will need to preserve the
16057 // first-qualifier-in-scope here, just in case we had a dependent
16058 // base (and therefore couldn't do the check) and a
16059 // nested-name-qualifier (and therefore could do the lookup).
16060 NamedDecl *FirstQualifierInScope = nullptr;
16061
16062 return getDerived().RebuildUnresolvedMemberExpr(
16063 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16064 TemplateKWLoc, FirstQualifierInScope, R,
16065 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16066}
16067
16068template<typename Derived>
16073 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16074 if (SubExpr.isInvalid())
16075 return ExprError();
16076
16077 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16078 return E;
16079
16080 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16081}
16082
16083template<typename Derived>
16086 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16087 if (Pattern.isInvalid())
16088 return ExprError();
16089
16090 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16091 return E;
16092
16093 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16094 E->getNumExpansions());
16095}
16096
16097template <typename Derived>
16099 ArrayRef<TemplateArgument> PackArgs) {
16101 for (const TemplateArgument &Arg : PackArgs) {
16102 if (!Arg.isPackExpansion()) {
16103 Result = *Result + 1;
16104 continue;
16105 }
16106
16107 TemplateArgumentLoc ArgLoc;
16108 InventTemplateArgumentLoc(Arg, ArgLoc);
16109
16110 // Find the pattern of the pack expansion.
16111 SourceLocation Ellipsis;
16112 UnsignedOrNone OrigNumExpansions = std::nullopt;
16113 TemplateArgumentLoc Pattern =
16114 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16115 OrigNumExpansions);
16116
16117 // Substitute under the pack expansion. Do not expand the pack (yet).
16118 TemplateArgumentLoc OutPattern;
16119 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16120 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16121 /*Uneval*/ true))
16122 return 1u;
16123
16124 // See if we can determine the number of arguments from the result.
16125 UnsignedOrNone NumExpansions =
16126 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16127 if (!NumExpansions) {
16128 // No: we must be in an alias template expansion, and we're going to
16129 // need to actually expand the packs.
16130 Result = std::nullopt;
16131 break;
16132 }
16133
16134 Result = *Result + *NumExpansions;
16135 }
16136 return Result;
16137}
16138
16139template<typename Derived>
16142 // If E is not value-dependent, then nothing will change when we transform it.
16143 // Note: This is an instantiation-centric view.
16144 if (!E->isValueDependent())
16145 return E;
16146
16149
16151 TemplateArgument ArgStorage;
16152
16153 // Find the argument list to transform.
16154 if (E->isPartiallySubstituted()) {
16155 PackArgs = E->getPartialArguments();
16156 } else if (E->isValueDependent()) {
16157 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16158 bool ShouldExpand = false;
16159 bool RetainExpansion = false;
16160 UnsignedOrNone NumExpansions = std::nullopt;
16161 if (getDerived().TryExpandParameterPacks(
16162 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16163 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16164 RetainExpansion, NumExpansions))
16165 return ExprError();
16166
16167 // If we need to expand the pack, build a template argument from it and
16168 // expand that.
16169 if (ShouldExpand) {
16170 auto *Pack = E->getPack();
16171 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16172 ArgStorage = getSema().Context.getPackExpansionType(
16173 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16174 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16175 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16176 } else {
16177 auto *VD = cast<ValueDecl>(Pack);
16178 ExprResult DRE = getSema().BuildDeclRefExpr(
16179 VD, VD->getType().getNonLValueExprType(getSema().Context),
16180 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16181 E->getPackLoc());
16182 if (DRE.isInvalid())
16183 return ExprError();
16184 ArgStorage = TemplateArgument(
16185 new (getSema().Context)
16186 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16187 /*IsCanonical=*/false);
16188 }
16189 PackArgs = ArgStorage;
16190 }
16191 }
16192
16193 // If we're not expanding the pack, just transform the decl.
16194 if (!PackArgs.size()) {
16195 auto *Pack = cast_or_null<NamedDecl>(
16196 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16197 if (!Pack)
16198 return ExprError();
16199 return getDerived().RebuildSizeOfPackExpr(
16200 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16201 std::nullopt, {});
16202 }
16203
16204 // Try to compute the result without performing a partial substitution.
16206 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16207
16208 // Common case: we could determine the number of expansions without
16209 // substituting.
16210 if (Result)
16211 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16212 E->getPackLoc(),
16213 E->getRParenLoc(), *Result, {});
16214
16215 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16216 E->getPackLoc());
16217 {
16218 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16220 Derived, const TemplateArgument*> PackLocIterator;
16221 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16222 PackLocIterator(*this, PackArgs.end()),
16223 TransformedPackArgs, /*Uneval*/true))
16224 return ExprError();
16225 }
16226
16227 // Check whether we managed to fully-expand the pack.
16228 // FIXME: Is it possible for us to do so and not hit the early exit path?
16230 bool PartialSubstitution = false;
16231 for (auto &Loc : TransformedPackArgs.arguments()) {
16232 Args.push_back(Loc.getArgument());
16233 if (Loc.getArgument().isPackExpansion())
16234 PartialSubstitution = true;
16235 }
16236
16237 if (PartialSubstitution)
16238 return getDerived().RebuildSizeOfPackExpr(
16239 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16240 std::nullopt, Args);
16241
16242 return getDerived().RebuildSizeOfPackExpr(
16243 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16244 /*Length=*/static_cast<unsigned>(Args.size()),
16245 /*PartialArgs=*/{});
16246}
16247
16248template <typename Derived>
16251 if (!E->isValueDependent())
16252 return E;
16253
16254 // Transform the index
16255 ExprResult IndexExpr;
16256 {
16257 EnterExpressionEvaluationContext ConstantContext(
16259 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16260 if (IndexExpr.isInvalid())
16261 return ExprError();
16262 }
16263
16264 SmallVector<Expr *, 5> ExpandedExprs;
16265 bool FullySubstituted = true;
16266 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16267 Expr *Pattern = E->getPackIdExpression();
16269 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16270 Unexpanded);
16271 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16272
16273 // Determine whether the set of unexpanded parameter packs can and should
16274 // be expanded.
16275 bool ShouldExpand = true;
16276 bool RetainExpansion = false;
16277 UnsignedOrNone OrigNumExpansions = std::nullopt,
16278 NumExpansions = std::nullopt;
16279 if (getDerived().TryExpandParameterPacks(
16280 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16281 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16282 RetainExpansion, NumExpansions))
16283 return true;
16284 if (!ShouldExpand) {
16285 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16286 ExprResult Pack = getDerived().TransformExpr(Pattern);
16287 if (Pack.isInvalid())
16288 return ExprError();
16289 return getDerived().RebuildPackIndexingExpr(
16290 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16291 {}, /*FullySubstituted=*/false);
16292 }
16293 for (unsigned I = 0; I != *NumExpansions; ++I) {
16294 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16295 ExprResult Out = getDerived().TransformExpr(Pattern);
16296 if (Out.isInvalid())
16297 return true;
16298 if (Out.get()->containsUnexpandedParameterPack()) {
16299 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16300 OrigNumExpansions);
16301 if (Out.isInvalid())
16302 return true;
16303 FullySubstituted = false;
16304 }
16305 ExpandedExprs.push_back(Out.get());
16306 }
16307 // If we're supposed to retain a pack expansion, do so by temporarily
16308 // forgetting the partially-substituted parameter pack.
16309 if (RetainExpansion) {
16310 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16311
16312 ExprResult Out = getDerived().TransformExpr(Pattern);
16313 if (Out.isInvalid())
16314 return true;
16315
16316 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16317 OrigNumExpansions);
16318 if (Out.isInvalid())
16319 return true;
16320 FullySubstituted = false;
16321 ExpandedExprs.push_back(Out.get());
16322 }
16323 } else if (!E->expandsToEmptyPack()) {
16324 if (getDerived().TransformExprs(E->getExpressions().data(),
16325 E->getExpressions().size(), false,
16326 ExpandedExprs))
16327 return ExprError();
16328 }
16329
16330 return getDerived().RebuildPackIndexingExpr(
16331 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16332 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16333}
16334
16335template <typename Derived>
16338 if (!getSema().ArgPackSubstIndex)
16339 // We aren't expanding the parameter pack, so just return ourselves.
16340 return E;
16341
16342 TemplateArgument Pack = E->getArgumentPack();
16344 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
16345 E->getAssociatedDecl(), E->getParameterPack(),
16346 E->getParameterPackLocation(), Arg, SemaRef.getPackIndex(Pack),
16347 E->getFinal());
16348}
16349
16350template <typename Derived>
16353 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16354 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
16355 if (Replacement.isInvalid())
16356 return true;
16357
16358 Decl *AssociatedDecl =
16359 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
16360 if (!AssociatedDecl)
16361 return true;
16362
16363 if (Replacement.get() == OrigReplacement &&
16364 AssociatedDecl == E->getAssociatedDecl())
16365 return E;
16366
16367 // If the replacement expression did not change, and the parameter type
16368 // did not change, we can skip the semantic action because it would
16369 // produce the same result anyway.
16370 auto *Param = cast<NonTypeTemplateParmDecl>(
16371 getReplacedTemplateParameterList(AssociatedDecl)
16372 ->asArray()[E->getIndex()]);
16373 if (QualType ParamType = Param->getType();
16374 !SemaRef.Context.hasSameType(ParamType, E->getParameter()->getType()) ||
16375 Replacement.get() != OrigReplacement) {
16376
16377 // When transforming the replacement expression previously, all Sema
16378 // specific annotations, such as implicit casts, are discarded. Calling the
16379 // corresponding sema action is necessary to recover those. Otherwise,
16380 // equivalency of the result would be lost.
16381 TemplateArgument SugaredConverted, CanonicalConverted;
16382 Replacement = SemaRef.CheckTemplateArgument(
16383 Param, ParamType, Replacement.get(), SugaredConverted,
16384 CanonicalConverted,
16385 /*StrictCheck=*/false, Sema::CTAK_Specified);
16386 if (Replacement.isInvalid())
16387 return true;
16388 } else {
16389 // Otherwise, the same expression would have been produced.
16390 Replacement = E->getReplacement();
16391 }
16392
16393 return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
16394 Replacement.get()->getType(), Replacement.get()->getValueKind(),
16395 E->getNameLoc(), Replacement.get(), AssociatedDecl, E->getIndex(),
16396 E->getPackIndex(), E->isReferenceParameter(), E->getFinal());
16397}
16398
16399template<typename Derived>
16402 // Default behavior is to do nothing with this transformation.
16403 return E;
16404}
16405
16406template<typename Derived>
16410 return getDerived().TransformExpr(E->getSubExpr());
16411}
16412
16413template<typename Derived>
16416 UnresolvedLookupExpr *Callee = nullptr;
16417 if (Expr *OldCallee = E->getCallee()) {
16418 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16419 if (CalleeResult.isInvalid())
16420 return ExprError();
16421 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16422 }
16423
16424 Expr *Pattern = E->getPattern();
16425
16427 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16428 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16429
16430 // Determine whether the set of unexpanded parameter packs can and should
16431 // be expanded.
16432 bool Expand = true;
16433 bool RetainExpansion = false;
16434 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
16435 NumExpansions = OrigNumExpansions;
16436 if (getDerived().TryExpandParameterPacks(
16437 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16438 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16439 NumExpansions))
16440 return true;
16441
16442 if (!Expand) {
16443 // Do not expand any packs here, just transform and rebuild a fold
16444 // expression.
16445 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16446
16447 ExprResult LHS =
16448 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16449 if (LHS.isInvalid())
16450 return true;
16451
16452 ExprResult RHS =
16453 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16454 if (RHS.isInvalid())
16455 return true;
16456
16457 if (!getDerived().AlwaysRebuild() &&
16458 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16459 return E;
16460
16461 return getDerived().RebuildCXXFoldExpr(
16462 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16463 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16464 }
16465
16466 // Formally a fold expression expands to nested parenthesized expressions.
16467 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16468 // them.
16469 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
16470 SemaRef.Diag(E->getEllipsisLoc(),
16471 clang::diag::err_fold_expression_limit_exceeded)
16472 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16473 << E->getSourceRange();
16474 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16475 return ExprError();
16476 }
16477
16478 // The transform has determined that we should perform an elementwise
16479 // expansion of the pattern. Do so.
16480 ExprResult Result = getDerived().TransformExpr(E->getInit());
16481 if (Result.isInvalid())
16482 return true;
16483 bool LeftFold = E->isLeftFold();
16484
16485 // If we're retaining an expansion for a right fold, it is the innermost
16486 // component and takes the init (if any).
16487 if (!LeftFold && RetainExpansion) {
16488 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16489
16490 ExprResult Out = getDerived().TransformExpr(Pattern);
16491 if (Out.isInvalid())
16492 return true;
16493
16494 Result = getDerived().RebuildCXXFoldExpr(
16495 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16496 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16497 if (Result.isInvalid())
16498 return true;
16499 }
16500
16501 bool WarnedOnComparison = false;
16502 for (unsigned I = 0; I != *NumExpansions; ++I) {
16503 Sema::ArgPackSubstIndexRAII SubstIndex(
16504 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16505 ExprResult Out = getDerived().TransformExpr(Pattern);
16506 if (Out.isInvalid())
16507 return true;
16508
16509 if (Out.get()->containsUnexpandedParameterPack()) {
16510 // We still have a pack; retain a pack expansion for this slice.
16511 Result = getDerived().RebuildCXXFoldExpr(
16512 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16513 E->getOperator(), E->getEllipsisLoc(),
16514 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16515 OrigNumExpansions);
16516 } else if (Result.isUsable()) {
16517 // We've got down to a single element; build a binary operator.
16518 Expr *LHS = LeftFold ? Result.get() : Out.get();
16519 Expr *RHS = LeftFold ? Out.get() : Result.get();
16520 if (Callee) {
16521 UnresolvedSet<16> Functions;
16522 Functions.append(Callee->decls_begin(), Callee->decls_end());
16523 Result = getDerived().RebuildCXXOperatorCallExpr(
16524 BinaryOperator::getOverloadedOperator(E->getOperator()),
16525 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16526 Functions, LHS, RHS);
16527 } else {
16528 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16529 E->getOperator(), LHS, RHS,
16530 /*ForFoldExpresion=*/true);
16531 if (!WarnedOnComparison && Result.isUsable()) {
16532 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
16533 BO && BO->isComparisonOp()) {
16534 WarnedOnComparison = true;
16535 SemaRef.Diag(BO->getBeginLoc(),
16536 diag::warn_comparison_in_fold_expression)
16537 << BO->getOpcodeStr();
16538 }
16539 }
16540 }
16541 } else
16542 Result = Out;
16543
16544 if (Result.isInvalid())
16545 return true;
16546 }
16547
16548 // If we're retaining an expansion for a left fold, it is the outermost
16549 // component and takes the complete expansion so far as its init (if any).
16550 if (LeftFold && RetainExpansion) {
16551 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16552
16553 ExprResult Out = getDerived().TransformExpr(Pattern);
16554 if (Out.isInvalid())
16555 return true;
16556
16557 Result = getDerived().RebuildCXXFoldExpr(
16558 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16559 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16560 if (Result.isInvalid())
16561 return true;
16562 }
16563
16564 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16565 PE->setIsProducedByFoldExpansion();
16566
16567 // If we had no init and an empty pack, and we're not retaining an expansion,
16568 // then produce a fallback value or error.
16569 if (Result.isUnset())
16570 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16571 E->getOperator());
16572 return Result;
16573}
16574
16575template <typename Derived>
16578 SmallVector<Expr *, 4> TransformedInits;
16579 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16580
16581 QualType T = getDerived().TransformType(E->getType());
16582
16583 bool ArgChanged = false;
16584
16585 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
16586 TransformedInits, &ArgChanged))
16587 return ExprError();
16588
16589 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
16590 return E;
16591
16592 return getDerived().RebuildCXXParenListInitExpr(
16593 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
16594 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
16595}
16596
16597template<typename Derived>
16601 return getDerived().TransformExpr(E->getSubExpr());
16602}
16603
16604template<typename Derived>
16607 return SemaRef.MaybeBindToTemporary(E);
16608}
16609
16610template<typename Derived>
16613 return E;
16614}
16615
16616template<typename Derived>
16619 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16620 if (SubExpr.isInvalid())
16621 return ExprError();
16622
16623 if (!getDerived().AlwaysRebuild() &&
16624 SubExpr.get() == E->getSubExpr())
16625 return E;
16626
16627 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16628}
16629
16630template<typename Derived>
16633 // Transform each of the elements.
16634 SmallVector<Expr *, 8> Elements;
16635 bool ArgChanged = false;
16636 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16637 /*IsCall=*/false, Elements, &ArgChanged))
16638 return ExprError();
16639
16640 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16641 return SemaRef.MaybeBindToTemporary(E);
16642
16643 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16644 Elements.data(),
16645 Elements.size());
16646}
16647
16648template<typename Derived>
16652 // Transform each of the elements.
16654 bool ArgChanged = false;
16655 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16656 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16657
16658 if (OrigElement.isPackExpansion()) {
16659 // This key/value element is a pack expansion.
16661 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16662 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16663 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16664
16665 // Determine whether the set of unexpanded parameter packs can
16666 // and should be expanded.
16667 bool Expand = true;
16668 bool RetainExpansion = false;
16669 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
16670 UnsignedOrNone NumExpansions = OrigNumExpansions;
16671 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16672 OrigElement.Value->getEndLoc());
16673 if (getDerived().TryExpandParameterPacks(
16674 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
16675 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16676 NumExpansions))
16677 return ExprError();
16678
16679 if (!Expand) {
16680 // The transform has determined that we should perform a simple
16681 // transformation on the pack expansion, producing another pack
16682 // expansion.
16683 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16684 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16685 if (Key.isInvalid())
16686 return ExprError();
16687
16688 if (Key.get() != OrigElement.Key)
16689 ArgChanged = true;
16690
16691 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16692 if (Value.isInvalid())
16693 return ExprError();
16694
16695 if (Value.get() != OrigElement.Value)
16696 ArgChanged = true;
16697
16698 ObjCDictionaryElement Expansion = {
16699 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16700 };
16701 Elements.push_back(Expansion);
16702 continue;
16703 }
16704
16705 // Record right away that the argument was changed. This needs
16706 // to happen even if the array expands to nothing.
16707 ArgChanged = true;
16708
16709 // The transform has determined that we should perform an elementwise
16710 // expansion of the pattern. Do so.
16711 for (unsigned I = 0; I != *NumExpansions; ++I) {
16712 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16713 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16714 if (Key.isInvalid())
16715 return ExprError();
16716
16717 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16718 if (Value.isInvalid())
16719 return ExprError();
16720
16721 ObjCDictionaryElement Element = {
16722 Key.get(), Value.get(), SourceLocation(), NumExpansions
16723 };
16724
16725 // If any unexpanded parameter packs remain, we still have a
16726 // pack expansion.
16727 // FIXME: Can this really happen?
16728 if (Key.get()->containsUnexpandedParameterPack() ||
16729 Value.get()->containsUnexpandedParameterPack())
16730 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16731
16732 Elements.push_back(Element);
16733 }
16734
16735 // FIXME: Retain a pack expansion if RetainExpansion is true.
16736
16737 // We've finished with this pack expansion.
16738 continue;
16739 }
16740
16741 // Transform and check key.
16742 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16743 if (Key.isInvalid())
16744 return ExprError();
16745
16746 if (Key.get() != OrigElement.Key)
16747 ArgChanged = true;
16748
16749 // Transform and check value.
16751 = getDerived().TransformExpr(OrigElement.Value);
16752 if (Value.isInvalid())
16753 return ExprError();
16754
16755 if (Value.get() != OrigElement.Value)
16756 ArgChanged = true;
16757
16758 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16759 std::nullopt};
16760 Elements.push_back(Element);
16761 }
16762
16763 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16764 return SemaRef.MaybeBindToTemporary(E);
16765
16766 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16767 Elements);
16768}
16769
16770template<typename Derived>
16773 TypeSourceInfo *EncodedTypeInfo
16774 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16775 if (!EncodedTypeInfo)
16776 return ExprError();
16777
16778 if (!getDerived().AlwaysRebuild() &&
16779 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16780 return E;
16781
16782 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16783 EncodedTypeInfo,
16784 E->getRParenLoc());
16785}
16786
16787template<typename Derived>
16790 // This is a kind of implicit conversion, and it needs to get dropped
16791 // and recomputed for the same general reasons that ImplicitCastExprs
16792 // do, as well a more specific one: this expression is only valid when
16793 // it appears *immediately* as an argument expression.
16794 return getDerived().TransformExpr(E->getSubExpr());
16795}
16796
16797template<typename Derived>
16800 TypeSourceInfo *TSInfo
16801 = getDerived().TransformType(E->getTypeInfoAsWritten());
16802 if (!TSInfo)
16803 return ExprError();
16804
16805 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16806 if (Result.isInvalid())
16807 return ExprError();
16808
16809 if (!getDerived().AlwaysRebuild() &&
16810 TSInfo == E->getTypeInfoAsWritten() &&
16811 Result.get() == E->getSubExpr())
16812 return E;
16813
16814 return SemaRef.ObjC().BuildObjCBridgedCast(
16815 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16816 Result.get());
16817}
16818
16819template <typename Derived>
16822 return E;
16823}
16824
16825template<typename Derived>
16828 // Transform arguments.
16829 bool ArgChanged = false;
16831 Args.reserve(E->getNumArgs());
16832 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16833 &ArgChanged))
16834 return ExprError();
16835
16836 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16837 // Class message: transform the receiver type.
16838 TypeSourceInfo *ReceiverTypeInfo
16839 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16840 if (!ReceiverTypeInfo)
16841 return ExprError();
16842
16843 // If nothing changed, just retain the existing message send.
16844 if (!getDerived().AlwaysRebuild() &&
16845 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16846 return SemaRef.MaybeBindToTemporary(E);
16847
16848 // Build a new class message send.
16850 E->getSelectorLocs(SelLocs);
16851 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16852 E->getSelector(),
16853 SelLocs,
16854 E->getMethodDecl(),
16855 E->getLeftLoc(),
16856 Args,
16857 E->getRightLoc());
16858 }
16859 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16860 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16861 if (!E->getMethodDecl())
16862 return ExprError();
16863
16864 // Build a new class message send to 'super'.
16866 E->getSelectorLocs(SelLocs);
16867 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16868 E->getSelector(),
16869 SelLocs,
16870 E->getReceiverType(),
16871 E->getMethodDecl(),
16872 E->getLeftLoc(),
16873 Args,
16874 E->getRightLoc());
16875 }
16876
16877 // Instance message: transform the receiver
16878 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16879 "Only class and instance messages may be instantiated");
16880 ExprResult Receiver
16881 = getDerived().TransformExpr(E->getInstanceReceiver());
16882 if (Receiver.isInvalid())
16883 return ExprError();
16884
16885 // If nothing changed, just retain the existing message send.
16886 if (!getDerived().AlwaysRebuild() &&
16887 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16888 return SemaRef.MaybeBindToTemporary(E);
16889
16890 // Build a new instance message send.
16892 E->getSelectorLocs(SelLocs);
16893 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16894 E->getSelector(),
16895 SelLocs,
16896 E->getMethodDecl(),
16897 E->getLeftLoc(),
16898 Args,
16899 E->getRightLoc());
16900}
16901
16902template<typename Derived>
16905 return E;
16906}
16907
16908template<typename Derived>
16911 return E;
16912}
16913
16914template<typename Derived>
16917 // Transform the base expression.
16918 ExprResult Base = getDerived().TransformExpr(E->getBase());
16919 if (Base.isInvalid())
16920 return ExprError();
16921
16922 // We don't need to transform the ivar; it will never change.
16923
16924 // If nothing changed, just retain the existing expression.
16925 if (!getDerived().AlwaysRebuild() &&
16926 Base.get() == E->getBase())
16927 return E;
16928
16929 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16930 E->getLocation(),
16931 E->isArrow(), E->isFreeIvar());
16932}
16933
16934template<typename Derived>
16937 // 'super' and types never change. Property never changes. Just
16938 // retain the existing expression.
16939 if (!E->isObjectReceiver())
16940 return E;
16941
16942 // Transform the base expression.
16943 ExprResult Base = getDerived().TransformExpr(E->getBase());
16944 if (Base.isInvalid())
16945 return ExprError();
16946
16947 // We don't need to transform the property; it will never change.
16948
16949 // If nothing changed, just retain the existing expression.
16950 if (!getDerived().AlwaysRebuild() &&
16951 Base.get() == E->getBase())
16952 return E;
16953
16954 if (E->isExplicitProperty())
16955 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16956 E->getExplicitProperty(),
16957 E->getLocation());
16958
16959 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16960 SemaRef.Context.PseudoObjectTy,
16961 E->getImplicitPropertyGetter(),
16962 E->getImplicitPropertySetter(),
16963 E->getLocation());
16964}
16965
16966template<typename Derived>
16969 // Transform the base expression.
16970 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16971 if (Base.isInvalid())
16972 return ExprError();
16973
16974 // Transform the key expression.
16975 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16976 if (Key.isInvalid())
16977 return ExprError();
16978
16979 // If nothing changed, just retain the existing expression.
16980 if (!getDerived().AlwaysRebuild() &&
16981 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16982 return E;
16983
16984 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16985 Base.get(), Key.get(),
16986 E->getAtIndexMethodDecl(),
16987 E->setAtIndexMethodDecl());
16988}
16989
16990template<typename Derived>
16993 // Transform the base expression.
16994 ExprResult Base = getDerived().TransformExpr(E->getBase());
16995 if (Base.isInvalid())
16996 return ExprError();
16997
16998 // If nothing changed, just retain the existing expression.
16999 if (!getDerived().AlwaysRebuild() &&
17000 Base.get() == E->getBase())
17001 return E;
17002
17003 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17004 E->getOpLoc(),
17005 E->isArrow());
17006}
17007
17008template<typename Derived>
17011 bool ArgumentChanged = false;
17012 SmallVector<Expr*, 8> SubExprs;
17013 SubExprs.reserve(E->getNumSubExprs());
17014 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17015 SubExprs, &ArgumentChanged))
17016 return ExprError();
17017
17018 if (!getDerived().AlwaysRebuild() &&
17019 !ArgumentChanged)
17020 return E;
17021
17022 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17023 SubExprs,
17024 E->getRParenLoc());
17025}
17026
17027template<typename Derived>
17030 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17031 if (SrcExpr.isInvalid())
17032 return ExprError();
17033
17034 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17035 if (!Type)
17036 return ExprError();
17037
17038 if (!getDerived().AlwaysRebuild() &&
17039 Type == E->getTypeSourceInfo() &&
17040 SrcExpr.get() == E->getSrcExpr())
17041 return E;
17042
17043 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17044 SrcExpr.get(), Type,
17045 E->getRParenLoc());
17046}
17047
17048template<typename Derived>
17051 BlockDecl *oldBlock = E->getBlockDecl();
17052
17053 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17054 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17055
17056 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17057 blockScope->TheDecl->setBlockMissingReturnType(
17058 oldBlock->blockMissingReturnType());
17059
17061 SmallVector<QualType, 4> paramTypes;
17062
17063 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17064
17065 // Parameter substitution.
17066 Sema::ExtParameterInfoBuilder extParamInfos;
17067 if (getDerived().TransformFunctionTypeParams(
17068 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17069 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17070 extParamInfos)) {
17071 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17072 return ExprError();
17073 }
17074
17075 QualType exprResultType =
17076 getDerived().TransformType(exprFunctionType->getReturnType());
17077
17078 auto epi = exprFunctionType->getExtProtoInfo();
17079 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17080
17082 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17083 blockScope->FunctionType = functionType;
17084
17085 // Set the parameters on the block decl.
17086 if (!params.empty())
17087 blockScope->TheDecl->setParams(params);
17088
17089 if (!oldBlock->blockMissingReturnType()) {
17090 blockScope->HasImplicitReturnType = false;
17091 blockScope->ReturnType = exprResultType;
17092 }
17093
17094 // Transform the body
17095 StmtResult body = getDerived().TransformStmt(E->getBody());
17096 if (body.isInvalid()) {
17097 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17098 return ExprError();
17099 }
17100
17101#ifndef NDEBUG
17102 // In builds with assertions, make sure that we captured everything we
17103 // captured before.
17104 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17105 for (const auto &I : oldBlock->captures()) {
17106 VarDecl *oldCapture = I.getVariable();
17107
17108 // Ignore parameter packs.
17109 if (oldCapture->isParameterPack())
17110 continue;
17111
17112 VarDecl *newCapture =
17113 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17114 oldCapture));
17115 assert(blockScope->CaptureMap.count(newCapture));
17116 }
17117
17118 // The this pointer may not be captured by the instantiated block, even when
17119 // it's captured by the original block, if the expression causing the
17120 // capture is in the discarded branch of a constexpr if statement.
17121 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17122 "this pointer isn't captured in the old block");
17123 }
17124#endif
17125
17126 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17127 /*Scope=*/nullptr);
17128}
17129
17130template<typename Derived>
17133 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17134 if (SrcExpr.isInvalid())
17135 return ExprError();
17136
17137 QualType Type = getDerived().TransformType(E->getType());
17138
17139 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17140 E->getRParenLoc());
17141}
17142
17143template<typename Derived>
17146 bool ArgumentChanged = false;
17147 SmallVector<Expr*, 8> SubExprs;
17148 SubExprs.reserve(E->getNumSubExprs());
17149 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17150 SubExprs, &ArgumentChanged))
17151 return ExprError();
17152
17153 if (!getDerived().AlwaysRebuild() &&
17154 !ArgumentChanged)
17155 return E;
17156
17157 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17158 E->getOp(), E->getRParenLoc());
17159}
17160
17161//===----------------------------------------------------------------------===//
17162// Type reconstruction
17163//===----------------------------------------------------------------------===//
17164
17165template<typename Derived>
17168 return SemaRef.BuildPointerType(PointeeType, Star,
17170}
17171
17172template<typename Derived>
17175 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17177}
17178
17179template<typename Derived>
17182 bool WrittenAsLValue,
17183 SourceLocation Sigil) {
17184 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17185 Sigil, getDerived().getBaseEntity());
17186}
17187
17188template <typename Derived>
17190 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17191 SourceLocation Sigil) {
17192 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17194}
17195
17196template<typename Derived>
17198 const ObjCTypeParamDecl *Decl,
17199 SourceLocation ProtocolLAngleLoc,
17201 ArrayRef<SourceLocation> ProtocolLocs,
17202 SourceLocation ProtocolRAngleLoc) {
17203 return SemaRef.ObjC().BuildObjCTypeParamType(
17204 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17205 /*FailOnError=*/true);
17206}
17207
17208template<typename Derived>
17210 QualType BaseType,
17211 SourceLocation Loc,
17212 SourceLocation TypeArgsLAngleLoc,
17214 SourceLocation TypeArgsRAngleLoc,
17215 SourceLocation ProtocolLAngleLoc,
17217 ArrayRef<SourceLocation> ProtocolLocs,
17218 SourceLocation ProtocolRAngleLoc) {
17219 return SemaRef.ObjC().BuildObjCObjectType(
17220 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17221 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17222 /*FailOnError=*/true,
17223 /*Rebuilding=*/true);
17224}
17225
17226template<typename Derived>
17228 QualType PointeeType,
17230 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17231}
17232
17233template <typename Derived>
17235 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17236 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17237 if (SizeExpr || !Size)
17238 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17239 IndexTypeQuals, BracketsRange,
17241
17242 QualType Types[] = {
17243 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17244 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17245 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17246 };
17247 QualType SizeType;
17248 for (const auto &T : Types)
17249 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17250 SizeType = T;
17251 break;
17252 }
17253
17254 // Note that we can return a VariableArrayType here in the case where
17255 // the element type was a dependent VariableArrayType.
17256 IntegerLiteral *ArraySize
17257 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17258 /*FIXME*/BracketsRange.getBegin());
17259 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17260 IndexTypeQuals, BracketsRange,
17262}
17263
17264template <typename Derived>
17266 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17267 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17268 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17269 IndexTypeQuals, BracketsRange);
17270}
17271
17272template <typename Derived>
17274 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17275 SourceRange BracketsRange) {
17276 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17277 IndexTypeQuals, BracketsRange);
17278}
17279
17280template <typename Derived>
17282 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17283 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17284 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17285 SizeExpr,
17286 IndexTypeQuals, BracketsRange);
17287}
17288
17289template <typename Derived>
17291 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17292 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17293 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17294 SizeExpr,
17295 IndexTypeQuals, BracketsRange);
17296}
17297
17298template <typename Derived>
17300 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17301 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17302 AttributeLoc);
17303}
17304
17305template <typename Derived>
17307 unsigned NumElements,
17308 VectorKind VecKind) {
17309 // FIXME: semantic checking!
17310 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17311}
17312
17313template <typename Derived>
17315 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17316 VectorKind VecKind) {
17317 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17318}
17319
17320template<typename Derived>
17322 unsigned NumElements,
17323 SourceLocation AttributeLoc) {
17324 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17325 NumElements, true);
17326 IntegerLiteral *VectorSize
17327 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17328 AttributeLoc);
17329 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17330}
17331
17332template<typename Derived>
17335 Expr *SizeExpr,
17336 SourceLocation AttributeLoc) {
17337 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17338}
17339
17340template <typename Derived>
17342 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17343 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17344 NumColumns);
17345}
17346
17347template <typename Derived>
17349 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17350 SourceLocation AttributeLoc) {
17351 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17352 AttributeLoc);
17353}
17354
17355template <typename Derived>
17359 return SemaRef.BuildFunctionType(T, ParamTypes,
17362 EPI);
17363}
17364
17365template<typename Derived>
17367 return SemaRef.Context.getFunctionNoProtoType(T);
17368}
17369
17370template <typename Derived>
17373 SourceLocation NameLoc, Decl *D) {
17374 assert(D && "no decl found");
17375 if (D->isInvalidDecl()) return QualType();
17376
17377 // FIXME: Doesn't account for ObjCInterfaceDecl!
17378 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17379 // A valid resolved using typename pack expansion decl can have multiple
17380 // UsingDecls, but they must each have exactly one type, and it must be
17381 // the same type in every case. But we must have at least one expansion!
17382 if (UPD->expansions().empty()) {
17383 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17384 << UPD->isCXXClassMember() << UPD;
17385 return QualType();
17386 }
17387
17388 // We might still have some unresolved types. Try to pick a resolved type
17389 // if we can. The final instantiation will check that the remaining
17390 // unresolved types instantiate to the type we pick.
17391 QualType FallbackT;
17392 QualType T;
17393 for (auto *E : UPD->expansions()) {
17394 QualType ThisT =
17395 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17396 if (ThisT.isNull())
17397 continue;
17398 if (ThisT->getAs<UnresolvedUsingType>())
17399 FallbackT = ThisT;
17400 else if (T.isNull())
17401 T = ThisT;
17402 else
17403 assert(getSema().Context.hasSameType(ThisT, T) &&
17404 "mismatched resolved types in using pack expansion");
17405 }
17406 return T.isNull() ? FallbackT : T;
17407 }
17408 if (auto *Using = dyn_cast<UsingDecl>(D)) {
17409 assert(Using->hasTypename() &&
17410 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17411
17412 // A valid resolved using typename decl points to exactly one type decl.
17413 assert(++Using->shadow_begin() == Using->shadow_end());
17414
17415 UsingShadowDecl *Shadow = *Using->shadow_begin();
17416 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
17417 return QualType();
17418 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
17419 }
17421 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17422 return SemaRef.Context.getUnresolvedUsingType(
17424}
17425
17426template <typename Derived>
17428 TypeOfKind Kind) {
17429 return SemaRef.BuildTypeofExprType(E, Kind);
17430}
17431
17432template<typename Derived>
17434 TypeOfKind Kind) {
17435 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17436}
17437
17438template <typename Derived>
17440 return SemaRef.BuildDecltypeType(E);
17441}
17442
17443template <typename Derived>
17445 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17446 SourceLocation EllipsisLoc, bool FullySubstituted,
17447 ArrayRef<QualType> Expansions) {
17448 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17449 FullySubstituted, Expansions);
17450}
17451
17452template<typename Derived>
17454 UnaryTransformType::UTTKind UKind,
17455 SourceLocation Loc) {
17456 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17457}
17458
17459template <typename Derived>
17462 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
17463 return SemaRef.CheckTemplateIdType(
17464 Keyword, Template, TemplateNameLoc, TemplateArgs,
17465 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
17466}
17467
17468template<typename Derived>
17470 SourceLocation KWLoc) {
17471 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17472}
17473
17474template<typename Derived>
17476 SourceLocation KWLoc,
17477 bool isReadPipe) {
17478 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17479 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17480}
17481
17482template <typename Derived>
17484 unsigned NumBits,
17485 SourceLocation Loc) {
17486 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17487 NumBits, true);
17488 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17489 SemaRef.Context.IntTy, Loc);
17490 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17491}
17492
17493template <typename Derived>
17495 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17496 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17497}
17498
17499template <typename Derived>
17501 bool TemplateKW,
17502 TemplateName Name) {
17503 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17504 Name);
17505}
17506
17507template <typename Derived>
17509 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
17510 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
17512 TemplateName.setIdentifier(&Name, NameLoc);
17514 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17515 TemplateName, ParsedType::make(ObjectType),
17516 /*EnteringContext=*/false, Template,
17517 AllowInjectedClassName);
17518 return Template.get();
17519}
17520
17521template<typename Derived>
17524 SourceLocation TemplateKWLoc,
17525 OverloadedOperatorKind Operator,
17526 SourceLocation NameLoc,
17527 QualType ObjectType,
17528 bool AllowInjectedClassName) {
17529 UnqualifiedId Name;
17530 // FIXME: Bogus location information.
17531 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17532 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17534 getSema().ActOnTemplateName(
17535 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17536 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17537 return Template.get();
17538}
17539
17540template <typename Derived>
17543 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17544 Expr *Second) {
17545 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17546
17547 if (First->getObjectKind() == OK_ObjCProperty) {
17550 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17551 Opc, First, Second);
17552 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
17553 if (Result.isInvalid())
17554 return ExprError();
17555 First = Result.get();
17556 }
17557
17558 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17559 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17560 if (Result.isInvalid())
17561 return ExprError();
17562 Second = Result.get();
17563 }
17564
17565 // Determine whether this should be a builtin operation.
17566 if (Op == OO_Subscript) {
17567 if (!First->getType()->isOverloadableType() &&
17568 !Second->getType()->isOverloadableType())
17569 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17570 OpLoc);
17571 } else if (Op == OO_Arrow) {
17572 // It is possible that the type refers to a RecoveryExpr created earlier
17573 // in the tree transformation.
17574 if (First->getType()->isDependentType())
17575 return ExprError();
17576 // -> is never a builtin operation.
17577 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17578 } else if (Second == nullptr || isPostIncDec) {
17579 if (!First->getType()->isOverloadableType() ||
17580 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17581 // The argument is not of overloadable type, or this is an expression
17582 // of the form &Class::member, so try to create a built-in unary
17583 // operation.
17585 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17586
17587 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17588 }
17589 } else {
17590 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17591 !First->getType()->isOverloadableType() &&
17592 !Second->getType()->isOverloadableType()) {
17593 // Neither of the arguments is type-dependent or has an overloadable
17594 // type, so try to create a built-in binary operation.
17597 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17598 if (Result.isInvalid())
17599 return ExprError();
17600
17601 return Result;
17602 }
17603 }
17604
17605 // Create the overloaded operator invocation for unary operators.
17606 if (!Second || isPostIncDec) {
17608 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17609 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17610 RequiresADL);
17611 }
17612
17613 // Create the overloaded operator invocation for binary operators.
17615 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17616 First, Second, RequiresADL);
17617 if (Result.isInvalid())
17618 return ExprError();
17619
17620 return Result;
17621}
17622
17623template<typename Derived>
17626 SourceLocation OperatorLoc,
17627 bool isArrow,
17628 CXXScopeSpec &SS,
17629 TypeSourceInfo *ScopeType,
17630 SourceLocation CCLoc,
17631 SourceLocation TildeLoc,
17632 PseudoDestructorTypeStorage Destroyed) {
17633 QualType CanonicalBaseType = Base->getType().getCanonicalType();
17634 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17635 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
17636 (isArrow && isa<PointerType>(CanonicalBaseType) &&
17637 !cast<PointerType>(CanonicalBaseType)
17638 ->getPointeeType()
17639 ->getAsCanonical<RecordType>())) {
17640 // This pseudo-destructor expression is still a pseudo-destructor.
17641 return SemaRef.BuildPseudoDestructorExpr(
17642 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17643 CCLoc, TildeLoc, Destroyed);
17644 }
17645
17646 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17647 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
17648 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17649 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17650 NameInfo.setNamedTypeInfo(DestroyedType);
17651
17652 // The scope type is now known to be a valid nested name specifier
17653 // component. Tack it on to the nested name specifier.
17654 if (ScopeType) {
17655 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
17656 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17657 diag::err_expected_class_or_namespace)
17658 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17659 return ExprError();
17660 }
17661 SS.clear();
17662 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
17663 }
17664
17665 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17666 return getSema().BuildMemberReferenceExpr(
17667 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
17668 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
17669 /*TemplateArgs*/ nullptr,
17670 /*S*/ nullptr);
17671}
17672
17673template<typename Derived>
17676 SourceLocation Loc = S->getBeginLoc();
17677 CapturedDecl *CD = S->getCapturedDecl();
17678 unsigned NumParams = CD->getNumParams();
17679 unsigned ContextParamPos = CD->getContextParamPosition();
17681 for (unsigned I = 0; I < NumParams; ++I) {
17682 if (I != ContextParamPos) {
17683 Params.push_back(
17684 std::make_pair(
17685 CD->getParam(I)->getName(),
17686 getDerived().TransformType(CD->getParam(I)->getType())));
17687 } else {
17688 Params.push_back(std::make_pair(StringRef(), QualType()));
17689 }
17690 }
17691 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17692 S->getCapturedRegionKind(), Params);
17693 StmtResult Body;
17694 {
17695 Sema::CompoundScopeRAII CompoundScope(getSema());
17696 Body = getDerived().TransformStmt(S->getCapturedStmt());
17697 }
17698
17699 if (Body.isInvalid()) {
17700 getSema().ActOnCapturedRegionError();
17701 return StmtError();
17702 }
17703
17704 return getSema().ActOnCapturedRegionEnd(Body.get());
17705}
17706
17707template <typename Derived>
17710 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
17711 // function definition or instantiation of a function template specialization
17712 // and will therefore never appear in a dependent context.
17713 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
17714 "context");
17715}
17716
17717template <typename Derived>
17719 // We can transform the base expression and allow argument resolution to fill
17720 // in the rest.
17721 return getDerived().TransformExpr(E->getArgLValue());
17722}
17723
17724} // end namespace clang
17725
17726#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:4484
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:5955
Represents a loop initializing the elements of an array.
Definition Expr.h:5902
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1813
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7105
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
Wrapper for source info for arrays.
Definition TypeLoc.h: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:2998
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3036
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3038
Expr * getDimensionExpression() const
Definition ExprCXX.h:3048
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3044
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3035
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6619
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6814
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h: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:4387
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2175
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4108
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2137
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8146
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4654
void setIsVariadic(bool value)
Definition Decl.h:4730
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6558
Wrapper for source info for block pointers.
Definition TypeLoc.h:1506
BreakStmt - This represents a break.
Definition Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5478
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5497
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5496
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:3903
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:234
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition ExprCXX.h:604
Represents binding an expression to a temporary.
Definition ExprCXX.h:1494
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:723
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
A C++ const_cast expression (C++ [expr.const.cast]).
Definition ExprCXX.h:566
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1730
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1692
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1642
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.cpp:581
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.cpp:575
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1631
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1689
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1271
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1039
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1378
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2628
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3872
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:481
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5034
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition ExprCXX.h:1833
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:375
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:406
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:413
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:409
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2357
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4311
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:768
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5143
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2747
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1854
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:526
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:286
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2198
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:73
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition DeclSpec.cpp:51
char * location_data() const
Retrieve the data associated with the source-location information.
Definition DeclSpec.h:206
SourceRange getRange() const
Definition DeclSpec.h:79
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition DeclSpec.cpp:75
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition DeclSpec.h:94
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition DeclSpec.cpp:123
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition DeclSpec.h:210
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition DeclSpec.cpp:62
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition DeclSpec.cpp:85
bool isEmpty() const
No scope specifier.
Definition DeclSpec.h:178
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition DeclSpec.cpp:103
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:800
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1901
Represents the this expression in C++.
Definition ExprCXX.h:1155
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:848
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3746
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3790
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3801
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3784
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3795
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3804
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1069
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1513
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4926
unsigned getNumParams() const
Definition Decl.h:4964
unsigned getContextParamPosition() const
Definition Decl.h:4993
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:4966
This captures a statement into a function.
Definition Stmt.h:3886
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp: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:3660
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4782
Represents a 'co_await' expression.
Definition ExprCXX.h:5371
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1720
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1770
body_range body()
Definition Stmt.h:1783
SourceLocation getLBracLoc() const
Definition Stmt.h:1857
bool hasStoredFPFeatures() const
Definition Stmt.h:1767
Stmt * getStmtExprResult()
Definition Stmt.h:1842
SourceLocation getRBracLoc() const
Definition Stmt.h:1858
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const TypeClass * getTypePtr() const
Definition TypeLoc.h:438
ConditionalOperator - The ?
Definition Expr.h:4325
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3760
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1082
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4373
ContinueStmt - This represents a continue.
Definition Stmt.h:3119
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4653
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition StmtCXX.h:473
Represents the body of a coroutine.
Definition StmtCXX.h:320
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3436
Represents a 'co_yield' expression.
Definition ExprCXX.h:5452
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h: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:1270
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1611
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInvalidDecl() const
Definition DeclBase.h:588
SourceLocation getLocation() const
Definition DeclBase.h:439
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
The name of a declaration.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1874
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h: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:4061
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5403
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2561
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3512
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3586
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3560
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3578
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3596
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3570
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3613
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3551
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3606
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3548
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4011
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2076
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4101
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4432
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2048
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4227
Represents a single C99 designator.
Definition Expr.h:5528
Represents a C99 designated initializer expression.
Definition Expr.h:5485
Designation - Represent a full designation, which is a sequence of designators.
Definition Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Designator.h:115
bool hasErrorOccurred() const
Definition Diagnostic.h:872
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2832
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition TypeBase.h:4986
Expr * getCondition() const
Definition TypeBase.h:4993
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:749
Represents a reference to emded data.
Definition Expr.h:5060
RAII object that enters a new expression evaluation context.
Wrapper for source info for enum types.
Definition TypeLoc.h:870
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3884
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3663
This represents one expression.
Definition Expr.h:112
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:451
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3077
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3209
QualType getType() const
Definition Expr.h:144
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:523
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:434
An expression trait intrinsic.
Definition ExprCXX.h:3071
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6498
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3160
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2888
Represents a function declaration or definition.
Definition Decl.h:2000
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2774
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5234
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:4879
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:5100
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4844
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4843
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5266
param_type_iterator param_type_begin() const
Definition TypeBase.h:5710
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:4488
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3395
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4857
Represents a C11 generic selection.
Definition Expr.h:6112
AssociationTy< false > Association
Definition Expr.h:6343
GotoStmt - This represents a direct goto.
Definition Stmt.h:2969
Type source information for HLSL attributed resource type.
Definition TypeLoc.h:1094
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7271
One of these records is kept for each identifier that is lexed.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2259
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1731
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3787
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:5991
Represents a C array with an unspecified size.
Definition TypeBase.h:3909
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3008
const TypeClass * getTypePtr() const
Definition TypeLoc.h:531
Describes an C or C++ initializer list.
Definition Expr.h:5233
InitListExpr * getSyntacticForm() const
Definition Expr.h:5406
Wrapper for source info for injected class names of class templates.
Definition TypeLoc.h: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:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2146
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1970
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1363
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1358
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1367
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2035
Represents the results of name lookup.
Definition Lookup.h:147
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition Lookup.h:607
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition Lookup.h:475
bool empty() const
Return true if no decls were found.
Definition Lookup.h:362
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition Lookup.h:666
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition Lookup.h:576
DeclarationName getLookupName() const
Gets the name to look up.
Definition Lookup.h:265
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3614
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Definition StmtCXX.h:253
An instance of this class represents the declaration of a property member.
Definition DeclCXX.h:4344
A member reference to an MSPropertyDecl.
Definition ExprCXX.h:936
MS property subscript expression.
Definition ExprCXX.h:1007
void setExpansionLoc(SourceLocation Loc)
Definition TypeLoc.h:1363
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4922
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2799
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2105
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
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:3653
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition Template.h:76
This represents a decl that may have a name.
Definition Decl.h:274
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:487
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents C++ namespaces and their aliases.
Definition Decl.h:573
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h:5811
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1683
This represents the 'absent' clause in the 'pragma omp assume' directive.
This represents 'acq_rel' clause in the 'pragma omp atomic|flush' directives.
This represents 'acquire' clause in the 'pragma omp atomic|flush' directives.
This represents clause 'affinity' in the 'pragma omp task'-based directives.
This represents the 'align' clause in the 'pragma omp allocate' directive.
This represents clause 'aligned' in the 'pragma omp ...' directives.
This represents clause 'allocate' in the 'pragma omp ...' directives.
This represents 'allocator' clause in the 'pragma omp ...' directive.
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition ExprOpenMP.h:24
This represents 'at' clause in the 'pragma omp error' directive.
This represents 'atomic_default_mem_order' clause in the 'pragma omp requires' directive.
This represents 'bind' clause in the 'pragma omp ...' directives.
This represents 'capture' clause in the 'pragma omp atomic' directive.
This is a basic class for representing single OpenMP clause.
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
This represents 'collapse' clause in the 'pragma omp ...' directive.
This represents 'compare' clause in the 'pragma omp atomic' directive.
This represents the 'contains' clause in the 'pragma omp assume' directive.
This represents clause 'copyin' in the 'pragma omp ...' directives.
This represents clause 'copyprivate' in the 'pragma omp ...' directives.
This represents 'default' clause in the 'pragma omp ...' directive.
This represents 'defaultmap' clause in the 'pragma omp ...' directive.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
This represents implicit clause 'depobj' for the 'pragma omp depobj' directive.
This represents 'destroy' clause in the 'pragma omp depobj' directive or the 'pragma omp interop' dir...
This represents 'detach' clause in the 'pragma omp task' directive.
This represents 'device' clause in the 'pragma omp ...' directive.
This represents 'dist_schedule' clause in the 'pragma omp ...' directive.
This represents the 'doacross' clause for the 'pragma omp ordered' directive.
This represents 'dynamic_allocators' clause in the 'pragma omp requires' directive.
This represents clause 'exclusive' in the 'pragma omp scan' directive.
This represents 'fail' clause in the 'pragma omp atomic' directive.
This represents 'filter' clause in the 'pragma omp ...' directive.
This represents 'final' clause in the 'pragma omp ...' directive.
This represents clause 'firstprivate' in the 'pragma omp ...' directives.
This represents implicit clause 'flush' for the 'pragma omp flush' directive.
This represents clause 'from' in the 'pragma omp ...' directives.
Representation of the 'full' clause of the 'pragma omp unroll' directive.
This represents 'grainsize' clause in the 'pragma omp ...' directive.
This represents clause 'has_device_ptr' in the 'pragma omp ...' directives.
This represents 'hint' clause in the 'pragma omp ...' directive.
This represents the 'holds' clause in the 'pragma omp assume' directive.
This represents 'if' clause in the 'pragma omp ...' directive.
This represents clause 'in_reduction' in the 'pragma omp task' directives.
This represents clause 'inclusive' in the 'pragma omp scan' directive.
This represents the 'init' clause in 'pragma omp ...' directives.
This represents clause 'is_device_ptr' in the 'pragma omp ...' directives.
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition ExprOpenMP.h:151
This represents clause 'lastprivate' in the 'pragma omp ...' directives.
This represents clause 'linear' in the 'pragma omp ...' directives.
This class represents the 'looprange' clause in the 'pragma omp fuse' directive.
This represents clauses with a list of expressions that are mappable.
This represents 'mergeable' clause in the 'pragma omp ...' directive.
This represents the 'message' clause in the 'pragma omp error' and the 'pragma omp parallel' directiv...
This represents the 'no_openmp' clause in the 'pragma omp assume' directive.
This represents the 'no_openmp_constructs' clause in the.
This represents the 'no_openmp_routines' clause in the 'pragma omp assume' directive.
This represents the 'no_parallelism' clause in the 'pragma omp assume' directive.
This represents 'nocontext' clause in the 'pragma omp ...' directive.
This represents 'nogroup' clause in the 'pragma omp ...' directive.
This represents clause 'nontemporal' in the 'pragma omp ...' directives.
This represents 'novariants' clause in the 'pragma omp ...' directive.
This represents 'nowait' clause in the 'pragma omp ...' directive.
This represents 'num_tasks' clause in the 'pragma omp ...' directive.
This represents 'num_teams' clause in the 'pragma omp ...' directive.
This represents 'num_threads' clause in the 'pragma omp ...' directive.
This represents 'order' clause in the 'pragma omp ...' directive.
This represents 'ordered' clause in the 'pragma omp ...' directive.
Representation of the 'partial' clause of the 'pragma omp unroll' directive.
This class represents the 'permutation' clause in the 'pragma omp interchange' directive.
This represents 'priority' clause in the 'pragma omp ...' directive.
This represents clause 'private' in the 'pragma omp ...' directives.
This represents 'proc_bind' clause in the 'pragma omp ...' directive.
This represents 'read' clause in the 'pragma omp atomic' directive.
This represents clause 'reduction' in the 'pragma omp ...' directives.
This represents 'relaxed' clause in the 'pragma omp atomic' directives.
This represents 'release' clause in the 'pragma omp atomic|flush' directives.
This represents 'reverse_offload' clause in the 'pragma omp requires' directive.
This represents 'simd' clause in the 'pragma omp ...' directive.
This represents 'safelen' clause in the 'pragma omp ...' directive.
This represents 'schedule' clause in the 'pragma omp ...' directive.
This represents 'self_maps' clause in the 'pragma omp requires' directive.
This represents 'seq_cst' clause in the 'pragma omp atomic|flush' directives.
This represents the 'severity' clause in the 'pragma omp error' and the 'pragma omp parallel' directi...
This represents clause 'shared' in the 'pragma omp ...' directives.
This represents 'simdlen' clause in the 'pragma omp ...' directive.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
This represents clause 'task_reduction' in the 'pragma omp taskgroup' directives.
This represents 'thread_limit' clause in the 'pragma omp ...' directive.
This represents 'threads' clause in the 'pragma omp ...' directive.
This represents clause 'to' in the 'pragma omp ...' directives.
This represents 'unified_address' clause in the 'pragma omp requires' directive.
This represents 'unified_shared_memory' clause in the 'pragma omp requires' directive.
This represents 'untied' clause in the 'pragma omp ...' directive.
This represents 'update' clause in the 'pragma omp atomic' directive.
This represents the 'use' clause in 'pragma omp ...' directives.
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
This represents clause 'uses_allocators' in the 'pragma omp target'-based directives.
This represents 'weak' clause in the 'pragma omp atomic' directives.
This represents 'write' clause in the 'pragma omp atomic' directive.
This represents 'ompx_attribute' clause in a directive that might generate an outlined function.
This represents 'ompx_bare' clause in the 'pragma omp target teams ...' directive.
This represents 'ompx_dyn_cgroup_mem' clause in the 'pragma omp target ...' directive.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:192
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
A runtime availability query.
Definition ExprObjC.h:1703
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:88
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:128
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1643
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:308
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:409
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition ExprObjC.h:1582
Wrapper for source info for ObjC interfaces.
Definition TypeLoc.h: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:2426
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2430
@ Field
A field.
Definition Expr.h:2428
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2433
static OpaquePtr make(QualType P)
Definition Ownership.h:61
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2090
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Represents a 'collapse' clause on a 'loop' construct.
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A 'default' clause, has the optional 'none' or 'present' argument.
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< OpenACCFirstPrivateRecipe > InitRecipes, SourceLocation EndLoc)
static OpenACCHostClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
An 'if' clause, which has a required condition expression.
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< OpenACCPrivateRecipe > InitRecipes, SourceLocation EndLoc)
A 'self' clause, which has an optional condition expression, or, in the event of an 'update' directiv...
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition ExprCXX.h:3130
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3282
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3264
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3243
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3256
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3252
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3326
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3229
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3332
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3240
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3272
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3279
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4365
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h: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:2182
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2207
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2211
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1391
Represents a parameter to a function.
Definition Decl.h:1790
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1850
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1823
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.cpp:2946
unsigned getFunctionScopeDepth() const
Definition Decl.h:1840
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2705
PipeType - OpenCL20.
Definition TypeBase.h:8112
bool isReadOnly() const
Definition TypeBase.h:8142
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:2005
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2696
const IdentifierInfo * getIdentifier() const
Definition ExprCXX.h:2716
SourceLocation getLocation() const
Definition ExprCXX.h:2720
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2712
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6690
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8294
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8334
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8388
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8326
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:7377
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3573
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3589
Represents the body of a requires-expression.
Definition DeclCXX.h:2098
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition DeclCXX.cpp:2389
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3160
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition Stmt.cpp: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 * ActOnOpenMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
Called on well-form 'looprange' clause after parsing its arguments.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * 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:13552
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8401
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:3476
A helper class for building up ExtParameterInfos.
Definition Sema.h:12955
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:12974
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:12962
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:13943
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:9291
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9299
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9294
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:7797
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7799
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7798
ExprResult BuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP, SourceLocation loc, TemplateArgument Replacement, UnsignedOrNone PackIndex, bool Final)
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:438
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Definition SemaStmt.cpp:485
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition Sema.h:1530
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
Definition Sema.h:11921
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 CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, bool DoCheckConstraintSatisfaction=true)
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:83
const LangOptions & getLangOpts() const
Definition Sema.h:918
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1495
@ ReuseLambdaContextDecl
Definition Sema.h:6978
bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, bool IsAddressOfOperand)
Check whether an expression might be an implicit class member access.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11724
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, UnresolvedLookupExpr *Lookup)
ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
bool buildCoroutineParameterMoves(SourceLocation Loc)
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a Microsoft __uuidof expression with a type operand.
sema::FunctionScopeInfo * getCurFunction() const
Definition Sema.h:1314
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
UnsignedOrNone getPackIndex(TemplateArgument Pack) const
Definition Sema.h:11719
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:13546
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:6696
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6706
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6675
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6701
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:8270
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:11011
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:7783
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:8609
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4577
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4443
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4505
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4528
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1709
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4533
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4502
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4508
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4511
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4951
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5011
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4529
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp: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:1799
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:4666
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4756
A structure for storing an already-substituted template template parameter pack.
A structure for storing the information associated with a substituted template template parameter.
Wrapper for substituted template type parameters.
Definition TypeLoc.h:1001
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2509
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
SourceLocation getNameLoc() const
Definition TypeLoc.h: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:105
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
TemplateArgument TransformNamedTemplateTemplateArgument(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, TemplateName Name, SourceLocation NameLoc)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
StmtResult RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TagDecl *Tag)
Build a new class/struct/union/enum type.
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
OMPClause * RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'use' clause.
StmtResult RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL)
Transform the given type-with-location into a new type, collecting location information in the given ...
ExprResult RebuildCXXRewrittenBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opcode, const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS)
Build a new rewritten operator expression.
QualType RebuildDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new expression pack expansion.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
OMPClause * RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'message' clause.
ExprResult RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth)
Build a new GNU statement expression.
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
QualType TransformType(QualType T)
Transforms the given type into another type.
UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(ArrayRef< TemplateArgument > PackArgs)
OMPClause * RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc)
Build a new OpenMP 'order' clause.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
ExprResult TransformRequiresTypeParams(SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > Params, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > &TransParams, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a requires expresison into the given vectors.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc)
Build a new initializer list expression.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
StmtResult RebuildOpenACCWaitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
OMPClause * RebuildOMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
OMPClause * RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nocontext' clause.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorKind VecKind)
Build a new vector type given the element type and number of elements.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
QualType RebuildMemberPointerType(QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the qualifier it refers into.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCCacheConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation EndLoc)
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed)
Transforms the parameters of a function type into the given vectors.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Build a new inline asm statement.
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateName Name)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool SuppressObjCLifetime)
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
StmtResult TransformSEHHandler(Stmt *Handler)
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, OverloadedOperatorKind Operator, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the overloaded operator name that is refe...
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_ptr' clause.
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation.
concepts::TypeRequirement * TransformTypeRequirement(concepts::TypeRequirement *Req)
const Derived & getDerived() const
Retrieves a reference to the derived class.
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS, bool ForFoldExpression=false)
Build a new binary operator expression.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs, QualType Type)
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, LambdaScopeInfo *LSI)
QualType RebuildIncompleteArrayType(QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers.
CXXRecordDecl::LambdaDependencyKind ComputeLambdaDependency(LambdaScopeInfo *LSI)
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool FullySubstituted=false)
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc, bool ListInitialization)
Build a new C++ functional-style cast expression.
QualType RebuildCanonicalTagType(TagDecl *Tag)
TypeSourceInfo * TransformType(TypeSourceInfo *DI)
Transforms the given type-with-location into a new type-with-location.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
OMPClause * RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocator' clause.
QualType RebuildDependentSizedArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression,...
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPClause * RebuildOMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'inclusive' clause.
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S)
This is mostly the same as above, but allows 'informational' class directives when rebuilding the stm...
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
Build a new C++1z fold-expression.
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
OMPClause * RebuildOMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
bool PreparePackForExpansion(TemplateArgumentLoc In, bool Uneval, TemplateArgumentLoc &Out, UnexpandedInfo &Info)
Checks if the argument pack from In will need to be expanded and does the necessary prework.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
QualType RebuildUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, UsingShadowDecl *D, QualType UnderlyingType)
Build a new type found via an alias.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=StmtDiscardKind::Discarded)
Transform the given statement.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
OMPClause * RebuildOMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_addr' clause.
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc)
Build a dependent bit-precise int given its value type.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
OMPClause * RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'severity' clause.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, IdentifierOrOverloadedOperator IO, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
concepts::NestedRequirement * TransformNestedRequirement(concepts::NestedRequirement *Req)
QualType RebuildConstantArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array,...
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketsRanges)
Build a new array shaping expression.
MultiLevelTemplateArgumentList ForgetSubstitution()
"Forget" the template substitution to allow transforming the AST without any template instantiations.
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'is_device_ptr' clause.
QualType RebuildMacroQualifiedType(QualType T, const IdentifierInfo *MacroII)
Build a new MacroDefined type.
concepts::NestedRequirement * RebuildNestedRequirement(Expr *Constraint)
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBracketLoc)
Build a new matrix subscript expression.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL)
QualType RebuildTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, VectorKind)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
bool AllowSkippingCXXConstructExpr()
Wether CXXConstructExpr can be skipped when they are implicit.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, SourceLocation RParenLoc)
Start building a new switch statement.
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
OMPClause * RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'filter' clause.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
OMPClause * RebuildOMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'bind' clause.
concepts::NestedRequirement * RebuildNestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction &Satisfaction)
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new pack expansion type.
QualType RebuildVariableArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression,...
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, TypeSourceInfo *ControllingType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with a type predicate.
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
concepts::TypeRequirement * RebuildTypeRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag)
OMPClause * RebuildOMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'permutation' clause.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< SemaOpenMP::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' clause.
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
ExprResult RebuildCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
OMPClause * RebuildOMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_attribute' clause.
void RememberSubstitution(MultiLevelTemplateArgumentList)
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
OMPClause * RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'init' clause.
OMPClause * RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'detach' clause.
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, NamedDecl *Found, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known),...
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL)
Build a new qualified type given its unqualified type and type location.
OMPClause * RebuildOMPDependClause(OMPDependClause::DependDataTy Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
unsigned TransformTemplateDepth(unsigned Depth)
Transform a template parameter depth level.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType RebuildTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TypedefNameDecl *Typedef)
Build a new typedef type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new template argument pack expansion.
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns)
Build a new matrix type given the element type and dimensions.
OMPClause * RebuildOMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'map' clause.
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ __builtin_bit_cast expression.
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt)
Build a new OpenMP Canonical loop.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
concepts::ExprRequirement * RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
OMPClause * RebuildOMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'full' clause.
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
OMPClause * RebuildOMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Build a new OpenMP 'affinity' clause.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *DI)
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast.
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with an expression predicate.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool SuppressObjCLifetime)
Derived & getDerived()
Retrieves a reference to the derived class.
OMPClause * RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'holds' clause.
StmtResult RebuildOpenACCAtomicConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, OpenACCAtomicKind AtKind, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssociatedStmt)
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
concepts::ExprRequirement * TransformExprRequirement(concepts::ExprRequirement *Req)
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, TypeOfKind Kind)
Build a new typeof(expr) type.
bool ReplacingOriginal()
Whether the transformation is forming an expression or statement that replaces the original.
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, OpenMPOriginalSharingModifier OriginalSharingModifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
void transformedLocalDecl(Decl *Old, ArrayRef< Decl * > New)
Note that a local declaration has been transformed by this transformer.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
bool TransformRequiresExprRequirements(ArrayRef< concepts::Requirement * > Reqs, llvm::SmallVectorImpl< concepts::Requirement * > &Transformed)
TemplateName TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument.
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Build a new requires expression.
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
OMPClause * RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'doacross' clause.
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
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:6177
A container of type source information.
Definition TypeBase.h:8265
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:8276
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:2898
The base class of the type hierarchy.
Definition TypeBase.h:1833
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2782
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2405
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9030
bool isObjCObjectPointerType() const
Definition TypeBase.h:8700
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9107
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
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:2625
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2289
Expr * getSubExpr() const
Definition Expr.h:2285
Opcode getOpcode() const
Definition Expr.h:2280
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1411
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h: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:3392
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3466
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3461
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4128
A set of unresolved declarations.
void append(iterator I, iterator E)
A set of unresolved declarations.
Wrapper for source info for unresolved typename using decls.
Definition TypeLoc.h:787
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h:5982
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition ExprCXX.h:640
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3399
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3463
Wrapper for source info for types used via transparent aliases.
Definition TypeLoc.h:790
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4891
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5512
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:926
@ CInit
C-style initialization with assignment.
Definition Decl.h:931
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:934
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3966
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2025
Represents a GCC generic vector type.
Definition TypeBase.h:4175
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2697
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Retains information about a block that is currently being parsed.
Definition ScopeInfo.h:790
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition ScopeInfo.h:728
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition ScopeInfo.h:871
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition ScopeInfo.h:874
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
VE builtins.
const AstTypeMatcher< FunctionType > functionType
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition Descriptor.h:29
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition Interp.h: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:236
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:918
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Expr * Cond
};
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition TypeTraits.h:51
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
ExprResult ExprEmpty()
Definition Ownership.h:272
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
StmtResult StmtError()
Definition Ownership.h:266
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3719
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
@ Template
We are parsing a template declaration.
Definition Parser.h:81
ActionResult< CXXBaseSpecifier * > BaseResult
Definition Ownership.h:252
OpenMPGrainsizeClauseModifier
OpenMPNumTasksClauseModifier
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:5890
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
TemplateParameterList * getReplacedTemplateParameterList(const Decl *D)
Internal helper used by Subst* nodes to retrieve the parameter list for their AssociatedDecl.
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition Sema.h:798
@ Exists
The symbol exists.
Definition Sema.h:791
@ Error
An error occurred.
Definition Sema.h:801
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:794
MutableArrayRef< Stmt * > MultiStmtArg
Definition Ownership.h:260
OpenMPNumThreadsClauseModifier
U cast(CodeGen::Address addr)
Definition Address.h:327
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition OpenMPKinds.h:48
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition Ownership.h:230
SourceLocIdentKind
Definition Expr.h:4938
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:5865
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5886
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5876
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:5883
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
TypeTrait
Names for traits that operate specifically on types.
Definition TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
Definition ExprCXX.h:2247
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition Expr.h:1989
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
ActionResult< Stmt * > StmtResult
Definition Ownership.h:250
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
UnsignedOrNone ArgPackSubstIndex
Definition Decl.h:89
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5003
Holds information about the various types of exception specification.
Definition TypeBase.h:5323
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5339
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5325
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5328
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5331
Extra information about a function prototype.
Definition TypeBase.h:5351
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5356
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:13001
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13032
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:3276
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions