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
3725 /// Build a new Objective-C boxed expression.
3726 ///
3727 /// By default, performs semantic analysis to build the new expression.
3728 /// Subclasses may override this routine to provide different behavior.
3730 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3731 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3733 CXXScopeSpec SS;
3734 SS.Adopt(NNS);
3735 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3736 ConceptNameInfo,
3737 FoundDecl,
3738 NamedConcept, TALI);
3739 if (Result.isInvalid())
3740 return ExprError();
3741 return Result;
3742 }
3743
3744 /// \brief Build a new requires expression.
3745 ///
3746 /// By default, performs semantic analysis to build the new expression.
3747 /// Subclasses may override this routine to provide different behavior.
3750 SourceLocation LParenLoc,
3751 ArrayRef<ParmVarDecl *> LocalParameters,
3752 SourceLocation RParenLoc,
3754 SourceLocation ClosingBraceLoc) {
3755 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3756 LocalParameters, RParenLoc, Requirements,
3757 ClosingBraceLoc);
3758 }
3759
3763 return SemaRef.BuildTypeRequirement(SubstDiag);
3764 }
3765
3767 return SemaRef.BuildTypeRequirement(T);
3768 }
3769
3772 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3773 SourceLocation NoexceptLoc,
3775 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3776 std::move(Ret));
3777 }
3778
3780 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3782 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3783 std::move(Ret));
3784 }
3785
3787 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3788 const ASTConstraintSatisfaction &Satisfaction) {
3789 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3790 Satisfaction);
3791 }
3792
3794 return SemaRef.BuildNestedRequirement(Constraint);
3795 }
3796
3797 /// \brief Build a new Objective-C boxed expression.
3798 ///
3799 /// By default, performs semantic analysis to build the new expression.
3800 /// Subclasses may override this routine to provide different behavior.
3802 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3803 }
3804
3805 /// Build a new Objective-C array literal.
3806 ///
3807 /// By default, performs semantic analysis to build the new expression.
3808 /// Subclasses may override this routine to provide different behavior.
3810 Expr **Elements, unsigned NumElements) {
3812 Range, MultiExprArg(Elements, NumElements));
3813 }
3814
3816 Expr *Base, Expr *Key,
3817 ObjCMethodDecl *getterMethod,
3818 ObjCMethodDecl *setterMethod) {
3820 RB, Base, Key, getterMethod, setterMethod);
3821 }
3822
3823 /// Build a new Objective-C dictionary literal.
3824 ///
3825 /// By default, performs semantic analysis to build the new expression.
3826 /// Subclasses may override this routine to provide different behavior.
3831
3832 /// Build a new Objective-C \@encode expression.
3833 ///
3834 /// By default, performs semantic analysis to build the new expression.
3835 /// Subclasses may override this routine to provide different behavior.
3837 TypeSourceInfo *EncodeTypeInfo,
3838 SourceLocation RParenLoc) {
3839 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3840 RParenLoc);
3841 }
3842
3843 /// Build a new Objective-C class message.
3845 Selector Sel,
3846 ArrayRef<SourceLocation> SelectorLocs,
3848 SourceLocation LBracLoc,
3849 MultiExprArg Args,
3850 SourceLocation RBracLoc) {
3851 return SemaRef.ObjC().BuildClassMessage(
3852 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3853 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3854 RBracLoc, Args);
3855 }
3856
3857 /// Build a new Objective-C instance message.
3859 Selector Sel,
3860 ArrayRef<SourceLocation> SelectorLocs,
3862 SourceLocation LBracLoc,
3863 MultiExprArg Args,
3864 SourceLocation RBracLoc) {
3865 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3866 /*SuperLoc=*/SourceLocation(),
3867 Sel, Method, LBracLoc,
3868 SelectorLocs, RBracLoc, Args);
3869 }
3870
3871 /// Build a new Objective-C instance/class message to 'super'.
3873 Selector Sel,
3874 ArrayRef<SourceLocation> SelectorLocs,
3875 QualType SuperType,
3877 SourceLocation LBracLoc,
3878 MultiExprArg Args,
3879 SourceLocation RBracLoc) {
3880 return Method->isInstanceMethod()
3881 ? SemaRef.ObjC().BuildInstanceMessage(
3882 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3883 SelectorLocs, RBracLoc, Args)
3884 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3885 Sel, Method, LBracLoc,
3886 SelectorLocs, RBracLoc, Args);
3887 }
3888
3889 /// Build a new Objective-C ivar reference expression.
3890 ///
3891 /// By default, performs semantic analysis to build the new expression.
3892 /// Subclasses may override this routine to provide different behavior.
3894 SourceLocation IvarLoc,
3895 bool IsArrow, bool IsFreeIvar) {
3896 CXXScopeSpec SS;
3897 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3899 BaseArg, BaseArg->getType(),
3900 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3901 /*FirstQualifierInScope=*/nullptr, NameInfo,
3902 /*TemplateArgs=*/nullptr,
3903 /*S=*/nullptr);
3904 if (IsFreeIvar && Result.isUsable())
3905 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3906 return Result;
3907 }
3908
3909 /// Build a new Objective-C property reference expression.
3910 ///
3911 /// By default, performs semantic analysis to build the new expression.
3912 /// Subclasses may override this routine to provide different behavior.
3915 SourceLocation PropertyLoc) {
3916 CXXScopeSpec SS;
3917 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3918 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3919 /*FIXME:*/PropertyLoc,
3920 /*IsArrow=*/false,
3921 SS, SourceLocation(),
3922 /*FirstQualifierInScope=*/nullptr,
3923 NameInfo,
3924 /*TemplateArgs=*/nullptr,
3925 /*S=*/nullptr);
3926 }
3927
3928 /// Build a new Objective-C property reference expression.
3929 ///
3930 /// By default, performs semantic analysis to build the new expression.
3931 /// Subclasses may override this routine to provide different behavior.
3933 ObjCMethodDecl *Getter,
3934 ObjCMethodDecl *Setter,
3935 SourceLocation PropertyLoc) {
3936 // Since these expressions can only be value-dependent, we do not
3937 // need to perform semantic analysis again.
3938 return Owned(
3939 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3941 PropertyLoc, Base));
3942 }
3943
3944 /// Build a new Objective-C "isa" expression.
3945 ///
3946 /// By default, performs semantic analysis to build the new expression.
3947 /// Subclasses may override this routine to provide different behavior.
3949 SourceLocation OpLoc, bool IsArrow) {
3950 CXXScopeSpec SS;
3951 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3952 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3953 OpLoc, IsArrow,
3954 SS, SourceLocation(),
3955 /*FirstQualifierInScope=*/nullptr,
3956 NameInfo,
3957 /*TemplateArgs=*/nullptr,
3958 /*S=*/nullptr);
3959 }
3960
3961 /// Build a new shuffle vector expression.
3962 ///
3963 /// By default, performs semantic analysis to build the new expression.
3964 /// Subclasses may override this routine to provide different behavior.
3966 MultiExprArg SubExprs,
3967 SourceLocation RParenLoc) {
3968 // Find the declaration for __builtin_shufflevector
3969 const IdentifierInfo &Name
3970 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3971 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3972 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3973 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3974
3975 // Build a reference to the __builtin_shufflevector builtin
3977 Expr *Callee = new (SemaRef.Context)
3978 DeclRefExpr(SemaRef.Context, Builtin, false,
3979 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3980 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3981 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3982 CK_BuiltinFnToFnPtr).get();
3983
3984 // Build the CallExpr
3985 ExprResult TheCall = CallExpr::Create(
3986 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3987 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3989
3990 // Type-check the __builtin_shufflevector expression.
3991 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3992 }
3993
3994 /// Build a new convert vector expression.
3996 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3997 SourceLocation RParenLoc) {
3998 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3999 }
4000
4001 /// Build a new template argument pack expansion.
4002 ///
4003 /// By default, performs semantic analysis to build a new pack expansion
4004 /// for a template argument. Subclasses may override this routine to provide
4005 /// different behavior.
4007 SourceLocation EllipsisLoc,
4008 UnsignedOrNone NumExpansions) {
4009 switch (Pattern.getArgument().getKind()) {
4013 EllipsisLoc, NumExpansions);
4014 if (Result.isInvalid())
4015 return TemplateArgumentLoc();
4016
4018 /*IsCanonical=*/false),
4019 Result.get());
4020 }
4021
4023 return TemplateArgumentLoc(
4024 SemaRef.Context,
4026 NumExpansions),
4027 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4028 Pattern.getTemplateNameLoc(), EllipsisLoc);
4029
4037 llvm_unreachable("Pack expansion pattern has no parameter packs");
4038
4040 if (TypeSourceInfo *Expansion
4041 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4042 EllipsisLoc,
4043 NumExpansions))
4044 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4045 Expansion);
4046 break;
4047 }
4048
4049 return TemplateArgumentLoc();
4050 }
4051
4052 /// Build a new expression pack expansion.
4053 ///
4054 /// By default, performs semantic analysis to build a new pack expansion
4055 /// for an expression. Subclasses may override this routine to provide
4056 /// different behavior.
4058 UnsignedOrNone NumExpansions) {
4059 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4060 }
4061
4062 /// Build a new C++1z fold-expression.
4063 ///
4064 /// By default, performs semantic analysis in order to build a new fold
4065 /// expression.
4067 SourceLocation LParenLoc, Expr *LHS,
4068 BinaryOperatorKind Operator,
4069 SourceLocation EllipsisLoc, Expr *RHS,
4070 SourceLocation RParenLoc,
4071 UnsignedOrNone NumExpansions) {
4072 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4073 EllipsisLoc, RHS, RParenLoc,
4074 NumExpansions);
4075 }
4076
4078 LambdaScopeInfo *LSI) {
4079 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4080 if (Expr *Init = PVD->getInit())
4082 Init->containsUnexpandedParameterPack();
4083 else if (PVD->hasUninstantiatedDefaultArg())
4085 PVD->getUninstantiatedDefaultArg()
4086 ->containsUnexpandedParameterPack();
4087 }
4088 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4089 }
4090
4091 /// Build an empty C++1z fold-expression with the given operator.
4092 ///
4093 /// By default, produces the fallback value for the fold-expression, or
4094 /// produce an error if there is no fallback value.
4096 BinaryOperatorKind Operator) {
4097 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4098 }
4099
4100 /// Build a new atomic operation expression.
4101 ///
4102 /// By default, performs semantic analysis to build the new expression.
4103 /// Subclasses may override this routine to provide different behavior.
4106 SourceLocation RParenLoc) {
4107 // Use this for all of the locations, since we don't know the difference
4108 // between the call and the expr at this point.
4109 SourceRange Range{BuiltinLoc, RParenLoc};
4110 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4112 }
4113
4115 ArrayRef<Expr *> SubExprs, QualType Type) {
4116 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4117 }
4118
4120 SourceLocation BeginLoc,
4121 SourceLocation DirLoc,
4122 SourceLocation EndLoc,
4124 StmtResult StrBlock) {
4126 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4127 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4128 }
4129
4140
4142 SourceLocation BeginLoc,
4143 SourceLocation DirLoc,
4144 SourceLocation EndLoc,
4146 StmtResult Loop) {
4148 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4149 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4150 }
4151
4153 SourceLocation DirLoc,
4154 SourceLocation EndLoc,
4156 StmtResult StrBlock) {
4158 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4160 Clauses, StrBlock);
4161 }
4162
4172
4182
4184 SourceLocation DirLoc,
4185 SourceLocation EndLoc,
4187 StmtResult StrBlock) {
4191 Clauses, StrBlock);
4192 }
4193
4195 SourceLocation DirLoc,
4196 SourceLocation EndLoc,
4197 ArrayRef<OpenACCClause *> Clauses) {
4199 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4201 Clauses, {});
4202 }
4203
4213
4215 SourceLocation DirLoc,
4216 SourceLocation EndLoc,
4217 ArrayRef<OpenACCClause *> Clauses) {
4219 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4221 Clauses, {});
4222 }
4223
4225 SourceLocation DirLoc,
4226 SourceLocation EndLoc,
4227 ArrayRef<OpenACCClause *> Clauses) {
4229 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4231 Clauses, {});
4232 }
4233
4235 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4236 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4237 SourceLocation RParenLoc, SourceLocation EndLoc,
4238 ArrayRef<OpenACCClause *> Clauses) {
4240 Exprs.push_back(DevNumExpr);
4241 llvm::append_range(Exprs, QueueIdExprs);
4243 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4244 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4245 }
4246
4248 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4249 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4250 SourceLocation RParenLoc, SourceLocation EndLoc) {
4252 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4253 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4254 }
4255
4257 SourceLocation DirLoc,
4258 OpenACCAtomicKind AtKind,
4259 SourceLocation EndLoc,
4261 StmtResult AssociatedStmt) {
4263 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4264 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4265 AssociatedStmt);
4266 }
4267
4271
4272private:
4273 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4274 QualType ObjectType,
4275 NamedDecl *FirstQualifierInScope);
4276
4277 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4278 QualType ObjectType,
4279 NamedDecl *FirstQualifierInScope) {
4280 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4281 return TSInfo;
4282
4283 TypeLocBuilder TLB;
4284 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4285 ObjectType, FirstQualifierInScope);
4286 if (T.isNull())
4287 return nullptr;
4288 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4289 }
4290
4291 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4292 DependentNameTypeLoc TL,
4293 bool DeducibleTSTContext,
4294 QualType ObjectType = QualType(),
4295 NamedDecl *UnqualLookup = nullptr);
4296
4298 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4300
4301 OpenACCClause *
4302 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4303 OpenACCDirectiveKind DirKind,
4304 const OpenACCClause *OldClause);
4305};
4306
4307template <typename Derived>
4309 if (!S)
4310 return S;
4311
4312 switch (S->getStmtClass()) {
4313 case Stmt::NoStmtClass: break;
4314
4315 // Transform individual statement nodes
4316 // Pass SDK into statements that can produce a value
4317#define STMT(Node, Parent) \
4318 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4319#define VALUESTMT(Node, Parent) \
4320 case Stmt::Node##Class: \
4321 return getDerived().Transform##Node(cast<Node>(S), SDK);
4322#define ABSTRACT_STMT(Node)
4323#define EXPR(Node, Parent)
4324#include "clang/AST/StmtNodes.inc"
4325
4326 // Transform expressions by calling TransformExpr.
4327#define STMT(Node, Parent)
4328#define ABSTRACT_STMT(Stmt)
4329#define EXPR(Node, Parent) case Stmt::Node##Class:
4330#include "clang/AST/StmtNodes.inc"
4331 {
4332 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4333
4335 E = getSema().ActOnStmtExprResult(E);
4336 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4337 }
4338 }
4339
4340 return S;
4341}
4342
4343template<typename Derived>
4345 if (!S)
4346 return S;
4347
4348 switch (S->getClauseKind()) {
4349 default: break;
4350 // Transform individual clause nodes
4351#define GEN_CLANG_CLAUSE_CLASS
4352#define CLAUSE_CLASS(Enum, Str, Class) \
4353 case Enum: \
4354 return getDerived().Transform##Class(cast<Class>(S));
4355#include "llvm/Frontend/OpenMP/OMP.inc"
4356 }
4357
4358 return S;
4359}
4360
4361
4362template<typename Derived>
4364 if (!E)
4365 return E;
4366
4367 switch (E->getStmtClass()) {
4368 case Stmt::NoStmtClass: break;
4369#define STMT(Node, Parent) case Stmt::Node##Class: break;
4370#define ABSTRACT_STMT(Stmt)
4371#define EXPR(Node, Parent) \
4372 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4373#include "clang/AST/StmtNodes.inc"
4374 }
4375
4376 return E;
4377}
4378
4379template<typename Derived>
4381 bool NotCopyInit) {
4382 // Initializers are instantiated like expressions, except that various outer
4383 // layers are stripped.
4384 if (!Init)
4385 return Init;
4386
4387 if (auto *FE = dyn_cast<FullExpr>(Init))
4388 Init = FE->getSubExpr();
4389
4390 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4391 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4392 Init = OVE->getSourceExpr();
4393 }
4394
4395 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4396 Init = MTE->getSubExpr();
4397
4398 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4399 Init = Binder->getSubExpr();
4400
4401 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4402 Init = ICE->getSubExprAsWritten();
4403
4404 if (CXXStdInitializerListExpr *ILE =
4405 dyn_cast<CXXStdInitializerListExpr>(Init))
4406 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4407
4408 // If this is copy-initialization, we only need to reconstruct
4409 // InitListExprs. Other forms of copy-initialization will be a no-op if
4410 // the initializer is already the right type.
4411 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4412 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4413 return getDerived().TransformExpr(Init);
4414
4415 // Revert value-initialization back to empty parens.
4416 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4417 SourceRange Parens = VIE->getSourceRange();
4418 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4419 Parens.getEnd());
4420 }
4421
4422 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4424 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4425 SourceLocation());
4426
4427 // Revert initialization by constructor back to a parenthesized or braced list
4428 // of expressions. Any other form of initializer can just be reused directly.
4429 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4430 return getDerived().TransformExpr(Init);
4431
4432 // If the initialization implicitly converted an initializer list to a
4433 // std::initializer_list object, unwrap the std::initializer_list too.
4434 if (Construct && Construct->isStdInitListInitialization())
4435 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4436
4437 // Enter a list-init context if this was list initialization.
4440 Construct->isListInitialization());
4441
4442 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4443 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4444 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4445 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4446 SmallVector<Expr*, 8> NewArgs;
4447 bool ArgChanged = false;
4448 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4449 /*IsCall*/true, NewArgs, &ArgChanged))
4450 return ExprError();
4451
4452 // If this was list initialization, revert to syntactic list form.
4453 if (Construct->isListInitialization())
4454 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4455 Construct->getEndLoc());
4456
4457 // Build a ParenListExpr to represent anything else.
4459 if (Parens.isInvalid()) {
4460 // This was a variable declaration's initialization for which no initializer
4461 // was specified.
4462 assert(NewArgs.empty() &&
4463 "no parens or braces but have direct init with arguments?");
4464 return ExprEmpty();
4465 }
4466 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4467 Parens.getEnd());
4468}
4469
4470template<typename Derived>
4472 unsigned NumInputs,
4473 bool IsCall,
4474 SmallVectorImpl<Expr *> &Outputs,
4475 bool *ArgChanged) {
4476 for (unsigned I = 0; I != NumInputs; ++I) {
4477 // If requested, drop call arguments that need to be dropped.
4478 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4479 if (ArgChanged)
4480 *ArgChanged = true;
4481
4482 break;
4483 }
4484
4485 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4486 Expr *Pattern = Expansion->getPattern();
4487
4489 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4490 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4491
4492 // Determine whether the set of unexpanded parameter packs can and should
4493 // be expanded.
4494 bool Expand = true;
4495 bool RetainExpansion = false;
4496 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4497 UnsignedOrNone NumExpansions = OrigNumExpansions;
4499 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4500 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4501 RetainExpansion, NumExpansions))
4502 return true;
4503
4504 if (!Expand) {
4505 // The transform has determined that we should perform a simple
4506 // transformation on the pack expansion, producing another pack
4507 // expansion.
4508 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4509 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4510 if (OutPattern.isInvalid())
4511 return true;
4512
4513 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4514 Expansion->getEllipsisLoc(),
4515 NumExpansions);
4516 if (Out.isInvalid())
4517 return true;
4518
4519 if (ArgChanged)
4520 *ArgChanged = true;
4521 Outputs.push_back(Out.get());
4522 continue;
4523 }
4524
4525 // Record right away that the argument was changed. This needs
4526 // to happen even if the array expands to nothing.
4527 if (ArgChanged) *ArgChanged = true;
4528
4529 // The transform has determined that we should perform an elementwise
4530 // expansion of the pattern. Do so.
4531 for (unsigned I = 0; I != *NumExpansions; ++I) {
4532 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4533 ExprResult Out = getDerived().TransformExpr(Pattern);
4534 if (Out.isInvalid())
4535 return true;
4536
4537 if (Out.get()->containsUnexpandedParameterPack()) {
4538 Out = getDerived().RebuildPackExpansion(
4539 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4540 if (Out.isInvalid())
4541 return true;
4542 }
4543
4544 Outputs.push_back(Out.get());
4545 }
4546
4547 // If we're supposed to retain a pack expansion, do so by temporarily
4548 // forgetting the partially-substituted parameter pack.
4549 if (RetainExpansion) {
4550 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4551
4552 ExprResult Out = getDerived().TransformExpr(Pattern);
4553 if (Out.isInvalid())
4554 return true;
4555
4556 Out = getDerived().RebuildPackExpansion(
4557 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4558 if (Out.isInvalid())
4559 return true;
4560
4561 Outputs.push_back(Out.get());
4562 }
4563
4564 continue;
4565 }
4566
4568 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4569 : getDerived().TransformExpr(Inputs[I]);
4570 if (Result.isInvalid())
4571 return true;
4572
4573 if (Result.get() != Inputs[I] && ArgChanged)
4574 *ArgChanged = true;
4575
4576 Outputs.push_back(Result.get());
4577 }
4578
4579 return false;
4580}
4581
4582template <typename Derived>
4585
4588 /*LambdaContextDecl=*/nullptr,
4590 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4591
4592 if (Var) {
4593 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4595
4596 if (!ConditionVar)
4597 return Sema::ConditionError();
4598
4599 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4600 }
4601
4602 if (Expr) {
4603 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4604
4605 if (CondExpr.isInvalid())
4606 return Sema::ConditionError();
4607
4608 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4609 /*MissingOK=*/true);
4610 }
4611
4612 return Sema::ConditionResult();
4613}
4614
4615template <typename Derived>
4617 NestedNameSpecifierLoc NNS, QualType ObjectType,
4618 NamedDecl *FirstQualifierInScope) {
4620
4621 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4622 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4623 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4624 Qualifiers.push_back(Qualifier);
4625 };
4626 insertNNS(NNS);
4627
4628 CXXScopeSpec SS;
4629 while (!Qualifiers.empty()) {
4630 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4632
4633 switch (QNNS.getKind()) {
4635 llvm_unreachable("unexpected null nested name specifier");
4636
4639 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4641 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4642 break;
4643 }
4644
4646 // There is no meaningful transformation that one could perform on the
4647 // global scope.
4648 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4649 break;
4650
4652 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4654 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4655 Q.getEndLoc());
4656 break;
4657 }
4658
4660 assert(SS.isEmpty());
4661 TypeLoc TL = Q.castAsTypeLoc();
4662
4663 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4664 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4665 if (QualifierLoc) {
4666 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4667 QualifierLoc, ObjectType, FirstQualifierInScope);
4668 if (!QualifierLoc)
4669 return NestedNameSpecifierLoc();
4670 ObjectType = QualType();
4671 FirstQualifierInScope = nullptr;
4672 }
4673 SS.Adopt(QualifierLoc);
4675 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4676 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4677 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4678 false, SS,
4679 FirstQualifierInScope, false))
4680 return NestedNameSpecifierLoc();
4681 return SS.getWithLocInContext(SemaRef.Context);
4682 }
4683
4684 QualType T = TL.getType();
4685 TypeLocBuilder TLB;
4687 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4688 FirstQualifierInScope);
4689 if (T.isNull())
4690 return NestedNameSpecifierLoc();
4691 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4692 }
4693
4694 if (T->isDependentType() || T->isRecordType() ||
4695 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4696 if (T->isEnumeralType())
4697 SemaRef.Diag(TL.getBeginLoc(),
4698 diag::warn_cxx98_compat_enum_nested_name_spec);
4699 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4700 break;
4701 }
4702 // If the nested-name-specifier is an invalid type def, don't emit an
4703 // error because a previous error should have already been emitted.
4705 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4706 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4707 << T << SS.getRange();
4708 }
4709 return NestedNameSpecifierLoc();
4710 }
4711 }
4712 }
4713
4714 // Don't rebuild the nested-name-specifier if we don't have to.
4715 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4717 return NNS;
4718
4719 // If we can re-use the source-location data from the original
4720 // nested-name-specifier, do so.
4721 if (SS.location_size() == NNS.getDataLength() &&
4722 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4724
4725 // Allocate new nested-name-specifier location information.
4726 return SS.getWithLocInContext(SemaRef.Context);
4727}
4728
4729template<typename Derived>
4733 DeclarationName Name = NameInfo.getName();
4734 if (!Name)
4735 return DeclarationNameInfo();
4736
4737 switch (Name.getNameKind()) {
4745 return NameInfo;
4746
4748 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4749 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4750 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4751 if (!NewTemplate)
4752 return DeclarationNameInfo();
4753
4754 DeclarationNameInfo NewNameInfo(NameInfo);
4755 NewNameInfo.setName(
4756 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4757 return NewNameInfo;
4758 }
4759
4763 TypeSourceInfo *NewTInfo;
4764 CanQualType NewCanTy;
4765 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4766 NewTInfo = getDerived().TransformType(OldTInfo);
4767 if (!NewTInfo)
4768 return DeclarationNameInfo();
4769 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4770 }
4771 else {
4772 NewTInfo = nullptr;
4773 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4774 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4775 if (NewT.isNull())
4776 return DeclarationNameInfo();
4777 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4778 }
4779
4780 DeclarationName NewName
4781 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4782 NewCanTy);
4783 DeclarationNameInfo NewNameInfo(NameInfo);
4784 NewNameInfo.setName(NewName);
4785 NewNameInfo.setNamedTypeInfo(NewTInfo);
4786 return NewNameInfo;
4787 }
4788 }
4789
4790 llvm_unreachable("Unknown name kind.");
4791}
4792
4793template <typename Derived>
4795 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4797 QualType ObjectType, bool AllowInjectedClassName) {
4798 if (const IdentifierInfo *II = IO.getIdentifier())
4799 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4800 ObjectType, AllowInjectedClassName);
4801 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4802 NameLoc, ObjectType,
4803 AllowInjectedClassName);
4804}
4805
4806template <typename Derived>
4808 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4809 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4810 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4812 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4813
4814 if (QualifierLoc) {
4815 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4816 QualifierLoc, ObjectType, FirstQualifierInScope);
4817 if (!QualifierLoc)
4818 return TemplateName();
4819 }
4820
4821 NestedNameSpecifierLoc UnderlyingQualifier;
4822 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4823 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4824 FirstQualifierInScope, AllowInjectedClassName);
4825 if (NewUnderlyingName.isNull())
4826 return TemplateName();
4827 assert(!UnderlyingQualifier && "unexpected qualifier");
4828
4829 if (!getDerived().AlwaysRebuild() &&
4830 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4831 NewUnderlyingName == UnderlyingName)
4832 return Name;
4833 CXXScopeSpec SS;
4834 SS.Adopt(QualifierLoc);
4835 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4836 NewUnderlyingName);
4837 }
4838
4840 if (QualifierLoc) {
4841 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4842 QualifierLoc, ObjectType, FirstQualifierInScope);
4843 if (!QualifierLoc)
4844 return TemplateName();
4845 // The qualifier-in-scope and object type only apply to the leftmost
4846 // entity.
4847 ObjectType = QualType();
4848 }
4849
4850 if (!getDerived().AlwaysRebuild() &&
4851 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4852 ObjectType.isNull())
4853 return Name;
4854
4855 CXXScopeSpec SS;
4856 SS.Adopt(QualifierLoc);
4857 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4858 NameLoc, ObjectType,
4859 AllowInjectedClassName);
4860 }
4861
4864 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4865
4866 NestedNameSpecifierLoc ReplacementQualifierLoc;
4867 TemplateName ReplacementName = S->getReplacement();
4868 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4870 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4871 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4872 }
4873
4874 TemplateName NewName = getDerived().TransformTemplateName(
4875 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4876 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4877 if (NewName.isNull())
4878 return TemplateName();
4879 Decl *AssociatedDecl =
4880 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4881 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4882 AssociatedDecl == S->getAssociatedDecl())
4883 return Name;
4884 return SemaRef.Context.getSubstTemplateTemplateParm(
4885 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4886 S->getFinal());
4887 }
4888
4889 assert(!Name.getAsDeducedTemplateName() &&
4890 "DeducedTemplateName should not escape partial ordering");
4891
4892 // FIXME: Preserve UsingTemplateName.
4893 if (auto *Template = Name.getAsTemplateDecl()) {
4894 assert(!QualifierLoc && "Unexpected qualifier");
4895 return TemplateName(cast_or_null<TemplateDecl>(
4896 getDerived().TransformDecl(NameLoc, Template)));
4897 }
4898
4901 assert(!QualifierLoc &&
4902 "Unexpected qualified SubstTemplateTemplateParmPack");
4903 return getDerived().RebuildTemplateName(
4904 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4905 SubstPack->getIndex(), SubstPack->getFinal());
4906 }
4907
4908 // These should be getting filtered out before they reach the AST.
4909 llvm_unreachable("overloaded function decl survived to here");
4910}
4911
4912template <typename Derived>
4914 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4915 TemplateName Name, SourceLocation NameLoc) {
4916 TemplateName TN = getDerived().TransformTemplateName(
4917 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
4918 if (TN.isNull())
4919 return TemplateArgument();
4920 return TemplateArgument(TN);
4921}
4922
4923template<typename Derived>
4925 const TemplateArgument &Arg,
4926 TemplateArgumentLoc &Output) {
4927 Output = getSema().getTrivialTemplateArgumentLoc(
4928 Arg, QualType(), getDerived().getBaseLocation());
4929}
4930
4931template <typename Derived>
4933 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4934 bool Uneval) {
4935 const TemplateArgument &Arg = Input.getArgument();
4936 switch (Arg.getKind()) {
4939 llvm_unreachable("Unexpected TemplateArgument");
4940
4945 // Transform a resolved template argument straight to a resolved template
4946 // argument. We get here when substituting into an already-substituted
4947 // template type argument during concept satisfaction checking.
4949 QualType NewT = getDerived().TransformType(T);
4950 if (NewT.isNull())
4951 return true;
4952
4954 ? Arg.getAsDecl()
4955 : nullptr;
4956 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4958 : nullptr;
4959 if (D && !NewD)
4960 return true;
4961
4962 if (NewT == T && D == NewD)
4963 Output = Input;
4964 else if (Arg.getKind() == TemplateArgument::Integral)
4965 Output = TemplateArgumentLoc(
4966 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4968 else if (Arg.getKind() == TemplateArgument::NullPtr)
4969 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4971 else if (Arg.getKind() == TemplateArgument::Declaration)
4972 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4975 Output = TemplateArgumentLoc(
4976 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4978 else
4979 llvm_unreachable("unexpected template argument kind");
4980
4981 return false;
4982 }
4983
4985 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4986 if (!DI)
4988
4989 DI = getDerived().TransformType(DI);
4990 if (!DI)
4991 return true;
4992
4993 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4994 return false;
4995 }
4996
4998 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4999
5000 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5001 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5002 Input.getTemplateNameLoc());
5003 if (Out.isNull())
5004 return true;
5005 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5006 QualifierLoc, Input.getTemplateNameLoc());
5007 return false;
5008 }
5009
5011 llvm_unreachable("Caller should expand pack expansions");
5012
5014 // Template argument expressions are constant expressions.
5016 getSema(),
5019 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5021
5022 Expr *InputExpr = Input.getSourceExpression();
5023 if (!InputExpr)
5024 InputExpr = Input.getArgument().getAsExpr();
5025
5026 ExprResult E = getDerived().TransformExpr(InputExpr);
5027 E = SemaRef.ActOnConstantExpression(E);
5028 if (E.isInvalid())
5029 return true;
5030 Output = TemplateArgumentLoc(
5031 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5032 return false;
5033 }
5034 }
5035
5036 // Work around bogus GCC warning
5037 return true;
5038}
5039
5040/// Iterator adaptor that invents template argument location information
5041/// for each of the template arguments in its underlying iterator.
5042template<typename Derived, typename InputIterator>
5045 InputIterator Iter;
5046
5047public:
5050 typedef typename std::iterator_traits<InputIterator>::difference_type
5052 typedef std::input_iterator_tag iterator_category;
5053
5054 class pointer {
5056
5057 public:
5058 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5059
5060 const TemplateArgumentLoc *operator->() const { return &Arg; }
5061 };
5062
5064 InputIterator Iter)
5065 : Self(Self), Iter(Iter) { }
5066
5068 ++Iter;
5069 return *this;
5070 }
5071
5074 ++(*this);
5075 return Old;
5076 }
5077
5080 Self.InventTemplateArgumentLoc(*Iter, Result);
5081 return Result;
5082 }
5083
5084 pointer operator->() const { return pointer(**this); }
5085
5088 return X.Iter == Y.Iter;
5089 }
5090
5093 return X.Iter != Y.Iter;
5094 }
5095};
5096
5097template<typename Derived>
5098template<typename InputIterator>
5100 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5101 bool Uneval) {
5102 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5104 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5105 // Unpack argument packs, which we translate them into separate
5106 // arguments.
5107 // FIXME: We could do much better if we could guarantee that the
5108 // TemplateArgumentLocInfo for the pack expansion would be usable for
5109 // all of the template arguments in the argument pack.
5110 typedef TemplateArgumentLocInventIterator<Derived,
5112 PackLocIterator;
5114 PackLocIterator(*this, In.getArgument().pack_begin()),
5115 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
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
5185// FIXME: Find ways to reduce code duplication for pack expansions.
5186template <typename Derived>
5188 bool Uneval,
5190 UnexpandedInfo &Info) {
5191 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5192 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5193 TemplateArgumentLoc &Pattern) {
5194 assert(Arg.getArgument().isPackExpansion());
5195 // We have a pack expansion, for which we will be substituting into the
5196 // pattern.
5197 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5198 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5200 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5201 if (IsLateExpansionAttempt) {
5202 // Request expansion only when there is an opportunity to expand a pack
5203 // that required a substituion first.
5204 bool SawPackTypes =
5205 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5206 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5207 });
5208 if (!SawPackTypes) {
5209 Info.Expand = false;
5210 return false;
5211 }
5212 }
5213 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5214
5215 // Determine whether the set of unexpanded parameter packs can and
5216 // should be expanded.
5217 Info.Expand = true;
5218 Info.RetainExpansion = false;
5219 Info.NumExpansions = Info.OrigNumExpansions;
5220 return getDerived().TryExpandParameterPacks(
5221 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5222 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5223 Info.RetainExpansion, Info.NumExpansions);
5224 };
5225
5226 TemplateArgumentLoc Pattern;
5227 if (ComputeInfo(In, false, Info, Pattern))
5228 return true;
5229
5230 if (Info.Expand) {
5231 Out = Pattern;
5232 return false;
5233 }
5234
5235 // The transform has determined that we should perform a simple
5236 // transformation on the pack expansion, producing another pack
5237 // expansion.
5238 TemplateArgumentLoc OutPattern;
5239 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5240 std::in_place, getSema(), std::nullopt);
5241 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5242 return true;
5243
5244 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5245 Info.NumExpansions);
5246 if (Out.getArgument().isNull())
5247 return true;
5248 SubstIndex.reset();
5249
5250 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5251 return false;
5252
5253 // Some packs will learn their length after substitution, e.g.
5254 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5255 // value of `T`.
5256 //
5257 // We only expand after we know sizes of all packs, check if this is the case
5258 // or not. However, we avoid a full template substitution and only do
5259 // expanstions after this point.
5260
5261 // E.g. when substituting template arguments of tuple with {T -> int} in the
5262 // following example:
5263 // template <class T>
5264 // struct TupleWithInt {
5265 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5266 // };
5267 // TupleWithInt<int>::type y;
5268 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5269 // lenght and run `ComputeInfo()` to provide the necessary information to our
5270 // caller.
5271 //
5272 // Note that we may still have situations where builtin is not going to be
5273 // expanded. For example:
5274 // template <class T>
5275 // struct Foo {
5276 // template <class U> using tuple_with_t =
5277 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5278 // tuple_with_t<short>;
5279 // }
5280 // Because the substitution into `type` happens in dependent context, `type`
5281 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5282 // and the caller will not be able to expand it.
5283 ForgetSubstitutionRAII ForgetSubst(getDerived());
5284 if (ComputeInfo(Out, true, Info, OutPattern))
5285 return true;
5286 if (!Info.Expand)
5287 return false;
5288 Out = OutPattern;
5289 Info.ExpandUnderForgetSubstitions = true;
5290 return false;
5291}
5292
5293//===----------------------------------------------------------------------===//
5294// Type transformation
5295//===----------------------------------------------------------------------===//
5296
5297template<typename Derived>
5300 return T;
5301
5302 // Temporary workaround. All of these transformations should
5303 // eventually turn into transformations on TypeLocs.
5304 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5306
5307 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5308
5309 if (!NewDI)
5310 return QualType();
5311
5312 return NewDI->getType();
5313}
5314
5315template<typename Derived>
5317 // Refine the base location to the type's location.
5318 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5321 return DI;
5322
5323 TypeLocBuilder TLB;
5324
5325 TypeLoc TL = DI->getTypeLoc();
5326 TLB.reserve(TL.getFullDataSize());
5327
5328 QualType Result = getDerived().TransformType(TLB, TL);
5329 if (Result.isNull())
5330 return nullptr;
5331
5332 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5333}
5334
5335template<typename Derived>
5338 switch (T.getTypeLocClass()) {
5339#define ABSTRACT_TYPELOC(CLASS, PARENT)
5340#define TYPELOC(CLASS, PARENT) \
5341 case TypeLoc::CLASS: \
5342 return getDerived().Transform##CLASS##Type(TLB, \
5343 T.castAs<CLASS##TypeLoc>());
5344#include "clang/AST/TypeLocNodes.def"
5345 }
5346
5347 llvm_unreachable("unhandled type loc!");
5348}
5349
5350template<typename Derived>
5353 return TransformType(T);
5354
5356 return T;
5357 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5359 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5360 return NewDI ? NewDI->getType() : QualType();
5361}
5362
5363template<typename Derived>
5366 if (!isa<DependentNameType>(DI->getType()))
5367 return TransformType(DI);
5368
5369 // Refine the base location to the type's location.
5370 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5373 return DI;
5374
5375 TypeLocBuilder TLB;
5376
5377 TypeLoc TL = DI->getTypeLoc();
5378 TLB.reserve(TL.getFullDataSize());
5379
5380 auto QTL = TL.getAs<QualifiedTypeLoc>();
5381 if (QTL)
5382 TL = QTL.getUnqualifiedLoc();
5383
5384 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5385
5386 QualType Result = getDerived().TransformDependentNameType(
5387 TLB, DNTL, /*DeducedTSTContext*/true);
5388 if (Result.isNull())
5389 return nullptr;
5390
5391 if (QTL) {
5392 Result = getDerived().RebuildQualifiedType(Result, QTL);
5393 if (Result.isNull())
5394 return nullptr;
5396 }
5397
5398 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5399}
5400
5401template<typename Derived>
5406 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5407 auto SuppressObjCLifetime =
5408 T.getType().getLocalQualifiers().hasObjCLifetime();
5409 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5410 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5411 SuppressObjCLifetime);
5412 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5413 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5414 TLB, STTP, SuppressObjCLifetime);
5415 } else {
5416 Result = getDerived().TransformType(TLB, UnqualTL);
5417 }
5418
5419 if (Result.isNull())
5420 return QualType();
5421
5422 Result = getDerived().RebuildQualifiedType(Result, T);
5423
5424 if (Result.isNull())
5425 return QualType();
5426
5427 // RebuildQualifiedType might have updated the type, but not in a way
5428 // that invalidates the TypeLoc. (There's no location information for
5429 // qualifiers.)
5431
5432 return Result;
5433}
5434
5435template <typename Derived>
5437 QualifiedTypeLoc TL) {
5438
5439 SourceLocation Loc = TL.getBeginLoc();
5440 Qualifiers Quals = TL.getType().getLocalQualifiers();
5441
5442 if ((T.getAddressSpace() != LangAS::Default &&
5443 Quals.getAddressSpace() != LangAS::Default) &&
5444 T.getAddressSpace() != Quals.getAddressSpace()) {
5445 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5446 << TL.getType() << T;
5447 return QualType();
5448 }
5449
5450 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5451 if (LocalPointerAuth.isPresent()) {
5452 if (T.getPointerAuth().isPresent()) {
5453 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5454 return QualType();
5455 }
5456 if (!T->isDependentType()) {
5457 if (!T->isSignableType(SemaRef.getASTContext())) {
5458 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5459 return QualType();
5460 }
5461 }
5462 }
5463 // C++ [dcl.fct]p7:
5464 // [When] adding cv-qualifications on top of the function type [...] the
5465 // cv-qualifiers are ignored.
5466 if (T->isFunctionType()) {
5467 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5468 Quals.getAddressSpace());
5469 return T;
5470 }
5471
5472 // C++ [dcl.ref]p1:
5473 // when the cv-qualifiers are introduced through the use of a typedef-name
5474 // or decltype-specifier [...] the cv-qualifiers are ignored.
5475 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5476 // applied to a reference type.
5477 if (T->isReferenceType()) {
5478 // The only qualifier that applies to a reference type is restrict.
5479 if (!Quals.hasRestrict())
5480 return T;
5482 }
5483
5484 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5485 // resulting type.
5486 if (Quals.hasObjCLifetime()) {
5487 if (!T->isObjCLifetimeType() && !T->isDependentType())
5488 Quals.removeObjCLifetime();
5489 else if (T.getObjCLifetime()) {
5490 // Objective-C ARC:
5491 // A lifetime qualifier applied to a substituted template parameter
5492 // overrides the lifetime qualifier from the template argument.
5493 const AutoType *AutoTy;
5494 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5495 // 'auto' types behave the same way as template parameters.
5496 QualType Deduced = AutoTy->getDeducedType();
5497 Qualifiers Qs = Deduced.getQualifiers();
5498 Qs.removeObjCLifetime();
5499 Deduced =
5500 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5501 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5502 AutoTy->isDependentType(),
5503 /*isPack=*/false,
5504 AutoTy->getTypeConstraintConcept(),
5505 AutoTy->getTypeConstraintArguments());
5506 } else {
5507 // Otherwise, complain about the addition of a qualifier to an
5508 // already-qualified type.
5509 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5510 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5511 Quals.removeObjCLifetime();
5512 }
5513 }
5514 }
5515
5516 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5517}
5518
5519template <typename Derived>
5520QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5521 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5522 NamedDecl *FirstQualifierInScope) {
5523 assert(!getDerived().AlreadyTransformed(TL.getType()));
5524
5525 switch (TL.getTypeLocClass()) {
5526 case TypeLoc::TemplateSpecialization:
5527 return getDerived().TransformTemplateSpecializationType(
5528 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5529 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5530 case TypeLoc::DependentName:
5531 return getDerived().TransformDependentNameType(
5532 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5533 ObjectType, FirstQualifierInScope);
5534 default:
5535 // Any dependent canonical type can appear here, through type alias
5536 // templates.
5537 return getDerived().TransformType(TLB, TL);
5538 }
5539}
5540
5541template <class TyLoc> static inline
5543 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5544 NewT.setNameLoc(T.getNameLoc());
5545 return T.getType();
5546}
5547
5548template<typename Derived>
5549QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5550 BuiltinTypeLoc T) {
5551 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5552 NewT.setBuiltinLoc(T.getBuiltinLoc());
5553 if (T.needsExtraLocalData())
5554 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5555 return T.getType();
5556}
5557
5558template<typename Derived>
5560 ComplexTypeLoc T) {
5561 // FIXME: recurse?
5562 return TransformTypeSpecType(TLB, T);
5563}
5564
5565template <typename Derived>
5567 AdjustedTypeLoc TL) {
5568 // Adjustments applied during transformation are handled elsewhere.
5569 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5570}
5571
5572template<typename Derived>
5574 DecayedTypeLoc TL) {
5575 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5576 if (OriginalType.isNull())
5577 return QualType();
5578
5579 QualType Result = TL.getType();
5580 if (getDerived().AlwaysRebuild() ||
5581 OriginalType != TL.getOriginalLoc().getType())
5582 Result = SemaRef.Context.getDecayedType(OriginalType);
5583 TLB.push<DecayedTypeLoc>(Result);
5584 // Nothing to set for DecayedTypeLoc.
5585 return Result;
5586}
5587
5588template <typename Derived>
5592 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5593 if (OriginalType.isNull())
5594 return QualType();
5595
5596 QualType Result = TL.getType();
5597 if (getDerived().AlwaysRebuild() ||
5598 OriginalType != TL.getElementLoc().getType())
5599 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5600 TLB.push<ArrayParameterTypeLoc>(Result);
5601 // Nothing to set for ArrayParameterTypeLoc.
5602 return Result;
5603}
5604
5605template<typename Derived>
5607 PointerTypeLoc TL) {
5608 QualType PointeeType
5609 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5610 if (PointeeType.isNull())
5611 return QualType();
5612
5613 QualType Result = TL.getType();
5614 if (PointeeType->getAs<ObjCObjectType>()) {
5615 // A dependent pointer type 'T *' has is being transformed such
5616 // that an Objective-C class type is being replaced for 'T'. The
5617 // resulting pointer type is an ObjCObjectPointerType, not a
5618 // PointerType.
5619 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5620
5622 NewT.setStarLoc(TL.getStarLoc());
5623 return Result;
5624 }
5625
5626 if (getDerived().AlwaysRebuild() ||
5627 PointeeType != TL.getPointeeLoc().getType()) {
5628 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5629 if (Result.isNull())
5630 return QualType();
5631 }
5632
5633 // Objective-C ARC can add lifetime qualifiers to the type that we're
5634 // pointing to.
5635 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5636
5637 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5638 NewT.setSigilLoc(TL.getSigilLoc());
5639 return Result;
5640}
5641
5642template<typename Derived>
5646 QualType PointeeType
5647 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5648 if (PointeeType.isNull())
5649 return QualType();
5650
5651 QualType Result = TL.getType();
5652 if (getDerived().AlwaysRebuild() ||
5653 PointeeType != TL.getPointeeLoc().getType()) {
5654 Result = getDerived().RebuildBlockPointerType(PointeeType,
5655 TL.getSigilLoc());
5656 if (Result.isNull())
5657 return QualType();
5658 }
5659
5661 NewT.setSigilLoc(TL.getSigilLoc());
5662 return Result;
5663}
5664
5665/// Transforms a reference type. Note that somewhat paradoxically we
5666/// don't care whether the type itself is an l-value type or an r-value
5667/// type; we only care if the type was *written* as an l-value type
5668/// or an r-value type.
5669template<typename Derived>
5672 ReferenceTypeLoc TL) {
5673 const ReferenceType *T = TL.getTypePtr();
5674
5675 // Note that this works with the pointee-as-written.
5676 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5677 if (PointeeType.isNull())
5678 return QualType();
5679
5680 QualType Result = TL.getType();
5681 if (getDerived().AlwaysRebuild() ||
5682 PointeeType != T->getPointeeTypeAsWritten()) {
5683 Result = getDerived().RebuildReferenceType(PointeeType,
5684 T->isSpelledAsLValue(),
5685 TL.getSigilLoc());
5686 if (Result.isNull())
5687 return QualType();
5688 }
5689
5690 // Objective-C ARC can add lifetime qualifiers to the type that we're
5691 // referring to.
5694
5695 // r-value references can be rebuilt as l-value references.
5696 ReferenceTypeLoc NewTL;
5698 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5699 else
5700 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5701 NewTL.setSigilLoc(TL.getSigilLoc());
5702
5703 return Result;
5704}
5705
5706template<typename Derived>
5710 return TransformReferenceType(TLB, TL);
5711}
5712
5713template<typename Derived>
5714QualType
5715TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5716 RValueReferenceTypeLoc TL) {
5717 return TransformReferenceType(TLB, TL);
5718}
5719
5720template<typename Derived>
5724 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5725 if (PointeeType.isNull())
5726 return QualType();
5727
5728 const MemberPointerType *T = TL.getTypePtr();
5729
5730 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5731 NestedNameSpecifierLoc NewQualifierLoc =
5732 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5733 if (!NewQualifierLoc)
5734 return QualType();
5735
5736 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5737 if (OldCls) {
5738 NewCls = cast_or_null<CXXRecordDecl>(
5739 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5740 if (!NewCls)
5741 return QualType();
5742 }
5743
5744 QualType Result = TL.getType();
5745 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5746 NewQualifierLoc.getNestedNameSpecifier() !=
5747 OldQualifierLoc.getNestedNameSpecifier() ||
5748 NewCls != OldCls) {
5749 CXXScopeSpec SS;
5750 SS.Adopt(NewQualifierLoc);
5751 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5752 TL.getStarLoc());
5753 if (Result.isNull())
5754 return QualType();
5755 }
5756
5757 // If we had to adjust the pointee type when building a member pointer, make
5758 // sure to push TypeLoc info for it.
5759 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5760 if (MPT && PointeeType != MPT->getPointeeType()) {
5761 assert(isa<AdjustedType>(MPT->getPointeeType()));
5762 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5763 }
5764
5766 NewTL.setSigilLoc(TL.getSigilLoc());
5767 NewTL.setQualifierLoc(NewQualifierLoc);
5768
5769 return Result;
5770}
5771
5772template<typename Derived>
5776 const ConstantArrayType *T = TL.getTypePtr();
5777 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5778 if (ElementType.isNull())
5779 return QualType();
5780
5781 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5782 Expr *OldSize = TL.getSizeExpr();
5783 if (!OldSize)
5784 OldSize = const_cast<Expr*>(T->getSizeExpr());
5785 Expr *NewSize = nullptr;
5786 if (OldSize) {
5789 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5790 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5791 }
5792
5793 QualType Result = TL.getType();
5794 if (getDerived().AlwaysRebuild() ||
5795 ElementType != T->getElementType() ||
5796 (T->getSizeExpr() && NewSize != OldSize)) {
5797 Result = getDerived().RebuildConstantArrayType(ElementType,
5798 T->getSizeModifier(),
5799 T->getSize(), NewSize,
5800 T->getIndexTypeCVRQualifiers(),
5801 TL.getBracketsRange());
5802 if (Result.isNull())
5803 return QualType();
5804 }
5805
5806 // We might have either a ConstantArrayType or a VariableArrayType now:
5807 // a ConstantArrayType is allowed to have an element type which is a
5808 // VariableArrayType if the type is dependent. Fortunately, all array
5809 // types have the same location layout.
5810 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5811 NewTL.setLBracketLoc(TL.getLBracketLoc());
5812 NewTL.setRBracketLoc(TL.getRBracketLoc());
5813 NewTL.setSizeExpr(NewSize);
5814
5815 return Result;
5816}
5817
5818template<typename Derived>
5820 TypeLocBuilder &TLB,
5822 const IncompleteArrayType *T = TL.getTypePtr();
5823 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5824 if (ElementType.isNull())
5825 return QualType();
5826
5827 QualType Result = TL.getType();
5828 if (getDerived().AlwaysRebuild() ||
5829 ElementType != T->getElementType()) {
5830 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5831 T->getSizeModifier(),
5832 T->getIndexTypeCVRQualifiers(),
5833 TL.getBracketsRange());
5834 if (Result.isNull())
5835 return QualType();
5836 }
5837
5839 NewTL.setLBracketLoc(TL.getLBracketLoc());
5840 NewTL.setRBracketLoc(TL.getRBracketLoc());
5841 NewTL.setSizeExpr(nullptr);
5842
5843 return Result;
5844}
5845
5846template<typename Derived>
5850 const VariableArrayType *T = TL.getTypePtr();
5851 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5852 if (ElementType.isNull())
5853 return QualType();
5854
5855 ExprResult SizeResult;
5856 {
5859 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5860 }
5861 if (SizeResult.isInvalid())
5862 return QualType();
5863 SizeResult =
5864 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5865 if (SizeResult.isInvalid())
5866 return QualType();
5867
5868 Expr *Size = SizeResult.get();
5869
5870 QualType Result = TL.getType();
5871 if (getDerived().AlwaysRebuild() ||
5872 ElementType != T->getElementType() ||
5873 Size != T->getSizeExpr()) {
5874 Result = getDerived().RebuildVariableArrayType(ElementType,
5875 T->getSizeModifier(),
5876 Size,
5877 T->getIndexTypeCVRQualifiers(),
5878 TL.getBracketsRange());
5879 if (Result.isNull())
5880 return QualType();
5881 }
5882
5883 // We might have constant size array now, but fortunately it has the same
5884 // location layout.
5885 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5886 NewTL.setLBracketLoc(TL.getLBracketLoc());
5887 NewTL.setRBracketLoc(TL.getRBracketLoc());
5888 NewTL.setSizeExpr(Size);
5889
5890 return Result;
5891}
5892
5893template<typename Derived>
5897 const DependentSizedArrayType *T = TL.getTypePtr();
5898 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5899 if (ElementType.isNull())
5900 return QualType();
5901
5902 // Array bounds are constant expressions.
5905
5906 // If we have a VLA then it won't be a constant.
5907 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5908
5909 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5910 Expr *origSize = TL.getSizeExpr();
5911 if (!origSize) origSize = T->getSizeExpr();
5912
5913 ExprResult sizeResult
5914 = getDerived().TransformExpr(origSize);
5915 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5916 if (sizeResult.isInvalid())
5917 return QualType();
5918
5919 Expr *size = sizeResult.get();
5920
5921 QualType Result = TL.getType();
5922 if (getDerived().AlwaysRebuild() ||
5923 ElementType != T->getElementType() ||
5924 size != origSize) {
5925 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5926 T->getSizeModifier(),
5927 size,
5928 T->getIndexTypeCVRQualifiers(),
5929 TL.getBracketsRange());
5930 if (Result.isNull())
5931 return QualType();
5932 }
5933
5934 // We might have any sort of array type now, but fortunately they
5935 // all have the same location layout.
5936 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5937 NewTL.setLBracketLoc(TL.getLBracketLoc());
5938 NewTL.setRBracketLoc(TL.getRBracketLoc());
5939 NewTL.setSizeExpr(size);
5940
5941 return Result;
5942}
5943
5944template <typename Derived>
5947 const DependentVectorType *T = TL.getTypePtr();
5948 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5949 if (ElementType.isNull())
5950 return QualType();
5951
5954
5955 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5956 Size = SemaRef.ActOnConstantExpression(Size);
5957 if (Size.isInvalid())
5958 return QualType();
5959
5960 QualType Result = TL.getType();
5961 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5962 Size.get() != T->getSizeExpr()) {
5963 Result = getDerived().RebuildDependentVectorType(
5964 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5965 if (Result.isNull())
5966 return QualType();
5967 }
5968
5969 // Result might be dependent or not.
5972 TLB.push<DependentVectorTypeLoc>(Result);
5973 NewTL.setNameLoc(TL.getNameLoc());
5974 } else {
5975 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5976 NewTL.setNameLoc(TL.getNameLoc());
5977 }
5978
5979 return Result;
5980}
5981
5982template<typename Derived>
5984 TypeLocBuilder &TLB,
5986 const DependentSizedExtVectorType *T = TL.getTypePtr();
5987
5988 // FIXME: ext vector locs should be nested
5989 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5990 if (ElementType.isNull())
5991 return QualType();
5992
5993 // Vector sizes are constant expressions.
5996
5997 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5998 Size = SemaRef.ActOnConstantExpression(Size);
5999 if (Size.isInvalid())
6000 return QualType();
6001
6002 QualType Result = TL.getType();
6003 if (getDerived().AlwaysRebuild() ||
6004 ElementType != T->getElementType() ||
6005 Size.get() != T->getSizeExpr()) {
6006 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6007 Size.get(),
6008 T->getAttributeLoc());
6009 if (Result.isNull())
6010 return QualType();
6011 }
6012
6013 // Result might be dependent or not.
6017 NewTL.setNameLoc(TL.getNameLoc());
6018 } else {
6019 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6020 NewTL.setNameLoc(TL.getNameLoc());
6021 }
6022
6023 return Result;
6024}
6025
6026template <typename Derived>
6030 const ConstantMatrixType *T = TL.getTypePtr();
6031 QualType ElementType = getDerived().TransformType(T->getElementType());
6032 if (ElementType.isNull())
6033 return QualType();
6034
6035 QualType Result = TL.getType();
6036 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6037 Result = getDerived().RebuildConstantMatrixType(
6038 ElementType, T->getNumRows(), T->getNumColumns());
6039 if (Result.isNull())
6040 return QualType();
6041 }
6042
6044 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6045 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6046 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6047 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6048
6049 return Result;
6050}
6051
6052template <typename Derived>
6055 const DependentSizedMatrixType *T = TL.getTypePtr();
6056
6057 QualType ElementType = getDerived().TransformType(T->getElementType());
6058 if (ElementType.isNull()) {
6059 return QualType();
6060 }
6061
6062 // Matrix dimensions are constant expressions.
6065
6066 Expr *origRows = TL.getAttrRowOperand();
6067 if (!origRows)
6068 origRows = T->getRowExpr();
6069 Expr *origColumns = TL.getAttrColumnOperand();
6070 if (!origColumns)
6071 origColumns = T->getColumnExpr();
6072
6073 ExprResult rowResult = getDerived().TransformExpr(origRows);
6074 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6075 if (rowResult.isInvalid())
6076 return QualType();
6077
6078 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6079 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6080 if (columnResult.isInvalid())
6081 return QualType();
6082
6083 Expr *rows = rowResult.get();
6084 Expr *columns = columnResult.get();
6085
6086 QualType Result = TL.getType();
6087 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6088 rows != origRows || columns != origColumns) {
6089 Result = getDerived().RebuildDependentSizedMatrixType(
6090 ElementType, rows, columns, T->getAttributeLoc());
6091
6092 if (Result.isNull())
6093 return QualType();
6094 }
6095
6096 // We might have any sort of matrix type now, but fortunately they
6097 // all have the same location layout.
6098 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6099 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6100 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6101 NewTL.setAttrRowOperand(rows);
6102 NewTL.setAttrColumnOperand(columns);
6103 return Result;
6104}
6105
6106template <typename Derived>
6109 const DependentAddressSpaceType *T = TL.getTypePtr();
6110
6111 QualType pointeeType =
6112 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6113
6114 if (pointeeType.isNull())
6115 return QualType();
6116
6117 // Address spaces are constant expressions.
6120
6121 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6122 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6123 if (AddrSpace.isInvalid())
6124 return QualType();
6125
6126 QualType Result = TL.getType();
6127 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6128 AddrSpace.get() != T->getAddrSpaceExpr()) {
6129 Result = getDerived().RebuildDependentAddressSpaceType(
6130 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6131 if (Result.isNull())
6132 return QualType();
6133 }
6134
6135 // Result might be dependent or not.
6139
6140 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6141 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6142 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6143
6144 } else {
6145 TLB.TypeWasModifiedSafely(Result);
6146 }
6147
6148 return Result;
6149}
6150
6151template <typename Derived>
6153 VectorTypeLoc TL) {
6154 const VectorType *T = TL.getTypePtr();
6155 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6156 if (ElementType.isNull())
6157 return QualType();
6158
6159 QualType Result = TL.getType();
6160 if (getDerived().AlwaysRebuild() ||
6161 ElementType != T->getElementType()) {
6162 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6163 T->getVectorKind());
6164 if (Result.isNull())
6165 return QualType();
6166 }
6167
6168 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6169 NewTL.setNameLoc(TL.getNameLoc());
6170
6171 return Result;
6172}
6173
6174template<typename Derived>
6176 ExtVectorTypeLoc TL) {
6177 const VectorType *T = TL.getTypePtr();
6178 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6179 if (ElementType.isNull())
6180 return QualType();
6181
6182 QualType Result = TL.getType();
6183 if (getDerived().AlwaysRebuild() ||
6184 ElementType != T->getElementType()) {
6185 Result = getDerived().RebuildExtVectorType(ElementType,
6186 T->getNumElements(),
6187 /*FIXME*/ SourceLocation());
6188 if (Result.isNull())
6189 return QualType();
6190 }
6191
6192 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6193 NewTL.setNameLoc(TL.getNameLoc());
6194
6195 return Result;
6196}
6197
6198template <typename Derived>
6200 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6201 bool ExpectParameterPack) {
6202 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6203 TypeSourceInfo *NewDI = nullptr;
6204
6205 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6206 // If we're substituting into a pack expansion type and we know the
6207 // length we want to expand to, just substitute for the pattern.
6208 TypeLoc OldTL = OldDI->getTypeLoc();
6209 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6210
6211 TypeLocBuilder TLB;
6212 TypeLoc NewTL = OldDI->getTypeLoc();
6213 TLB.reserve(NewTL.getFullDataSize());
6214
6215 QualType Result = getDerived().TransformType(TLB,
6216 OldExpansionTL.getPatternLoc());
6217 if (Result.isNull())
6218 return nullptr;
6219
6221 OldExpansionTL.getPatternLoc().getSourceRange(),
6222 OldExpansionTL.getEllipsisLoc(),
6223 NumExpansions);
6224 if (Result.isNull())
6225 return nullptr;
6226
6227 PackExpansionTypeLoc NewExpansionTL
6228 = TLB.push<PackExpansionTypeLoc>(Result);
6229 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6230 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6231 } else
6232 NewDI = getDerived().TransformType(OldDI);
6233 if (!NewDI)
6234 return nullptr;
6235
6236 if (NewDI == OldDI && indexAdjustment == 0)
6237 return OldParm;
6238
6239 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6240 OldParm->getDeclContext(),
6241 OldParm->getInnerLocStart(),
6242 OldParm->getLocation(),
6243 OldParm->getIdentifier(),
6244 NewDI->getType(),
6245 NewDI,
6246 OldParm->getStorageClass(),
6247 /* DefArg */ nullptr);
6248 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6249 OldParm->getFunctionScopeIndex() + indexAdjustment);
6250 transformedLocalDecl(OldParm, {newParm});
6251 return newParm;
6252}
6253
6254template <typename Derived>
6257 const QualType *ParamTypes,
6258 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6259 SmallVectorImpl<QualType> &OutParamTypes,
6262 unsigned *LastParamTransformed) {
6263 int indexAdjustment = 0;
6264
6265 unsigned NumParams = Params.size();
6266 for (unsigned i = 0; i != NumParams; ++i) {
6267 if (LastParamTransformed)
6268 *LastParamTransformed = i;
6269 if (ParmVarDecl *OldParm = Params[i]) {
6270 assert(OldParm->getFunctionScopeIndex() == i);
6271
6272 UnsignedOrNone NumExpansions = std::nullopt;
6273 ParmVarDecl *NewParm = nullptr;
6274 if (OldParm->isParameterPack()) {
6275 // We have a function parameter pack that may need to be expanded.
6277
6278 // Find the parameter packs that could be expanded.
6279 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6281 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6282 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6283
6284 // Determine whether we should expand the parameter packs.
6285 bool ShouldExpand = false;
6286 bool RetainExpansion = false;
6287 UnsignedOrNone OrigNumExpansions = std::nullopt;
6288 if (Unexpanded.size() > 0) {
6289 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6290 NumExpansions = OrigNumExpansions;
6292 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6293 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6294 ShouldExpand, RetainExpansion, NumExpansions)) {
6295 return true;
6296 }
6297 } else {
6298#ifndef NDEBUG
6299 const AutoType *AT =
6300 Pattern.getType().getTypePtr()->getContainedAutoType();
6301 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6302 "Could not find parameter packs or undeduced auto type!");
6303#endif
6304 }
6305
6306 if (ShouldExpand) {
6307 // Expand the function parameter pack into multiple, separate
6308 // parameters.
6309 getDerived().ExpandingFunctionParameterPack(OldParm);
6310 for (unsigned I = 0; I != *NumExpansions; ++I) {
6311 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6312 ParmVarDecl *NewParm
6313 = getDerived().TransformFunctionTypeParam(OldParm,
6314 indexAdjustment++,
6315 OrigNumExpansions,
6316 /*ExpectParameterPack=*/false);
6317 if (!NewParm)
6318 return true;
6319
6320 if (ParamInfos)
6321 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6322 OutParamTypes.push_back(NewParm->getType());
6323 if (PVars)
6324 PVars->push_back(NewParm);
6325 }
6326
6327 // If we're supposed to retain a pack expansion, do so by temporarily
6328 // forgetting the partially-substituted parameter pack.
6329 if (RetainExpansion) {
6330 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6331 ParmVarDecl *NewParm
6332 = getDerived().TransformFunctionTypeParam(OldParm,
6333 indexAdjustment++,
6334 OrigNumExpansions,
6335 /*ExpectParameterPack=*/false);
6336 if (!NewParm)
6337 return true;
6338
6339 if (ParamInfos)
6340 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6341 OutParamTypes.push_back(NewParm->getType());
6342 if (PVars)
6343 PVars->push_back(NewParm);
6344 }
6345
6346 // The next parameter should have the same adjustment as the
6347 // last thing we pushed, but we post-incremented indexAdjustment
6348 // on every push. Also, if we push nothing, the adjustment should
6349 // go down by one.
6350 indexAdjustment--;
6351
6352 // We're done with the pack expansion.
6353 continue;
6354 }
6355
6356 // We'll substitute the parameter now without expanding the pack
6357 // expansion.
6358 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6359 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6360 indexAdjustment,
6361 NumExpansions,
6362 /*ExpectParameterPack=*/true);
6363 assert(NewParm->isParameterPack() &&
6364 "Parameter pack no longer a parameter pack after "
6365 "transformation.");
6366 } else {
6367 NewParm = getDerived().TransformFunctionTypeParam(
6368 OldParm, indexAdjustment, std::nullopt,
6369 /*ExpectParameterPack=*/false);
6370 }
6371
6372 if (!NewParm)
6373 return true;
6374
6375 if (ParamInfos)
6376 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6377 OutParamTypes.push_back(NewParm->getType());
6378 if (PVars)
6379 PVars->push_back(NewParm);
6380 continue;
6381 }
6382
6383 // Deal with the possibility that we don't have a parameter
6384 // declaration for this parameter.
6385 assert(ParamTypes);
6386 QualType OldType = ParamTypes[i];
6387 bool IsPackExpansion = false;
6388 UnsignedOrNone NumExpansions = std::nullopt;
6389 QualType NewType;
6390 if (const PackExpansionType *Expansion
6391 = dyn_cast<PackExpansionType>(OldType)) {
6392 // We have a function parameter pack that may need to be expanded.
6393 QualType Pattern = Expansion->getPattern();
6395 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6396
6397 // Determine whether we should expand the parameter packs.
6398 bool ShouldExpand = false;
6399 bool RetainExpansion = false;
6401 Loc, SourceRange(), Unexpanded,
6402 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6403 RetainExpansion, NumExpansions)) {
6404 return true;
6405 }
6406
6407 if (ShouldExpand) {
6408 // Expand the function parameter pack into multiple, separate
6409 // parameters.
6410 for (unsigned I = 0; I != *NumExpansions; ++I) {
6411 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6412 QualType NewType = getDerived().TransformType(Pattern);
6413 if (NewType.isNull())
6414 return true;
6415
6416 if (NewType->containsUnexpandedParameterPack()) {
6417 NewType = getSema().getASTContext().getPackExpansionType(
6418 NewType, std::nullopt);
6419
6420 if (NewType.isNull())
6421 return true;
6422 }
6423
6424 if (ParamInfos)
6425 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6426 OutParamTypes.push_back(NewType);
6427 if (PVars)
6428 PVars->push_back(nullptr);
6429 }
6430
6431 // We're done with the pack expansion.
6432 continue;
6433 }
6434
6435 // If we're supposed to retain a pack expansion, do so by temporarily
6436 // forgetting the partially-substituted parameter pack.
6437 if (RetainExpansion) {
6438 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6439 QualType NewType = getDerived().TransformType(Pattern);
6440 if (NewType.isNull())
6441 return true;
6442
6443 if (ParamInfos)
6444 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6445 OutParamTypes.push_back(NewType);
6446 if (PVars)
6447 PVars->push_back(nullptr);
6448 }
6449
6450 // We'll substitute the parameter now without expanding the pack
6451 // expansion.
6452 OldType = Expansion->getPattern();
6453 IsPackExpansion = true;
6454 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6455 NewType = getDerived().TransformType(OldType);
6456 } else {
6457 NewType = getDerived().TransformType(OldType);
6458 }
6459
6460 if (NewType.isNull())
6461 return true;
6462
6463 if (IsPackExpansion)
6464 NewType = getSema().Context.getPackExpansionType(NewType,
6465 NumExpansions);
6466
6467 if (ParamInfos)
6468 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6469 OutParamTypes.push_back(NewType);
6470 if (PVars)
6471 PVars->push_back(nullptr);
6472 }
6473
6474#ifndef NDEBUG
6475 if (PVars) {
6476 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6477 if (ParmVarDecl *parm = (*PVars)[i])
6478 assert(parm->getFunctionScopeIndex() == i);
6479 }
6480#endif
6481
6482 return false;
6483}
6484
6485template<typename Derived>
6489 SmallVector<QualType, 4> ExceptionStorage;
6490 return getDerived().TransformFunctionProtoType(
6491 TLB, TL, nullptr, Qualifiers(),
6492 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6493 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6494 ExceptionStorage, Changed);
6495 });
6496}
6497
6498template<typename Derived> template<typename Fn>
6500 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6501 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6502
6503 // Transform the parameters and return type.
6504 //
6505 // We are required to instantiate the params and return type in source order.
6506 // When the function has a trailing return type, we instantiate the
6507 // parameters before the return type, since the return type can then refer
6508 // to the parameters themselves (via decltype, sizeof, etc.).
6509 //
6510 SmallVector<QualType, 4> ParamTypes;
6512 Sema::ExtParameterInfoBuilder ExtParamInfos;
6513 const FunctionProtoType *T = TL.getTypePtr();
6514
6515 QualType ResultType;
6516
6517 if (T->hasTrailingReturn()) {
6519 TL.getBeginLoc(), TL.getParams(),
6521 T->getExtParameterInfosOrNull(),
6522 ParamTypes, &ParamDecls, ExtParamInfos))
6523 return QualType();
6524
6525 {
6526 // C++11 [expr.prim.general]p3:
6527 // If a declaration declares a member function or member function
6528 // template of a class X, the expression this is a prvalue of type
6529 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6530 // and the end of the function-definition, member-declarator, or
6531 // declarator.
6532 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6533 Sema::CXXThisScopeRAII ThisScope(
6534 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6535
6536 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6537 if (ResultType.isNull())
6538 return QualType();
6539 }
6540 }
6541 else {
6542 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6543 if (ResultType.isNull())
6544 return QualType();
6545
6547 TL.getBeginLoc(), TL.getParams(),
6549 T->getExtParameterInfosOrNull(),
6550 ParamTypes, &ParamDecls, ExtParamInfos))
6551 return QualType();
6552 }
6553
6554 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6555
6556 bool EPIChanged = false;
6557 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6558 return QualType();
6559
6560 // Handle extended parameter information.
6561 if (auto NewExtParamInfos =
6562 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6563 if (!EPI.ExtParameterInfos ||
6565 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6566 EPIChanged = true;
6567 }
6568 EPI.ExtParameterInfos = NewExtParamInfos;
6569 } else if (EPI.ExtParameterInfos) {
6570 EPIChanged = true;
6571 EPI.ExtParameterInfos = nullptr;
6572 }
6573
6574 // Transform any function effects with unevaluated conditions.
6575 // Hold this set in a local for the rest of this function, since EPI
6576 // may need to hold a FunctionEffectsRef pointing into it.
6577 std::optional<FunctionEffectSet> NewFX;
6578 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6579 NewFX.emplace();
6582
6583 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6584 FunctionEffectWithCondition NewEC = PrevEC;
6585 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6586 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6587 if (NewExpr.isInvalid())
6588 return QualType();
6589 std::optional<FunctionEffectMode> Mode =
6590 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6591 if (!Mode)
6592 return QualType();
6593
6594 // The condition expression has been transformed, and re-evaluated.
6595 // It may or may not have become constant.
6596 switch (*Mode) {
6598 NewEC.Cond = {};
6599 break;
6601 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6602 NewEC.Cond = {};
6603 break;
6605 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6606 break;
6608 llvm_unreachable(
6609 "FunctionEffectMode::None shouldn't be possible here");
6610 }
6611 }
6612 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6613 TL.getBeginLoc())) {
6615 NewFX->insert(NewEC, Errs);
6616 assert(Errs.empty());
6617 }
6618 }
6619 EPI.FunctionEffects = *NewFX;
6620 EPIChanged = true;
6621 }
6622
6623 QualType Result = TL.getType();
6624 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6625 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6626 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6627 if (Result.isNull())
6628 return QualType();
6629 }
6630
6633 NewTL.setLParenLoc(TL.getLParenLoc());
6634 NewTL.setRParenLoc(TL.getRParenLoc());
6637 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6638 NewTL.setParam(i, ParamDecls[i]);
6639
6640 return Result;
6641}
6642
6643template<typename Derived>
6646 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6647 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6648
6649 // Instantiate a dynamic noexcept expression, if any.
6650 if (isComputedNoexcept(ESI.Type)) {
6651 // Update this scrope because ContextDecl in Sema will be used in
6652 // TransformExpr.
6653 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6654 Sema::CXXThisScopeRAII ThisScope(
6655 SemaRef, Method ? Method->getParent() : nullptr,
6656 Method ? Method->getMethodQualifiers() : Qualifiers{},
6657 Method != nullptr);
6660 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6661 if (NoexceptExpr.isInvalid())
6662 return true;
6663
6665 NoexceptExpr =
6666 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6667 if (NoexceptExpr.isInvalid())
6668 return true;
6669
6670 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6671 Changed = true;
6672 ESI.NoexceptExpr = NoexceptExpr.get();
6673 ESI.Type = EST;
6674 }
6675
6676 if (ESI.Type != EST_Dynamic)
6677 return false;
6678
6679 // Instantiate a dynamic exception specification's type.
6680 for (QualType T : ESI.Exceptions) {
6681 if (const PackExpansionType *PackExpansion =
6682 T->getAs<PackExpansionType>()) {
6683 Changed = true;
6684
6685 // We have a pack expansion. Instantiate it.
6687 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6688 Unexpanded);
6689 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6690
6691 // Determine whether the set of unexpanded parameter packs can and
6692 // should
6693 // be expanded.
6694 bool Expand = false;
6695 bool RetainExpansion = false;
6696 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6697 // FIXME: Track the location of the ellipsis (and track source location
6698 // information for the types in the exception specification in general).
6700 Loc, SourceRange(), Unexpanded,
6701 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6702 NumExpansions))
6703 return true;
6704
6705 if (!Expand) {
6706 // We can't expand this pack expansion into separate arguments yet;
6707 // just substitute into the pattern and create a new pack expansion
6708 // type.
6709 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6710 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6711 if (U.isNull())
6712 return true;
6713
6714 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6715 Exceptions.push_back(U);
6716 continue;
6717 }
6718
6719 // Substitute into the pack expansion pattern for each slice of the
6720 // pack.
6721 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6722 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6723
6724 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6725 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6726 return true;
6727
6728 Exceptions.push_back(U);
6729 }
6730 } else {
6731 QualType U = getDerived().TransformType(T);
6732 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6733 return true;
6734 if (T != U)
6735 Changed = true;
6736
6737 Exceptions.push_back(U);
6738 }
6739 }
6740
6741 ESI.Exceptions = Exceptions;
6742 if (ESI.Exceptions.empty())
6743 ESI.Type = EST_DynamicNone;
6744 return false;
6745}
6746
6747template<typename Derived>
6749 TypeLocBuilder &TLB,
6751 const FunctionNoProtoType *T = TL.getTypePtr();
6752 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6753 if (ResultType.isNull())
6754 return QualType();
6755
6756 QualType Result = TL.getType();
6757 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6758 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6759
6762 NewTL.setLParenLoc(TL.getLParenLoc());
6763 NewTL.setRParenLoc(TL.getRParenLoc());
6765
6766 return Result;
6767}
6768
6769template <typename Derived>
6770QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6771 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6772
6773 const UnresolvedUsingType *T = TL.getTypePtr();
6774 bool Changed = false;
6775
6776 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6777 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6778 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6779 if (!QualifierLoc)
6780 return QualType();
6781 Changed |= QualifierLoc != OldQualifierLoc;
6782 }
6783
6784 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6785 if (!D)
6786 return QualType();
6787 Changed |= D != T->getDecl();
6788
6789 QualType Result = TL.getType();
6790 if (getDerived().AlwaysRebuild() || Changed) {
6791 Result = getDerived().RebuildUnresolvedUsingType(
6792 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6793 D);
6794 if (Result.isNull())
6795 return QualType();
6796 }
6797
6799 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6800 QualifierLoc, TL.getNameLoc());
6801 else
6802 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6803 QualifierLoc, TL.getNameLoc());
6804 return Result;
6805}
6806
6807template <typename Derived>
6809 UsingTypeLoc TL) {
6810 const UsingType *T = TL.getTypePtr();
6811 bool Changed = false;
6812
6813 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6814 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6815 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6816 if (!QualifierLoc)
6817 return QualType();
6818 Changed |= QualifierLoc != OldQualifierLoc;
6819 }
6820
6821 auto *D = cast_or_null<UsingShadowDecl>(
6822 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6823 if (!D)
6824 return QualType();
6825 Changed |= D != T->getDecl();
6826
6827 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6828 if (UnderlyingType.isNull())
6829 return QualType();
6830 Changed |= UnderlyingType != T->desugar();
6831
6832 QualType Result = TL.getType();
6833 if (getDerived().AlwaysRebuild() || Changed) {
6834 Result = getDerived().RebuildUsingType(
6835 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6836 UnderlyingType);
6837 if (Result.isNull())
6838 return QualType();
6839 }
6840 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6841 TL.getNameLoc());
6842 return Result;
6843}
6844
6845template<typename Derived>
6847 TypedefTypeLoc TL) {
6848 const TypedefType *T = TL.getTypePtr();
6849 bool Changed = false;
6850
6851 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6852 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6853 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6854 if (!QualifierLoc)
6855 return QualType();
6856 Changed |= QualifierLoc != OldQualifierLoc;
6857 }
6858
6859 auto *Typedef = cast_or_null<TypedefNameDecl>(
6860 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6861 if (!Typedef)
6862 return QualType();
6863 Changed |= Typedef != T->getDecl();
6864
6865 // FIXME: Transform the UnderlyingType if different from decl.
6866
6867 QualType Result = TL.getType();
6868 if (getDerived().AlwaysRebuild() || Changed) {
6869 Result = getDerived().RebuildTypedefType(
6870 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6871 if (Result.isNull())
6872 return QualType();
6873 }
6874
6875 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6876 QualifierLoc, TL.getNameLoc());
6877 return Result;
6878}
6879
6880template<typename Derived>
6882 TypeOfExprTypeLoc TL) {
6883 // typeof expressions are not potentially evaluated contexts
6887
6888 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6889 if (E.isInvalid())
6890 return QualType();
6891
6892 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6893 if (E.isInvalid())
6894 return QualType();
6895
6896 QualType Result = TL.getType();
6898 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6899 Result =
6900 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6901 if (Result.isNull())
6902 return QualType();
6903 }
6904
6905 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6906 NewTL.setTypeofLoc(TL.getTypeofLoc());
6907 NewTL.setLParenLoc(TL.getLParenLoc());
6908 NewTL.setRParenLoc(TL.getRParenLoc());
6909
6910 return Result;
6911}
6912
6913template<typename Derived>
6915 TypeOfTypeLoc TL) {
6916 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6917 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6918 if (!New_Under_TI)
6919 return QualType();
6920
6921 QualType Result = TL.getType();
6922 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6923 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6924 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6925 if (Result.isNull())
6926 return QualType();
6927 }
6928
6929 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6930 NewTL.setTypeofLoc(TL.getTypeofLoc());
6931 NewTL.setLParenLoc(TL.getLParenLoc());
6932 NewTL.setRParenLoc(TL.getRParenLoc());
6933 NewTL.setUnmodifiedTInfo(New_Under_TI);
6934
6935 return Result;
6936}
6937
6938template<typename Derived>
6940 DecltypeTypeLoc TL) {
6941 const DecltypeType *T = TL.getTypePtr();
6942
6943 // decltype expressions are not potentially evaluated contexts
6947
6948 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6949 if (E.isInvalid())
6950 return QualType();
6951
6952 E = getSema().ActOnDecltypeExpression(E.get());
6953 if (E.isInvalid())
6954 return QualType();
6955
6956 QualType Result = TL.getType();
6957 if (getDerived().AlwaysRebuild() ||
6958 E.get() != T->getUnderlyingExpr()) {
6959 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6960 if (Result.isNull())
6961 return QualType();
6962 }
6963 else E.get();
6964
6965 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6966 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6967 NewTL.setRParenLoc(TL.getRParenLoc());
6968 return Result;
6969}
6970
6971template <typename Derived>
6975 // Transform the index
6976 ExprResult IndexExpr;
6977 {
6978 EnterExpressionEvaluationContext ConstantContext(
6980
6981 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6982 if (IndexExpr.isInvalid())
6983 return QualType();
6984 }
6985 QualType Pattern = TL.getPattern();
6986
6987 const PackIndexingType *PIT = TL.getTypePtr();
6988 SmallVector<QualType, 5> SubtitutedTypes;
6989 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6990
6991 bool NotYetExpanded = Types.empty();
6992 bool FullySubstituted = true;
6993
6994 if (Types.empty() && !PIT->expandsToEmptyPack())
6995 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6996
6997 for (QualType T : Types) {
6998 if (!T->containsUnexpandedParameterPack()) {
6999 QualType Transformed = getDerived().TransformType(T);
7000 if (Transformed.isNull())
7001 return QualType();
7002 SubtitutedTypes.push_back(Transformed);
7003 continue;
7004 }
7005
7007 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7008 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7009 // Determine whether the set of unexpanded parameter packs can and should
7010 // be expanded.
7011 bool ShouldExpand = true;
7012 bool RetainExpansion = false;
7013 UnsignedOrNone NumExpansions = std::nullopt;
7014 if (getDerived().TryExpandParameterPacks(
7015 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7016 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7017 RetainExpansion, NumExpansions))
7018 return QualType();
7019 if (!ShouldExpand) {
7020 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7021 // FIXME: should we keep TypeLoc for individual expansions in
7022 // PackIndexingTypeLoc?
7023 TypeSourceInfo *TI =
7024 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7025 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7026 if (Pack.isNull())
7027 return QualType();
7028 if (NotYetExpanded) {
7029 FullySubstituted = false;
7030 QualType Out = getDerived().RebuildPackIndexingType(
7031 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7032 FullySubstituted);
7033 if (Out.isNull())
7034 return QualType();
7035
7037 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7038 return Out;
7039 }
7040 SubtitutedTypes.push_back(Pack);
7041 continue;
7042 }
7043 for (unsigned I = 0; I != *NumExpansions; ++I) {
7044 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7045 QualType Out = getDerived().TransformType(T);
7046 if (Out.isNull())
7047 return QualType();
7048 SubtitutedTypes.push_back(Out);
7049 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7050 }
7051 // If we're supposed to retain a pack expansion, do so by temporarily
7052 // forgetting the partially-substituted parameter pack.
7053 if (RetainExpansion) {
7054 FullySubstituted = false;
7055 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7056 QualType Out = getDerived().TransformType(T);
7057 if (Out.isNull())
7058 return QualType();
7059 SubtitutedTypes.push_back(Out);
7060 }
7061 }
7062
7063 // A pack indexing type can appear in a larger pack expansion,
7064 // e.g. `Pack...[pack_of_indexes]...`
7065 // so we need to temporarily disable substitution of pack elements
7066 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7067 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7068
7069 QualType Out = getDerived().RebuildPackIndexingType(
7070 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7071 FullySubstituted, SubtitutedTypes);
7072 if (Out.isNull())
7073 return Out;
7074
7076 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7077 return Out;
7078}
7079
7080template<typename Derived>
7082 TypeLocBuilder &TLB,
7084 QualType Result = TL.getType();
7085 if (Result->isDependentType()) {
7086 const UnaryTransformType *T = TL.getTypePtr();
7087
7088 TypeSourceInfo *NewBaseTSI =
7089 getDerived().TransformType(TL.getUnderlyingTInfo());
7090 if (!NewBaseTSI)
7091 return QualType();
7092 QualType NewBase = NewBaseTSI->getType();
7093
7094 Result = getDerived().RebuildUnaryTransformType(NewBase,
7095 T->getUTTKind(),
7096 TL.getKWLoc());
7097 if (Result.isNull())
7098 return QualType();
7099 }
7100
7102 NewTL.setKWLoc(TL.getKWLoc());
7103 NewTL.setParensRange(TL.getParensRange());
7104 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
7105 return Result;
7106}
7107
7108template<typename Derived>
7111 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7112
7113 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7114 TemplateName TemplateName = getDerived().TransformTemplateName(
7115 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7116 TL.getTemplateNameLoc());
7117 if (TemplateName.isNull())
7118 return QualType();
7119
7120 QualType OldDeduced = T->getDeducedType();
7121 QualType NewDeduced;
7122 if (!OldDeduced.isNull()) {
7123 NewDeduced = getDerived().TransformType(OldDeduced);
7124 if (NewDeduced.isNull())
7125 return QualType();
7126 }
7127
7128 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7129 T->getKeyword(), TemplateName, NewDeduced);
7130 if (Result.isNull())
7131 return QualType();
7132
7133 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7134 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7135 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7136 NewTL.setQualifierLoc(QualifierLoc);
7137 return Result;
7138}
7139
7140template <typename Derived>
7142 TagTypeLoc TL) {
7143 const TagType *T = TL.getTypePtr();
7144
7145 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7146 if (QualifierLoc) {
7147 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7148 if (!QualifierLoc)
7149 return QualType();
7150 }
7151
7152 auto *TD = cast_or_null<TagDecl>(
7153 getDerived().TransformDecl(TL.getNameLoc(), T->getOriginalDecl()));
7154 if (!TD)
7155 return QualType();
7156
7157 QualType Result = TL.getType();
7158 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7159 TD != T->getOriginalDecl()) {
7160 if (T->isCanonicalUnqualified())
7161 Result = getDerived().RebuildCanonicalTagType(TD);
7162 else
7163 Result = getDerived().RebuildTagType(
7164 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7165 if (Result.isNull())
7166 return QualType();
7167 }
7168
7169 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7171 NewTL.setQualifierLoc(QualifierLoc);
7172 NewTL.setNameLoc(TL.getNameLoc());
7173
7174 return Result;
7175}
7176
7177template <typename Derived>
7179 EnumTypeLoc TL) {
7180 return getDerived().TransformTagType(TLB, TL);
7181}
7182
7183template <typename Derived>
7184QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7185 RecordTypeLoc TL) {
7186 return getDerived().TransformTagType(TLB, TL);
7187}
7188
7189template<typename Derived>
7191 TypeLocBuilder &TLB,
7193 return getDerived().TransformTagType(TLB, TL);
7194}
7195
7196template<typename Derived>
7198 TypeLocBuilder &TLB,
7200 return getDerived().TransformTemplateTypeParmType(
7201 TLB, TL,
7202 /*SuppressObjCLifetime=*/false);
7203}
7204
7205template <typename Derived>
7207 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7208 return TransformTypeSpecType(TLB, TL);
7209}
7210
7211template<typename Derived>
7212QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7213 TypeLocBuilder &TLB,
7214 SubstTemplateTypeParmTypeLoc TL) {
7215 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7216
7217 Decl *NewReplaced =
7218 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7219
7220 // Substitute into the replacement type, which itself might involve something
7221 // that needs to be transformed. This only tends to occur with default
7222 // template arguments of template template parameters.
7223 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7224 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7225 if (Replacement.isNull())
7226 return QualType();
7227
7228 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7229 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7230 T->getFinal());
7231
7232 // Propagate type-source information.
7233 SubstTemplateTypeParmTypeLoc NewTL
7234 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7235 NewTL.setNameLoc(TL.getNameLoc());
7236 return Result;
7237
7238}
7239template <typename Derived>
7242 return TransformTypeSpecType(TLB, TL);
7243}
7244
7245template<typename Derived>
7247 TypeLocBuilder &TLB,
7249 return getDerived().TransformSubstTemplateTypeParmPackType(
7250 TLB, TL, /*SuppressObjCLifetime=*/false);
7251}
7252
7253template <typename Derived>
7256 return TransformTypeSpecType(TLB, TL);
7257}
7258
7259template<typename Derived>
7260QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7261 AtomicTypeLoc TL) {
7262 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7263 if (ValueType.isNull())
7264 return QualType();
7265
7266 QualType Result = TL.getType();
7267 if (getDerived().AlwaysRebuild() ||
7268 ValueType != TL.getValueLoc().getType()) {
7269 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7270 if (Result.isNull())
7271 return QualType();
7272 }
7273
7274 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7275 NewTL.setKWLoc(TL.getKWLoc());
7276 NewTL.setLParenLoc(TL.getLParenLoc());
7277 NewTL.setRParenLoc(TL.getRParenLoc());
7278
7279 return Result;
7280}
7281
7282template <typename Derived>
7284 PipeTypeLoc TL) {
7285 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7286 if (ValueType.isNull())
7287 return QualType();
7288
7289 QualType Result = TL.getType();
7290 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7291 const PipeType *PT = Result->castAs<PipeType>();
7292 bool isReadPipe = PT->isReadOnly();
7293 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7294 if (Result.isNull())
7295 return QualType();
7296 }
7297
7298 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7299 NewTL.setKWLoc(TL.getKWLoc());
7300
7301 return Result;
7302}
7303
7304template <typename Derived>
7306 BitIntTypeLoc TL) {
7307 const BitIntType *EIT = TL.getTypePtr();
7308 QualType Result = TL.getType();
7309
7310 if (getDerived().AlwaysRebuild()) {
7311 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7312 EIT->getNumBits(), TL.getNameLoc());
7313 if (Result.isNull())
7314 return QualType();
7315 }
7316
7317 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7318 NewTL.setNameLoc(TL.getNameLoc());
7319 return Result;
7320}
7321
7322template <typename Derived>
7325 const DependentBitIntType *EIT = TL.getTypePtr();
7326
7329 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7330 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7331
7332 if (BitsExpr.isInvalid())
7333 return QualType();
7334
7335 QualType Result = TL.getType();
7336
7337 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7338 Result = getDerived().RebuildDependentBitIntType(
7339 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7340
7341 if (Result.isNull())
7342 return QualType();
7343 }
7344
7347 NewTL.setNameLoc(TL.getNameLoc());
7348 } else {
7349 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7350 NewTL.setNameLoc(TL.getNameLoc());
7351 }
7352 return Result;
7353}
7354
7355template <typename Derived>
7358 llvm_unreachable("This type does not need to be transformed.");
7359}
7360
7361 /// Simple iterator that traverses the template arguments in a
7362 /// container that provides a \c getArgLoc() member function.
7363 ///
7364 /// This iterator is intended to be used with the iterator form of
7365 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7366 template<typename ArgLocContainer>
7368 ArgLocContainer *Container;
7369 unsigned Index;
7370
7371 public:
7374 typedef int difference_type;
7375 typedef std::input_iterator_tag iterator_category;
7376
7377 class pointer {
7379
7380 public:
7381 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7382
7384 return &Arg;
7385 }
7386 };
7387
7388
7390
7391 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7392 unsigned Index)
7393 : Container(&Container), Index(Index) { }
7394
7396 ++Index;
7397 return *this;
7398 }
7399
7402 ++(*this);
7403 return Old;
7404 }
7405
7407 return Container->getArgLoc(Index);
7408 }
7409
7411 return pointer(Container->getArgLoc(Index));
7412 }
7413
7416 return X.Container == Y.Container && X.Index == Y.Index;
7417 }
7418
7421 return !(X == Y);
7422 }
7423 };
7424
7425template<typename Derived>
7426QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7427 AutoTypeLoc TL) {
7428 const AutoType *T = TL.getTypePtr();
7429 QualType OldDeduced = T->getDeducedType();
7430 QualType NewDeduced;
7431 if (!OldDeduced.isNull()) {
7432 NewDeduced = getDerived().TransformType(OldDeduced);
7433 if (NewDeduced.isNull())
7434 return QualType();
7435 }
7436
7437 ConceptDecl *NewCD = nullptr;
7438 TemplateArgumentListInfo NewTemplateArgs;
7439 NestedNameSpecifierLoc NewNestedNameSpec;
7440 if (T->isConstrained()) {
7441 assert(TL.getConceptReference());
7442 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7443 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7444
7445 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7446 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7448 if (getDerived().TransformTemplateArguments(
7449 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7450 NewTemplateArgs))
7451 return QualType();
7452
7453 if (TL.getNestedNameSpecifierLoc()) {
7454 NewNestedNameSpec
7455 = getDerived().TransformNestedNameSpecifierLoc(
7456 TL.getNestedNameSpecifierLoc());
7457 if (!NewNestedNameSpec)
7458 return QualType();
7459 }
7460 }
7461
7462 QualType Result = TL.getType();
7463 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7464 T->isDependentType() || T->isConstrained()) {
7465 // FIXME: Maybe don't rebuild if all template arguments are the same.
7467 NewArgList.reserve(NewTemplateArgs.size());
7468 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7469 NewArgList.push_back(ArgLoc.getArgument());
7470 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7471 NewArgList);
7472 if (Result.isNull())
7473 return QualType();
7474 }
7475
7476 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7477 NewTL.setNameLoc(TL.getNameLoc());
7478 NewTL.setRParenLoc(TL.getRParenLoc());
7479 NewTL.setConceptReference(nullptr);
7480
7481 if (T->isConstrained()) {
7483 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7484 TL.getConceptNameLoc(),
7485 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7486 auto *CR = ConceptReference::Create(
7487 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7488 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7489 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7490 NewTL.setConceptReference(CR);
7491 }
7492
7493 return Result;
7494}
7495
7496template <typename Derived>
7499 return getDerived().TransformTemplateSpecializationType(
7500 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7501 /*AllowInjectedClassName=*/false);
7502}
7503
7504template <typename Derived>
7507 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7508 const TemplateSpecializationType *T = TL.getTypePtr();
7509
7510 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7511 TemplateName Template = getDerived().TransformTemplateName(
7512 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7513 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7514 AllowInjectedClassName);
7515 if (Template.isNull())
7516 return QualType();
7517
7518 TemplateArgumentListInfo NewTemplateArgs;
7519 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7520 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7522 ArgIterator;
7523 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7524 ArgIterator(TL, TL.getNumArgs()),
7525 NewTemplateArgs))
7526 return QualType();
7527
7528 // This needs to be rebuilt if either the arguments changed, or if the
7529 // original template changed. If the template changed, and even if the
7530 // arguments didn't change, these arguments might not correspond to their
7531 // respective parameters, therefore needing conversions.
7532 QualType Result = getDerived().RebuildTemplateSpecializationType(
7533 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7534 NewTemplateArgs);
7535
7536 if (!Result.isNull()) {
7538 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7539 TL.getTemplateNameLoc(), NewTemplateArgs);
7540 }
7541
7542 return Result;
7543}
7544
7545template <typename Derived>
7547 AttributedTypeLoc TL) {
7548 const AttributedType *oldType = TL.getTypePtr();
7549 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7550 if (modifiedType.isNull())
7551 return QualType();
7552
7553 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7554 const Attr *oldAttr = TL.getAttr();
7555 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7556 if (oldAttr && !newAttr)
7557 return QualType();
7558
7559 QualType result = TL.getType();
7560
7561 // FIXME: dependent operand expressions?
7562 if (getDerived().AlwaysRebuild() ||
7563 modifiedType != oldType->getModifiedType()) {
7564 // If the equivalent type is equal to the modified type, we don't want to
7565 // transform it as well because:
7566 //
7567 // 1. The transformation would yield the same result and is therefore
7568 // superfluous, and
7569 //
7570 // 2. Transforming the same type twice can cause problems, e.g. if it
7571 // is a FunctionProtoType, we may end up instantiating the function
7572 // parameters twice, which causes an assertion since the parameters
7573 // are already bound to their counterparts in the template for this
7574 // instantiation.
7575 //
7576 QualType equivalentType = modifiedType;
7577 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7578 TypeLocBuilder AuxiliaryTLB;
7579 AuxiliaryTLB.reserve(TL.getFullDataSize());
7580 equivalentType =
7581 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7582 if (equivalentType.isNull())
7583 return QualType();
7584 }
7585
7586 // Check whether we can add nullability; it is only represented as
7587 // type sugar, and therefore cannot be diagnosed in any other way.
7588 if (auto nullability = oldType->getImmediateNullability()) {
7589 if (!modifiedType->canHaveNullability()) {
7590 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7591 : TL.getModifiedLoc().getBeginLoc()),
7592 diag::err_nullability_nonpointer)
7593 << DiagNullabilityKind(*nullability, false) << modifiedType;
7594 return QualType();
7595 }
7596 }
7597
7598 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7599 modifiedType,
7600 equivalentType,
7601 TL.getAttr());
7602 }
7603
7604 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7605 newTL.setAttr(newAttr);
7606 return result;
7607}
7608
7609template <typename Derived>
7612 const CountAttributedType *OldTy = TL.getTypePtr();
7613 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7614 if (InnerTy.isNull())
7615 return QualType();
7616
7617 Expr *OldCount = TL.getCountExpr();
7618 Expr *NewCount = nullptr;
7619 if (OldCount) {
7620 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7621 if (CountResult.isInvalid())
7622 return QualType();
7623 NewCount = CountResult.get();
7624 }
7625
7626 QualType Result = TL.getType();
7627 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7628 OldCount != NewCount) {
7629 // Currently, CountAttributedType can only wrap incomplete array types.
7631 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7632 }
7633
7634 TLB.push<CountAttributedTypeLoc>(Result);
7635 return Result;
7636}
7637
7638template <typename Derived>
7641 // The BTFTagAttributedType is available for C only.
7642 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7643}
7644
7645template <typename Derived>
7648
7649 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7650
7651 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7652 if (WrappedTy.isNull())
7653 return QualType();
7654
7655 QualType ContainedTy = QualType();
7656 QualType OldContainedTy = oldType->getContainedType();
7657 if (!OldContainedTy.isNull()) {
7658 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7659 if (!oldContainedTSI)
7660 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7661 OldContainedTy, SourceLocation());
7662 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7663 if (!ContainedTSI)
7664 return QualType();
7665 ContainedTy = ContainedTSI->getType();
7666 }
7667
7668 QualType Result = TL.getType();
7669 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7670 ContainedTy != oldType->getContainedType()) {
7672 WrappedTy, ContainedTy, oldType->getAttrs());
7673 }
7674
7676 return Result;
7677}
7678
7679template <typename Derived>
7682 // No transformations needed.
7683 return TL.getType();
7684}
7685
7686template<typename Derived>
7689 ParenTypeLoc TL) {
7690 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7691 if (Inner.isNull())
7692 return QualType();
7693
7694 QualType Result = TL.getType();
7695 if (getDerived().AlwaysRebuild() ||
7696 Inner != TL.getInnerLoc().getType()) {
7697 Result = getDerived().RebuildParenType(Inner);
7698 if (Result.isNull())
7699 return QualType();
7700 }
7701
7702 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7703 NewTL.setLParenLoc(TL.getLParenLoc());
7704 NewTL.setRParenLoc(TL.getRParenLoc());
7705 return Result;
7706}
7707
7708template <typename Derived>
7712 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7713 if (Inner.isNull())
7714 return QualType();
7715
7716 QualType Result = TL.getType();
7717 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7718 Result =
7719 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7720 if (Result.isNull())
7721 return QualType();
7722 }
7723
7725 NewTL.setExpansionLoc(TL.getExpansionLoc());
7726 return Result;
7727}
7728
7729template<typename Derived>
7730QualType TreeTransform<Derived>::TransformDependentNameType(
7732 return TransformDependentNameType(TLB, TL, false);
7733}
7734
7735template <typename Derived>
7736QualType TreeTransform<Derived>::TransformDependentNameType(
7737 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7738 QualType ObjectType, NamedDecl *UnqualLookup) {
7739 const DependentNameType *T = TL.getTypePtr();
7740
7741 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7742 if (QualifierLoc) {
7743 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7744 QualifierLoc, ObjectType, UnqualLookup);
7745 if (!QualifierLoc)
7746 return QualType();
7747 } else {
7748 assert((ObjectType.isNull() && !UnqualLookup) &&
7749 "must be transformed by TransformNestedNameSpecifierLoc");
7750 }
7751
7753 = getDerived().RebuildDependentNameType(T->getKeyword(),
7754 TL.getElaboratedKeywordLoc(),
7755 QualifierLoc,
7756 T->getIdentifier(),
7757 TL.getNameLoc(),
7758 DeducedTSTContext);
7759 if (Result.isNull())
7760 return QualType();
7761
7762 if (isa<TagType>(Result)) {
7763 auto NewTL = TLB.push<TagTypeLoc>(Result);
7764 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7765 NewTL.setQualifierLoc(QualifierLoc);
7766 NewTL.setNameLoc(TL.getNameLoc());
7768 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7769 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7770 NewTL.setTemplateNameLoc(TL.getNameLoc());
7771 NewTL.setQualifierLoc(QualifierLoc);
7772 } else if (isa<TypedefType>(Result)) {
7773 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7774 QualifierLoc, TL.getNameLoc());
7775 } else if (isa<UnresolvedUsingType>(Result)) {
7776 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7777 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7778 } else {
7779 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7780 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7781 NewTL.setQualifierLoc(QualifierLoc);
7782 NewTL.setNameLoc(TL.getNameLoc());
7783 }
7784 return Result;
7785}
7786
7787template<typename Derived>
7790 QualType Pattern
7791 = getDerived().TransformType(TLB, TL.getPatternLoc());
7792 if (Pattern.isNull())
7793 return QualType();
7794
7795 QualType Result = TL.getType();
7796 if (getDerived().AlwaysRebuild() ||
7797 Pattern != TL.getPatternLoc().getType()) {
7798 Result = getDerived().RebuildPackExpansionType(Pattern,
7799 TL.getPatternLoc().getSourceRange(),
7800 TL.getEllipsisLoc(),
7801 TL.getTypePtr()->getNumExpansions());
7802 if (Result.isNull())
7803 return QualType();
7804 }
7805
7807 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7808 return Result;
7809}
7810
7811template<typename Derived>
7815 // ObjCInterfaceType is never dependent.
7816 TLB.pushFullCopy(TL);
7817 return TL.getType();
7818}
7819
7820template<typename Derived>
7824 const ObjCTypeParamType *T = TL.getTypePtr();
7825 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7826 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7827 if (!OTP)
7828 return QualType();
7829
7830 QualType Result = TL.getType();
7831 if (getDerived().AlwaysRebuild() ||
7832 OTP != T->getDecl()) {
7833 Result = getDerived().RebuildObjCTypeParamType(
7834 OTP, TL.getProtocolLAngleLoc(),
7835 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7836 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7837 if (Result.isNull())
7838 return QualType();
7839 }
7840
7842 if (TL.getNumProtocols()) {
7843 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7844 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7845 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7846 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7847 }
7848 return Result;
7849}
7850
7851template<typename Derived>
7854 ObjCObjectTypeLoc TL) {
7855 // Transform base type.
7856 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7857 if (BaseType.isNull())
7858 return QualType();
7859
7860 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7861
7862 // Transform type arguments.
7863 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7864 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7865 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7866 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7867 QualType TypeArg = TypeArgInfo->getType();
7868 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7869 AnyChanged = true;
7870
7871 // We have a pack expansion. Instantiate it.
7872 const auto *PackExpansion = PackExpansionLoc.getType()
7873 ->castAs<PackExpansionType>();
7875 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7876 Unexpanded);
7877 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7878
7879 // Determine whether the set of unexpanded parameter packs can
7880 // and should be expanded.
7881 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7882 bool Expand = false;
7883 bool RetainExpansion = false;
7884 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7885 if (getDerived().TryExpandParameterPacks(
7886 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7887 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
7888 RetainExpansion, NumExpansions))
7889 return QualType();
7890
7891 if (!Expand) {
7892 // We can't expand this pack expansion into separate arguments yet;
7893 // just substitute into the pattern and create a new pack expansion
7894 // type.
7895 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7896
7897 TypeLocBuilder TypeArgBuilder;
7898 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7899 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7900 PatternLoc);
7901 if (NewPatternType.isNull())
7902 return QualType();
7903
7904 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7905 NewPatternType, NumExpansions);
7906 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7907 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7908 NewTypeArgInfos.push_back(
7909 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7910 continue;
7911 }
7912
7913 // Substitute into the pack expansion pattern for each slice of the
7914 // pack.
7915 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7916 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
7917
7918 TypeLocBuilder TypeArgBuilder;
7919 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7920
7921 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7922 PatternLoc);
7923 if (NewTypeArg.isNull())
7924 return QualType();
7925
7926 NewTypeArgInfos.push_back(
7927 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7928 }
7929
7930 continue;
7931 }
7932
7933 TypeLocBuilder TypeArgBuilder;
7934 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7935 QualType NewTypeArg =
7936 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7937 if (NewTypeArg.isNull())
7938 return QualType();
7939
7940 // If nothing changed, just keep the old TypeSourceInfo.
7941 if (NewTypeArg == TypeArg) {
7942 NewTypeArgInfos.push_back(TypeArgInfo);
7943 continue;
7944 }
7945
7946 NewTypeArgInfos.push_back(
7947 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7948 AnyChanged = true;
7949 }
7950
7951 QualType Result = TL.getType();
7952 if (getDerived().AlwaysRebuild() || AnyChanged) {
7953 // Rebuild the type.
7954 Result = getDerived().RebuildObjCObjectType(
7955 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7956 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7957 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7958 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7959
7960 if (Result.isNull())
7961 return QualType();
7962 }
7963
7964 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7965 NewT.setHasBaseTypeAsWritten(true);
7966 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7967 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7968 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7969 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7970 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7971 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7972 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7973 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7974 return Result;
7975}
7976
7977template<typename Derived>
7981 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7982 if (PointeeType.isNull())
7983 return QualType();
7984
7985 QualType Result = TL.getType();
7986 if (getDerived().AlwaysRebuild() ||
7987 PointeeType != TL.getPointeeLoc().getType()) {
7988 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7989 TL.getStarLoc());
7990 if (Result.isNull())
7991 return QualType();
7992 }
7993
7995 NewT.setStarLoc(TL.getStarLoc());
7996 return Result;
7997}
7998
7999//===----------------------------------------------------------------------===//
8000// Statement transformation
8001//===----------------------------------------------------------------------===//
8002template<typename Derived>
8005 return S;
8006}
8007
8008template<typename Derived>
8011 return getDerived().TransformCompoundStmt(S, false);
8012}
8013
8014template<typename Derived>
8017 bool IsStmtExpr) {
8018 Sema::CompoundScopeRAII CompoundScope(getSema());
8019 Sema::FPFeaturesStateRAII FPSave(getSema());
8020 if (S->hasStoredFPFeatures())
8021 getSema().resetFPOptions(
8022 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8023
8024 const Stmt *ExprResult = S->getStmtExprResult();
8025 bool SubStmtInvalid = false;
8026 bool SubStmtChanged = false;
8027 SmallVector<Stmt*, 8> Statements;
8028 for (auto *B : S->body()) {
8029 StmtResult Result = getDerived().TransformStmt(
8030 B, IsStmtExpr && B == ExprResult ? StmtDiscardKind::StmtExprResult
8031 : StmtDiscardKind::Discarded);
8032
8033 if (Result.isInvalid()) {
8034 // Immediately fail if this was a DeclStmt, since it's very
8035 // likely that this will cause problems for future statements.
8036 if (isa<DeclStmt>(B))
8037 return StmtError();
8038
8039 // Otherwise, just keep processing substatements and fail later.
8040 SubStmtInvalid = true;
8041 continue;
8042 }
8043
8044 SubStmtChanged = SubStmtChanged || Result.get() != B;
8045 Statements.push_back(Result.getAs<Stmt>());
8046 }
8047
8048 if (SubStmtInvalid)
8049 return StmtError();
8050
8051 if (!getDerived().AlwaysRebuild() &&
8052 !SubStmtChanged)
8053 return S;
8054
8055 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8056 Statements,
8057 S->getRBracLoc(),
8058 IsStmtExpr);
8059}
8060
8061template<typename Derived>
8064 ExprResult LHS, RHS;
8065 {
8068
8069 // Transform the left-hand case value.
8070 LHS = getDerived().TransformExpr(S->getLHS());
8071 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8072 if (LHS.isInvalid())
8073 return StmtError();
8074
8075 // Transform the right-hand case value (for the GNU case-range extension).
8076 RHS = getDerived().TransformExpr(S->getRHS());
8077 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8078 if (RHS.isInvalid())
8079 return StmtError();
8080 }
8081
8082 // Build the case statement.
8083 // Case statements are always rebuilt so that they will attached to their
8084 // transformed switch statement.
8085 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8086 LHS.get(),
8087 S->getEllipsisLoc(),
8088 RHS.get(),
8089 S->getColonLoc());
8090 if (Case.isInvalid())
8091 return StmtError();
8092
8093 // Transform the statement following the case
8094 StmtResult SubStmt =
8095 getDerived().TransformStmt(S->getSubStmt());
8096 if (SubStmt.isInvalid())
8097 return StmtError();
8098
8099 // Attach the body to the case statement
8100 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8101}
8102
8103template <typename Derived>
8105 // Transform the statement following the default case
8106 StmtResult SubStmt =
8107 getDerived().TransformStmt(S->getSubStmt());
8108 if (SubStmt.isInvalid())
8109 return StmtError();
8110
8111 // Default statements are always rebuilt
8112 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8113 SubStmt.get());
8114}
8115
8116template<typename Derived>
8119 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8120 if (SubStmt.isInvalid())
8121 return StmtError();
8122
8123 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8124 S->getDecl());
8125 if (!LD)
8126 return StmtError();
8127
8128 // If we're transforming "in-place" (we're not creating new local
8129 // declarations), assume we're replacing the old label statement
8130 // and clear out the reference to it.
8131 if (LD == S->getDecl())
8132 S->getDecl()->setStmt(nullptr);
8133
8134 // FIXME: Pass the real colon location in.
8135 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8137 SubStmt.get());
8138}
8139
8140template <typename Derived>
8142 if (!R)
8143 return R;
8144
8145 switch (R->getKind()) {
8146// Transform attributes by calling TransformXXXAttr.
8147#define ATTR(X) \
8148 case attr::X: \
8149 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8150#include "clang/Basic/AttrList.inc"
8151 }
8152 return R;
8153}
8154
8155template <typename Derived>
8157 const Stmt *InstS,
8158 const Attr *R) {
8159 if (!R)
8160 return R;
8161
8162 switch (R->getKind()) {
8163// Transform attributes by calling TransformStmtXXXAttr.
8164#define ATTR(X) \
8165 case attr::X: \
8166 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8167#include "clang/Basic/AttrList.inc"
8168 }
8169 return TransformAttr(R);
8170}
8171
8172template <typename Derived>
8175 StmtDiscardKind SDK) {
8176 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8177 if (SubStmt.isInvalid())
8178 return StmtError();
8179
8180 bool AttrsChanged = false;
8182
8183 // Visit attributes and keep track if any are transformed.
8184 for (const auto *I : S->getAttrs()) {
8185 const Attr *R =
8186 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8187 AttrsChanged |= (I != R);
8188 if (R)
8189 Attrs.push_back(R);
8190 }
8191
8192 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8193 return S;
8194
8195 // If transforming the attributes failed for all of the attributes in the
8196 // statement, don't make an AttributedStmt without attributes.
8197 if (Attrs.empty())
8198 return SubStmt;
8199
8200 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8201 SubStmt.get());
8202}
8203
8204template<typename Derived>
8207 // Transform the initialization statement
8208 StmtResult Init = getDerived().TransformStmt(S->getInit());
8209 if (Init.isInvalid())
8210 return StmtError();
8211
8213 if (!S->isConsteval()) {
8214 // Transform the condition
8215 Cond = getDerived().TransformCondition(
8216 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8217 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8219 if (Cond.isInvalid())
8220 return StmtError();
8221 }
8222
8223 // If this is a constexpr if, determine which arm we should instantiate.
8224 std::optional<bool> ConstexprConditionValue;
8225 if (S->isConstexpr())
8226 ConstexprConditionValue = Cond.getKnownValue();
8227
8228 // Transform the "then" branch.
8229 StmtResult Then;
8230 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8234 S->isNonNegatedConsteval());
8235
8236 Then = getDerived().TransformStmt(S->getThen());
8237 if (Then.isInvalid())
8238 return StmtError();
8239 } else {
8240 // Discarded branch is replaced with empty CompoundStmt so we can keep
8241 // proper source location for start and end of original branch, so
8242 // subsequent transformations like CoverageMapping work properly
8243 Then = new (getSema().Context)
8244 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8245 }
8246
8247 // Transform the "else" branch.
8248 StmtResult Else;
8249 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8253 S->isNegatedConsteval());
8254
8255 Else = getDerived().TransformStmt(S->getElse());
8256 if (Else.isInvalid())
8257 return StmtError();
8258 } else if (S->getElse() && ConstexprConditionValue &&
8259 *ConstexprConditionValue) {
8260 // Same thing here as with <then> branch, we are discarding it, we can't
8261 // replace it with NULL nor NullStmt as we need to keep for source location
8262 // range, for CoverageMapping
8263 Else = new (getSema().Context)
8264 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8265 }
8266
8267 if (!getDerived().AlwaysRebuild() &&
8268 Init.get() == S->getInit() &&
8269 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8270 Then.get() == S->getThen() &&
8271 Else.get() == S->getElse())
8272 return S;
8273
8274 return getDerived().RebuildIfStmt(
8275 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8276 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8277}
8278
8279template<typename Derived>
8282 // Transform the initialization statement
8283 StmtResult Init = getDerived().TransformStmt(S->getInit());
8284 if (Init.isInvalid())
8285 return StmtError();
8286
8287 // Transform the condition.
8288 Sema::ConditionResult Cond = getDerived().TransformCondition(
8289 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8291 if (Cond.isInvalid())
8292 return StmtError();
8293
8294 // Rebuild the switch statement.
8296 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8297 Init.get(), Cond, S->getRParenLoc());
8298 if (Switch.isInvalid())
8299 return StmtError();
8300
8301 // Transform the body of the switch statement.
8302 StmtResult Body = getDerived().TransformStmt(S->getBody());
8303 if (Body.isInvalid())
8304 return StmtError();
8305
8306 // Complete the switch statement.
8307 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8308 Body.get());
8309}
8310
8311template<typename Derived>
8314 // Transform the condition
8315 Sema::ConditionResult Cond = getDerived().TransformCondition(
8316 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8318 if (Cond.isInvalid())
8319 return StmtError();
8320
8321 // OpenACC Restricts a while-loop inside of certain construct/clause
8322 // combinations, so diagnose that here in OpenACC mode.
8324 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8325
8326 // Transform the body
8327 StmtResult Body = getDerived().TransformStmt(S->getBody());
8328 if (Body.isInvalid())
8329 return StmtError();
8330
8331 if (!getDerived().AlwaysRebuild() &&
8332 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8333 Body.get() == S->getBody())
8334 return Owned(S);
8335
8336 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8337 Cond, S->getRParenLoc(), Body.get());
8338}
8339
8340template<typename Derived>
8343 // OpenACC Restricts a do-loop inside of certain construct/clause
8344 // combinations, so diagnose that here in OpenACC mode.
8346 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8347
8348 // Transform the body
8349 StmtResult Body = getDerived().TransformStmt(S->getBody());
8350 if (Body.isInvalid())
8351 return StmtError();
8352
8353 // Transform the condition
8354 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8355 if (Cond.isInvalid())
8356 return StmtError();
8357
8358 if (!getDerived().AlwaysRebuild() &&
8359 Cond.get() == S->getCond() &&
8360 Body.get() == S->getBody())
8361 return S;
8362
8363 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8364 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8365 S->getRParenLoc());
8366}
8367
8368template<typename Derived>
8371 if (getSema().getLangOpts().OpenMP)
8372 getSema().OpenMP().startOpenMPLoop();
8373
8374 // Transform the initialization statement
8375 StmtResult Init = getDerived().TransformStmt(S->getInit());
8376 if (Init.isInvalid())
8377 return StmtError();
8378
8379 // In OpenMP loop region loop control variable must be captured and be
8380 // private. Perform analysis of first part (if any).
8381 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8382 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8383 Init.get());
8384
8385 // Transform the condition
8386 Sema::ConditionResult Cond = getDerived().TransformCondition(
8387 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8389 if (Cond.isInvalid())
8390 return StmtError();
8391
8392 // Transform the increment
8393 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8394 if (Inc.isInvalid())
8395 return StmtError();
8396
8397 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8398 if (S->getInc() && !FullInc.get())
8399 return StmtError();
8400
8401 // OpenACC Restricts a for-loop inside of certain construct/clause
8402 // combinations, so diagnose that here in OpenACC mode.
8404 SemaRef.OpenACC().ActOnForStmtBegin(
8405 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8406 Cond.get().second, S->getInc(), Inc.get());
8407
8408 // Transform the body
8409 StmtResult Body = getDerived().TransformStmt(S->getBody());
8410 if (Body.isInvalid())
8411 return StmtError();
8412
8413 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8414
8415 if (!getDerived().AlwaysRebuild() &&
8416 Init.get() == S->getInit() &&
8417 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8418 Inc.get() == S->getInc() &&
8419 Body.get() == S->getBody())
8420 return S;
8421
8422 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8423 Init.get(), Cond, FullInc,
8424 S->getRParenLoc(), Body.get());
8425}
8426
8427template<typename Derived>
8430 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8431 S->getLabel());
8432 if (!LD)
8433 return StmtError();
8434
8435 // Goto statements must always be rebuilt, to resolve the label.
8436 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8437 cast<LabelDecl>(LD));
8438}
8439
8440template<typename Derived>
8443 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8444 if (Target.isInvalid())
8445 return StmtError();
8446 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8447
8448 if (!getDerived().AlwaysRebuild() &&
8449 Target.get() == S->getTarget())
8450 return S;
8451
8452 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8453 Target.get());
8454}
8455
8456template<typename Derived>
8459 if (!S->hasLabelTarget())
8460 return S;
8461
8462 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8463 S->getLabelDecl());
8464 if (!LD)
8465 return StmtError();
8466
8467 return new (SemaRef.Context)
8468 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8469}
8470
8471template<typename Derived>
8474 if (!S->hasLabelTarget())
8475 return S;
8476
8477 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8478 S->getLabelDecl());
8479 if (!LD)
8480 return StmtError();
8481
8482 return new (SemaRef.Context)
8483 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8484}
8485
8486template<typename Derived>
8489 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8490 /*NotCopyInit*/false);
8491 if (Result.isInvalid())
8492 return StmtError();
8493
8494 // FIXME: We always rebuild the return statement because there is no way
8495 // to tell whether the return type of the function has changed.
8496 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8497}
8498
8499template<typename Derived>
8502 bool DeclChanged = false;
8504 LambdaScopeInfo *LSI = getSema().getCurLambda();
8505 for (auto *D : S->decls()) {
8506 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8507 if (!Transformed)
8508 return StmtError();
8509
8510 if (Transformed != D)
8511 DeclChanged = true;
8512
8513 if (LSI) {
8514 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8515 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8516 LSI->ContainsUnexpandedParameterPack |=
8517 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8518 } else {
8519 LSI->ContainsUnexpandedParameterPack |=
8520 getSema()
8521 .getASTContext()
8522 .getTypeDeclType(TD)
8523 ->containsUnexpandedParameterPack();
8524 }
8525 }
8526 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8527 LSI->ContainsUnexpandedParameterPack |=
8528 VD->getType()->containsUnexpandedParameterPack();
8529 }
8530
8531 Decls.push_back(Transformed);
8532 }
8533
8534 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8535 return S;
8536
8537 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8538}
8539
8540template<typename Derived>
8543
8544 SmallVector<Expr*, 8> Constraints;
8547
8548 SmallVector<Expr*, 8> Clobbers;
8549
8550 bool ExprsChanged = false;
8551
8552 auto RebuildString = [&](Expr *E) {
8553 ExprResult Result = getDerived().TransformExpr(E);
8554 if (!Result.isUsable())
8555 return Result;
8556 if (Result.get() != E) {
8557 ExprsChanged = true;
8558 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8559 }
8560 return Result;
8561 };
8562
8563 // Go through the outputs.
8564 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8565 Names.push_back(S->getOutputIdentifier(I));
8566
8567 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8568 if (Result.isInvalid())
8569 return StmtError();
8570
8571 Constraints.push_back(Result.get());
8572
8573 // Transform the output expr.
8574 Expr *OutputExpr = S->getOutputExpr(I);
8575 Result = getDerived().TransformExpr(OutputExpr);
8576 if (Result.isInvalid())
8577 return StmtError();
8578
8579 ExprsChanged |= Result.get() != OutputExpr;
8580
8581 Exprs.push_back(Result.get());
8582 }
8583
8584 // Go through the inputs.
8585 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8586 Names.push_back(S->getInputIdentifier(I));
8587
8588 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8589 if (Result.isInvalid())
8590 return StmtError();
8591
8592 Constraints.push_back(Result.get());
8593
8594 // Transform the input expr.
8595 Expr *InputExpr = S->getInputExpr(I);
8596 Result = getDerived().TransformExpr(InputExpr);
8597 if (Result.isInvalid())
8598 return StmtError();
8599
8600 ExprsChanged |= Result.get() != InputExpr;
8601
8602 Exprs.push_back(Result.get());
8603 }
8604
8605 // Go through the Labels.
8606 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8607 Names.push_back(S->getLabelIdentifier(I));
8608
8609 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8610 if (Result.isInvalid())
8611 return StmtError();
8612 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8613 Exprs.push_back(Result.get());
8614 }
8615
8616 // Go through the clobbers.
8617 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8618 ExprResult Result = RebuildString(S->getClobberExpr(I));
8619 if (Result.isInvalid())
8620 return StmtError();
8621 Clobbers.push_back(Result.get());
8622 }
8623
8624 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8625 if (AsmString.isInvalid())
8626 return StmtError();
8627
8628 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8629 return S;
8630
8631 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8632 S->isVolatile(), S->getNumOutputs(),
8633 S->getNumInputs(), Names.data(),
8634 Constraints, Exprs, AsmString.get(),
8635 Clobbers, S->getNumLabels(),
8636 S->getRParenLoc());
8637}
8638
8639template<typename Derived>
8642 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8643
8644 bool HadError = false, HadChange = false;
8645
8646 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8647 SmallVector<Expr*, 8> TransformedExprs;
8648 TransformedExprs.reserve(SrcExprs.size());
8649 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8650 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8651 if (!Result.isUsable()) {
8652 HadError = true;
8653 } else {
8654 HadChange |= (Result.get() != SrcExprs[i]);
8655 TransformedExprs.push_back(Result.get());
8656 }
8657 }
8658
8659 if (HadError) return StmtError();
8660 if (!HadChange && !getDerived().AlwaysRebuild())
8661 return Owned(S);
8662
8663 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8664 AsmToks, S->getAsmString(),
8665 S->getNumOutputs(), S->getNumInputs(),
8666 S->getAllConstraints(), S->getClobbers(),
8667 TransformedExprs, S->getEndLoc());
8668}
8669
8670// C++ Coroutines
8671template<typename Derived>
8674 auto *ScopeInfo = SemaRef.getCurFunction();
8675 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8676 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8677 ScopeInfo->NeedsCoroutineSuspends &&
8678 ScopeInfo->CoroutineSuspends.first == nullptr &&
8679 ScopeInfo->CoroutineSuspends.second == nullptr &&
8680 "expected clean scope info");
8681
8682 // Set that we have (possibly-invalid) suspend points before we do anything
8683 // that may fail.
8684 ScopeInfo->setNeedsCoroutineSuspends(false);
8685
8686 // We re-build the coroutine promise object (and the coroutine parameters its
8687 // type and constructor depend on) based on the types used in our current
8688 // function. We must do so, and set it on the current FunctionScopeInfo,
8689 // before attempting to transform the other parts of the coroutine body
8690 // statement, such as the implicit suspend statements (because those
8691 // statements reference the FunctionScopeInfo::CoroutinePromise).
8692 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8693 return StmtError();
8694 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8695 if (!Promise)
8696 return StmtError();
8697 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8698 ScopeInfo->CoroutinePromise = Promise;
8699
8700 // Transform the implicit coroutine statements constructed using dependent
8701 // types during the previous parse: initial and final suspensions, the return
8702 // object, and others. We also transform the coroutine function's body.
8703 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8704 if (InitSuspend.isInvalid())
8705 return StmtError();
8706 StmtResult FinalSuspend =
8707 getDerived().TransformStmt(S->getFinalSuspendStmt());
8708 if (FinalSuspend.isInvalid() ||
8709 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8710 return StmtError();
8711 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8712 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8713
8714 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8715 if (BodyRes.isInvalid())
8716 return StmtError();
8717
8718 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8719 if (Builder.isInvalid())
8720 return StmtError();
8721
8722 Expr *ReturnObject = S->getReturnValueInit();
8723 assert(ReturnObject && "the return object is expected to be valid");
8724 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8725 /*NoCopyInit*/ false);
8726 if (Res.isInvalid())
8727 return StmtError();
8728 Builder.ReturnValue = Res.get();
8729
8730 // If during the previous parse the coroutine still had a dependent promise
8731 // statement, we may need to build some implicit coroutine statements
8732 // (such as exception and fallthrough handlers) for the first time.
8733 if (S->hasDependentPromiseType()) {
8734 // We can only build these statements, however, if the current promise type
8735 // is not dependent.
8736 if (!Promise->getType()->isDependentType()) {
8737 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8738 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8739 "these nodes should not have been built yet");
8740 if (!Builder.buildDependentStatements())
8741 return StmtError();
8742 }
8743 } else {
8744 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8745 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8746 if (Res.isInvalid())
8747 return StmtError();
8748 Builder.OnFallthrough = Res.get();
8749 }
8750
8751 if (auto *OnException = S->getExceptionHandler()) {
8752 StmtResult Res = getDerived().TransformStmt(OnException);
8753 if (Res.isInvalid())
8754 return StmtError();
8755 Builder.OnException = Res.get();
8756 }
8757
8758 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8759 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8760 if (Res.isInvalid())
8761 return StmtError();
8762 Builder.ReturnStmtOnAllocFailure = Res.get();
8763 }
8764
8765 // Transform any additional statements we may have already built
8766 assert(S->getAllocate() && S->getDeallocate() &&
8767 "allocation and deallocation calls must already be built");
8768 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8769 if (AllocRes.isInvalid())
8770 return StmtError();
8771 Builder.Allocate = AllocRes.get();
8772
8773 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8774 if (DeallocRes.isInvalid())
8775 return StmtError();
8776 Builder.Deallocate = DeallocRes.get();
8777
8778 if (auto *ResultDecl = S->getResultDecl()) {
8779 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8780 if (Res.isInvalid())
8781 return StmtError();
8782 Builder.ResultDecl = Res.get();
8783 }
8784
8785 if (auto *ReturnStmt = S->getReturnStmt()) {
8786 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8787 if (Res.isInvalid())
8788 return StmtError();
8789 Builder.ReturnStmt = Res.get();
8790 }
8791 }
8792
8793 return getDerived().RebuildCoroutineBodyStmt(Builder);
8794}
8795
8796template<typename Derived>
8799 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8800 /*NotCopyInit*/false);
8801 if (Result.isInvalid())
8802 return StmtError();
8803
8804 // Always rebuild; we don't know if this needs to be injected into a new
8805 // context or if the promise type has changed.
8806 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8807 S->isImplicit());
8808}
8809
8810template <typename Derived>
8812 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8813 /*NotCopyInit*/ false);
8814 if (Operand.isInvalid())
8815 return ExprError();
8816
8817 // Rebuild the common-expr from the operand rather than transforming it
8818 // separately.
8819
8820 // FIXME: getCurScope() should not be used during template instantiation.
8821 // We should pick up the set of unqualified lookup results for operator
8822 // co_await during the initial parse.
8823 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8824 getSema().getCurScope(), E->getKeywordLoc());
8825
8826 // Always rebuild; we don't know if this needs to be injected into a new
8827 // context or if the promise type has changed.
8828 return getDerived().RebuildCoawaitExpr(
8829 E->getKeywordLoc(), Operand.get(),
8830 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8831}
8832
8833template <typename Derived>
8836 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8837 /*NotCopyInit*/ false);
8838 if (OperandResult.isInvalid())
8839 return ExprError();
8840
8841 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8842 E->getOperatorCoawaitLookup());
8843
8844 if (LookupResult.isInvalid())
8845 return ExprError();
8846
8847 // Always rebuild; we don't know if this needs to be injected into a new
8848 // context or if the promise type has changed.
8849 return getDerived().RebuildDependentCoawaitExpr(
8850 E->getKeywordLoc(), OperandResult.get(),
8852}
8853
8854template<typename Derived>
8857 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8858 /*NotCopyInit*/false);
8859 if (Result.isInvalid())
8860 return ExprError();
8861
8862 // Always rebuild; we don't know if this needs to be injected into a new
8863 // context or if the promise type has changed.
8864 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8865}
8866
8867// Objective-C Statements.
8868
8869template<typename Derived>
8872 // Transform the body of the @try.
8873 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8874 if (TryBody.isInvalid())
8875 return StmtError();
8876
8877 // Transform the @catch statements (if present).
8878 bool AnyCatchChanged = false;
8879 SmallVector<Stmt*, 8> CatchStmts;
8880 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8881 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8882 if (Catch.isInvalid())
8883 return StmtError();
8884 if (Catch.get() != S->getCatchStmt(I))
8885 AnyCatchChanged = true;
8886 CatchStmts.push_back(Catch.get());
8887 }
8888
8889 // Transform the @finally statement (if present).
8890 StmtResult Finally;
8891 if (S->getFinallyStmt()) {
8892 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8893 if (Finally.isInvalid())
8894 return StmtError();
8895 }
8896
8897 // If nothing changed, just retain this statement.
8898 if (!getDerived().AlwaysRebuild() &&
8899 TryBody.get() == S->getTryBody() &&
8900 !AnyCatchChanged &&
8901 Finally.get() == S->getFinallyStmt())
8902 return S;
8903
8904 // Build a new statement.
8905 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8906 CatchStmts, Finally.get());
8907}
8908
8909template<typename Derived>
8912 // Transform the @catch parameter, if there is one.
8913 VarDecl *Var = nullptr;
8914 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8915 TypeSourceInfo *TSInfo = nullptr;
8916 if (FromVar->getTypeSourceInfo()) {
8917 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8918 if (!TSInfo)
8919 return StmtError();
8920 }
8921
8922 QualType T;
8923 if (TSInfo)
8924 T = TSInfo->getType();
8925 else {
8926 T = getDerived().TransformType(FromVar->getType());
8927 if (T.isNull())
8928 return StmtError();
8929 }
8930
8931 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8932 if (!Var)
8933 return StmtError();
8934 }
8935
8936 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8937 if (Body.isInvalid())
8938 return StmtError();
8939
8940 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8941 S->getRParenLoc(),
8942 Var, Body.get());
8943}
8944
8945template<typename Derived>
8948 // Transform the body.
8949 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8950 if (Body.isInvalid())
8951 return StmtError();
8952
8953 // If nothing changed, just retain this statement.
8954 if (!getDerived().AlwaysRebuild() &&
8955 Body.get() == S->getFinallyBody())
8956 return S;
8957
8958 // Build a new statement.
8959 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8960 Body.get());
8961}
8962
8963template<typename Derived>
8967 if (S->getThrowExpr()) {
8968 Operand = getDerived().TransformExpr(S->getThrowExpr());
8969 if (Operand.isInvalid())
8970 return StmtError();
8971 }
8972
8973 if (!getDerived().AlwaysRebuild() &&
8974 Operand.get() == S->getThrowExpr())
8975 return S;
8976
8977 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8978}
8979
8980template<typename Derived>
8984 // Transform the object we are locking.
8985 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8986 if (Object.isInvalid())
8987 return StmtError();
8988 Object =
8989 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8990 Object.get());
8991 if (Object.isInvalid())
8992 return StmtError();
8993
8994 // Transform the body.
8995 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8996 if (Body.isInvalid())
8997 return StmtError();
8998
8999 // If nothing change, just retain the current statement.
9000 if (!getDerived().AlwaysRebuild() &&
9001 Object.get() == S->getSynchExpr() &&
9002 Body.get() == S->getSynchBody())
9003 return S;
9004
9005 // Build a new statement.
9006 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9007 Object.get(), Body.get());
9008}
9009
9010template<typename Derived>
9014 // Transform the body.
9015 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9016 if (Body.isInvalid())
9017 return StmtError();
9018
9019 // If nothing changed, just retain this statement.
9020 if (!getDerived().AlwaysRebuild() &&
9021 Body.get() == S->getSubStmt())
9022 return S;
9023
9024 // Build a new statement.
9025 return getDerived().RebuildObjCAutoreleasePoolStmt(
9026 S->getAtLoc(), Body.get());
9027}
9028
9029template<typename Derived>
9033 // Transform the element statement.
9034 StmtResult Element = getDerived().TransformStmt(
9035 S->getElement(), StmtDiscardKind::NotDiscarded);
9036 if (Element.isInvalid())
9037 return StmtError();
9038
9039 // Transform the collection expression.
9040 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9041 if (Collection.isInvalid())
9042 return StmtError();
9043
9044 // Transform the body.
9045 StmtResult Body = getDerived().TransformStmt(S->getBody());
9046 if (Body.isInvalid())
9047 return StmtError();
9048
9049 // If nothing changed, just retain this statement.
9050 if (!getDerived().AlwaysRebuild() &&
9051 Element.get() == S->getElement() &&
9052 Collection.get() == S->getCollection() &&
9053 Body.get() == S->getBody())
9054 return S;
9055
9056 // Build a new statement.
9057 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9058 Element.get(),
9059 Collection.get(),
9060 S->getRParenLoc(),
9061 Body.get());
9062}
9063
9064template <typename Derived>
9066 // Transform the exception declaration, if any.
9067 VarDecl *Var = nullptr;
9068 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9069 TypeSourceInfo *T =
9070 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9071 if (!T)
9072 return StmtError();
9073
9074 Var = getDerived().RebuildExceptionDecl(
9075 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9076 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9077 if (!Var || Var->isInvalidDecl())
9078 return StmtError();
9079 }
9080
9081 // Transform the actual exception handler.
9082 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9083 if (Handler.isInvalid())
9084 return StmtError();
9085
9086 if (!getDerived().AlwaysRebuild() && !Var &&
9087 Handler.get() == S->getHandlerBlock())
9088 return S;
9089
9090 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9091}
9092
9093template <typename Derived>
9095 // Transform the try block itself.
9096 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9097 if (TryBlock.isInvalid())
9098 return StmtError();
9099
9100 // Transform the handlers.
9101 bool HandlerChanged = false;
9102 SmallVector<Stmt *, 8> Handlers;
9103 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9104 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9105 if (Handler.isInvalid())
9106 return StmtError();
9107
9108 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9109 Handlers.push_back(Handler.getAs<Stmt>());
9110 }
9111
9112 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9113
9114 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9115 !HandlerChanged)
9116 return S;
9117
9118 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9119 Handlers);
9120}
9121
9122template<typename Derived>
9125 EnterExpressionEvaluationContext ForRangeInitContext(
9127 /*LambdaContextDecl=*/nullptr,
9129 getSema().getLangOpts().CPlusPlus23);
9130
9131 // P2718R0 - Lifetime extension in range-based for loops.
9132 if (getSema().getLangOpts().CPlusPlus23) {
9133 auto &LastRecord = getSema().currentEvaluationContext();
9134 LastRecord.InLifetimeExtendingContext = true;
9135 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9136 }
9138 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9139 if (Init.isInvalid())
9140 return StmtError();
9141
9142 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9143 if (Range.isInvalid())
9144 return StmtError();
9145
9146 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9147 assert(getSema().getLangOpts().CPlusPlus23 ||
9148 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9149 auto ForRangeLifetimeExtendTemps =
9150 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9151
9152 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9153 if (Begin.isInvalid())
9154 return StmtError();
9155 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9156 if (End.isInvalid())
9157 return StmtError();
9158
9159 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9160 if (Cond.isInvalid())
9161 return StmtError();
9162 if (Cond.get())
9163 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9164 if (Cond.isInvalid())
9165 return StmtError();
9166 if (Cond.get())
9167 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9168
9169 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9170 if (Inc.isInvalid())
9171 return StmtError();
9172 if (Inc.get())
9173 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9174
9175 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9176 if (LoopVar.isInvalid())
9177 return StmtError();
9178
9179 StmtResult NewStmt = S;
9180 if (getDerived().AlwaysRebuild() ||
9181 Init.get() != S->getInit() ||
9182 Range.get() != S->getRangeStmt() ||
9183 Begin.get() != S->getBeginStmt() ||
9184 End.get() != S->getEndStmt() ||
9185 Cond.get() != S->getCond() ||
9186 Inc.get() != S->getInc() ||
9187 LoopVar.get() != S->getLoopVarStmt()) {
9188 NewStmt = getDerived().RebuildCXXForRangeStmt(
9189 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9190 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9191 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9192 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9193 // Might not have attached any initializer to the loop variable.
9194 getSema().ActOnInitializerError(
9195 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9196 return StmtError();
9197 }
9198 }
9199
9200 // OpenACC Restricts a while-loop inside of certain construct/clause
9201 // combinations, so diagnose that here in OpenACC mode.
9203 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9204
9205 StmtResult Body = getDerived().TransformStmt(S->getBody());
9206 if (Body.isInvalid())
9207 return StmtError();
9208
9209 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9210
9211 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9212 // it now so we have a new statement to attach the body to.
9213 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9214 NewStmt = getDerived().RebuildCXXForRangeStmt(
9215 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9216 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9217 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9218 if (NewStmt.isInvalid())
9219 return StmtError();
9220 }
9221
9222 if (NewStmt.get() == S)
9223 return S;
9224
9225 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9226}
9227
9228template<typename Derived>
9232 // Transform the nested-name-specifier, if any.
9233 NestedNameSpecifierLoc QualifierLoc;
9234 if (S->getQualifierLoc()) {
9235 QualifierLoc
9236 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9237 if (!QualifierLoc)
9238 return StmtError();
9239 }
9240
9241 // Transform the declaration name.
9242 DeclarationNameInfo NameInfo = S->getNameInfo();
9243 if (NameInfo.getName()) {
9244 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9245 if (!NameInfo.getName())
9246 return StmtError();
9247 }
9248
9249 // Check whether anything changed.
9250 if (!getDerived().AlwaysRebuild() &&
9251 QualifierLoc == S->getQualifierLoc() &&
9252 NameInfo.getName() == S->getNameInfo().getName())
9253 return S;
9254
9255 // Determine whether this name exists, if we can.
9256 CXXScopeSpec SS;
9257 SS.Adopt(QualifierLoc);
9258 bool Dependent = false;
9259 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9261 if (S->isIfExists())
9262 break;
9263
9264 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9265
9267 if (S->isIfNotExists())
9268 break;
9269
9270 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9271
9273 Dependent = true;
9274 break;
9275
9277 return StmtError();
9278 }
9279
9280 // We need to continue with the instantiation, so do so now.
9281 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9282 if (SubStmt.isInvalid())
9283 return StmtError();
9284
9285 // If we have resolved the name, just transform to the substatement.
9286 if (!Dependent)
9287 return SubStmt;
9288
9289 // The name is still dependent, so build a dependent expression again.
9290 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9291 S->isIfExists(),
9292 QualifierLoc,
9293 NameInfo,
9294 SubStmt.get());
9295}
9296
9297template<typename Derived>
9300 NestedNameSpecifierLoc QualifierLoc;
9301 if (E->getQualifierLoc()) {
9302 QualifierLoc
9303 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9304 if (!QualifierLoc)
9305 return ExprError();
9306 }
9307
9308 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9309 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9310 if (!PD)
9311 return ExprError();
9312
9313 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9314 if (Base.isInvalid())
9315 return ExprError();
9316
9317 return new (SemaRef.getASTContext())
9318 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9320 QualifierLoc, E->getMemberLoc());
9321}
9322
9323template <typename Derived>
9326 auto BaseRes = getDerived().TransformExpr(E->getBase());
9327 if (BaseRes.isInvalid())
9328 return ExprError();
9329 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9330 if (IdxRes.isInvalid())
9331 return ExprError();
9332
9333 if (!getDerived().AlwaysRebuild() &&
9334 BaseRes.get() == E->getBase() &&
9335 IdxRes.get() == E->getIdx())
9336 return E;
9337
9338 return getDerived().RebuildArraySubscriptExpr(
9339 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9340}
9341
9342template <typename Derived>
9344 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9345 if (TryBlock.isInvalid())
9346 return StmtError();
9347
9348 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9349 if (Handler.isInvalid())
9350 return StmtError();
9351
9352 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9353 Handler.get() == S->getHandler())
9354 return S;
9355
9356 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9357 TryBlock.get(), Handler.get());
9358}
9359
9360template <typename Derived>
9362 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9363 if (Block.isInvalid())
9364 return StmtError();
9365
9366 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9367}
9368
9369template <typename Derived>
9371 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9372 if (FilterExpr.isInvalid())
9373 return StmtError();
9374
9375 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9376 if (Block.isInvalid())
9377 return StmtError();
9378
9379 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9380 Block.get());
9381}
9382
9383template <typename Derived>
9385 if (isa<SEHFinallyStmt>(Handler))
9386 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9387 else
9388 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9389}
9390
9391template<typename Derived>
9394 return S;
9395}
9396
9397//===----------------------------------------------------------------------===//
9398// OpenMP directive transformation
9399//===----------------------------------------------------------------------===//
9400
9401template <typename Derived>
9402StmtResult
9403TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9404 // OMPCanonicalLoops are eliminated during transformation, since they will be
9405 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9406 // after transformation.
9407 return getDerived().TransformStmt(L->getLoopStmt());
9408}
9409
9410template <typename Derived>
9413
9414 // Transform the clauses
9416 ArrayRef<OMPClause *> Clauses = D->clauses();
9417 TClauses.reserve(Clauses.size());
9418 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9419 I != E; ++I) {
9420 if (*I) {
9421 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9422 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9423 getDerived().getSema().OpenMP().EndOpenMPClause();
9424 if (Clause)
9425 TClauses.push_back(Clause);
9426 } else {
9427 TClauses.push_back(nullptr);
9428 }
9429 }
9430 StmtResult AssociatedStmt;
9431 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9432 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9433 D->getDirectiveKind(),
9434 /*CurScope=*/nullptr);
9435 StmtResult Body;
9436 {
9437 Sema::CompoundScopeRAII CompoundScope(getSema());
9438 Stmt *CS;
9439 if (D->getDirectiveKind() == OMPD_atomic ||
9440 D->getDirectiveKind() == OMPD_critical ||
9441 D->getDirectiveKind() == OMPD_section ||
9442 D->getDirectiveKind() == OMPD_master)
9443 CS = D->getAssociatedStmt();
9444 else
9445 CS = D->getRawStmt();
9446 Body = getDerived().TransformStmt(CS);
9447 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9448 getSema().getLangOpts().OpenMPIRBuilder)
9449 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9450 }
9451 AssociatedStmt =
9452 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9453 if (AssociatedStmt.isInvalid()) {
9454 return StmtError();
9455 }
9456 }
9457 if (TClauses.size() != Clauses.size()) {
9458 return StmtError();
9459 }
9460
9461 // Transform directive name for 'omp critical' directive.
9462 DeclarationNameInfo DirName;
9463 if (D->getDirectiveKind() == OMPD_critical) {
9464 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9465 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9466 }
9467 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9468 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9469 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9470 } else if (D->getDirectiveKind() == OMPD_cancel) {
9471 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9472 }
9473
9474 return getDerived().RebuildOMPExecutableDirective(
9475 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9476 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9477}
9478
9479/// This is mostly the same as above, but allows 'informational' class
9480/// directives when rebuilding the stmt. It still takes an
9481/// OMPExecutableDirective-type argument because we're reusing that as the
9482/// superclass for the 'assume' directive at present, instead of defining a
9483/// mostly-identical OMPInformationalDirective parent class.
9484template <typename Derived>
9487
9488 // Transform the clauses
9490 ArrayRef<OMPClause *> Clauses = D->clauses();
9491 TClauses.reserve(Clauses.size());
9492 for (OMPClause *C : Clauses) {
9493 if (C) {
9494 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9495 OMPClause *Clause = getDerived().TransformOMPClause(C);
9496 getDerived().getSema().OpenMP().EndOpenMPClause();
9497 if (Clause)
9498 TClauses.push_back(Clause);
9499 } else {
9500 TClauses.push_back(nullptr);
9501 }
9502 }
9503 StmtResult AssociatedStmt;
9504 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9505 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9506 D->getDirectiveKind(),
9507 /*CurScope=*/nullptr);
9508 StmtResult Body;
9509 {
9510 Sema::CompoundScopeRAII CompoundScope(getSema());
9511 assert(D->getDirectiveKind() == OMPD_assume &&
9512 "Unexpected informational directive");
9513 Stmt *CS = D->getAssociatedStmt();
9514 Body = getDerived().TransformStmt(CS);
9515 }
9516 AssociatedStmt =
9517 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9518 if (AssociatedStmt.isInvalid())
9519 return StmtError();
9520 }
9521 if (TClauses.size() != Clauses.size())
9522 return StmtError();
9523
9524 DeclarationNameInfo DirName;
9525
9526 return getDerived().RebuildOMPInformationalDirective(
9527 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9528 D->getBeginLoc(), D->getEndLoc());
9529}
9530
9531template <typename Derived>
9534 // TODO: Fix This
9535 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9536 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9537 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9538 return StmtError();
9539}
9540
9541template <typename Derived>
9542StmtResult
9543TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9544 DeclarationNameInfo DirName;
9545 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9546 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9547 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9548 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9549 return Res;
9550}
9551
9552template <typename Derived>
9555 DeclarationNameInfo DirName;
9556 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9557 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9559 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9560 return Res;
9561}
9562
9563template <typename Derived>
9566 DeclarationNameInfo DirName;
9567 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9568 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9570 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9571 return Res;
9572}
9573
9574template <typename Derived>
9577 DeclarationNameInfo DirName;
9578 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9579 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9580 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9581 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9582 return Res;
9583}
9584
9585template <typename Derived>
9588 DeclarationNameInfo DirName;
9589 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9590 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9591 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9592 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9593 return Res;
9594}
9595
9596template <typename Derived>
9599 DeclarationNameInfo DirName;
9600 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9601 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9602 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9603 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9604 return Res;
9605}
9606
9607template <typename Derived>
9609 OMPInterchangeDirective *D) {
9610 DeclarationNameInfo DirName;
9611 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9612 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9613 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9614 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9615 return Res;
9616}
9617
9618template <typename Derived>
9621 DeclarationNameInfo DirName;
9622 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9623 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9625 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9626 return Res;
9627}
9628
9629template <typename Derived>
9632 DeclarationNameInfo DirName;
9633 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9634 OMPD_for, DirName, nullptr, D->getBeginLoc());
9635 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9636 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9637 return Res;
9638}
9639
9640template <typename Derived>
9643 DeclarationNameInfo DirName;
9644 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9645 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9646 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9647 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9648 return Res;
9649}
9650
9651template <typename Derived>
9654 DeclarationNameInfo DirName;
9655 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9656 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9657 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9658 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9659 return Res;
9660}
9661
9662template <typename Derived>
9665 DeclarationNameInfo DirName;
9666 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9667 OMPD_section, DirName, nullptr, D->getBeginLoc());
9668 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9669 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9670 return Res;
9671}
9672
9673template <typename Derived>
9676 DeclarationNameInfo DirName;
9677 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9678 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9679 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9680 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9681 return Res;
9682}
9683
9684template <typename Derived>
9687 DeclarationNameInfo DirName;
9688 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9689 OMPD_single, DirName, nullptr, D->getBeginLoc());
9690 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9691 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9692 return Res;
9693}
9694
9695template <typename Derived>
9698 DeclarationNameInfo DirName;
9699 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9700 OMPD_master, DirName, nullptr, D->getBeginLoc());
9701 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9702 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9703 return Res;
9704}
9705
9706template <typename Derived>
9709 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9710 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9711 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9712 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9713 return Res;
9714}
9715
9716template <typename Derived>
9718 OMPParallelForDirective *D) {
9719 DeclarationNameInfo DirName;
9720 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9721 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9722 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9723 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9724 return Res;
9725}
9726
9727template <typename Derived>
9729 OMPParallelForSimdDirective *D) {
9730 DeclarationNameInfo DirName;
9731 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9732 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9733 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9734 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9735 return Res;
9736}
9737
9738template <typename Derived>
9740 OMPParallelMasterDirective *D) {
9741 DeclarationNameInfo DirName;
9742 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9743 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9744 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9745 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9746 return Res;
9747}
9748
9749template <typename Derived>
9751 OMPParallelMaskedDirective *D) {
9752 DeclarationNameInfo DirName;
9753 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9754 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9755 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9756 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9757 return Res;
9758}
9759
9760template <typename Derived>
9762 OMPParallelSectionsDirective *D) {
9763 DeclarationNameInfo DirName;
9764 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9765 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9766 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9767 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9768 return Res;
9769}
9770
9771template <typename Derived>
9774 DeclarationNameInfo DirName;
9775 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9776 OMPD_task, DirName, nullptr, D->getBeginLoc());
9777 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9778 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9779 return Res;
9780}
9781
9782template <typename Derived>
9784 OMPTaskyieldDirective *D) {
9785 DeclarationNameInfo DirName;
9786 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9787 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9788 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9789 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9790 return Res;
9791}
9792
9793template <typename Derived>
9796 DeclarationNameInfo DirName;
9797 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9798 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9799 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9800 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9801 return Res;
9802}
9803
9804template <typename Derived>
9807 DeclarationNameInfo DirName;
9808 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9809 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9810 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9811 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9812 return Res;
9813}
9814
9815template <typename Derived>
9818 DeclarationNameInfo DirName;
9819 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9820 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9821 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9822 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9823 return Res;
9824}
9825
9826template <typename Derived>
9829 DeclarationNameInfo DirName;
9830 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9831 OMPD_error, DirName, nullptr, D->getBeginLoc());
9832 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9833 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9834 return Res;
9835}
9836
9837template <typename Derived>
9839 OMPTaskgroupDirective *D) {
9840 DeclarationNameInfo DirName;
9841 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9842 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9843 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9844 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9845 return Res;
9846}
9847
9848template <typename Derived>
9851 DeclarationNameInfo DirName;
9852 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9853 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9854 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9855 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9856 return Res;
9857}
9858
9859template <typename Derived>
9862 DeclarationNameInfo DirName;
9863 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9864 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9865 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9866 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9867 return Res;
9868}
9869
9870template <typename Derived>
9873 DeclarationNameInfo DirName;
9874 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9875 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9876 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9877 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9878 return Res;
9879}
9880
9881template <typename Derived>
9884 DeclarationNameInfo DirName;
9885 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9886 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9887 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9888 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9889 return Res;
9890}
9891
9892template <typename Derived>
9895 DeclarationNameInfo DirName;
9896 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9897 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9898 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9899 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9900 return Res;
9901}
9902
9903template <typename Derived>
9906 DeclarationNameInfo DirName;
9907 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9908 OMPD_target, DirName, nullptr, D->getBeginLoc());
9909 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9910 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9911 return Res;
9912}
9913
9914template <typename Derived>
9916 OMPTargetDataDirective *D) {
9917 DeclarationNameInfo DirName;
9918 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9919 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9920 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9921 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9922 return Res;
9923}
9924
9925template <typename Derived>
9927 OMPTargetEnterDataDirective *D) {
9928 DeclarationNameInfo DirName;
9929 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9930 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9931 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9932 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9933 return Res;
9934}
9935
9936template <typename Derived>
9938 OMPTargetExitDataDirective *D) {
9939 DeclarationNameInfo DirName;
9940 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9941 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9942 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9943 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9944 return Res;
9945}
9946
9947template <typename Derived>
9949 OMPTargetParallelDirective *D) {
9950 DeclarationNameInfo DirName;
9951 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9952 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9953 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9954 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9955 return Res;
9956}
9957
9958template <typename Derived>
9960 OMPTargetParallelForDirective *D) {
9961 DeclarationNameInfo DirName;
9962 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9963 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9964 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9965 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9966 return Res;
9967}
9968
9969template <typename Derived>
9971 OMPTargetUpdateDirective *D) {
9972 DeclarationNameInfo DirName;
9973 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9974 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9975 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9976 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9977 return Res;
9978}
9979
9980template <typename Derived>
9983 DeclarationNameInfo DirName;
9984 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9985 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9986 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9987 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9988 return Res;
9989}
9990
9991template <typename Derived>
9993 OMPCancellationPointDirective *D) {
9994 DeclarationNameInfo DirName;
9995 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9996 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9997 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9998 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9999 return Res;
10000}
10001
10002template <typename Derived>
10005 DeclarationNameInfo DirName;
10006 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10007 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10008 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10009 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10010 return Res;
10011}
10012
10013template <typename Derived>
10016 DeclarationNameInfo DirName;
10017 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10018 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10019 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10020 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10021 return Res;
10022}
10023
10024template <typename Derived>
10026 OMPTaskLoopSimdDirective *D) {
10027 DeclarationNameInfo DirName;
10028 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10029 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10030 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10031 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10032 return Res;
10033}
10034
10035template <typename Derived>
10037 OMPMasterTaskLoopDirective *D) {
10038 DeclarationNameInfo DirName;
10039 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10040 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10041 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10042 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10043 return Res;
10044}
10045
10046template <typename Derived>
10048 OMPMaskedTaskLoopDirective *D) {
10049 DeclarationNameInfo DirName;
10050 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10051 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10052 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10053 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10054 return Res;
10055}
10056
10057template <typename Derived>
10059 OMPMasterTaskLoopSimdDirective *D) {
10060 DeclarationNameInfo DirName;
10061 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10062 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10063 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10064 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10065 return Res;
10066}
10067
10068template <typename Derived>
10070 OMPMaskedTaskLoopSimdDirective *D) {
10071 DeclarationNameInfo DirName;
10072 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10073 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10074 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10075 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10076 return Res;
10077}
10078
10079template <typename Derived>
10081 OMPParallelMasterTaskLoopDirective *D) {
10082 DeclarationNameInfo DirName;
10083 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10084 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10085 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10086 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10087 return Res;
10088}
10089
10090template <typename Derived>
10092 OMPParallelMaskedTaskLoopDirective *D) {
10093 DeclarationNameInfo DirName;
10094 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10095 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10096 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10097 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10098 return Res;
10099}
10100
10101template <typename Derived>
10104 OMPParallelMasterTaskLoopSimdDirective *D) {
10105 DeclarationNameInfo DirName;
10106 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10107 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10108 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10109 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10110 return Res;
10111}
10112
10113template <typename Derived>
10116 OMPParallelMaskedTaskLoopSimdDirective *D) {
10117 DeclarationNameInfo DirName;
10118 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10119 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10121 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10122 return Res;
10123}
10124
10125template <typename Derived>
10127 OMPDistributeDirective *D) {
10128 DeclarationNameInfo DirName;
10129 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10130 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10132 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10133 return Res;
10134}
10135
10136template <typename Derived>
10138 OMPDistributeParallelForDirective *D) {
10139 DeclarationNameInfo DirName;
10140 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10141 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10143 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10144 return Res;
10145}
10146
10147template <typename Derived>
10150 OMPDistributeParallelForSimdDirective *D) {
10151 DeclarationNameInfo DirName;
10152 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10153 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10155 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10156 return Res;
10157}
10158
10159template <typename Derived>
10161 OMPDistributeSimdDirective *D) {
10162 DeclarationNameInfo DirName;
10163 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10164 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10166 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10167 return Res;
10168}
10169
10170template <typename Derived>
10172 OMPTargetParallelForSimdDirective *D) {
10173 DeclarationNameInfo DirName;
10174 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10175 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10177 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10178 return Res;
10179}
10180
10181template <typename Derived>
10183 OMPTargetSimdDirective *D) {
10184 DeclarationNameInfo DirName;
10185 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10186 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10187 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10188 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10189 return Res;
10190}
10191
10192template <typename Derived>
10194 OMPTeamsDistributeDirective *D) {
10195 DeclarationNameInfo DirName;
10196 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10197 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10198 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10199 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10200 return Res;
10201}
10202
10203template <typename Derived>
10205 OMPTeamsDistributeSimdDirective *D) {
10206 DeclarationNameInfo DirName;
10207 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10208 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10209 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10210 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10211 return Res;
10212}
10213
10214template <typename Derived>
10216 OMPTeamsDistributeParallelForSimdDirective *D) {
10217 DeclarationNameInfo DirName;
10218 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10219 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10220 D->getBeginLoc());
10221 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10222 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10223 return Res;
10224}
10225
10226template <typename Derived>
10228 OMPTeamsDistributeParallelForDirective *D) {
10229 DeclarationNameInfo DirName;
10230 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10231 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10232 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10233 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10234 return Res;
10235}
10236
10237template <typename Derived>
10239 OMPTargetTeamsDirective *D) {
10240 DeclarationNameInfo DirName;
10241 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10242 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10243 auto Res = getDerived().TransformOMPExecutableDirective(D);
10244 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10245 return Res;
10246}
10247
10248template <typename Derived>
10250 OMPTargetTeamsDistributeDirective *D) {
10251 DeclarationNameInfo DirName;
10252 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10253 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10254 auto Res = getDerived().TransformOMPExecutableDirective(D);
10255 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10256 return Res;
10257}
10258
10259template <typename Derived>
10262 OMPTargetTeamsDistributeParallelForDirective *D) {
10263 DeclarationNameInfo DirName;
10264 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10265 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10266 D->getBeginLoc());
10267 auto Res = getDerived().TransformOMPExecutableDirective(D);
10268 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10269 return Res;
10270}
10271
10272template <typename Derived>
10275 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10276 DeclarationNameInfo DirName;
10277 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10278 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10279 D->getBeginLoc());
10280 auto Res = getDerived().TransformOMPExecutableDirective(D);
10281 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10282 return Res;
10283}
10284
10285template <typename Derived>
10288 OMPTargetTeamsDistributeSimdDirective *D) {
10289 DeclarationNameInfo DirName;
10290 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10291 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10292 auto Res = getDerived().TransformOMPExecutableDirective(D);
10293 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10294 return Res;
10295}
10296
10297template <typename Derived>
10300 DeclarationNameInfo DirName;
10301 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10302 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10303 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10304 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10305 return Res;
10306}
10307
10308template <typename Derived>
10311 DeclarationNameInfo DirName;
10312 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10313 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10314 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10315 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10316 return Res;
10317}
10318
10319template <typename Derived>
10322 DeclarationNameInfo DirName;
10323 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10324 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10325 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10326 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10327 return Res;
10328}
10329
10330template <typename Derived>
10332 OMPGenericLoopDirective *D) {
10333 DeclarationNameInfo DirName;
10334 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10335 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10336 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10337 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10338 return Res;
10339}
10340
10341template <typename Derived>
10343 OMPTeamsGenericLoopDirective *D) {
10344 DeclarationNameInfo DirName;
10345 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10346 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10347 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10348 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10349 return Res;
10350}
10351
10352template <typename Derived>
10354 OMPTargetTeamsGenericLoopDirective *D) {
10355 DeclarationNameInfo DirName;
10356 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10357 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10358 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10359 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10360 return Res;
10361}
10362
10363template <typename Derived>
10365 OMPParallelGenericLoopDirective *D) {
10366 DeclarationNameInfo DirName;
10367 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10368 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10369 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10370 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10371 return Res;
10372}
10373
10374template <typename Derived>
10377 OMPTargetParallelGenericLoopDirective *D) {
10378 DeclarationNameInfo DirName;
10379 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10380 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10381 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10382 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10383 return Res;
10384}
10385
10386//===----------------------------------------------------------------------===//
10387// OpenMP clause transformation
10388//===----------------------------------------------------------------------===//
10389template <typename Derived>
10391 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10392 if (Cond.isInvalid())
10393 return nullptr;
10394 return getDerived().RebuildOMPIfClause(
10395 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10396 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10397}
10398
10399template <typename Derived>
10401 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10402 if (Cond.isInvalid())
10403 return nullptr;
10404 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10405 C->getLParenLoc(), C->getEndLoc());
10406}
10407
10408template <typename Derived>
10409OMPClause *
10411 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10412 if (NumThreads.isInvalid())
10413 return nullptr;
10414 return getDerived().RebuildOMPNumThreadsClause(
10415 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10416 C->getModifierLoc(), C->getEndLoc());
10417}
10418
10419template <typename Derived>
10420OMPClause *
10422 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10423 if (E.isInvalid())
10424 return nullptr;
10425 return getDerived().RebuildOMPSafelenClause(
10426 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10427}
10428
10429template <typename Derived>
10430OMPClause *
10432 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10433 if (E.isInvalid())
10434 return nullptr;
10435 return getDerived().RebuildOMPAllocatorClause(
10436 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10437}
10438
10439template <typename Derived>
10440OMPClause *
10442 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10443 if (E.isInvalid())
10444 return nullptr;
10445 return getDerived().RebuildOMPSimdlenClause(
10446 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10447}
10448
10449template <typename Derived>
10451 SmallVector<Expr *, 4> TransformedSizes;
10452 TransformedSizes.reserve(C->getNumSizes());
10453 bool Changed = false;
10454 for (Expr *E : C->getSizesRefs()) {
10455 if (!E) {
10456 TransformedSizes.push_back(nullptr);
10457 continue;
10458 }
10459
10460 ExprResult T = getDerived().TransformExpr(E);
10461 if (T.isInvalid())
10462 return nullptr;
10463 if (E != T.get())
10464 Changed = true;
10465 TransformedSizes.push_back(T.get());
10466 }
10467
10468 if (!Changed && !getDerived().AlwaysRebuild())
10469 return C;
10470 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10471 C->getLParenLoc(), C->getEndLoc());
10472}
10473
10474template <typename Derived>
10475OMPClause *
10477 SmallVector<Expr *> TransformedArgs;
10478 TransformedArgs.reserve(C->getNumLoops());
10479 bool Changed = false;
10480 for (Expr *E : C->getArgsRefs()) {
10481 if (!E) {
10482 TransformedArgs.push_back(nullptr);
10483 continue;
10484 }
10485
10486 ExprResult T = getDerived().TransformExpr(E);
10487 if (T.isInvalid())
10488 return nullptr;
10489 if (E != T.get())
10490 Changed = true;
10491 TransformedArgs.push_back(T.get());
10492 }
10493
10494 if (!Changed && !getDerived().AlwaysRebuild())
10495 return C;
10496 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10497 C->getLParenLoc(), C->getEndLoc());
10498}
10499
10500template <typename Derived>
10502 if (!getDerived().AlwaysRebuild())
10503 return C;
10504 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10505}
10506
10507template <typename Derived>
10508OMPClause *
10510 ExprResult T = getDerived().TransformExpr(C->getFactor());
10511 if (T.isInvalid())
10512 return nullptr;
10513 Expr *Factor = T.get();
10514 bool Changed = Factor != C->getFactor();
10515
10516 if (!Changed && !getDerived().AlwaysRebuild())
10517 return C;
10518 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10519 C->getEndLoc());
10520}
10521
10522template <typename Derived>
10523OMPClause *
10525 ExprResult F = getDerived().TransformExpr(C->getFirst());
10526 if (F.isInvalid())
10527 return nullptr;
10528
10529 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10530 if (Cn.isInvalid())
10531 return nullptr;
10532
10533 Expr *First = F.get();
10534 Expr *Count = Cn.get();
10535
10536 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10537
10538 // If no changes and AlwaysRebuild() is false, return the original clause
10539 if (!Changed && !getDerived().AlwaysRebuild())
10540 return C;
10541
10542 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10543 C->getLParenLoc(), C->getFirstLoc(),
10544 C->getCountLoc(), C->getEndLoc());
10545}
10546
10547template <typename Derived>
10548OMPClause *
10550 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10551 if (E.isInvalid())
10552 return nullptr;
10553 return getDerived().RebuildOMPCollapseClause(
10554 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10555}
10556
10557template <typename Derived>
10558OMPClause *
10560 return getDerived().RebuildOMPDefaultClause(
10561 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10562 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10563 C->getEndLoc());
10564}
10565
10566template <typename Derived>
10567OMPClause *
10569 return getDerived().RebuildOMPProcBindClause(
10570 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10571 C->getLParenLoc(), C->getEndLoc());
10572}
10573
10574template <typename Derived>
10575OMPClause *
10577 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10578 if (E.isInvalid())
10579 return nullptr;
10580 return getDerived().RebuildOMPScheduleClause(
10581 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10582 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10583 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10584 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10585}
10586
10587template <typename Derived>
10588OMPClause *
10590 ExprResult E;
10591 if (auto *Num = C->getNumForLoops()) {
10592 E = getDerived().TransformExpr(Num);
10593 if (E.isInvalid())
10594 return nullptr;
10595 }
10596 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10597 C->getLParenLoc(), E.get());
10598}
10599
10600template <typename Derived>
10601OMPClause *
10603 ExprResult E;
10604 if (Expr *Evt = C->getEventHandler()) {
10605 E = getDerived().TransformExpr(Evt);
10606 if (E.isInvalid())
10607 return nullptr;
10608 }
10609 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10610 C->getLParenLoc(), C->getEndLoc());
10611}
10612
10613template <typename Derived>
10614OMPClause *
10616 // No need to rebuild this clause, no template-dependent parameters.
10617 return C;
10618}
10619
10620template <typename Derived>
10621OMPClause *
10623 // No need to rebuild this clause, no template-dependent parameters.
10624 return C;
10625}
10626
10627template <typename Derived>
10628OMPClause *
10630 // No need to rebuild this clause, no template-dependent parameters.
10631 return C;
10632}
10633
10634template <typename Derived>
10636 // No need to rebuild this clause, no template-dependent parameters.
10637 return C;
10638}
10639
10640template <typename Derived>
10642 // No need to rebuild this clause, no template-dependent parameters.
10643 return C;
10644}
10645
10646template <typename Derived>
10647OMPClause *
10649 // No need to rebuild this clause, no template-dependent parameters.
10650 return C;
10651}
10652
10653template <typename Derived>
10654OMPClause *
10656 // No need to rebuild this clause, no template-dependent parameters.
10657 return C;
10658}
10659
10660template <typename Derived>
10661OMPClause *
10663 // No need to rebuild this clause, no template-dependent parameters.
10664 return C;
10665}
10666
10667template <typename Derived>
10669 // No need to rebuild this clause, no template-dependent parameters.
10670 return C;
10671}
10672
10673template <typename Derived>
10674OMPClause *
10676 return C;
10677}
10678
10679template <typename Derived>
10681 ExprResult E = getDerived().TransformExpr(C->getExpr());
10682 if (E.isInvalid())
10683 return nullptr;
10684 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10685 C->getLParenLoc(), C->getEndLoc());
10686}
10687
10688template <typename Derived>
10689OMPClause *
10691 return C;
10692}
10693
10694template <typename Derived>
10695OMPClause *
10697 return C;
10698}
10699template <typename Derived>
10702 return C;
10703}
10704template <typename Derived>
10707 return C;
10708}
10709template <typename Derived>
10712 return C;
10713}
10714
10715template <typename Derived>
10716OMPClause *
10718 // No need to rebuild this clause, no template-dependent parameters.
10719 return C;
10720}
10721
10722template <typename Derived>
10723OMPClause *
10725 // No need to rebuild this clause, no template-dependent parameters.
10726 return C;
10727}
10728
10729template <typename Derived>
10730OMPClause *
10732 // No need to rebuild this clause, no template-dependent parameters.
10733 return C;
10734}
10735
10736template <typename Derived>
10737OMPClause *
10739 // No need to rebuild this clause, no template-dependent parameters.
10740 return C;
10741}
10742
10743template <typename Derived>
10744OMPClause *
10746 // No need to rebuild this clause, no template-dependent parameters.
10747 return C;
10748}
10749
10750template <typename Derived>
10752 // No need to rebuild this clause, no template-dependent parameters.
10753 return C;
10754}
10755
10756template <typename Derived>
10757OMPClause *
10759 // No need to rebuild this clause, no template-dependent parameters.
10760 return C;
10761}
10762
10763template <typename Derived>
10765 // No need to rebuild this clause, no template-dependent parameters.
10766 return C;
10767}
10768
10769template <typename Derived>
10770OMPClause *
10772 // No need to rebuild this clause, no template-dependent parameters.
10773 return C;
10774}
10775
10776template <typename Derived>
10778 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10779 if (IVR.isInvalid())
10780 return nullptr;
10781
10782 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10783 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10784 for (Expr *E : llvm::drop_begin(C->varlist())) {
10785 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10786 if (ER.isInvalid())
10787 return nullptr;
10788 InteropInfo.PreferTypes.push_back(ER.get());
10789 }
10790 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10791 C->getBeginLoc(), C->getLParenLoc(),
10792 C->getVarLoc(), C->getEndLoc());
10793}
10794
10795template <typename Derived>
10797 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10798 if (ER.isInvalid())
10799 return nullptr;
10800 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10801 C->getLParenLoc(), C->getVarLoc(),
10802 C->getEndLoc());
10803}
10804
10805template <typename Derived>
10806OMPClause *
10808 ExprResult ER;
10809 if (Expr *IV = C->getInteropVar()) {
10810 ER = getDerived().TransformExpr(IV);
10811 if (ER.isInvalid())
10812 return nullptr;
10813 }
10814 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10815 C->getLParenLoc(), C->getVarLoc(),
10816 C->getEndLoc());
10817}
10818
10819template <typename Derived>
10820OMPClause *
10822 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10823 if (Cond.isInvalid())
10824 return nullptr;
10825 return getDerived().RebuildOMPNovariantsClause(
10826 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10827}
10828
10829template <typename Derived>
10830OMPClause *
10832 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10833 if (Cond.isInvalid())
10834 return nullptr;
10835 return getDerived().RebuildOMPNocontextClause(
10836 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10837}
10838
10839template <typename Derived>
10840OMPClause *
10842 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10843 if (ThreadID.isInvalid())
10844 return nullptr;
10845 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10846 C->getLParenLoc(), C->getEndLoc());
10847}
10848
10849template <typename Derived>
10851 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10852 if (E.isInvalid())
10853 return nullptr;
10854 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10855 C->getLParenLoc(), C->getEndLoc());
10856}
10857
10858template <typename Derived>
10861 llvm_unreachable("unified_address clause cannot appear in dependent context");
10862}
10863
10864template <typename Derived>
10867 llvm_unreachable(
10868 "unified_shared_memory clause cannot appear in dependent context");
10869}
10870
10871template <typename Derived>
10874 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10875}
10876
10877template <typename Derived>
10880 llvm_unreachable(
10881 "dynamic_allocators clause cannot appear in dependent context");
10882}
10883
10884template <typename Derived>
10887 llvm_unreachable(
10888 "atomic_default_mem_order clause cannot appear in dependent context");
10889}
10890
10891template <typename Derived>
10892OMPClause *
10894 llvm_unreachable("self_maps clause cannot appear in dependent context");
10895}
10896
10897template <typename Derived>
10899 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10900 C->getBeginLoc(), C->getLParenLoc(),
10901 C->getEndLoc());
10902}
10903
10904template <typename Derived>
10905OMPClause *
10907 return getDerived().RebuildOMPSeverityClause(
10908 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10909 C->getLParenLoc(), C->getEndLoc());
10910}
10911
10912template <typename Derived>
10913OMPClause *
10915 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10916 if (E.isInvalid())
10917 return nullptr;
10918 return getDerived().RebuildOMPMessageClause(
10919 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10920}
10921
10922template <typename Derived>
10923OMPClause *
10926 Vars.reserve(C->varlist_size());
10927 for (auto *VE : C->varlist()) {
10928 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10929 if (EVar.isInvalid())
10930 return nullptr;
10931 Vars.push_back(EVar.get());
10932 }
10933 return getDerived().RebuildOMPPrivateClause(
10934 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10935}
10936
10937template <typename Derived>
10941 Vars.reserve(C->varlist_size());
10942 for (auto *VE : C->varlist()) {
10943 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10944 if (EVar.isInvalid())
10945 return nullptr;
10946 Vars.push_back(EVar.get());
10947 }
10948 return getDerived().RebuildOMPFirstprivateClause(
10949 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10950}
10951
10952template <typename Derived>
10953OMPClause *
10956 Vars.reserve(C->varlist_size());
10957 for (auto *VE : C->varlist()) {
10958 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10959 if (EVar.isInvalid())
10960 return nullptr;
10961 Vars.push_back(EVar.get());
10962 }
10963 return getDerived().RebuildOMPLastprivateClause(
10964 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10965 C->getLParenLoc(), C->getEndLoc());
10966}
10967
10968template <typename Derived>
10969OMPClause *
10972 Vars.reserve(C->varlist_size());
10973 for (auto *VE : C->varlist()) {
10974 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10975 if (EVar.isInvalid())
10976 return nullptr;
10977 Vars.push_back(EVar.get());
10978 }
10979 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10980 C->getLParenLoc(), C->getEndLoc());
10981}
10982
10983template <typename Derived>
10984OMPClause *
10987 Vars.reserve(C->varlist_size());
10988 for (auto *VE : C->varlist()) {
10989 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10990 if (EVar.isInvalid())
10991 return nullptr;
10992 Vars.push_back(EVar.get());
10993 }
10994 CXXScopeSpec ReductionIdScopeSpec;
10995 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10996
10997 DeclarationNameInfo NameInfo = C->getNameInfo();
10998 if (NameInfo.getName()) {
10999 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11000 if (!NameInfo.getName())
11001 return nullptr;
11002 }
11003 // Build a list of all UDR decls with the same names ranged by the Scopes.
11004 // The Scope boundary is a duplication of the previous decl.
11005 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11006 for (auto *E : C->reduction_ops()) {
11007 // Transform all the decls.
11008 if (E) {
11009 auto *ULE = cast<UnresolvedLookupExpr>(E);
11010 UnresolvedSet<8> Decls;
11011 for (auto *D : ULE->decls()) {
11012 NamedDecl *InstD =
11013 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11014 Decls.addDecl(InstD, InstD->getAccess());
11015 }
11016 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11017 SemaRef.Context, /*NamingClass=*/nullptr,
11018 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11019 /*ADL=*/true, Decls.begin(), Decls.end(),
11020 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11021 } else
11022 UnresolvedReductions.push_back(nullptr);
11023 }
11024 return getDerived().RebuildOMPReductionClause(
11025 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11026 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11027 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11028}
11029
11030template <typename Derived>
11034 Vars.reserve(C->varlist_size());
11035 for (auto *VE : C->varlist()) {
11036 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11037 if (EVar.isInvalid())
11038 return nullptr;
11039 Vars.push_back(EVar.get());
11040 }
11041 CXXScopeSpec ReductionIdScopeSpec;
11042 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11043
11044 DeclarationNameInfo NameInfo = C->getNameInfo();
11045 if (NameInfo.getName()) {
11046 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11047 if (!NameInfo.getName())
11048 return nullptr;
11049 }
11050 // Build a list of all UDR decls with the same names ranged by the Scopes.
11051 // The Scope boundary is a duplication of the previous decl.
11052 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11053 for (auto *E : C->reduction_ops()) {
11054 // Transform all the decls.
11055 if (E) {
11056 auto *ULE = cast<UnresolvedLookupExpr>(E);
11057 UnresolvedSet<8> Decls;
11058 for (auto *D : ULE->decls()) {
11059 NamedDecl *InstD =
11060 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11061 Decls.addDecl(InstD, InstD->getAccess());
11062 }
11063 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11064 SemaRef.Context, /*NamingClass=*/nullptr,
11065 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11066 /*ADL=*/true, Decls.begin(), Decls.end(),
11067 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11068 } else
11069 UnresolvedReductions.push_back(nullptr);
11070 }
11071 return getDerived().RebuildOMPTaskReductionClause(
11072 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11073 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11074}
11075
11076template <typename Derived>
11077OMPClause *
11080 Vars.reserve(C->varlist_size());
11081 for (auto *VE : C->varlist()) {
11082 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11083 if (EVar.isInvalid())
11084 return nullptr;
11085 Vars.push_back(EVar.get());
11086 }
11087 CXXScopeSpec ReductionIdScopeSpec;
11088 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11089
11090 DeclarationNameInfo NameInfo = C->getNameInfo();
11091 if (NameInfo.getName()) {
11092 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11093 if (!NameInfo.getName())
11094 return nullptr;
11095 }
11096 // Build a list of all UDR decls with the same names ranged by the Scopes.
11097 // The Scope boundary is a duplication of the previous decl.
11098 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11099 for (auto *E : C->reduction_ops()) {
11100 // Transform all the decls.
11101 if (E) {
11102 auto *ULE = cast<UnresolvedLookupExpr>(E);
11103 UnresolvedSet<8> Decls;
11104 for (auto *D : ULE->decls()) {
11105 NamedDecl *InstD =
11106 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11107 Decls.addDecl(InstD, InstD->getAccess());
11108 }
11109 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11110 SemaRef.Context, /*NamingClass=*/nullptr,
11111 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11112 /*ADL=*/true, Decls.begin(), Decls.end(),
11113 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11114 } else
11115 UnresolvedReductions.push_back(nullptr);
11116 }
11117 return getDerived().RebuildOMPInReductionClause(
11118 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11119 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11120}
11121
11122template <typename Derived>
11123OMPClause *
11126 Vars.reserve(C->varlist_size());
11127 for (auto *VE : C->varlist()) {
11128 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11129 if (EVar.isInvalid())
11130 return nullptr;
11131 Vars.push_back(EVar.get());
11132 }
11133 ExprResult Step = getDerived().TransformExpr(C->getStep());
11134 if (Step.isInvalid())
11135 return nullptr;
11136 return getDerived().RebuildOMPLinearClause(
11137 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11138 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11139 C->getEndLoc());
11140}
11141
11142template <typename Derived>
11143OMPClause *
11146 Vars.reserve(C->varlist_size());
11147 for (auto *VE : C->varlist()) {
11148 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11149 if (EVar.isInvalid())
11150 return nullptr;
11151 Vars.push_back(EVar.get());
11152 }
11153 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11154 if (Alignment.isInvalid())
11155 return nullptr;
11156 return getDerived().RebuildOMPAlignedClause(
11157 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11158 C->getColonLoc(), C->getEndLoc());
11159}
11160
11161template <typename Derived>
11162OMPClause *
11165 Vars.reserve(C->varlist_size());
11166 for (auto *VE : C->varlist()) {
11167 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11168 if (EVar.isInvalid())
11169 return nullptr;
11170 Vars.push_back(EVar.get());
11171 }
11172 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11173 C->getLParenLoc(), C->getEndLoc());
11174}
11175
11176template <typename Derived>
11177OMPClause *
11180 Vars.reserve(C->varlist_size());
11181 for (auto *VE : C->varlist()) {
11182 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11183 if (EVar.isInvalid())
11184 return nullptr;
11185 Vars.push_back(EVar.get());
11186 }
11187 return getDerived().RebuildOMPCopyprivateClause(
11188 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11189}
11190
11191template <typename Derived>
11194 Vars.reserve(C->varlist_size());
11195 for (auto *VE : C->varlist()) {
11196 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11197 if (EVar.isInvalid())
11198 return nullptr;
11199 Vars.push_back(EVar.get());
11200 }
11201 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11202 C->getLParenLoc(), C->getEndLoc());
11203}
11204
11205template <typename Derived>
11206OMPClause *
11208 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11209 if (E.isInvalid())
11210 return nullptr;
11211 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11212 C->getLParenLoc(), C->getEndLoc());
11213}
11214
11215template <typename Derived>
11216OMPClause *
11219 Expr *DepModifier = C->getModifier();
11220 if (DepModifier) {
11221 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11222 if (DepModRes.isInvalid())
11223 return nullptr;
11224 DepModifier = DepModRes.get();
11225 }
11226 Vars.reserve(C->varlist_size());
11227 for (auto *VE : C->varlist()) {
11228 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11229 if (EVar.isInvalid())
11230 return nullptr;
11231 Vars.push_back(EVar.get());
11232 }
11233 return getDerived().RebuildOMPDependClause(
11234 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11235 C->getOmpAllMemoryLoc()},
11236 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11237}
11238
11239template <typename Derived>
11240OMPClause *
11242 ExprResult E = getDerived().TransformExpr(C->getDevice());
11243 if (E.isInvalid())
11244 return nullptr;
11245 return getDerived().RebuildOMPDeviceClause(
11246 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11247 C->getModifierLoc(), C->getEndLoc());
11248}
11249
11250template <typename Derived, class T>
11253 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11254 DeclarationNameInfo &MapperIdInfo,
11255 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11256 // Transform expressions in the list.
11257 Vars.reserve(C->varlist_size());
11258 for (auto *VE : C->varlist()) {
11259 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11260 if (EVar.isInvalid())
11261 return true;
11262 Vars.push_back(EVar.get());
11263 }
11264 // Transform mapper scope specifier and identifier.
11265 NestedNameSpecifierLoc QualifierLoc;
11266 if (C->getMapperQualifierLoc()) {
11267 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11268 C->getMapperQualifierLoc());
11269 if (!QualifierLoc)
11270 return true;
11271 }
11272 MapperIdScopeSpec.Adopt(QualifierLoc);
11273 MapperIdInfo = C->getMapperIdInfo();
11274 if (MapperIdInfo.getName()) {
11275 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11276 if (!MapperIdInfo.getName())
11277 return true;
11278 }
11279 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11280 // the previous user-defined mapper lookup in dependent environment.
11281 for (auto *E : C->mapperlists()) {
11282 // Transform all the decls.
11283 if (E) {
11284 auto *ULE = cast<UnresolvedLookupExpr>(E);
11285 UnresolvedSet<8> Decls;
11286 for (auto *D : ULE->decls()) {
11287 NamedDecl *InstD =
11288 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11289 Decls.addDecl(InstD, InstD->getAccess());
11290 }
11291 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11292 TT.getSema().Context, /*NamingClass=*/nullptr,
11293 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11294 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11295 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11296 } else {
11297 UnresolvedMappers.push_back(nullptr);
11298 }
11299 }
11300 return false;
11301}
11302
11303template <typename Derived>
11304OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11305 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11307 Expr *IteratorModifier = C->getIteratorModifier();
11308 if (IteratorModifier) {
11309 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11310 if (MapModRes.isInvalid())
11311 return nullptr;
11312 IteratorModifier = MapModRes.get();
11313 }
11314 CXXScopeSpec MapperIdScopeSpec;
11315 DeclarationNameInfo MapperIdInfo;
11316 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11318 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11319 return nullptr;
11320 return getDerived().RebuildOMPMapClause(
11321 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11322 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11323 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11324}
11325
11326template <typename Derived>
11327OMPClause *
11329 Expr *Allocator = C->getAllocator();
11330 if (Allocator) {
11331 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11332 if (AllocatorRes.isInvalid())
11333 return nullptr;
11334 Allocator = AllocatorRes.get();
11335 }
11336 Expr *Alignment = C->getAlignment();
11337 if (Alignment) {
11338 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11339 if (AlignmentRes.isInvalid())
11340 return nullptr;
11341 Alignment = AlignmentRes.get();
11342 }
11344 Vars.reserve(C->varlist_size());
11345 for (auto *VE : C->varlist()) {
11346 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11347 if (EVar.isInvalid())
11348 return nullptr;
11349 Vars.push_back(EVar.get());
11350 }
11351 return getDerived().RebuildOMPAllocateClause(
11352 Allocator, Alignment, C->getFirstAllocateModifier(),
11353 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11354 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11355 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11356}
11357
11358template <typename Derived>
11359OMPClause *
11362 Vars.reserve(C->varlist_size());
11363 for (auto *VE : C->varlist()) {
11364 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11365 if (EVar.isInvalid())
11366 return nullptr;
11367 Vars.push_back(EVar.get());
11368 }
11369 return getDerived().RebuildOMPNumTeamsClause(
11370 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11371}
11372
11373template <typename Derived>
11374OMPClause *
11377 Vars.reserve(C->varlist_size());
11378 for (auto *VE : C->varlist()) {
11379 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11380 if (EVar.isInvalid())
11381 return nullptr;
11382 Vars.push_back(EVar.get());
11383 }
11384 return getDerived().RebuildOMPThreadLimitClause(
11385 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11386}
11387
11388template <typename Derived>
11389OMPClause *
11391 ExprResult E = getDerived().TransformExpr(C->getPriority());
11392 if (E.isInvalid())
11393 return nullptr;
11394 return getDerived().RebuildOMPPriorityClause(
11395 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11396}
11397
11398template <typename Derived>
11399OMPClause *
11401 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11402 if (E.isInvalid())
11403 return nullptr;
11404 return getDerived().RebuildOMPGrainsizeClause(
11405 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11406 C->getModifierLoc(), C->getEndLoc());
11407}
11408
11409template <typename Derived>
11410OMPClause *
11412 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11413 if (E.isInvalid())
11414 return nullptr;
11415 return getDerived().RebuildOMPNumTasksClause(
11416 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11417 C->getModifierLoc(), C->getEndLoc());
11418}
11419
11420template <typename Derived>
11422 ExprResult E = getDerived().TransformExpr(C->getHint());
11423 if (E.isInvalid())
11424 return nullptr;
11425 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11426 C->getLParenLoc(), C->getEndLoc());
11427}
11428
11429template <typename Derived>
11432 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11433 if (E.isInvalid())
11434 return nullptr;
11435 return getDerived().RebuildOMPDistScheduleClause(
11436 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11437 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11438}
11439
11440template <typename Derived>
11441OMPClause *
11443 // Rebuild Defaultmap Clause since we need to invoke the checking of
11444 // defaultmap(none:variable-category) after template initialization.
11445 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11446 C->getDefaultmapKind(),
11447 C->getBeginLoc(),
11448 C->getLParenLoc(),
11449 C->getDefaultmapModifierLoc(),
11450 C->getDefaultmapKindLoc(),
11451 C->getEndLoc());
11452}
11453
11454template <typename Derived>
11456 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11458 CXXScopeSpec MapperIdScopeSpec;
11459 DeclarationNameInfo MapperIdInfo;
11460 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11462 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11463 return nullptr;
11464 return getDerived().RebuildOMPToClause(
11465 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11466 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11467}
11468
11469template <typename Derived>
11471 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11473 CXXScopeSpec MapperIdScopeSpec;
11474 DeclarationNameInfo MapperIdInfo;
11475 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11477 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11478 return nullptr;
11479 return getDerived().RebuildOMPFromClause(
11480 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11481 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11482}
11483
11484template <typename Derived>
11488 Vars.reserve(C->varlist_size());
11489 for (auto *VE : C->varlist()) {
11490 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11491 if (EVar.isInvalid())
11492 return nullptr;
11493 Vars.push_back(EVar.get());
11494 }
11495 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11496 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11497}
11498
11499template <typename Derived>
11503 Vars.reserve(C->varlist_size());
11504 for (auto *VE : C->varlist()) {
11505 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11506 if (EVar.isInvalid())
11507 return nullptr;
11508 Vars.push_back(EVar.get());
11509 }
11510 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11511 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11512}
11513
11514template <typename Derived>
11515OMPClause *
11518 Vars.reserve(C->varlist_size());
11519 for (auto *VE : C->varlist()) {
11520 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11521 if (EVar.isInvalid())
11522 return nullptr;
11523 Vars.push_back(EVar.get());
11524 }
11525 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11526 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11527}
11528
11529template <typename Derived>
11533 Vars.reserve(C->varlist_size());
11534 for (auto *VE : C->varlist()) {
11535 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11536 if (EVar.isInvalid())
11537 return nullptr;
11538 Vars.push_back(EVar.get());
11539 }
11540 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11541 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11542}
11543
11544template <typename Derived>
11545OMPClause *
11548 Vars.reserve(C->varlist_size());
11549 for (auto *VE : C->varlist()) {
11550 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11551 if (EVar.isInvalid())
11552 return nullptr;
11553 Vars.push_back(EVar.get());
11554 }
11555 return getDerived().RebuildOMPNontemporalClause(
11556 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11557}
11558
11559template <typename Derived>
11560OMPClause *
11563 Vars.reserve(C->varlist_size());
11564 for (auto *VE : C->varlist()) {
11565 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11566 if (EVar.isInvalid())
11567 return nullptr;
11568 Vars.push_back(EVar.get());
11569 }
11570 return getDerived().RebuildOMPInclusiveClause(
11571 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11572}
11573
11574template <typename Derived>
11575OMPClause *
11578 Vars.reserve(C->varlist_size());
11579 for (auto *VE : C->varlist()) {
11580 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11581 if (EVar.isInvalid())
11582 return nullptr;
11583 Vars.push_back(EVar.get());
11584 }
11585 return getDerived().RebuildOMPExclusiveClause(
11586 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11587}
11588
11589template <typename Derived>
11593 Data.reserve(C->getNumberOfAllocators());
11594 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11595 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11596 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11597 if (Allocator.isInvalid())
11598 continue;
11599 ExprResult AllocatorTraits;
11600 if (Expr *AT = D.AllocatorTraits) {
11601 AllocatorTraits = getDerived().TransformExpr(AT);
11602 if (AllocatorTraits.isInvalid())
11603 continue;
11604 }
11605 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11606 NewD.Allocator = Allocator.get();
11607 NewD.AllocatorTraits = AllocatorTraits.get();
11608 NewD.LParenLoc = D.LParenLoc;
11609 NewD.RParenLoc = D.RParenLoc;
11610 }
11611 return getDerived().RebuildOMPUsesAllocatorsClause(
11612 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11613}
11614
11615template <typename Derived>
11616OMPClause *
11618 SmallVector<Expr *, 4> Locators;
11619 Locators.reserve(C->varlist_size());
11620 ExprResult ModifierRes;
11621 if (Expr *Modifier = C->getModifier()) {
11622 ModifierRes = getDerived().TransformExpr(Modifier);
11623 if (ModifierRes.isInvalid())
11624 return nullptr;
11625 }
11626 for (Expr *E : C->varlist()) {
11627 ExprResult Locator = getDerived().TransformExpr(E);
11628 if (Locator.isInvalid())
11629 continue;
11630 Locators.push_back(Locator.get());
11631 }
11632 return getDerived().RebuildOMPAffinityClause(
11633 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11634 ModifierRes.get(), Locators);
11635}
11636
11637template <typename Derived>
11639 return getDerived().RebuildOMPOrderClause(
11640 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11641 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11642}
11643
11644template <typename Derived>
11646 return getDerived().RebuildOMPBindClause(
11647 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11648 C->getLParenLoc(), C->getEndLoc());
11649}
11650
11651template <typename Derived>
11654 ExprResult Size = getDerived().TransformExpr(C->getSize());
11655 if (Size.isInvalid())
11656 return nullptr;
11657 return getDerived().RebuildOMPXDynCGroupMemClause(
11658 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11659}
11660
11661template <typename Derived>
11662OMPClause *
11665 Vars.reserve(C->varlist_size());
11666 for (auto *VE : C->varlist()) {
11667 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11668 if (EVar.isInvalid())
11669 return nullptr;
11670 Vars.push_back(EVar.get());
11671 }
11672 return getDerived().RebuildOMPDoacrossClause(
11673 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11674 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11675}
11676
11677template <typename Derived>
11678OMPClause *
11681 for (auto *A : C->getAttrs())
11682 NewAttrs.push_back(getDerived().TransformAttr(A));
11683 return getDerived().RebuildOMPXAttributeClause(
11684 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11685}
11686
11687template <typename Derived>
11689 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11690}
11691
11692//===----------------------------------------------------------------------===//
11693// OpenACC transformation
11694//===----------------------------------------------------------------------===//
11695namespace {
11696template <typename Derived>
11697class OpenACCClauseTransform final
11698 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11699 TreeTransform<Derived> &Self;
11700 ArrayRef<const OpenACCClause *> ExistingClauses;
11701 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11702 OpenACCClause *NewClause = nullptr;
11703
11704 ExprResult VisitVar(Expr *VarRef) {
11705 ExprResult Res = Self.TransformExpr(VarRef);
11706
11707 if (!Res.isUsable())
11708 return Res;
11709
11710 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11711 ParsedClause.getClauseKind(),
11712 Res.get());
11713
11714 return Res;
11715 }
11716
11717 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11718 llvm::SmallVector<Expr *> InstantiatedVarList;
11719 for (Expr *CurVar : VarList) {
11720 ExprResult VarRef = VisitVar(CurVar);
11721
11722 if (VarRef.isUsable())
11723 InstantiatedVarList.push_back(VarRef.get());
11724 }
11725
11726 return InstantiatedVarList;
11727 }
11728
11729public:
11730 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11731 ArrayRef<const OpenACCClause *> ExistingClauses,
11732 SemaOpenACC::OpenACCParsedClause &PC)
11733 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11734
11735 OpenACCClause *CreatedClause() const { return NewClause; }
11736
11737#define VISIT_CLAUSE(CLAUSE_NAME) \
11738 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11739#include "clang/Basic/OpenACCClauses.def"
11740};
11741
11742template <typename Derived>
11743void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11744 const OpenACCDefaultClause &C) {
11745 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11746
11747 NewClause = OpenACCDefaultClause::Create(
11748 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11749 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11750 ParsedClause.getEndLoc());
11751}
11752
11753template <typename Derived>
11754void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11755 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11756 assert(Cond && "If constructed with invalid Condition");
11757 Sema::ConditionResult Res = Self.TransformCondition(
11758 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11759
11760 if (Res.isInvalid() || !Res.get().second)
11761 return;
11762
11763 ParsedClause.setConditionDetails(Res.get().second);
11764
11765 NewClause = OpenACCIfClause::Create(
11766 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11767 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11768 ParsedClause.getEndLoc());
11769}
11770
11771template <typename Derived>
11772void OpenACCClauseTransform<Derived>::VisitSelfClause(
11773 const OpenACCSelfClause &C) {
11774
11775 // If this is an 'update' 'self' clause, this is actually a var list instead.
11776 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11777 llvm::SmallVector<Expr *> InstantiatedVarList;
11778 for (Expr *CurVar : C.getVarList()) {
11779 ExprResult Res = Self.TransformExpr(CurVar);
11780
11781 if (!Res.isUsable())
11782 continue;
11783
11784 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11785 ParsedClause.getClauseKind(),
11786 Res.get());
11787
11788 if (Res.isUsable())
11789 InstantiatedVarList.push_back(Res.get());
11790 }
11791
11792 ParsedClause.setVarListDetails(InstantiatedVarList,
11794
11795 NewClause = OpenACCSelfClause::Create(
11796 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11797 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11798 ParsedClause.getEndLoc());
11799 } else {
11800
11801 if (C.hasConditionExpr()) {
11802 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11804 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11806
11807 if (Res.isInvalid() || !Res.get().second)
11808 return;
11809
11810 ParsedClause.setConditionDetails(Res.get().second);
11811 }
11812
11813 NewClause = OpenACCSelfClause::Create(
11814 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11815 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11816 ParsedClause.getEndLoc());
11817 }
11818}
11819
11820template <typename Derived>
11821void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11822 const OpenACCNumGangsClause &C) {
11823 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11824
11825 for (Expr *CurIntExpr : C.getIntExprs()) {
11826 ExprResult Res = Self.TransformExpr(CurIntExpr);
11827
11828 if (!Res.isUsable())
11829 return;
11830
11831 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11832 C.getClauseKind(),
11833 C.getBeginLoc(), Res.get());
11834 if (!Res.isUsable())
11835 return;
11836
11837 InstantiatedIntExprs.push_back(Res.get());
11838 }
11839
11840 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11842 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11843 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11844 ParsedClause.getEndLoc());
11845}
11846
11847template <typename Derived>
11848void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11849 const OpenACCPrivateClause &C) {
11850 llvm::SmallVector<Expr *> InstantiatedVarList;
11852
11853 for (const auto [RefExpr, InitRecipe] :
11854 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11855 ExprResult VarRef = VisitVar(RefExpr);
11856
11857 if (VarRef.isUsable()) {
11858 InstantiatedVarList.push_back(VarRef.get());
11859
11860 // We only have to create a new one if it is dependent, and Sema won't
11861 // make one of these unless the type is non-dependent.
11862 if (InitRecipe.isSet())
11863 InitRecipes.push_back(InitRecipe);
11864 else
11865 InitRecipes.push_back(
11866 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
11867 }
11868 }
11869 ParsedClause.setVarListDetails(InstantiatedVarList,
11871
11872 NewClause = OpenACCPrivateClause::Create(
11873 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11874 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11875 ParsedClause.getEndLoc());
11876}
11877
11878template <typename Derived>
11879void OpenACCClauseTransform<Derived>::VisitHostClause(
11880 const OpenACCHostClause &C) {
11881 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11883
11884 NewClause = OpenACCHostClause::Create(
11885 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11886 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11887 ParsedClause.getEndLoc());
11888}
11889
11890template <typename Derived>
11891void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11892 const OpenACCDeviceClause &C) {
11893 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11895
11896 NewClause = OpenACCDeviceClause::Create(
11897 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11898 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11899 ParsedClause.getEndLoc());
11900}
11901
11902template <typename Derived>
11903void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11905 llvm::SmallVector<Expr *> InstantiatedVarList;
11907
11908 for (const auto [RefExpr, InitRecipe] :
11909 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11910 ExprResult VarRef = VisitVar(RefExpr);
11911
11912 if (VarRef.isUsable()) {
11913 InstantiatedVarList.push_back(VarRef.get());
11914
11915 // We only have to create a new one if it is dependent, and Sema won't
11916 // make one of these unless the type is non-dependent.
11917 if (InitRecipe.isSet())
11918 InitRecipes.push_back(InitRecipe);
11919 else
11920 InitRecipes.push_back(
11921 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
11922 VarRef.get()));
11923 }
11924 }
11925 ParsedClause.setVarListDetails(InstantiatedVarList,
11927
11929 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11930 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11931 ParsedClause.getEndLoc());
11932}
11933
11934template <typename Derived>
11935void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11936 const OpenACCNoCreateClause &C) {
11937 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11939
11941 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11942 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11943 ParsedClause.getEndLoc());
11944}
11945
11946template <typename Derived>
11947void OpenACCClauseTransform<Derived>::VisitPresentClause(
11948 const OpenACCPresentClause &C) {
11949 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11951
11952 NewClause = OpenACCPresentClause::Create(
11953 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11954 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11955 ParsedClause.getEndLoc());
11956}
11957
11958template <typename Derived>
11959void OpenACCClauseTransform<Derived>::VisitCopyClause(
11960 const OpenACCCopyClause &C) {
11961 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11962 C.getModifierList());
11963
11964 NewClause = OpenACCCopyClause::Create(
11965 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11966 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11967 ParsedClause.getModifierList(), ParsedClause.getVarList(),
11968 ParsedClause.getEndLoc());
11969}
11970
11971template <typename Derived>
11972void OpenACCClauseTransform<Derived>::VisitLinkClause(
11973 const OpenACCLinkClause &C) {
11974 llvm_unreachable("link clause not valid unless a decl transform");
11975}
11976
11977template <typename Derived>
11978void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
11980 llvm_unreachable("device_resident clause not valid unless a decl transform");
11981}
11982template <typename Derived>
11983void OpenACCClauseTransform<Derived>::VisitNoHostClause(
11984 const OpenACCNoHostClause &C) {
11985 llvm_unreachable("nohost clause not valid unless a decl transform");
11986}
11987template <typename Derived>
11988void OpenACCClauseTransform<Derived>::VisitBindClause(
11989 const OpenACCBindClause &C) {
11990 llvm_unreachable("bind clause not valid unless a decl transform");
11991}
11992
11993template <typename Derived>
11994void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11995 const OpenACCCopyInClause &C) {
11996 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11997 C.getModifierList());
11998
11999 NewClause = OpenACCCopyInClause::Create(
12000 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12001 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12002 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12003 ParsedClause.getEndLoc());
12004}
12005
12006template <typename Derived>
12007void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12008 const OpenACCCopyOutClause &C) {
12009 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12010 C.getModifierList());
12011
12012 NewClause = OpenACCCopyOutClause::Create(
12013 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12014 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12015 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12016 ParsedClause.getEndLoc());
12017}
12018
12019template <typename Derived>
12020void OpenACCClauseTransform<Derived>::VisitCreateClause(
12021 const OpenACCCreateClause &C) {
12022 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12023 C.getModifierList());
12024
12025 NewClause = OpenACCCreateClause::Create(
12026 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12027 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12028 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12029 ParsedClause.getEndLoc());
12030}
12031template <typename Derived>
12032void OpenACCClauseTransform<Derived>::VisitAttachClause(
12033 const OpenACCAttachClause &C) {
12034 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12035
12036 // Ensure each var is a pointer type.
12037 llvm::erase_if(VarList, [&](Expr *E) {
12038 return Self.getSema().OpenACC().CheckVarIsPointerType(
12040 });
12041
12042 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12043 NewClause = OpenACCAttachClause::Create(
12044 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12045 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12046 ParsedClause.getEndLoc());
12047}
12048
12049template <typename Derived>
12050void OpenACCClauseTransform<Derived>::VisitDetachClause(
12051 const OpenACCDetachClause &C) {
12052 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12053
12054 // Ensure each var is a pointer type.
12055 llvm::erase_if(VarList, [&](Expr *E) {
12056 return Self.getSema().OpenACC().CheckVarIsPointerType(
12058 });
12059
12060 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12061 NewClause = OpenACCDetachClause::Create(
12062 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12063 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12064 ParsedClause.getEndLoc());
12065}
12066
12067template <typename Derived>
12068void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12069 const OpenACCDeleteClause &C) {
12070 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12072 NewClause = OpenACCDeleteClause::Create(
12073 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12074 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12075 ParsedClause.getEndLoc());
12076}
12077
12078template <typename Derived>
12079void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12080 const OpenACCUseDeviceClause &C) {
12081 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12084 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12085 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12086 ParsedClause.getEndLoc());
12087}
12088
12089template <typename Derived>
12090void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12091 const OpenACCDevicePtrClause &C) {
12092 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12093
12094 // Ensure each var is a pointer type.
12095 llvm::erase_if(VarList, [&](Expr *E) {
12096 return Self.getSema().OpenACC().CheckVarIsPointerType(
12098 });
12099
12100 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12102 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12103 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12104 ParsedClause.getEndLoc());
12105}
12106
12107template <typename Derived>
12108void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12109 const OpenACCNumWorkersClause &C) {
12110 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12111 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12112
12113 ExprResult Res = Self.TransformExpr(IntExpr);
12114 if (!Res.isUsable())
12115 return;
12116
12117 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12118 C.getClauseKind(),
12119 C.getBeginLoc(), Res.get());
12120 if (!Res.isUsable())
12121 return;
12122
12123 ParsedClause.setIntExprDetails(Res.get());
12125 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12126 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12127 ParsedClause.getEndLoc());
12128}
12129
12130template <typename Derived>
12131void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12132 const OpenACCDeviceNumClause &C) {
12133 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12134 assert(IntExpr && "device_num clause constructed with invalid int expr");
12135
12136 ExprResult Res = Self.TransformExpr(IntExpr);
12137 if (!Res.isUsable())
12138 return;
12139
12140 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12141 C.getClauseKind(),
12142 C.getBeginLoc(), Res.get());
12143 if (!Res.isUsable())
12144 return;
12145
12146 ParsedClause.setIntExprDetails(Res.get());
12148 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12149 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12150 ParsedClause.getEndLoc());
12151}
12152
12153template <typename Derived>
12154void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12156 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12157 assert(IntExpr && "default_async clause constructed with invalid int expr");
12158
12159 ExprResult Res = Self.TransformExpr(IntExpr);
12160 if (!Res.isUsable())
12161 return;
12162
12163 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12164 C.getClauseKind(),
12165 C.getBeginLoc(), Res.get());
12166 if (!Res.isUsable())
12167 return;
12168
12169 ParsedClause.setIntExprDetails(Res.get());
12171 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12172 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12173 ParsedClause.getEndLoc());
12174}
12175
12176template <typename Derived>
12177void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12179 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12180 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12181
12182 ExprResult Res = Self.TransformExpr(IntExpr);
12183 if (!Res.isUsable())
12184 return;
12185
12186 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12187 C.getClauseKind(),
12188 C.getBeginLoc(), Res.get());
12189 if (!Res.isUsable())
12190 return;
12191
12192 ParsedClause.setIntExprDetails(Res.get());
12194 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12195 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12196 ParsedClause.getEndLoc());
12197}
12198
12199template <typename Derived>
12200void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12201 const OpenACCAsyncClause &C) {
12202 if (C.hasIntExpr()) {
12203 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12204 if (!Res.isUsable())
12205 return;
12206
12207 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12208 C.getClauseKind(),
12209 C.getBeginLoc(), Res.get());
12210 if (!Res.isUsable())
12211 return;
12212 ParsedClause.setIntExprDetails(Res.get());
12213 }
12214
12215 NewClause = OpenACCAsyncClause::Create(
12216 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12217 ParsedClause.getLParenLoc(),
12218 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12219 : nullptr,
12220 ParsedClause.getEndLoc());
12221}
12222
12223template <typename Derived>
12224void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12225 const OpenACCWorkerClause &C) {
12226 if (C.hasIntExpr()) {
12227 // restrictions on this expression are all "does it exist in certain
12228 // situations" that are not possible to be dependent, so the only check we
12229 // have is that it transforms, and is an int expression.
12230 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12231 if (!Res.isUsable())
12232 return;
12233
12234 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12235 C.getClauseKind(),
12236 C.getBeginLoc(), Res.get());
12237 if (!Res.isUsable())
12238 return;
12239 ParsedClause.setIntExprDetails(Res.get());
12240 }
12241
12242 NewClause = OpenACCWorkerClause::Create(
12243 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12244 ParsedClause.getLParenLoc(),
12245 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12246 : nullptr,
12247 ParsedClause.getEndLoc());
12248}
12249
12250template <typename Derived>
12251void OpenACCClauseTransform<Derived>::VisitVectorClause(
12252 const OpenACCVectorClause &C) {
12253 if (C.hasIntExpr()) {
12254 // restrictions on this expression are all "does it exist in certain
12255 // situations" that are not possible to be dependent, so the only check we
12256 // have is that it transforms, and is an int expression.
12257 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12258 if (!Res.isUsable())
12259 return;
12260
12261 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12262 C.getClauseKind(),
12263 C.getBeginLoc(), Res.get());
12264 if (!Res.isUsable())
12265 return;
12266 ParsedClause.setIntExprDetails(Res.get());
12267 }
12268
12269 NewClause = OpenACCVectorClause::Create(
12270 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12271 ParsedClause.getLParenLoc(),
12272 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12273 : nullptr,
12274 ParsedClause.getEndLoc());
12275}
12276
12277template <typename Derived>
12278void OpenACCClauseTransform<Derived>::VisitWaitClause(
12279 const OpenACCWaitClause &C) {
12280 if (C.hasExprs()) {
12281 Expr *DevNumExpr = nullptr;
12282 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12283
12284 // Instantiate devnum expr if it exists.
12285 if (C.getDevNumExpr()) {
12286 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12287 if (!Res.isUsable())
12288 return;
12289 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12290 C.getClauseKind(),
12291 C.getBeginLoc(), Res.get());
12292 if (!Res.isUsable())
12293 return;
12294
12295 DevNumExpr = Res.get();
12296 }
12297
12298 // Instantiate queue ids.
12299 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12300 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12301 if (!Res.isUsable())
12302 return;
12303 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12304 C.getClauseKind(),
12305 C.getBeginLoc(), Res.get());
12306 if (!Res.isUsable())
12307 return;
12308
12309 InstantiatedQueueIdExprs.push_back(Res.get());
12310 }
12311
12312 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12313 std::move(InstantiatedQueueIdExprs));
12314 }
12315
12316 NewClause = OpenACCWaitClause::Create(
12317 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12318 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12319 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12320 ParsedClause.getEndLoc());
12321}
12322
12323template <typename Derived>
12324void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12325 const OpenACCDeviceTypeClause &C) {
12326 // Nothing to transform here, just create a new version of 'C'.
12328 Self.getSema().getASTContext(), C.getClauseKind(),
12329 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12330 C.getArchitectures(), ParsedClause.getEndLoc());
12331}
12332
12333template <typename Derived>
12334void OpenACCClauseTransform<Derived>::VisitAutoClause(
12335 const OpenACCAutoClause &C) {
12336 // Nothing to do, so just create a new node.
12337 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12338 ParsedClause.getBeginLoc(),
12339 ParsedClause.getEndLoc());
12340}
12341
12342template <typename Derived>
12343void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12344 const OpenACCIndependentClause &C) {
12345 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12346 ParsedClause.getBeginLoc(),
12347 ParsedClause.getEndLoc());
12348}
12349
12350template <typename Derived>
12351void OpenACCClauseTransform<Derived>::VisitSeqClause(
12352 const OpenACCSeqClause &C) {
12353 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12354 ParsedClause.getBeginLoc(),
12355 ParsedClause.getEndLoc());
12356}
12357template <typename Derived>
12358void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12359 const OpenACCFinalizeClause &C) {
12360 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12361 ParsedClause.getBeginLoc(),
12362 ParsedClause.getEndLoc());
12363}
12364
12365template <typename Derived>
12366void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12367 const OpenACCIfPresentClause &C) {
12368 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12369 ParsedClause.getBeginLoc(),
12370 ParsedClause.getEndLoc());
12371}
12372
12373template <typename Derived>
12374void OpenACCClauseTransform<Derived>::VisitReductionClause(
12375 const OpenACCReductionClause &C) {
12376 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12377 SmallVector<Expr *> ValidVars;
12379
12380 for (const auto [Var, OrigRecipe] :
12381 llvm::zip(TransformedVars, C.getRecipes())) {
12382 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12383 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12384 if (Res.isUsable()) {
12385 ValidVars.push_back(Res.get());
12386
12387 if (OrigRecipe.isSet())
12388 Recipes.push_back(OrigRecipe);
12389 else
12390 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12391 C.getReductionOp(), Res.get()));
12392 }
12393 }
12394
12395 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12396 ExistingClauses, ParsedClause.getDirectiveKind(),
12397 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12398 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12399}
12400
12401template <typename Derived>
12402void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12403 const OpenACCCollapseClause &C) {
12404 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12405 assert(LoopCount && "collapse clause constructed with invalid loop count");
12406
12407 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12408
12409 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12410 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12411 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12412
12413 NewLoopCount =
12414 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12415
12416 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12418 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12419 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12420 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12421}
12422
12423template <typename Derived>
12424void OpenACCClauseTransform<Derived>::VisitTileClause(
12425 const OpenACCTileClause &C) {
12426
12427 llvm::SmallVector<Expr *> TransformedExprs;
12428
12429 for (Expr *E : C.getSizeExprs()) {
12430 ExprResult NewSizeExpr = Self.TransformExpr(E);
12431
12432 if (!NewSizeExpr.isUsable())
12433 return;
12434
12435 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12436 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12437 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12438
12439 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12440
12441 if (!NewSizeExpr.isUsable())
12442 return;
12443 TransformedExprs.push_back(NewSizeExpr.get());
12444 }
12445
12446 ParsedClause.setIntExprDetails(TransformedExprs);
12447 NewClause = OpenACCTileClause::Create(
12448 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12449 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12450 ParsedClause.getEndLoc());
12451}
12452template <typename Derived>
12453void OpenACCClauseTransform<Derived>::VisitGangClause(
12454 const OpenACCGangClause &C) {
12455 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12456 llvm::SmallVector<Expr *> TransformedIntExprs;
12457
12458 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12459 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12460 if (!ER.isUsable())
12461 continue;
12462
12463 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12464 ParsedClause.getDirectiveKind(),
12465 C.getExpr(I).first, ER.get());
12466 if (!ER.isUsable())
12467 continue;
12468 TransformedGangKinds.push_back(C.getExpr(I).first);
12469 TransformedIntExprs.push_back(ER.get());
12470 }
12471
12472 NewClause = Self.getSema().OpenACC().CheckGangClause(
12473 ParsedClause.getDirectiveKind(), ExistingClauses,
12474 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12475 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12476}
12477} // namespace
12478template <typename Derived>
12479OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12480 ArrayRef<const OpenACCClause *> ExistingClauses,
12481 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12482
12484 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12485 ParsedClause.setEndLoc(OldClause->getEndLoc());
12486
12487 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12488 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12489
12490 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12491 ParsedClause};
12492 Transform.Visit(OldClause);
12493
12494 return Transform.CreatedClause();
12495}
12496
12497template <typename Derived>
12499TreeTransform<Derived>::TransformOpenACCClauseList(
12501 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12502 for (const auto *Clause : OldClauses) {
12503 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12504 TransformedClauses, DirKind, Clause))
12505 TransformedClauses.push_back(TransformedClause);
12506 }
12507 return TransformedClauses;
12508}
12509
12510template <typename Derived>
12513 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12514
12515 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12516 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12517 C->clauses());
12518
12519 if (getSema().OpenACC().ActOnStartStmtDirective(
12520 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12521 return StmtError();
12522
12523 // Transform Structured Block.
12524 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12525 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12526 C->clauses(), TransformedClauses);
12527 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12528 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12529 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12530
12531 return getDerived().RebuildOpenACCComputeConstruct(
12532 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12533 C->getEndLoc(), TransformedClauses, StrBlock);
12534}
12535
12536template <typename Derived>
12539
12540 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12541
12542 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12543 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12544 C->clauses());
12545
12546 if (getSema().OpenACC().ActOnStartStmtDirective(
12547 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12548 return StmtError();
12549
12550 // Transform Loop.
12551 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12552 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12553 C->clauses(), TransformedClauses);
12554 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12555 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12556 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12557
12558 return getDerived().RebuildOpenACCLoopConstruct(
12559 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12560 TransformedClauses, Loop);
12561}
12562
12563template <typename Derived>
12565 OpenACCCombinedConstruct *C) {
12566 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12567
12568 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12569 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12570 C->clauses());
12571
12572 if (getSema().OpenACC().ActOnStartStmtDirective(
12573 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12574 return StmtError();
12575
12576 // Transform Loop.
12577 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12578 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12579 C->clauses(), TransformedClauses);
12580 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12581 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12582 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12583
12584 return getDerived().RebuildOpenACCCombinedConstruct(
12585 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12586 C->getEndLoc(), TransformedClauses, Loop);
12587}
12588
12589template <typename Derived>
12592 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12593
12594 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12595 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12596 C->clauses());
12597 if (getSema().OpenACC().ActOnStartStmtDirective(
12598 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12599 return StmtError();
12600
12601 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12602 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12603 C->clauses(), TransformedClauses);
12604 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12605 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12606 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12607
12608 return getDerived().RebuildOpenACCDataConstruct(
12609 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12610 TransformedClauses, StrBlock);
12611}
12612
12613template <typename Derived>
12615 OpenACCEnterDataConstruct *C) {
12616 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12617
12618 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12619 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12620 C->clauses());
12621 if (getSema().OpenACC().ActOnStartStmtDirective(
12622 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12623 return StmtError();
12624
12625 return getDerived().RebuildOpenACCEnterDataConstruct(
12626 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12627 TransformedClauses);
12628}
12629
12630template <typename Derived>
12632 OpenACCExitDataConstruct *C) {
12633 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12634
12635 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12636 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12637 C->clauses());
12638 if (getSema().OpenACC().ActOnStartStmtDirective(
12639 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12640 return StmtError();
12641
12642 return getDerived().RebuildOpenACCExitDataConstruct(
12643 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12644 TransformedClauses);
12645}
12646
12647template <typename Derived>
12649 OpenACCHostDataConstruct *C) {
12650 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12651
12652 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12653 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12654 C->clauses());
12655 if (getSema().OpenACC().ActOnStartStmtDirective(
12656 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12657 return StmtError();
12658
12659 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12660 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12661 C->clauses(), TransformedClauses);
12662 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12663 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12664 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12665
12666 return getDerived().RebuildOpenACCHostDataConstruct(
12667 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12668 TransformedClauses, StrBlock);
12669}
12670
12671template <typename Derived>
12674 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12675
12676 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12677 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12678 C->clauses());
12679 if (getSema().OpenACC().ActOnStartStmtDirective(
12680 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12681 return StmtError();
12682
12683 return getDerived().RebuildOpenACCInitConstruct(
12684 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12685 TransformedClauses);
12686}
12687
12688template <typename Derived>
12690 OpenACCShutdownConstruct *C) {
12691 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12692
12693 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12694 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12695 C->clauses());
12696 if (getSema().OpenACC().ActOnStartStmtDirective(
12697 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12698 return StmtError();
12699
12700 return getDerived().RebuildOpenACCShutdownConstruct(
12701 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12702 TransformedClauses);
12703}
12704template <typename Derived>
12707 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12708
12709 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12710 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12711 C->clauses());
12712 if (getSema().OpenACC().ActOnStartStmtDirective(
12713 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12714 return StmtError();
12715
12716 return getDerived().RebuildOpenACCSetConstruct(
12717 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12718 TransformedClauses);
12719}
12720
12721template <typename Derived>
12723 OpenACCUpdateConstruct *C) {
12724 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12725
12726 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12727 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12728 C->clauses());
12729 if (getSema().OpenACC().ActOnStartStmtDirective(
12730 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12731 return StmtError();
12732
12733 return getDerived().RebuildOpenACCUpdateConstruct(
12734 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12735 TransformedClauses);
12736}
12737
12738template <typename Derived>
12741 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12742
12743 ExprResult DevNumExpr;
12744 if (C->hasDevNumExpr()) {
12745 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12746
12747 if (DevNumExpr.isUsable())
12748 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12750 C->getBeginLoc(), DevNumExpr.get());
12751 }
12752
12753 llvm::SmallVector<Expr *> QueueIdExprs;
12754
12755 for (Expr *QE : C->getQueueIdExprs()) {
12756 assert(QE && "Null queue id expr?");
12757 ExprResult NewEQ = getDerived().TransformExpr(QE);
12758
12759 if (!NewEQ.isUsable())
12760 break;
12761 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12763 C->getBeginLoc(), NewEQ.get());
12764 if (NewEQ.isUsable())
12765 QueueIdExprs.push_back(NewEQ.get());
12766 }
12767
12768 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12769 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12770 C->clauses());
12771
12772 if (getSema().OpenACC().ActOnStartStmtDirective(
12773 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12774 return StmtError();
12775
12776 return getDerived().RebuildOpenACCWaitConstruct(
12777 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12778 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12779 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12780}
12781template <typename Derived>
12783 OpenACCCacheConstruct *C) {
12784 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12785
12786 llvm::SmallVector<Expr *> TransformedVarList;
12787 for (Expr *Var : C->getVarList()) {
12788 assert(Var && "Null var listexpr?");
12789
12790 ExprResult NewVar = getDerived().TransformExpr(Var);
12791
12792 if (!NewVar.isUsable())
12793 break;
12794
12795 NewVar = getSema().OpenACC().ActOnVar(
12796 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
12797 if (!NewVar.isUsable())
12798 break;
12799
12800 TransformedVarList.push_back(NewVar.get());
12801 }
12802
12803 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12804 C->getBeginLoc(), {}))
12805 return StmtError();
12806
12807 return getDerived().RebuildOpenACCCacheConstruct(
12808 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12809 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
12810 C->getEndLoc());
12811}
12812
12813template <typename Derived>
12815 OpenACCAtomicConstruct *C) {
12816 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12817
12818 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12819 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12820 C->clauses());
12821
12822 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12823 C->getBeginLoc(), {}))
12824 return StmtError();
12825
12826 // Transform Associated Stmt.
12827 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12828 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
12829
12830 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
12831 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
12832 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
12833 AssocStmt);
12834
12835 return getDerived().RebuildOpenACCAtomicConstruct(
12836 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
12837 C->getEndLoc(), TransformedClauses, AssocStmt);
12838}
12839
12840template <typename Derived>
12843 if (getDerived().AlwaysRebuild())
12844 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12845 // Nothing can ever change, so there is never anything to transform.
12846 return E;
12847}
12848
12849//===----------------------------------------------------------------------===//
12850// Expression transformation
12851//===----------------------------------------------------------------------===//
12852template<typename Derived>
12855 return TransformExpr(E->getSubExpr());
12856}
12857
12858template <typename Derived>
12861 if (!E->isTypeDependent())
12862 return E;
12863
12864 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12865
12866 if (!NewT)
12867 return ExprError();
12868
12869 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12870 return E;
12871
12872 return getDerived().RebuildSYCLUniqueStableNameExpr(
12873 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12874}
12875
12876template<typename Derived>
12879 if (!E->isTypeDependent())
12880 return E;
12881
12882 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12883 E->getIdentKind());
12884}
12885
12886template<typename Derived>
12889 NestedNameSpecifierLoc QualifierLoc;
12890 if (E->getQualifierLoc()) {
12891 QualifierLoc
12892 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12893 if (!QualifierLoc)
12894 return ExprError();
12895 }
12896
12897 ValueDecl *ND
12898 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12899 E->getDecl()));
12900 if (!ND || ND->isInvalidDecl())
12901 return ExprError();
12902
12903 NamedDecl *Found = ND;
12904 if (E->getFoundDecl() != E->getDecl()) {
12905 Found = cast_or_null<NamedDecl>(
12906 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12907 if (!Found)
12908 return ExprError();
12909 }
12910
12911 DeclarationNameInfo NameInfo = E->getNameInfo();
12912 if (NameInfo.getName()) {
12913 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12914 if (!NameInfo.getName())
12915 return ExprError();
12916 }
12917
12918 if (!getDerived().AlwaysRebuild() &&
12919 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12920 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12921 Found == E->getFoundDecl() &&
12922 NameInfo.getName() == E->getDecl()->getDeclName() &&
12923 !E->hasExplicitTemplateArgs()) {
12924
12925 // Mark it referenced in the new context regardless.
12926 // FIXME: this is a bit instantiation-specific.
12927 SemaRef.MarkDeclRefReferenced(E);
12928
12929 return E;
12930 }
12931
12932 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12933 if (E->hasExplicitTemplateArgs()) {
12934 TemplateArgs = &TransArgs;
12935 TransArgs.setLAngleLoc(E->getLAngleLoc());
12936 TransArgs.setRAngleLoc(E->getRAngleLoc());
12937 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12938 E->getNumTemplateArgs(),
12939 TransArgs))
12940 return ExprError();
12941 }
12942
12943 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12944 Found, TemplateArgs);
12945}
12946
12947template<typename Derived>
12950 return E;
12951}
12952
12953template <typename Derived>
12955 FixedPointLiteral *E) {
12956 return E;
12957}
12958
12959template<typename Derived>
12962 return E;
12963}
12964
12965template<typename Derived>
12968 return E;
12969}
12970
12971template<typename Derived>
12974 return E;
12975}
12976
12977template<typename Derived>
12980 return E;
12981}
12982
12983template<typename Derived>
12986 return getDerived().TransformCallExpr(E);
12987}
12988
12989template<typename Derived>
12992 ExprResult ControllingExpr;
12993 TypeSourceInfo *ControllingType = nullptr;
12994 if (E->isExprPredicate())
12995 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12996 else
12997 ControllingType = getDerived().TransformType(E->getControllingType());
12998
12999 if (ControllingExpr.isInvalid() && !ControllingType)
13000 return ExprError();
13001
13002 SmallVector<Expr *, 4> AssocExprs;
13004 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13005 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13006 if (TSI) {
13007 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13008 if (!AssocType)
13009 return ExprError();
13010 AssocTypes.push_back(AssocType);
13011 } else {
13012 AssocTypes.push_back(nullptr);
13013 }
13014
13015 ExprResult AssocExpr =
13016 getDerived().TransformExpr(Assoc.getAssociationExpr());
13017 if (AssocExpr.isInvalid())
13018 return ExprError();
13019 AssocExprs.push_back(AssocExpr.get());
13020 }
13021
13022 if (!ControllingType)
13023 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13024 E->getDefaultLoc(),
13025 E->getRParenLoc(),
13026 ControllingExpr.get(),
13027 AssocTypes,
13028 AssocExprs);
13029 return getDerived().RebuildGenericSelectionExpr(
13030 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13031 ControllingType, AssocTypes, AssocExprs);
13032}
13033
13034template<typename Derived>
13037 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13038 if (SubExpr.isInvalid())
13039 return ExprError();
13040
13041 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13042 return E;
13043
13044 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13045 E->getRParen());
13046}
13047
13048/// The operand of a unary address-of operator has special rules: it's
13049/// allowed to refer to a non-static member of a class even if there's no 'this'
13050/// object available.
13051template<typename Derived>
13054 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13055 return getDerived().TransformDependentScopeDeclRefExpr(
13056 DRE, /*IsAddressOfOperand=*/true, nullptr);
13057 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13058 return getDerived().TransformUnresolvedLookupExpr(
13059 ULE, /*IsAddressOfOperand=*/true);
13060 else
13061 return getDerived().TransformExpr(E);
13062}
13063
13064template<typename Derived>
13067 ExprResult SubExpr;
13068 if (E->getOpcode() == UO_AddrOf)
13069 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13070 else
13071 SubExpr = TransformExpr(E->getSubExpr());
13072 if (SubExpr.isInvalid())
13073 return ExprError();
13074
13075 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13076 return E;
13077
13078 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13079 E->getOpcode(),
13080 SubExpr.get());
13081}
13082
13083template<typename Derived>
13085TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13086 // Transform the type.
13087 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13088 if (!Type)
13089 return ExprError();
13090
13091 // Transform all of the components into components similar to what the
13092 // parser uses.
13093 // FIXME: It would be slightly more efficient in the non-dependent case to
13094 // just map FieldDecls, rather than requiring the rebuilder to look for
13095 // the fields again. However, __builtin_offsetof is rare enough in
13096 // template code that we don't care.
13097 bool ExprChanged = false;
13098 typedef Sema::OffsetOfComponent Component;
13099 SmallVector<Component, 4> Components;
13100 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13101 const OffsetOfNode &ON = E->getComponent(I);
13102 Component Comp;
13103 Comp.isBrackets = true;
13104 Comp.LocStart = ON.getSourceRange().getBegin();
13105 Comp.LocEnd = ON.getSourceRange().getEnd();
13106 switch (ON.getKind()) {
13107 case OffsetOfNode::Array: {
13108 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13109 ExprResult Index = getDerived().TransformExpr(FromIndex);
13110 if (Index.isInvalid())
13111 return ExprError();
13112
13113 ExprChanged = ExprChanged || Index.get() != FromIndex;
13114 Comp.isBrackets = true;
13115 Comp.U.E = Index.get();
13116 break;
13117 }
13118
13121 Comp.isBrackets = false;
13122 Comp.U.IdentInfo = ON.getFieldName();
13123 if (!Comp.U.IdentInfo)
13124 continue;
13125
13126 break;
13127
13128 case OffsetOfNode::Base:
13129 // Will be recomputed during the rebuild.
13130 continue;
13131 }
13132
13133 Components.push_back(Comp);
13134 }
13135
13136 // If nothing changed, retain the existing expression.
13137 if (!getDerived().AlwaysRebuild() &&
13138 Type == E->getTypeSourceInfo() &&
13139 !ExprChanged)
13140 return E;
13141
13142 // Build a new offsetof expression.
13143 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
13144 Components, E->getRParenLoc());
13145}
13146
13147template<typename Derived>
13150 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13151 "opaque value expression requires transformation");
13152 return E;
13153}
13154
13155template <typename Derived>
13158 bool Changed = false;
13159 for (Expr *C : E->subExpressions()) {
13160 ExprResult NewC = getDerived().TransformExpr(C);
13161 if (NewC.isInvalid())
13162 return ExprError();
13163 Children.push_back(NewC.get());
13164
13165 Changed |= NewC.get() != C;
13166 }
13167 if (!getDerived().AlwaysRebuild() && !Changed)
13168 return E;
13169 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13170 Children, E->getType());
13171}
13172
13173template<typename Derived>
13176 // Rebuild the syntactic form. The original syntactic form has
13177 // opaque-value expressions in it, so strip those away and rebuild
13178 // the result. This is a really awful way of doing this, but the
13179 // better solution (rebuilding the semantic expressions and
13180 // rebinding OVEs as necessary) doesn't work; we'd need
13181 // TreeTransform to not strip away implicit conversions.
13182 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13183 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13184 if (result.isInvalid()) return ExprError();
13185
13186 // If that gives us a pseudo-object result back, the pseudo-object
13187 // expression must have been an lvalue-to-rvalue conversion which we
13188 // should reapply.
13189 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13190 result = SemaRef.PseudoObject().checkRValue(result.get());
13191
13192 return result;
13193}
13194
13195template<typename Derived>
13199 if (E->isArgumentType()) {
13200 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13201
13202 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13203 if (!NewT)
13204 return ExprError();
13205
13206 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13207 return E;
13208
13209 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13210 E->getKind(),
13211 E->getSourceRange());
13212 }
13213
13214 // C++0x [expr.sizeof]p1:
13215 // The operand is either an expression, which is an unevaluated operand
13216 // [...]
13220
13221 // Try to recover if we have something like sizeof(T::X) where X is a type.
13222 // Notably, there must be *exactly* one set of parens if X is a type.
13223 TypeSourceInfo *RecoveryTSI = nullptr;
13224 ExprResult SubExpr;
13225 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13226 if (auto *DRE =
13227 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13228 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13229 PE, DRE, false, &RecoveryTSI);
13230 else
13231 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13232
13233 if (RecoveryTSI) {
13234 return getDerived().RebuildUnaryExprOrTypeTrait(
13235 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13236 } else if (SubExpr.isInvalid())
13237 return ExprError();
13238
13239 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13240 return E;
13241
13242 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13243 E->getOperatorLoc(),
13244 E->getKind(),
13245 E->getSourceRange());
13246}
13247
13248template<typename Derived>
13251 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13252 if (LHS.isInvalid())
13253 return ExprError();
13254
13255 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13256 if (RHS.isInvalid())
13257 return ExprError();
13258
13259
13260 if (!getDerived().AlwaysRebuild() &&
13261 LHS.get() == E->getLHS() &&
13262 RHS.get() == E->getRHS())
13263 return E;
13264
13265 return getDerived().RebuildArraySubscriptExpr(
13266 LHS.get(),
13267 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13268}
13269
13270template <typename Derived>
13273 ExprResult Base = getDerived().TransformExpr(E->getBase());
13274 if (Base.isInvalid())
13275 return ExprError();
13276
13277 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13278 if (RowIdx.isInvalid())
13279 return ExprError();
13280
13281 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13282 if (ColumnIdx.isInvalid())
13283 return ExprError();
13284
13285 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13286 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13287 return E;
13288
13289 return getDerived().RebuildMatrixSubscriptExpr(
13290 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13291}
13292
13293template <typename Derived>
13296 ExprResult Base = getDerived().TransformExpr(E->getBase());
13297 if (Base.isInvalid())
13298 return ExprError();
13299
13300 ExprResult LowerBound;
13301 if (E->getLowerBound()) {
13302 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13303 if (LowerBound.isInvalid())
13304 return ExprError();
13305 }
13306
13307 ExprResult Length;
13308 if (E->getLength()) {
13309 Length = getDerived().TransformExpr(E->getLength());
13310 if (Length.isInvalid())
13311 return ExprError();
13312 }
13313
13314 ExprResult Stride;
13315 if (E->isOMPArraySection()) {
13316 if (Expr *Str = E->getStride()) {
13317 Stride = getDerived().TransformExpr(Str);
13318 if (Stride.isInvalid())
13319 return ExprError();
13320 }
13321 }
13322
13323 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13324 LowerBound.get() == E->getLowerBound() &&
13325 Length.get() == E->getLength() &&
13326 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13327 return E;
13328
13329 return getDerived().RebuildArraySectionExpr(
13330 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13331 LowerBound.get(), E->getColonLocFirst(),
13332 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13333 Length.get(), Stride.get(), E->getRBracketLoc());
13334}
13335
13336template <typename Derived>
13339 ExprResult Base = getDerived().TransformExpr(E->getBase());
13340 if (Base.isInvalid())
13341 return ExprError();
13342
13344 bool ErrorFound = false;
13345 for (Expr *Dim : E->getDimensions()) {
13346 ExprResult DimRes = getDerived().TransformExpr(Dim);
13347 if (DimRes.isInvalid()) {
13348 ErrorFound = true;
13349 continue;
13350 }
13351 Dims.push_back(DimRes.get());
13352 }
13353
13354 if (ErrorFound)
13355 return ExprError();
13356 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13357 E->getRParenLoc(), Dims,
13358 E->getBracketsRanges());
13359}
13360
13361template <typename Derived>
13364 unsigned NumIterators = E->numOfIterators();
13366
13367 bool ErrorFound = false;
13368 bool NeedToRebuild = getDerived().AlwaysRebuild();
13369 for (unsigned I = 0; I < NumIterators; ++I) {
13370 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13371 Data[I].DeclIdent = D->getIdentifier();
13372 Data[I].DeclIdentLoc = D->getLocation();
13373 if (D->getLocation() == D->getBeginLoc()) {
13374 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13375 "Implicit type must be int.");
13376 } else {
13377 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13378 QualType DeclTy = getDerived().TransformType(D->getType());
13379 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13380 }
13381 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13382 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13383 ExprResult End = getDerived().TransformExpr(Range.End);
13384 ExprResult Step = getDerived().TransformExpr(Range.Step);
13385 ErrorFound = ErrorFound ||
13386 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13387 !Data[I].Type.get().isNull())) ||
13388 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13389 if (ErrorFound)
13390 continue;
13391 Data[I].Range.Begin = Begin.get();
13392 Data[I].Range.End = End.get();
13393 Data[I].Range.Step = Step.get();
13394 Data[I].AssignLoc = E->getAssignLoc(I);
13395 Data[I].ColonLoc = E->getColonLoc(I);
13396 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13397 NeedToRebuild =
13398 NeedToRebuild ||
13399 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13400 D->getType().getTypePtrOrNull()) ||
13401 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13402 Range.Step != Data[I].Range.Step;
13403 }
13404 if (ErrorFound)
13405 return ExprError();
13406 if (!NeedToRebuild)
13407 return E;
13408
13409 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13410 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13411 if (!Res.isUsable())
13412 return Res;
13413 auto *IE = cast<OMPIteratorExpr>(Res.get());
13414 for (unsigned I = 0; I < NumIterators; ++I)
13415 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13416 IE->getIteratorDecl(I));
13417 return Res;
13418}
13419
13420template<typename Derived>
13423 // Transform the callee.
13424 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13425 if (Callee.isInvalid())
13426 return ExprError();
13427
13428 // Transform arguments.
13429 bool ArgChanged = false;
13431 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13432 &ArgChanged))
13433 return ExprError();
13434
13435 if (!getDerived().AlwaysRebuild() &&
13436 Callee.get() == E->getCallee() &&
13437 !ArgChanged)
13438 return SemaRef.MaybeBindToTemporary(E);
13439
13440 // FIXME: Wrong source location information for the '('.
13441 SourceLocation FakeLParenLoc
13442 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13443
13444 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13445 if (E->hasStoredFPFeatures()) {
13446 FPOptionsOverride NewOverrides = E->getFPFeatures();
13447 getSema().CurFPFeatures =
13448 NewOverrides.applyOverrides(getSema().getLangOpts());
13449 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13450 }
13451
13452 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13453 Args,
13454 E->getRParenLoc());
13455}
13456
13457template<typename Derived>
13460 ExprResult Base = getDerived().TransformExpr(E->getBase());
13461 if (Base.isInvalid())
13462 return ExprError();
13463
13464 NestedNameSpecifierLoc QualifierLoc;
13465 if (E->hasQualifier()) {
13466 QualifierLoc
13467 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13468
13469 if (!QualifierLoc)
13470 return ExprError();
13471 }
13472 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13473
13475 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13476 E->getMemberDecl()));
13477 if (!Member)
13478 return ExprError();
13479
13480 NamedDecl *FoundDecl = E->getFoundDecl();
13481 if (FoundDecl == E->getMemberDecl()) {
13482 FoundDecl = Member;
13483 } else {
13484 FoundDecl = cast_or_null<NamedDecl>(
13485 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13486 if (!FoundDecl)
13487 return ExprError();
13488 }
13489
13490 if (!getDerived().AlwaysRebuild() &&
13491 Base.get() == E->getBase() &&
13492 QualifierLoc == E->getQualifierLoc() &&
13493 Member == E->getMemberDecl() &&
13494 FoundDecl == E->getFoundDecl() &&
13495 !E->hasExplicitTemplateArgs()) {
13496
13497 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13498 // for Openmp where the field need to be privatizized in the case.
13499 if (!(isa<CXXThisExpr>(E->getBase()) &&
13500 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13502 // Mark it referenced in the new context regardless.
13503 // FIXME: this is a bit instantiation-specific.
13504 SemaRef.MarkMemberReferenced(E);
13505 return E;
13506 }
13507 }
13508
13509 TemplateArgumentListInfo TransArgs;
13510 if (E->hasExplicitTemplateArgs()) {
13511 TransArgs.setLAngleLoc(E->getLAngleLoc());
13512 TransArgs.setRAngleLoc(E->getRAngleLoc());
13513 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13514 E->getNumTemplateArgs(),
13515 TransArgs))
13516 return ExprError();
13517 }
13518
13519 // FIXME: Bogus source location for the operator
13520 SourceLocation FakeOperatorLoc =
13521 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13522
13523 // FIXME: to do this check properly, we will need to preserve the
13524 // first-qualifier-in-scope here, just in case we had a dependent
13525 // base (and therefore couldn't do the check) and a
13526 // nested-name-qualifier (and therefore could do the lookup).
13527 NamedDecl *FirstQualifierInScope = nullptr;
13528 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13529 if (MemberNameInfo.getName()) {
13530 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13531 if (!MemberNameInfo.getName())
13532 return ExprError();
13533 }
13534
13535 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13536 E->isArrow(),
13537 QualifierLoc,
13538 TemplateKWLoc,
13539 MemberNameInfo,
13540 Member,
13541 FoundDecl,
13542 (E->hasExplicitTemplateArgs()
13543 ? &TransArgs : nullptr),
13544 FirstQualifierInScope);
13545}
13546
13547template<typename Derived>
13550 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13551 if (LHS.isInvalid())
13552 return ExprError();
13553
13554 ExprResult RHS =
13555 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13556 if (RHS.isInvalid())
13557 return ExprError();
13558
13559 if (!getDerived().AlwaysRebuild() &&
13560 LHS.get() == E->getLHS() &&
13561 RHS.get() == E->getRHS())
13562 return E;
13563
13564 if (E->isCompoundAssignmentOp())
13565 // FPFeatures has already been established from trailing storage
13566 return getDerived().RebuildBinaryOperator(
13567 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13568 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13569 FPOptionsOverride NewOverrides(E->getFPFeatures());
13570 getSema().CurFPFeatures =
13571 NewOverrides.applyOverrides(getSema().getLangOpts());
13572 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13573 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13574 LHS.get(), RHS.get());
13575}
13576
13577template <typename Derived>
13580 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13581
13582 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13583 if (LHS.isInvalid())
13584 return ExprError();
13585
13586 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13587 if (RHS.isInvalid())
13588 return ExprError();
13589
13590 // Extract the already-resolved callee declarations so that we can restrict
13591 // ourselves to using them as the unqualified lookup results when rebuilding.
13592 UnresolvedSet<2> UnqualLookups;
13593 bool ChangedAnyLookups = false;
13594 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13595 const_cast<Expr *>(Decomp.InnerBinOp)};
13596 for (Expr *PossibleBinOp : PossibleBinOps) {
13597 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13598 if (!Op)
13599 continue;
13600 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13601 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13602 continue;
13603
13604 // Transform the callee in case we built a call to a local extern
13605 // declaration.
13606 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13607 E->getOperatorLoc(), Callee->getFoundDecl()));
13608 if (!Found)
13609 return ExprError();
13610 if (Found != Callee->getFoundDecl())
13611 ChangedAnyLookups = true;
13612 UnqualLookups.addDecl(Found);
13613 }
13614
13615 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13616 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13617 // Mark all functions used in the rewrite as referenced. Note that when
13618 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13619 // function calls, and/or there might be a user-defined conversion sequence
13620 // applied to the operands of the <.
13621 // FIXME: this is a bit instantiation-specific.
13622 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13623 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13624 return E;
13625 }
13626
13627 return getDerived().RebuildCXXRewrittenBinaryOperator(
13628 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13629}
13630
13631template<typename Derived>
13635 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13636 FPOptionsOverride NewOverrides(E->getFPFeatures());
13637 getSema().CurFPFeatures =
13638 NewOverrides.applyOverrides(getSema().getLangOpts());
13639 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13640 return getDerived().TransformBinaryOperator(E);
13641}
13642
13643template<typename Derived>
13646 // Just rebuild the common and RHS expressions and see whether we
13647 // get any changes.
13648
13649 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13650 if (commonExpr.isInvalid())
13651 return ExprError();
13652
13653 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13654 if (rhs.isInvalid())
13655 return ExprError();
13656
13657 if (!getDerived().AlwaysRebuild() &&
13658 commonExpr.get() == e->getCommon() &&
13659 rhs.get() == e->getFalseExpr())
13660 return e;
13661
13662 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13663 e->getQuestionLoc(),
13664 nullptr,
13665 e->getColonLoc(),
13666 rhs.get());
13667}
13668
13669template<typename Derived>
13672 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13673 if (Cond.isInvalid())
13674 return ExprError();
13675
13676 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13677 if (LHS.isInvalid())
13678 return ExprError();
13679
13680 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13681 if (RHS.isInvalid())
13682 return ExprError();
13683
13684 if (!getDerived().AlwaysRebuild() &&
13685 Cond.get() == E->getCond() &&
13686 LHS.get() == E->getLHS() &&
13687 RHS.get() == E->getRHS())
13688 return E;
13689
13690 return getDerived().RebuildConditionalOperator(Cond.get(),
13691 E->getQuestionLoc(),
13692 LHS.get(),
13693 E->getColonLoc(),
13694 RHS.get());
13695}
13696
13697template<typename Derived>
13700 // Implicit casts are eliminated during transformation, since they
13701 // will be recomputed by semantic analysis after transformation.
13702 return getDerived().TransformExpr(E->getSubExprAsWritten());
13703}
13704
13705template<typename Derived>
13708 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13709 if (!Type)
13710 return ExprError();
13711
13712 ExprResult SubExpr
13713 = getDerived().TransformExpr(E->getSubExprAsWritten());
13714 if (SubExpr.isInvalid())
13715 return ExprError();
13716
13717 if (!getDerived().AlwaysRebuild() &&
13718 Type == E->getTypeInfoAsWritten() &&
13719 SubExpr.get() == E->getSubExpr())
13720 return E;
13721
13722 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13723 Type,
13724 E->getRParenLoc(),
13725 SubExpr.get());
13726}
13727
13728template<typename Derived>
13731 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13732 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13733 if (!NewT)
13734 return ExprError();
13735
13736 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13737 if (Init.isInvalid())
13738 return ExprError();
13739
13740 if (!getDerived().AlwaysRebuild() &&
13741 OldT == NewT &&
13742 Init.get() == E->getInitializer())
13743 return SemaRef.MaybeBindToTemporary(E);
13744
13745 // Note: the expression type doesn't necessarily match the
13746 // type-as-written, but that's okay, because it should always be
13747 // derivable from the initializer.
13748
13749 return getDerived().RebuildCompoundLiteralExpr(
13750 E->getLParenLoc(), NewT,
13751 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13752}
13753
13754template<typename Derived>
13757 ExprResult Base = getDerived().TransformExpr(E->getBase());
13758 if (Base.isInvalid())
13759 return ExprError();
13760
13761 if (!getDerived().AlwaysRebuild() &&
13762 Base.get() == E->getBase())
13763 return E;
13764
13765 // FIXME: Bad source location
13766 SourceLocation FakeOperatorLoc =
13767 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13768 return getDerived().RebuildExtVectorElementExpr(
13769 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13770 E->getAccessor());
13771}
13772
13773template<typename Derived>
13776 if (InitListExpr *Syntactic = E->getSyntacticForm())
13777 E = Syntactic;
13778
13779 bool InitChanged = false;
13780
13783
13785 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13786 Inits, &InitChanged))
13787 return ExprError();
13788
13789 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13790 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13791 // in some cases. We can't reuse it in general, because the syntactic and
13792 // semantic forms are linked, and we can't know that semantic form will
13793 // match even if the syntactic form does.
13794 }
13795
13796 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13797 E->getRBraceLoc());
13798}
13799
13800template<typename Derived>
13803 Designation Desig;
13804
13805 // transform the initializer value
13806 ExprResult Init = getDerived().TransformExpr(E->getInit());
13807 if (Init.isInvalid())
13808 return ExprError();
13809
13810 // transform the designators.
13811 SmallVector<Expr*, 4> ArrayExprs;
13812 bool ExprChanged = false;
13813 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13814 if (D.isFieldDesignator()) {
13815 if (D.getFieldDecl()) {
13816 FieldDecl *Field = cast_or_null<FieldDecl>(
13817 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13818 if (Field != D.getFieldDecl())
13819 // Rebuild the expression when the transformed FieldDecl is
13820 // different to the already assigned FieldDecl.
13821 ExprChanged = true;
13822 if (Field->isAnonymousStructOrUnion())
13823 continue;
13824 } else {
13825 // Ensure that the designator expression is rebuilt when there isn't
13826 // a resolved FieldDecl in the designator as we don't want to assign
13827 // a FieldDecl to a pattern designator that will be instantiated again.
13828 ExprChanged = true;
13829 }
13830 Desig.AddDesignator(Designator::CreateFieldDesignator(
13831 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13832 continue;
13833 }
13834
13835 if (D.isArrayDesignator()) {
13836 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13837 if (Index.isInvalid())
13838 return ExprError();
13839
13840 Desig.AddDesignator(
13841 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13842
13843 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
13844 ArrayExprs.push_back(Index.get());
13845 continue;
13846 }
13847
13848 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13849 ExprResult Start
13850 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13851 if (Start.isInvalid())
13852 return ExprError();
13853
13854 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13855 if (End.isInvalid())
13856 return ExprError();
13857
13858 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13859 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13860
13861 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13862 End.get() != E->getArrayRangeEnd(D);
13863
13864 ArrayExprs.push_back(Start.get());
13865 ArrayExprs.push_back(End.get());
13866 }
13867
13868 if (!getDerived().AlwaysRebuild() &&
13869 Init.get() == E->getInit() &&
13870 !ExprChanged)
13871 return E;
13872
13873 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13874 E->getEqualOrColonLoc(),
13875 E->usesGNUSyntax(), Init.get());
13876}
13877
13878// Seems that if TransformInitListExpr() only works on the syntactic form of an
13879// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13880template<typename Derived>
13884 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13885 "initializer");
13886 return ExprError();
13887}
13888
13889template<typename Derived>
13892 NoInitExpr *E) {
13893 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13894 return ExprError();
13895}
13896
13897template<typename Derived>
13900 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13901 return ExprError();
13902}
13903
13904template<typename Derived>
13907 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13908 return ExprError();
13909}
13910
13911template<typename Derived>
13915 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13916
13917 // FIXME: Will we ever have proper type location here? Will we actually
13918 // need to transform the type?
13919 QualType T = getDerived().TransformType(E->getType());
13920 if (T.isNull())
13921 return ExprError();
13922
13923 if (!getDerived().AlwaysRebuild() &&
13924 T == E->getType())
13925 return E;
13926
13927 return getDerived().RebuildImplicitValueInitExpr(T);
13928}
13929
13930template<typename Derived>
13933 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13934 if (!TInfo)
13935 return ExprError();
13936
13937 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13938 if (SubExpr.isInvalid())
13939 return ExprError();
13940
13941 if (!getDerived().AlwaysRebuild() &&
13942 TInfo == E->getWrittenTypeInfo() &&
13943 SubExpr.get() == E->getSubExpr())
13944 return E;
13945
13946 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13947 TInfo, E->getRParenLoc());
13948}
13949
13950template<typename Derived>
13953 bool ArgumentChanged = false;
13955 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13956 &ArgumentChanged))
13957 return ExprError();
13958
13959 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13960 Inits,
13961 E->getRParenLoc());
13962}
13963
13964/// Transform an address-of-label expression.
13965///
13966/// By default, the transformation of an address-of-label expression always
13967/// rebuilds the expression, so that the label identifier can be resolved to
13968/// the corresponding label statement by semantic analysis.
13969template<typename Derived>
13972 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13973 E->getLabel());
13974 if (!LD)
13975 return ExprError();
13976
13977 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13978 cast<LabelDecl>(LD));
13979}
13980
13981template<typename Derived>
13984 SemaRef.ActOnStartStmtExpr();
13985 StmtResult SubStmt
13986 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13987 if (SubStmt.isInvalid()) {
13988 SemaRef.ActOnStmtExprError();
13989 return ExprError();
13990 }
13991
13992 unsigned OldDepth = E->getTemplateDepth();
13993 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13994
13995 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13996 SubStmt.get() == E->getSubStmt()) {
13997 // Calling this an 'error' is unintuitive, but it does the right thing.
13998 SemaRef.ActOnStmtExprError();
13999 return SemaRef.MaybeBindToTemporary(E);
14000 }
14001
14002 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14003 E->getRParenLoc(), NewDepth);
14004}
14005
14006template<typename Derived>
14009 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14010 if (Cond.isInvalid())
14011 return ExprError();
14012
14013 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14014 if (LHS.isInvalid())
14015 return ExprError();
14016
14017 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14018 if (RHS.isInvalid())
14019 return ExprError();
14020
14021 if (!getDerived().AlwaysRebuild() &&
14022 Cond.get() == E->getCond() &&
14023 LHS.get() == E->getLHS() &&
14024 RHS.get() == E->getRHS())
14025 return E;
14026
14027 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14028 Cond.get(), LHS.get(), RHS.get(),
14029 E->getRParenLoc());
14030}
14031
14032template<typename Derived>
14035 return E;
14036}
14037
14038template<typename Derived>
14041 switch (E->getOperator()) {
14042 case OO_New:
14043 case OO_Delete:
14044 case OO_Array_New:
14045 case OO_Array_Delete:
14046 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14047
14048 case OO_Subscript:
14049 case OO_Call: {
14050 // This is a call to an object's operator().
14051 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14052
14053 // Transform the object itself.
14054 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14055 if (Object.isInvalid())
14056 return ExprError();
14057
14058 // FIXME: Poor location information. Also, if the location for the end of
14059 // the token is within a macro expansion, getLocForEndOfToken() will return
14060 // an invalid source location. If that happens and we have an otherwise
14061 // valid end location, use the valid one instead of the invalid one.
14062 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14063 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14064 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14065 FakeLParenLoc = EndLoc;
14066
14067 // Transform the call arguments.
14069 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14070 Args))
14071 return ExprError();
14072
14073 if (E->getOperator() == OO_Subscript)
14074 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14075 Args, E->getEndLoc());
14076
14077 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14078 E->getEndLoc());
14079 }
14080
14081#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14082 case OO_##Name: \
14083 break;
14084
14085#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14086#include "clang/Basic/OperatorKinds.def"
14087
14088 case OO_Conditional:
14089 llvm_unreachable("conditional operator is not actually overloadable");
14090
14091 case OO_None:
14093 llvm_unreachable("not an overloaded operator?");
14094 }
14095
14097 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14098 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14099 else
14100 First = getDerived().TransformExpr(E->getArg(0));
14101 if (First.isInvalid())
14102 return ExprError();
14103
14104 ExprResult Second;
14105 if (E->getNumArgs() == 2) {
14106 Second =
14107 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14108 if (Second.isInvalid())
14109 return ExprError();
14110 }
14111
14112 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14113 FPOptionsOverride NewOverrides(E->getFPFeatures());
14114 getSema().CurFPFeatures =
14115 NewOverrides.applyOverrides(getSema().getLangOpts());
14116 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14117
14118 Expr *Callee = E->getCallee();
14119 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14120 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14122 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14123 return ExprError();
14124
14125 return getDerived().RebuildCXXOperatorCallExpr(
14126 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14127 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14128 }
14129
14130 UnresolvedSet<1> Functions;
14131 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14132 Callee = ICE->getSubExprAsWritten();
14133 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14134 ValueDecl *VD = cast_or_null<ValueDecl>(
14135 getDerived().TransformDecl(DR->getLocation(), DR));
14136 if (!VD)
14137 return ExprError();
14138
14139 if (!isa<CXXMethodDecl>(VD))
14140 Functions.addDecl(VD);
14141
14142 return getDerived().RebuildCXXOperatorCallExpr(
14143 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14144 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14145}
14146
14147template<typename Derived>
14150 return getDerived().TransformCallExpr(E);
14151}
14152
14153template <typename Derived>
14155 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14156 getSema().CurContext != E->getParentContext();
14157
14158 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14159 return E;
14160
14161 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14162 E->getBeginLoc(), E->getEndLoc(),
14163 getSema().CurContext);
14164}
14165
14166template <typename Derived>
14168 return E;
14169}
14170
14171template<typename Derived>
14174 // Transform the callee.
14175 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14176 if (Callee.isInvalid())
14177 return ExprError();
14178
14179 // Transform exec config.
14180 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14181 if (EC.isInvalid())
14182 return ExprError();
14183
14184 // Transform arguments.
14185 bool ArgChanged = false;
14187 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14188 &ArgChanged))
14189 return ExprError();
14190
14191 if (!getDerived().AlwaysRebuild() &&
14192 Callee.get() == E->getCallee() &&
14193 !ArgChanged)
14194 return SemaRef.MaybeBindToTemporary(E);
14195
14196 // FIXME: Wrong source location information for the '('.
14197 SourceLocation FakeLParenLoc
14198 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14199 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14200 Args,
14201 E->getRParenLoc(), EC.get());
14202}
14203
14204template<typename Derived>
14207 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14208 if (!Type)
14209 return ExprError();
14210
14211 ExprResult SubExpr
14212 = getDerived().TransformExpr(E->getSubExprAsWritten());
14213 if (SubExpr.isInvalid())
14214 return ExprError();
14215
14216 if (!getDerived().AlwaysRebuild() &&
14217 Type == E->getTypeInfoAsWritten() &&
14218 SubExpr.get() == E->getSubExpr())
14219 return E;
14220 return getDerived().RebuildCXXNamedCastExpr(
14223 // FIXME. this should be '(' location
14224 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14225}
14226
14227template<typename Derived>
14230 TypeSourceInfo *TSI =
14231 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14232 if (!TSI)
14233 return ExprError();
14234
14235 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14236 if (Sub.isInvalid())
14237 return ExprError();
14238
14239 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14240 Sub.get(), BCE->getEndLoc());
14241}
14242
14243template<typename Derived>
14245TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14246 return getDerived().TransformCXXNamedCastExpr(E);
14247}
14248
14249template<typename Derived>
14252 return getDerived().TransformCXXNamedCastExpr(E);
14253}
14254
14255template<typename Derived>
14259 return getDerived().TransformCXXNamedCastExpr(E);
14260}
14261
14262template<typename Derived>
14265 return getDerived().TransformCXXNamedCastExpr(E);
14266}
14267
14268template<typename Derived>
14271 return getDerived().TransformCXXNamedCastExpr(E);
14272}
14273
14274template<typename Derived>
14279 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14280 if (!Type)
14281 return ExprError();
14282
14283 ExprResult SubExpr
14284 = getDerived().TransformExpr(E->getSubExprAsWritten());
14285 if (SubExpr.isInvalid())
14286 return ExprError();
14287
14288 if (!getDerived().AlwaysRebuild() &&
14289 Type == E->getTypeInfoAsWritten() &&
14290 SubExpr.get() == E->getSubExpr())
14291 return E;
14292
14293 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14294 E->getLParenLoc(),
14295 SubExpr.get(),
14296 E->getRParenLoc(),
14297 E->isListInitialization());
14298}
14299
14300template<typename Derived>
14303 if (E->isTypeOperand()) {
14304 TypeSourceInfo *TInfo
14305 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14306 if (!TInfo)
14307 return ExprError();
14308
14309 if (!getDerived().AlwaysRebuild() &&
14310 TInfo == E->getTypeOperandSourceInfo())
14311 return E;
14312
14313 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14314 TInfo, E->getEndLoc());
14315 }
14316
14317 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14318 // type. We must not unilaterally enter unevaluated context here, as then
14319 // semantic processing can re-transform an already transformed operand.
14320 Expr *Op = E->getExprOperand();
14322 if (E->isGLValue())
14323 if (auto *RD = Op->getType()->getAsCXXRecordDecl();
14324 RD && RD->isPolymorphic())
14325 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14326
14329
14330 ExprResult SubExpr = getDerived().TransformExpr(Op);
14331 if (SubExpr.isInvalid())
14332 return ExprError();
14333
14334 if (!getDerived().AlwaysRebuild() &&
14335 SubExpr.get() == E->getExprOperand())
14336 return E;
14337
14338 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14339 SubExpr.get(), E->getEndLoc());
14340}
14341
14342template<typename Derived>
14345 if (E->isTypeOperand()) {
14346 TypeSourceInfo *TInfo
14347 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14348 if (!TInfo)
14349 return ExprError();
14350
14351 if (!getDerived().AlwaysRebuild() &&
14352 TInfo == E->getTypeOperandSourceInfo())
14353 return E;
14354
14355 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14356 TInfo, E->getEndLoc());
14357 }
14358
14361
14362 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14363 if (SubExpr.isInvalid())
14364 return ExprError();
14365
14366 if (!getDerived().AlwaysRebuild() &&
14367 SubExpr.get() == E->getExprOperand())
14368 return E;
14369
14370 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14371 SubExpr.get(), E->getEndLoc());
14372}
14373
14374template<typename Derived>
14377 return E;
14378}
14379
14380template<typename Derived>
14384 return E;
14385}
14386
14387template<typename Derived>
14390
14391 // In lambdas, the qualifiers of the type depends of where in
14392 // the call operator `this` appear, and we do not have a good way to
14393 // rebuild this information, so we transform the type.
14394 //
14395 // In other contexts, the type of `this` may be overrided
14396 // for type deduction, so we need to recompute it.
14397 //
14398 // Always recompute the type if we're in the body of a lambda, and
14399 // 'this' is dependent on a lambda's explicit object parameter; we
14400 // also need to always rebuild the expression in this case to clear
14401 // the flag.
14402 QualType T = [&]() {
14403 auto &S = getSema();
14404 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14405 return S.getCurrentThisType();
14406 if (S.getCurLambda())
14407 return getDerived().TransformType(E->getType());
14408 return S.getCurrentThisType();
14409 }();
14410
14411 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14412 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14413 // Mark it referenced in the new context regardless.
14414 // FIXME: this is a bit instantiation-specific.
14415 getSema().MarkThisReferenced(E);
14416 return E;
14417 }
14418
14419 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14420}
14421
14422template<typename Derived>
14425 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14426 if (SubExpr.isInvalid())
14427 return ExprError();
14428
14429 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14430
14431 if (!getDerived().AlwaysRebuild() &&
14432 SubExpr.get() == E->getSubExpr())
14433 return E;
14434
14435 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14436 E->isThrownVariableInScope());
14437}
14438
14439template<typename Derived>
14442 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14443 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14444 if (!Param)
14445 return ExprError();
14446
14447 ExprResult InitRes;
14448 if (E->hasRewrittenInit()) {
14449 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14450 if (InitRes.isInvalid())
14451 return ExprError();
14452 }
14453
14454 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14455 E->getUsedContext() == SemaRef.CurContext &&
14456 InitRes.get() == E->getRewrittenExpr())
14457 return E;
14458
14459 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14460 InitRes.get());
14461}
14462
14463template<typename Derived>
14466 FieldDecl *Field = cast_or_null<FieldDecl>(
14467 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14468 if (!Field)
14469 return ExprError();
14470
14471 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14472 E->getUsedContext() == SemaRef.CurContext)
14473 return E;
14474
14475 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14476}
14477
14478template<typename Derived>
14482 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14483 if (!T)
14484 return ExprError();
14485
14486 if (!getDerived().AlwaysRebuild() &&
14487 T == E->getTypeSourceInfo())
14488 return E;
14489
14490 return getDerived().RebuildCXXScalarValueInitExpr(T,
14491 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14492 E->getRParenLoc());
14493}
14494
14495template<typename Derived>
14498 // Transform the type that we're allocating
14499 TypeSourceInfo *AllocTypeInfo =
14500 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14501 if (!AllocTypeInfo)
14502 return ExprError();
14503
14504 // Transform the size of the array we're allocating (if any).
14505 std::optional<Expr *> ArraySize;
14506 if (E->isArray()) {
14507 ExprResult NewArraySize;
14508 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14509 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14510 if (NewArraySize.isInvalid())
14511 return ExprError();
14512 }
14513 ArraySize = NewArraySize.get();
14514 }
14515
14516 // Transform the placement arguments (if any).
14517 bool ArgumentChanged = false;
14518 SmallVector<Expr*, 8> PlacementArgs;
14519 if (getDerived().TransformExprs(E->getPlacementArgs(),
14520 E->getNumPlacementArgs(), true,
14521 PlacementArgs, &ArgumentChanged))
14522 return ExprError();
14523
14524 // Transform the initializer (if any).
14525 Expr *OldInit = E->getInitializer();
14526 ExprResult NewInit;
14527 if (OldInit)
14528 NewInit = getDerived().TransformInitializer(OldInit, true);
14529 if (NewInit.isInvalid())
14530 return ExprError();
14531
14532 // Transform new operator and delete operator.
14533 FunctionDecl *OperatorNew = nullptr;
14534 if (E->getOperatorNew()) {
14535 OperatorNew = cast_or_null<FunctionDecl>(
14536 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14537 if (!OperatorNew)
14538 return ExprError();
14539 }
14540
14541 FunctionDecl *OperatorDelete = nullptr;
14542 if (E->getOperatorDelete()) {
14543 OperatorDelete = cast_or_null<FunctionDecl>(
14544 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14545 if (!OperatorDelete)
14546 return ExprError();
14547 }
14548
14549 if (!getDerived().AlwaysRebuild() &&
14550 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14551 ArraySize == E->getArraySize() &&
14552 NewInit.get() == OldInit &&
14553 OperatorNew == E->getOperatorNew() &&
14554 OperatorDelete == E->getOperatorDelete() &&
14555 !ArgumentChanged) {
14556 // Mark any declarations we need as referenced.
14557 // FIXME: instantiation-specific.
14558 if (OperatorNew)
14559 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14560 if (OperatorDelete)
14561 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14562
14563 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14564 QualType ElementType
14565 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14566 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
14568 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
14569 }
14570 }
14571
14572 return E;
14573 }
14574
14575 QualType AllocType = AllocTypeInfo->getType();
14576 if (!ArraySize) {
14577 // If no array size was specified, but the new expression was
14578 // instantiated with an array type (e.g., "new T" where T is
14579 // instantiated with "int[4]"), extract the outer bound from the
14580 // array type as our array size. We do this with constant and
14581 // dependently-sized array types.
14582 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14583 if (!ArrayT) {
14584 // Do nothing
14585 } else if (const ConstantArrayType *ConsArrayT
14586 = dyn_cast<ConstantArrayType>(ArrayT)) {
14587 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14588 SemaRef.Context.getSizeType(),
14589 /*FIXME:*/ E->getBeginLoc());
14590 AllocType = ConsArrayT->getElementType();
14591 } else if (const DependentSizedArrayType *DepArrayT
14592 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14593 if (DepArrayT->getSizeExpr()) {
14594 ArraySize = DepArrayT->getSizeExpr();
14595 AllocType = DepArrayT->getElementType();
14596 }
14597 }
14598 }
14599
14600 return getDerived().RebuildCXXNewExpr(
14601 E->getBeginLoc(), E->isGlobalNew(),
14602 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14603 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14604 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14605}
14606
14607template<typename Derived>
14610 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14611 if (Operand.isInvalid())
14612 return ExprError();
14613
14614 // Transform the delete operator, if known.
14615 FunctionDecl *OperatorDelete = nullptr;
14616 if (E->getOperatorDelete()) {
14617 OperatorDelete = cast_or_null<FunctionDecl>(
14618 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14619 if (!OperatorDelete)
14620 return ExprError();
14621 }
14622
14623 if (!getDerived().AlwaysRebuild() &&
14624 Operand.get() == E->getArgument() &&
14625 OperatorDelete == E->getOperatorDelete()) {
14626 // Mark any declarations we need as referenced.
14627 // FIXME: instantiation-specific.
14628 if (OperatorDelete)
14629 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14630
14631 if (!E->getArgument()->isTypeDependent()) {
14632 QualType Destroyed = SemaRef.Context.getBaseElementType(
14633 E->getDestroyedType());
14634 if (auto *Record = Destroyed->getAsCXXRecordDecl())
14635 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
14636 SemaRef.LookupDestructor(Record));
14637 }
14638
14639 return E;
14640 }
14641
14642 return getDerived().RebuildCXXDeleteExpr(
14643 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14644}
14645
14646template<typename Derived>
14650 ExprResult Base = getDerived().TransformExpr(E->getBase());
14651 if (Base.isInvalid())
14652 return ExprError();
14653
14654 ParsedType ObjectTypePtr;
14655 bool MayBePseudoDestructor = false;
14656 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14657 E->getOperatorLoc(),
14658 E->isArrow()? tok::arrow : tok::period,
14659 ObjectTypePtr,
14660 MayBePseudoDestructor);
14661 if (Base.isInvalid())
14662 return ExprError();
14663
14664 QualType ObjectType = ObjectTypePtr.get();
14665 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14666 if (QualifierLoc) {
14667 QualifierLoc
14668 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14669 if (!QualifierLoc)
14670 return ExprError();
14671 }
14672 CXXScopeSpec SS;
14673 SS.Adopt(QualifierLoc);
14674
14676 if (E->getDestroyedTypeInfo()) {
14677 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
14678 E->getDestroyedTypeInfo(), ObjectType,
14679 /*FirstQualifierInScope=*/nullptr);
14680 if (!DestroyedTypeInfo)
14681 return ExprError();
14682 Destroyed = DestroyedTypeInfo;
14683 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14684 // We aren't likely to be able to resolve the identifier down to a type
14685 // now anyway, so just retain the identifier.
14686 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14687 E->getDestroyedTypeLoc());
14688 } else {
14689 // Look for a destructor known with the given name.
14690 ParsedType T = SemaRef.getDestructorName(
14691 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14692 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14693 if (!T)
14694 return ExprError();
14695
14696 Destroyed
14698 E->getDestroyedTypeLoc());
14699 }
14700
14701 TypeSourceInfo *ScopeTypeInfo = nullptr;
14702 if (E->getScopeTypeInfo()) {
14703 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14704 E->getScopeTypeInfo(), ObjectType, nullptr);
14705 if (!ScopeTypeInfo)
14706 return ExprError();
14707 }
14708
14709 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14710 E->getOperatorLoc(),
14711 E->isArrow(),
14712 SS,
14713 ScopeTypeInfo,
14714 E->getColonColonLoc(),
14715 E->getTildeLoc(),
14716 Destroyed);
14717}
14718
14719template <typename Derived>
14721 bool RequiresADL,
14722 LookupResult &R) {
14723 // Transform all the decls.
14724 bool AllEmptyPacks = true;
14725 for (auto *OldD : Old->decls()) {
14726 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14727 if (!InstD) {
14728 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14729 // This can happen because of dependent hiding.
14730 if (isa<UsingShadowDecl>(OldD))
14731 continue;
14732 else {
14733 R.clear();
14734 return true;
14735 }
14736 }
14737
14738 // Expand using pack declarations.
14739 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14740 ArrayRef<NamedDecl*> Decls = SingleDecl;
14741 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14742 Decls = UPD->expansions();
14743
14744 // Expand using declarations.
14745 for (auto *D : Decls) {
14746 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14747 for (auto *SD : UD->shadows())
14748 R.addDecl(SD);
14749 } else {
14750 R.addDecl(D);
14751 }
14752 }
14753
14754 AllEmptyPacks &= Decls.empty();
14755 }
14756
14757 // C++ [temp.res]/8.4.2:
14758 // The program is ill-formed, no diagnostic required, if [...] lookup for
14759 // a name in the template definition found a using-declaration, but the
14760 // lookup in the corresponding scope in the instantiation odoes not find
14761 // any declarations because the using-declaration was a pack expansion and
14762 // the corresponding pack is empty
14763 if (AllEmptyPacks && !RequiresADL) {
14764 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14765 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14766 return true;
14767 }
14768
14769 // Resolve a kind, but don't do any further analysis. If it's
14770 // ambiguous, the callee needs to deal with it.
14771 R.resolveKind();
14772
14773 if (Old->hasTemplateKeyword() && !R.empty()) {
14775 getSema().FilterAcceptableTemplateNames(R,
14776 /*AllowFunctionTemplates=*/true,
14777 /*AllowDependent=*/true);
14778 if (R.empty()) {
14779 // If a 'template' keyword was used, a lookup that finds only non-template
14780 // names is an error.
14781 getSema().Diag(R.getNameLoc(),
14782 diag::err_template_kw_refers_to_non_template)
14784 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14785 getSema().Diag(FoundDecl->getLocation(),
14786 diag::note_template_kw_refers_to_non_template)
14787 << R.getLookupName();
14788 return true;
14789 }
14790 }
14791
14792 return false;
14793}
14794
14795template <typename Derived>
14800
14801template <typename Derived>
14804 bool IsAddressOfOperand) {
14805 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14807
14808 // Transform the declaration set.
14809 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14810 return ExprError();
14811
14812 // Rebuild the nested-name qualifier, if present.
14813 CXXScopeSpec SS;
14814 if (Old->getQualifierLoc()) {
14815 NestedNameSpecifierLoc QualifierLoc
14816 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14817 if (!QualifierLoc)
14818 return ExprError();
14819
14820 SS.Adopt(QualifierLoc);
14821 }
14822
14823 if (Old->getNamingClass()) {
14824 CXXRecordDecl *NamingClass
14825 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14826 Old->getNameLoc(),
14827 Old->getNamingClass()));
14828 if (!NamingClass) {
14829 R.clear();
14830 return ExprError();
14831 }
14832
14833 R.setNamingClass(NamingClass);
14834 }
14835
14836 // Rebuild the template arguments, if any.
14837 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14838 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14839 if (Old->hasExplicitTemplateArgs() &&
14840 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14841 Old->getNumTemplateArgs(),
14842 TransArgs)) {
14843 R.clear();
14844 return ExprError();
14845 }
14846
14847 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14848 // a non-static data member is named in an unevaluated operand, or when
14849 // a member is named in a dependent class scope function template explicit
14850 // specialization that is neither declared static nor with an explicit object
14851 // parameter.
14852 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14853 return SemaRef.BuildPossibleImplicitMemberExpr(
14854 SS, TemplateKWLoc, R,
14855 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14856 /*S=*/nullptr);
14857
14858 // If we have neither explicit template arguments, nor the template keyword,
14859 // it's a normal declaration name or member reference.
14860 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14861 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14862
14863 // If we have template arguments, then rebuild the template-id expression.
14864 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14865 Old->requiresADL(), &TransArgs);
14866}
14867
14868template<typename Derived>
14871 bool ArgChanged = false;
14873 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14874 TypeSourceInfo *From = E->getArg(I);
14875 TypeLoc FromTL = From->getTypeLoc();
14876 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14877 TypeLocBuilder TLB;
14878 TLB.reserve(FromTL.getFullDataSize());
14879 QualType To = getDerived().TransformType(TLB, FromTL);
14880 if (To.isNull())
14881 return ExprError();
14882
14883 if (To == From->getType())
14884 Args.push_back(From);
14885 else {
14886 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14887 ArgChanged = true;
14888 }
14889 continue;
14890 }
14891
14892 ArgChanged = true;
14893
14894 // We have a pack expansion. Instantiate it.
14895 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14896 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14898 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14899
14900 // Determine whether the set of unexpanded parameter packs can and should
14901 // be expanded.
14902 bool Expand = true;
14903 bool RetainExpansion = false;
14904 UnsignedOrNone OrigNumExpansions =
14905 ExpansionTL.getTypePtr()->getNumExpansions();
14906 UnsignedOrNone NumExpansions = OrigNumExpansions;
14907 if (getDerived().TryExpandParameterPacks(
14908 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
14909 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
14910 RetainExpansion, NumExpansions))
14911 return ExprError();
14912
14913 if (!Expand) {
14914 // The transform has determined that we should perform a simple
14915 // transformation on the pack expansion, producing another pack
14916 // expansion.
14917 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
14918
14919 TypeLocBuilder TLB;
14920 TLB.reserve(From->getTypeLoc().getFullDataSize());
14921
14922 QualType To = getDerived().TransformType(TLB, PatternTL);
14923 if (To.isNull())
14924 return ExprError();
14925
14926 To = getDerived().RebuildPackExpansionType(To,
14927 PatternTL.getSourceRange(),
14928 ExpansionTL.getEllipsisLoc(),
14929 NumExpansions);
14930 if (To.isNull())
14931 return ExprError();
14932
14933 PackExpansionTypeLoc ToExpansionTL
14934 = TLB.push<PackExpansionTypeLoc>(To);
14935 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14936 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14937 continue;
14938 }
14939
14940 // Expand the pack expansion by substituting for each argument in the
14941 // pack(s).
14942 for (unsigned I = 0; I != *NumExpansions; ++I) {
14943 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
14944 TypeLocBuilder TLB;
14945 TLB.reserve(PatternTL.getFullDataSize());
14946 QualType To = getDerived().TransformType(TLB, PatternTL);
14947 if (To.isNull())
14948 return ExprError();
14949
14950 if (To->containsUnexpandedParameterPack()) {
14951 To = getDerived().RebuildPackExpansionType(To,
14952 PatternTL.getSourceRange(),
14953 ExpansionTL.getEllipsisLoc(),
14954 NumExpansions);
14955 if (To.isNull())
14956 return ExprError();
14957
14958 PackExpansionTypeLoc ToExpansionTL
14959 = TLB.push<PackExpansionTypeLoc>(To);
14960 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14961 }
14962
14963 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14964 }
14965
14966 if (!RetainExpansion)
14967 continue;
14968
14969 // If we're supposed to retain a pack expansion, do so by temporarily
14970 // forgetting the partially-substituted parameter pack.
14971 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14972
14973 TypeLocBuilder TLB;
14974 TLB.reserve(From->getTypeLoc().getFullDataSize());
14975
14976 QualType To = getDerived().TransformType(TLB, PatternTL);
14977 if (To.isNull())
14978 return ExprError();
14979
14980 To = getDerived().RebuildPackExpansionType(To,
14981 PatternTL.getSourceRange(),
14982 ExpansionTL.getEllipsisLoc(),
14983 NumExpansions);
14984 if (To.isNull())
14985 return ExprError();
14986
14987 PackExpansionTypeLoc ToExpansionTL
14988 = TLB.push<PackExpansionTypeLoc>(To);
14989 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14990 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14991 }
14992
14993 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14994 return E;
14995
14996 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14997 E->getEndLoc());
14998}
14999
15000template<typename Derived>
15004 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15005 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15006 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15007 Old->NumTemplateArgs, TransArgs))
15008 return ExprError();
15009
15010 return getDerived().RebuildConceptSpecializationExpr(
15011 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15012 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15013 &TransArgs);
15014}
15015
15016template<typename Derived>
15019 SmallVector<ParmVarDecl*, 4> TransParams;
15020 SmallVector<QualType, 4> TransParamTypes;
15021 Sema::ExtParameterInfoBuilder ExtParamInfos;
15022
15023 // C++2a [expr.prim.req]p2
15024 // Expressions appearing within a requirement-body are unevaluated operands.
15028
15030 getSema().Context, getSema().CurContext,
15031 E->getBody()->getBeginLoc());
15032
15033 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15034
15035 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15036 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15037 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15038
15039 for (ParmVarDecl *Param : TransParams)
15040 if (Param)
15041 Param->setDeclContext(Body);
15042
15043 // On failure to transform, TransformRequiresTypeParams returns an expression
15044 // in the event that the transformation of the type params failed in some way.
15045 // It is expected that this will result in a 'not satisfied' Requires clause
15046 // when instantiating.
15047 if (!TypeParamResult.isUnset())
15048 return TypeParamResult;
15049
15051 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15052 TransReqs))
15053 return ExprError();
15054
15055 for (concepts::Requirement *Req : TransReqs) {
15056 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15057 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15058 ER->getReturnTypeRequirement()
15059 .getTypeConstraintTemplateParameterList()->getParam(0)
15060 ->setDeclContext(Body);
15061 }
15062 }
15063 }
15064
15065 return getDerived().RebuildRequiresExpr(
15066 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15067 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15068}
15069
15070template<typename Derived>
15074 for (concepts::Requirement *Req : Reqs) {
15075 concepts::Requirement *TransReq = nullptr;
15076 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15077 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15078 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15079 TransReq = getDerived().TransformExprRequirement(ExprReq);
15080 else
15081 TransReq = getDerived().TransformNestedRequirement(
15083 if (!TransReq)
15084 return true;
15085 Transformed.push_back(TransReq);
15086 }
15087 return false;
15088}
15089
15090template<typename Derived>
15094 if (Req->isSubstitutionFailure()) {
15095 if (getDerived().AlwaysRebuild())
15096 return getDerived().RebuildTypeRequirement(
15098 return Req;
15099 }
15100 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15101 if (!TransType)
15102 return nullptr;
15103 return getDerived().RebuildTypeRequirement(TransType);
15104}
15105
15106template<typename Derived>
15109 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15110 if (Req->isExprSubstitutionFailure())
15111 TransExpr = Req->getExprSubstitutionDiagnostic();
15112 else {
15113 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15114 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15115 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15116 if (TransExprRes.isInvalid())
15117 return nullptr;
15118 TransExpr = TransExprRes.get();
15119 }
15120
15121 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15122 const auto &RetReq = Req->getReturnTypeRequirement();
15123 if (RetReq.isEmpty())
15124 TransRetReq.emplace();
15125 else if (RetReq.isSubstitutionFailure())
15126 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15127 else if (RetReq.isTypeConstraint()) {
15128 TemplateParameterList *OrigTPL =
15129 RetReq.getTypeConstraintTemplateParameterList();
15131 getDerived().TransformTemplateParameterList(OrigTPL);
15132 if (!TPL)
15133 return nullptr;
15134 TransRetReq.emplace(TPL);
15135 }
15136 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15137 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15138 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15139 Req->getNoexceptLoc(),
15140 std::move(*TransRetReq));
15141 return getDerived().RebuildExprRequirement(
15143 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15144}
15145
15146template<typename Derived>
15150 if (Req->hasInvalidConstraint()) {
15151 if (getDerived().AlwaysRebuild())
15152 return getDerived().RebuildNestedRequirement(
15154 return Req;
15155 }
15156 ExprResult TransConstraint =
15157 getDerived().TransformExpr(Req->getConstraintExpr());
15158 if (TransConstraint.isInvalid())
15159 return nullptr;
15160 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15161}
15162
15163template<typename Derived>
15166 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15167 if (!T)
15168 return ExprError();
15169
15170 if (!getDerived().AlwaysRebuild() &&
15172 return E;
15173
15174 ExprResult SubExpr;
15175 {
15178 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15179 if (SubExpr.isInvalid())
15180 return ExprError();
15181 }
15182
15183 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15184 SubExpr.get(), E->getEndLoc());
15185}
15186
15187template<typename Derived>
15190 ExprResult SubExpr;
15191 {
15194 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15195 if (SubExpr.isInvalid())
15196 return ExprError();
15197
15198 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15199 return E;
15200 }
15201
15202 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15203 SubExpr.get(), E->getEndLoc());
15204}
15205
15206template <typename Derived>
15208 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15209 TypeSourceInfo **RecoveryTSI) {
15210 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15211 DRE, AddrTaken, RecoveryTSI);
15212
15213 // Propagate both errors and recovered types, which return ExprEmpty.
15214 if (!NewDRE.isUsable())
15215 return NewDRE;
15216
15217 // We got an expr, wrap it up in parens.
15218 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15219 return PE;
15220 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15221 PE->getRParen());
15222}
15223
15224template <typename Derived>
15230
15231template <typename Derived>
15233 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15234 TypeSourceInfo **RecoveryTSI) {
15235 assert(E->getQualifierLoc());
15236 NestedNameSpecifierLoc QualifierLoc =
15237 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15238 if (!QualifierLoc)
15239 return ExprError();
15240 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15241
15242 // TODO: If this is a conversion-function-id, verify that the
15243 // destination type name (if present) resolves the same way after
15244 // instantiation as it did in the local scope.
15245
15246 DeclarationNameInfo NameInfo =
15247 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15248 if (!NameInfo.getName())
15249 return ExprError();
15250
15251 if (!E->hasExplicitTemplateArgs()) {
15252 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15253 // Note: it is sufficient to compare the Name component of NameInfo:
15254 // if name has not changed, DNLoc has not changed either.
15255 NameInfo.getName() == E->getDeclName())
15256 return E;
15257
15258 return getDerived().RebuildDependentScopeDeclRefExpr(
15259 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15260 IsAddressOfOperand, RecoveryTSI);
15261 }
15262
15263 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15264 if (getDerived().TransformTemplateArguments(
15265 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15266 return ExprError();
15267
15268 return getDerived().RebuildDependentScopeDeclRefExpr(
15269 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15270 RecoveryTSI);
15271}
15272
15273template<typename Derived>
15276 // CXXConstructExprs other than for list-initialization and
15277 // CXXTemporaryObjectExpr are always implicit, so when we have
15278 // a 1-argument construction we just transform that argument.
15279 if (getDerived().AllowSkippingCXXConstructExpr() &&
15280 ((E->getNumArgs() == 1 ||
15281 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15282 (!getDerived().DropCallArgument(E->getArg(0))) &&
15283 !E->isListInitialization()))
15284 return getDerived().TransformInitializer(E->getArg(0),
15285 /*DirectInit*/ false);
15286
15287 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15288
15289 QualType T = getDerived().TransformType(E->getType());
15290 if (T.isNull())
15291 return ExprError();
15292
15293 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15294 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15295 if (!Constructor)
15296 return ExprError();
15297
15298 bool ArgumentChanged = false;
15300 {
15303 E->isListInitialization());
15304 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15305 &ArgumentChanged))
15306 return ExprError();
15307 }
15308
15309 if (!getDerived().AlwaysRebuild() &&
15310 T == E->getType() &&
15311 Constructor == E->getConstructor() &&
15312 !ArgumentChanged) {
15313 // Mark the constructor as referenced.
15314 // FIXME: Instantiation-specific
15315 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15316 return E;
15317 }
15318
15319 return getDerived().RebuildCXXConstructExpr(
15320 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15321 E->hadMultipleCandidates(), E->isListInitialization(),
15322 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15323 E->getConstructionKind(), E->getParenOrBraceRange());
15324}
15325
15326template<typename Derived>
15329 QualType T = getDerived().TransformType(E->getType());
15330 if (T.isNull())
15331 return ExprError();
15332
15333 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15334 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15335 if (!Constructor)
15336 return ExprError();
15337
15338 if (!getDerived().AlwaysRebuild() &&
15339 T == E->getType() &&
15340 Constructor == E->getConstructor()) {
15341 // Mark the constructor as referenced.
15342 // FIXME: Instantiation-specific
15343 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15344 return E;
15345 }
15346
15347 return getDerived().RebuildCXXInheritedCtorInitExpr(
15348 T, E->getLocation(), Constructor,
15349 E->constructsVBase(), E->inheritedFromVBase());
15350}
15351
15352/// Transform a C++ temporary-binding expression.
15353///
15354/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15355/// transform the subexpression and return that.
15356template<typename Derived>
15359 if (auto *Dtor = E->getTemporary()->getDestructor())
15360 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15361 const_cast<CXXDestructorDecl *>(Dtor));
15362 return getDerived().TransformExpr(E->getSubExpr());
15363}
15364
15365/// Transform a C++ expression that contains cleanups that should
15366/// be run after the expression is evaluated.
15367///
15368/// Since ExprWithCleanups nodes are implicitly generated, we
15369/// just transform the subexpression and return that.
15370template<typename Derived>
15373 return getDerived().TransformExpr(E->getSubExpr());
15374}
15375
15376template<typename Derived>
15380 TypeSourceInfo *T =
15381 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15382 if (!T)
15383 return ExprError();
15384
15385 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15386 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15387 if (!Constructor)
15388 return ExprError();
15389
15390 bool ArgumentChanged = false;
15392 Args.reserve(E->getNumArgs());
15393 {
15396 E->isListInitialization());
15397 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15398 &ArgumentChanged))
15399 return ExprError();
15400
15401 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15402 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15403 if (Res.isInvalid())
15404 return ExprError();
15405 Args = {Res.get()};
15406 }
15407 }
15408
15409 if (!getDerived().AlwaysRebuild() &&
15410 T == E->getTypeSourceInfo() &&
15411 Constructor == E->getConstructor() &&
15412 !ArgumentChanged) {
15413 // FIXME: Instantiation-specific
15414 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15415 return SemaRef.MaybeBindToTemporary(E);
15416 }
15417
15418 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15419 return getDerived().RebuildCXXTemporaryObjectExpr(
15420 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15421}
15422
15423template<typename Derived>
15426 // Transform any init-capture expressions before entering the scope of the
15427 // lambda body, because they are not semantically within that scope.
15428 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15429 struct TransformedInitCapture {
15430 // The location of the ... if the result is retaining a pack expansion.
15431 SourceLocation EllipsisLoc;
15432 // Zero or more expansions of the init-capture.
15433 SmallVector<InitCaptureInfoTy, 4> Expansions;
15434 };
15436 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15437 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15438 CEnd = E->capture_end();
15439 C != CEnd; ++C) {
15440 if (!E->isInitCapture(C))
15441 continue;
15442
15443 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15444 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15445
15446 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15447 UnsignedOrNone NumExpansions) {
15448 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15449 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15450
15451 if (NewExprInitResult.isInvalid()) {
15452 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15453 return;
15454 }
15455 Expr *NewExprInit = NewExprInitResult.get();
15456
15457 QualType NewInitCaptureType =
15458 getSema().buildLambdaInitCaptureInitialization(
15459 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15460 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15461 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15463 NewExprInit);
15464 Result.Expansions.push_back(
15465 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15466 };
15467
15468 // If this is an init-capture pack, consider expanding the pack now.
15469 if (OldVD->isParameterPack()) {
15470 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15471 ->getTypeLoc()
15474 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15475
15476 // Determine whether the set of unexpanded parameter packs can and should
15477 // be expanded.
15478 bool Expand = true;
15479 bool RetainExpansion = false;
15480 UnsignedOrNone OrigNumExpansions =
15481 ExpansionTL.getTypePtr()->getNumExpansions();
15482 UnsignedOrNone NumExpansions = OrigNumExpansions;
15483 if (getDerived().TryExpandParameterPacks(
15484 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
15485 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15486 RetainExpansion, NumExpansions))
15487 return ExprError();
15488 assert(!RetainExpansion && "Should not need to retain expansion after a "
15489 "capture since it cannot be extended");
15490 if (Expand) {
15491 for (unsigned I = 0; I != *NumExpansions; ++I) {
15492 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15493 SubstInitCapture(SourceLocation(), std::nullopt);
15494 }
15495 } else {
15496 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15497 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15498 }
15499 } else {
15500 SubstInitCapture(SourceLocation(), std::nullopt);
15501 }
15502 }
15503
15504 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15505 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15506
15507 // Create the local class that will describe the lambda.
15508
15509 // FIXME: DependencyKind below is wrong when substituting inside a templated
15510 // context that isn't a DeclContext (such as a variable template), or when
15511 // substituting an unevaluated lambda inside of a function's parameter's type
15512 // - as parameter types are not instantiated from within a function's DC. We
15513 // use evaluation contexts to distinguish the function parameter case.
15516 DeclContext *DC = getSema().CurContext;
15517 // A RequiresExprBodyDecl is not interesting for dependencies.
15518 // For the following case,
15519 //
15520 // template <typename>
15521 // concept C = requires { [] {}; };
15522 //
15523 // template <class F>
15524 // struct Widget;
15525 //
15526 // template <C F>
15527 // struct Widget<F> {};
15528 //
15529 // While we are substituting Widget<F>, the parent of DC would be
15530 // the template specialization itself. Thus, the lambda expression
15531 // will be deemed as dependent even if there are no dependent template
15532 // arguments.
15533 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15534 while (DC->isRequiresExprBody())
15535 DC = DC->getParent();
15536 if ((getSema().isUnevaluatedContext() ||
15537 getSema().isConstantEvaluatedContext()) &&
15538 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15539 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15540
15541 CXXRecordDecl *OldClass = E->getLambdaClass();
15542 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15543 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15544 E->getCaptureDefault());
15545 getDerived().transformedLocalDecl(OldClass, {Class});
15546
15547 CXXMethodDecl *NewCallOperator =
15548 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15549
15550 // Enter the scope of the lambda.
15551 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15552 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15553 E->hasExplicitParameters(), E->isMutable());
15554
15555 // Introduce the context of the call operator.
15556 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15557 /*NewThisContext*/false);
15558
15559 bool Invalid = false;
15560
15561 // Transform captures.
15562 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15563 CEnd = E->capture_end();
15564 C != CEnd; ++C) {
15565 // When we hit the first implicit capture, tell Sema that we've finished
15566 // the list of explicit captures.
15567 if (C->isImplicit())
15568 break;
15569
15570 // Capturing 'this' is trivial.
15571 if (C->capturesThis()) {
15572 // If this is a lambda that is part of a default member initialiser
15573 // and which we're instantiating outside the class that 'this' is
15574 // supposed to refer to, adjust the type of 'this' accordingly.
15575 //
15576 // Otherwise, leave the type of 'this' as-is.
15577 Sema::CXXThisScopeRAII ThisScope(
15578 getSema(),
15579 dyn_cast_if_present<CXXRecordDecl>(
15580 getSema().getFunctionLevelDeclContext()),
15581 Qualifiers());
15582 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15583 /*BuildAndDiagnose*/ true, nullptr,
15584 C->getCaptureKind() == LCK_StarThis);
15585 continue;
15586 }
15587 // Captured expression will be recaptured during captured variables
15588 // rebuilding.
15589 if (C->capturesVLAType())
15590 continue;
15591
15592 // Rebuild init-captures, including the implied field declaration.
15593 if (E->isInitCapture(C)) {
15594 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15595
15596 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15598
15599 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15600 ExprResult Init = Info.first;
15601 QualType InitQualType = Info.second;
15602 if (Init.isInvalid() || InitQualType.isNull()) {
15603 Invalid = true;
15604 break;
15605 }
15606 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15607 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15608 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15609 getSema().CurContext);
15610 if (!NewVD) {
15611 Invalid = true;
15612 break;
15613 }
15614 NewVDs.push_back(NewVD);
15615 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15616 // Cases we want to tackle:
15617 // ([C(Pack)] {}, ...)
15618 // But rule out cases e.g.
15619 // [...C = Pack()] {}
15620 if (NewC.EllipsisLoc.isInvalid())
15621 LSI->ContainsUnexpandedParameterPack |=
15622 Init.get()->containsUnexpandedParameterPack();
15623 }
15624
15625 if (Invalid)
15626 break;
15627
15628 getDerived().transformedLocalDecl(OldVD, NewVDs);
15629 continue;
15630 }
15631
15632 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15633
15634 // Determine the capture kind for Sema.
15636 : C->getCaptureKind() == LCK_ByCopy
15639 SourceLocation EllipsisLoc;
15640 if (C->isPackExpansion()) {
15641 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15642 bool ShouldExpand = false;
15643 bool RetainExpansion = false;
15644 UnsignedOrNone NumExpansions = std::nullopt;
15645 if (getDerived().TryExpandParameterPacks(
15646 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
15647 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
15648 RetainExpansion, NumExpansions)) {
15649 Invalid = true;
15650 continue;
15651 }
15652
15653 if (ShouldExpand) {
15654 // The transform has determined that we should perform an expansion;
15655 // transform and capture each of the arguments.
15656 // expansion of the pattern. Do so.
15657 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
15658 for (unsigned I = 0; I != *NumExpansions; ++I) {
15659 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15660 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
15661 getDerived().TransformDecl(C->getLocation(), Pack));
15662 if (!CapturedVar) {
15663 Invalid = true;
15664 continue;
15665 }
15666
15667 // Capture the transformed variable.
15668 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15669 }
15670
15671 // FIXME: Retain a pack expansion if RetainExpansion is true.
15672
15673 continue;
15674 }
15675
15676 EllipsisLoc = C->getEllipsisLoc();
15677 }
15678
15679 // Transform the captured variable.
15680 auto *CapturedVar = cast_or_null<ValueDecl>(
15681 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15682 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15683 Invalid = true;
15684 continue;
15685 }
15686
15687 // This is not an init-capture; however it contains an unexpanded pack e.g.
15688 // ([Pack] {}(), ...)
15689 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15690 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15691
15692 // Capture the transformed variable.
15693 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15694 EllipsisLoc);
15695 }
15696 getSema().finishLambdaExplicitCaptures(LSI);
15697
15698 // Transform the template parameters, and add them to the current
15699 // instantiation scope. The null case is handled correctly.
15700 auto TPL = getDerived().TransformTemplateParameterList(
15701 E->getTemplateParameterList());
15702 LSI->GLTemplateParameterList = TPL;
15703 if (TPL) {
15704 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15705 TPL);
15706 LSI->ContainsUnexpandedParameterPack |=
15707 TPL->containsUnexpandedParameterPack();
15708 }
15709
15710 TypeLocBuilder NewCallOpTLBuilder;
15711 TypeLoc OldCallOpTypeLoc =
15712 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15713 QualType NewCallOpType =
15714 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15715 if (NewCallOpType.isNull())
15716 return ExprError();
15717 LSI->ContainsUnexpandedParameterPack |=
15718 NewCallOpType->containsUnexpandedParameterPack();
15719 TypeSourceInfo *NewCallOpTSI =
15720 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15721
15722 // The type may be an AttributedType or some other kind of sugar;
15723 // get the actual underlying FunctionProtoType.
15724 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15725 assert(FPTL && "Not a FunctionProtoType?");
15726
15727 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
15728 if (!TRC.ArgPackSubstIndex)
15730
15731 getSema().CompleteLambdaCallOperator(
15732 NewCallOperator, E->getCallOperator()->getLocation(),
15733 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
15734 E->getCallOperator()->getConstexprKind(),
15735 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15736 E->hasExplicitResultType());
15737
15738 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15739 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15740
15741 {
15742 // Number the lambda for linkage purposes if necessary.
15743 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15744
15745 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15746 if (getDerived().ReplacingOriginal()) {
15747 Numbering = OldClass->getLambdaNumbering();
15748 }
15749
15750 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15751 }
15752
15753 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15754 // evaluation context even if we're not transforming the function body.
15755 getSema().PushExpressionEvaluationContextForFunction(
15757 E->getCallOperator());
15758
15761 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15762 getSema().pushCodeSynthesisContext(C);
15763
15764 // Instantiate the body of the lambda expression.
15765 StmtResult Body =
15766 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15767
15768 getSema().popCodeSynthesisContext();
15769
15770 // ActOnLambda* will pop the function scope for us.
15771 FuncScopeCleanup.disable();
15772
15773 if (Body.isInvalid()) {
15774 SavedContext.pop();
15775 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15776 /*IsInstantiation=*/true);
15777 return ExprError();
15778 }
15779
15780 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15781 /*IsInstantiation=*/true,
15782 /*RetainFunctionScopeInfo=*/true);
15783 SavedContext.pop();
15784
15785 // Recompute the dependency of the lambda so that we can defer the lambda call
15786 // construction until after we have all the necessary template arguments. For
15787 // example, given
15788 //
15789 // template <class> struct S {
15790 // template <class U>
15791 // using Type = decltype([](U){}(42.0));
15792 // };
15793 // void foo() {
15794 // using T = S<int>::Type<float>;
15795 // ^~~~~~
15796 // }
15797 //
15798 // We would end up here from instantiating S<int> when ensuring its
15799 // completeness. That would transform the lambda call expression regardless of
15800 // the absence of the corresponding argument for U.
15801 //
15802 // Going ahead with unsubstituted type U makes things worse: we would soon
15803 // compare the argument type (which is float) against the parameter U
15804 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15805 // error suggesting unmatched types 'U' and 'float'!
15806 //
15807 // That said, everything will be fine if we defer that semantic checking.
15808 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15809 // dependent. Since the CallExpr's dependency boils down to the lambda's
15810 // dependency in this case, we can harness that by recomputing the dependency
15811 // from the instantiation arguments.
15812 //
15813 // FIXME: Creating the type of a lambda requires us to have a dependency
15814 // value, which happens before its substitution. We update its dependency
15815 // *after* the substitution in case we can't decide the dependency
15816 // so early, e.g. because we want to see if any of the *substituted*
15817 // parameters are dependent.
15818 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15819 Class->setLambdaDependencyKind(DependencyKind);
15820
15821 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15822 Body.get()->getEndLoc(), LSI);
15823}
15824
15825template<typename Derived>
15830
15831template<typename Derived>
15834 // Transform captures.
15836 CEnd = E->capture_end();
15837 C != CEnd; ++C) {
15838 // When we hit the first implicit capture, tell Sema that we've finished
15839 // the list of explicit captures.
15840 if (!C->isImplicit())
15841 continue;
15842
15843 // Capturing 'this' is trivial.
15844 if (C->capturesThis()) {
15845 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15846 /*BuildAndDiagnose*/ true, nullptr,
15847 C->getCaptureKind() == LCK_StarThis);
15848 continue;
15849 }
15850 // Captured expression will be recaptured during captured variables
15851 // rebuilding.
15852 if (C->capturesVLAType())
15853 continue;
15854
15855 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15856 assert(!E->isInitCapture(C) && "implicit init-capture?");
15857
15858 // Transform the captured variable.
15859 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15860 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15861 if (!CapturedVar || CapturedVar->isInvalidDecl())
15862 return StmtError();
15863
15864 // Capture the transformed variable.
15865 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15866 }
15867
15868 return S;
15869}
15870
15871template<typename Derived>
15875 TypeSourceInfo *T =
15876 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15877 if (!T)
15878 return ExprError();
15879
15880 bool ArgumentChanged = false;
15882 Args.reserve(E->getNumArgs());
15883 {
15887 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15888 &ArgumentChanged))
15889 return ExprError();
15890 }
15891
15892 if (!getDerived().AlwaysRebuild() &&
15893 T == E->getTypeSourceInfo() &&
15894 !ArgumentChanged)
15895 return E;
15896
15897 // FIXME: we're faking the locations of the commas
15898 return getDerived().RebuildCXXUnresolvedConstructExpr(
15899 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15900}
15901
15902template<typename Derived>
15906 // Transform the base of the expression.
15907 ExprResult Base((Expr*) nullptr);
15908 Expr *OldBase;
15909 QualType BaseType;
15910 QualType ObjectType;
15911 if (!E->isImplicitAccess()) {
15912 OldBase = E->getBase();
15913 Base = getDerived().TransformExpr(OldBase);
15914 if (Base.isInvalid())
15915 return ExprError();
15916
15917 // Start the member reference and compute the object's type.
15918 ParsedType ObjectTy;
15919 bool MayBePseudoDestructor = false;
15920 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15921 E->getOperatorLoc(),
15922 E->isArrow()? tok::arrow : tok::period,
15923 ObjectTy,
15924 MayBePseudoDestructor);
15925 if (Base.isInvalid())
15926 return ExprError();
15927
15928 ObjectType = ObjectTy.get();
15929 BaseType = ((Expr*) Base.get())->getType();
15930 } else {
15931 OldBase = nullptr;
15932 BaseType = getDerived().TransformType(E->getBaseType());
15933 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15934 }
15935
15936 // Transform the first part of the nested-name-specifier that qualifies
15937 // the member name.
15938 NamedDecl *FirstQualifierInScope
15939 = getDerived().TransformFirstQualifierInScope(
15940 E->getFirstQualifierFoundInScope(),
15941 E->getQualifierLoc().getBeginLoc());
15942
15943 NestedNameSpecifierLoc QualifierLoc;
15944 if (E->getQualifier()) {
15945 QualifierLoc
15946 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15947 ObjectType,
15948 FirstQualifierInScope);
15949 if (!QualifierLoc)
15950 return ExprError();
15951 }
15952
15953 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15954
15955 // TODO: If this is a conversion-function-id, verify that the
15956 // destination type name (if present) resolves the same way after
15957 // instantiation as it did in the local scope.
15958
15959 DeclarationNameInfo NameInfo
15960 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15961 if (!NameInfo.getName())
15962 return ExprError();
15963
15964 if (!E->hasExplicitTemplateArgs()) {
15965 // This is a reference to a member without an explicitly-specified
15966 // template argument list. Optimize for this common case.
15967 if (!getDerived().AlwaysRebuild() &&
15968 Base.get() == OldBase &&
15969 BaseType == E->getBaseType() &&
15970 QualifierLoc == E->getQualifierLoc() &&
15971 NameInfo.getName() == E->getMember() &&
15972 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15973 return E;
15974
15975 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15976 BaseType,
15977 E->isArrow(),
15978 E->getOperatorLoc(),
15979 QualifierLoc,
15980 TemplateKWLoc,
15981 FirstQualifierInScope,
15982 NameInfo,
15983 /*TemplateArgs*/nullptr);
15984 }
15985
15986 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15987 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15988 E->getNumTemplateArgs(),
15989 TransArgs))
15990 return ExprError();
15991
15992 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15993 BaseType,
15994 E->isArrow(),
15995 E->getOperatorLoc(),
15996 QualifierLoc,
15997 TemplateKWLoc,
15998 FirstQualifierInScope,
15999 NameInfo,
16000 &TransArgs);
16001}
16002
16003template <typename Derived>
16005 UnresolvedMemberExpr *Old) {
16006 // Transform the base of the expression.
16007 ExprResult Base((Expr *)nullptr);
16008 QualType BaseType;
16009 if (!Old->isImplicitAccess()) {
16010 Base = getDerived().TransformExpr(Old->getBase());
16011 if (Base.isInvalid())
16012 return ExprError();
16013 Base =
16014 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16015 if (Base.isInvalid())
16016 return ExprError();
16017 BaseType = Base.get()->getType();
16018 } else {
16019 BaseType = getDerived().TransformType(Old->getBaseType());
16020 }
16021
16022 NestedNameSpecifierLoc QualifierLoc;
16023 if (Old->getQualifierLoc()) {
16024 QualifierLoc =
16025 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16026 if (!QualifierLoc)
16027 return ExprError();
16028 }
16029
16030 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16031
16032 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16033
16034 // Transform the declaration set.
16035 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16036 return ExprError();
16037
16038 // Determine the naming class.
16039 if (Old->getNamingClass()) {
16040 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16041 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16042 if (!NamingClass)
16043 return ExprError();
16044
16045 R.setNamingClass(NamingClass);
16046 }
16047
16048 TemplateArgumentListInfo TransArgs;
16049 if (Old->hasExplicitTemplateArgs()) {
16050 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16051 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16052 if (getDerived().TransformTemplateArguments(
16053 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16054 return ExprError();
16055 }
16056
16057 // FIXME: to do this check properly, we will need to preserve the
16058 // first-qualifier-in-scope here, just in case we had a dependent
16059 // base (and therefore couldn't do the check) and a
16060 // nested-name-qualifier (and therefore could do the lookup).
16061 NamedDecl *FirstQualifierInScope = nullptr;
16062
16063 return getDerived().RebuildUnresolvedMemberExpr(
16064 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16065 TemplateKWLoc, FirstQualifierInScope, R,
16066 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16067}
16068
16069template<typename Derived>
16074 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16075 if (SubExpr.isInvalid())
16076 return ExprError();
16077
16078 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16079 return E;
16080
16081 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16082}
16083
16084template<typename Derived>
16087 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16088 if (Pattern.isInvalid())
16089 return ExprError();
16090
16091 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16092 return E;
16093
16094 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16095 E->getNumExpansions());
16096}
16097
16098template <typename Derived>
16100 ArrayRef<TemplateArgument> PackArgs) {
16102 for (const TemplateArgument &Arg : PackArgs) {
16103 if (!Arg.isPackExpansion()) {
16104 Result = *Result + 1;
16105 continue;
16106 }
16107
16108 TemplateArgumentLoc ArgLoc;
16109 InventTemplateArgumentLoc(Arg, ArgLoc);
16110
16111 // Find the pattern of the pack expansion.
16112 SourceLocation Ellipsis;
16113 UnsignedOrNone OrigNumExpansions = std::nullopt;
16114 TemplateArgumentLoc Pattern =
16115 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16116 OrigNumExpansions);
16117
16118 // Substitute under the pack expansion. Do not expand the pack (yet).
16119 TemplateArgumentLoc OutPattern;
16120 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16121 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16122 /*Uneval*/ true))
16123 return 1u;
16124
16125 // See if we can determine the number of arguments from the result.
16126 UnsignedOrNone NumExpansions =
16127 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16128 if (!NumExpansions) {
16129 // No: we must be in an alias template expansion, and we're going to
16130 // need to actually expand the packs.
16131 Result = std::nullopt;
16132 break;
16133 }
16134
16135 Result = *Result + *NumExpansions;
16136 }
16137 return Result;
16138}
16139
16140template<typename Derived>
16143 // If E is not value-dependent, then nothing will change when we transform it.
16144 // Note: This is an instantiation-centric view.
16145 if (!E->isValueDependent())
16146 return E;
16147
16150
16152 TemplateArgument ArgStorage;
16153
16154 // Find the argument list to transform.
16155 if (E->isPartiallySubstituted()) {
16156 PackArgs = E->getPartialArguments();
16157 } else if (E->isValueDependent()) {
16158 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16159 bool ShouldExpand = false;
16160 bool RetainExpansion = false;
16161 UnsignedOrNone NumExpansions = std::nullopt;
16162 if (getDerived().TryExpandParameterPacks(
16163 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16164 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16165 RetainExpansion, NumExpansions))
16166 return ExprError();
16167
16168 // If we need to expand the pack, build a template argument from it and
16169 // expand that.
16170 if (ShouldExpand) {
16171 auto *Pack = E->getPack();
16172 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16173 ArgStorage = getSema().Context.getPackExpansionType(
16174 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16175 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16176 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16177 } else {
16178 auto *VD = cast<ValueDecl>(Pack);
16179 ExprResult DRE = getSema().BuildDeclRefExpr(
16180 VD, VD->getType().getNonLValueExprType(getSema().Context),
16181 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16182 E->getPackLoc());
16183 if (DRE.isInvalid())
16184 return ExprError();
16185 ArgStorage = TemplateArgument(
16186 new (getSema().Context)
16187 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16188 /*IsCanonical=*/false);
16189 }
16190 PackArgs = ArgStorage;
16191 }
16192 }
16193
16194 // If we're not expanding the pack, just transform the decl.
16195 if (!PackArgs.size()) {
16196 auto *Pack = cast_or_null<NamedDecl>(
16197 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16198 if (!Pack)
16199 return ExprError();
16200 return getDerived().RebuildSizeOfPackExpr(
16201 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16202 std::nullopt, {});
16203 }
16204
16205 // Try to compute the result without performing a partial substitution.
16207 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16208
16209 // Common case: we could determine the number of expansions without
16210 // substituting.
16211 if (Result)
16212 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16213 E->getPackLoc(),
16214 E->getRParenLoc(), *Result, {});
16215
16216 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16217 E->getPackLoc());
16218 {
16219 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16221 Derived, const TemplateArgument*> PackLocIterator;
16222 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16223 PackLocIterator(*this, PackArgs.end()),
16224 TransformedPackArgs, /*Uneval*/true))
16225 return ExprError();
16226 }
16227
16228 // Check whether we managed to fully-expand the pack.
16229 // FIXME: Is it possible for us to do so and not hit the early exit path?
16231 bool PartialSubstitution = false;
16232 for (auto &Loc : TransformedPackArgs.arguments()) {
16233 Args.push_back(Loc.getArgument());
16234 if (Loc.getArgument().isPackExpansion())
16235 PartialSubstitution = true;
16236 }
16237
16238 if (PartialSubstitution)
16239 return getDerived().RebuildSizeOfPackExpr(
16240 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16241 std::nullopt, Args);
16242
16243 return getDerived().RebuildSizeOfPackExpr(
16244 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16245 /*Length=*/static_cast<unsigned>(Args.size()),
16246 /*PartialArgs=*/{});
16247}
16248
16249template <typename Derived>
16252 if (!E->isValueDependent())
16253 return E;
16254
16255 // Transform the index
16256 ExprResult IndexExpr;
16257 {
16258 EnterExpressionEvaluationContext ConstantContext(
16260 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16261 if (IndexExpr.isInvalid())
16262 return ExprError();
16263 }
16264
16265 SmallVector<Expr *, 5> ExpandedExprs;
16266 bool FullySubstituted = true;
16267 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16268 Expr *Pattern = E->getPackIdExpression();
16270 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16271 Unexpanded);
16272 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16273
16274 // Determine whether the set of unexpanded parameter packs can and should
16275 // be expanded.
16276 bool ShouldExpand = true;
16277 bool RetainExpansion = false;
16278 UnsignedOrNone OrigNumExpansions = std::nullopt,
16279 NumExpansions = std::nullopt;
16280 if (getDerived().TryExpandParameterPacks(
16281 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16282 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16283 RetainExpansion, NumExpansions))
16284 return true;
16285 if (!ShouldExpand) {
16286 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16287 ExprResult Pack = getDerived().TransformExpr(Pattern);
16288 if (Pack.isInvalid())
16289 return ExprError();
16290 return getDerived().RebuildPackIndexingExpr(
16291 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16292 {}, /*FullySubstituted=*/false);
16293 }
16294 for (unsigned I = 0; I != *NumExpansions; ++I) {
16295 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16296 ExprResult Out = getDerived().TransformExpr(Pattern);
16297 if (Out.isInvalid())
16298 return true;
16299 if (Out.get()->containsUnexpandedParameterPack()) {
16300 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16301 OrigNumExpansions);
16302 if (Out.isInvalid())
16303 return true;
16304 FullySubstituted = false;
16305 }
16306 ExpandedExprs.push_back(Out.get());
16307 }
16308 // If we're supposed to retain a pack expansion, do so by temporarily
16309 // forgetting the partially-substituted parameter pack.
16310 if (RetainExpansion) {
16311 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16312
16313 ExprResult Out = getDerived().TransformExpr(Pattern);
16314 if (Out.isInvalid())
16315 return true;
16316
16317 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16318 OrigNumExpansions);
16319 if (Out.isInvalid())
16320 return true;
16321 FullySubstituted = false;
16322 ExpandedExprs.push_back(Out.get());
16323 }
16324 } else if (!E->expandsToEmptyPack()) {
16325 if (getDerived().TransformExprs(E->getExpressions().data(),
16326 E->getExpressions().size(), false,
16327 ExpandedExprs))
16328 return ExprError();
16329 }
16330
16331 return getDerived().RebuildPackIndexingExpr(
16332 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16333 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16334}
16335
16336template <typename Derived>
16339 if (!getSema().ArgPackSubstIndex)
16340 // We aren't expanding the parameter pack, so just return ourselves.
16341 return E;
16342
16343 TemplateArgument Pack = E->getArgumentPack();
16345 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
16346 E->getAssociatedDecl(), E->getParameterPack(),
16347 E->getParameterPackLocation(), Arg, SemaRef.getPackIndex(Pack),
16348 E->getFinal());
16349}
16350
16351template <typename Derived>
16354 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16355 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
16356 if (Replacement.isInvalid())
16357 return true;
16358
16359 Decl *AssociatedDecl =
16360 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
16361 if (!AssociatedDecl)
16362 return true;
16363
16364 if (Replacement.get() == OrigReplacement &&
16365 AssociatedDecl == E->getAssociatedDecl())
16366 return E;
16367
16368 // If the replacement expression did not change, and the parameter type
16369 // did not change, we can skip the semantic action because it would
16370 // produce the same result anyway.
16371 auto *Param = cast<NonTypeTemplateParmDecl>(
16372 getReplacedTemplateParameterList(AssociatedDecl)
16373 ->asArray()[E->getIndex()]);
16374 if (QualType ParamType = Param->getType();
16375 !SemaRef.Context.hasSameType(ParamType, E->getParameter()->getType()) ||
16376 Replacement.get() != OrigReplacement) {
16377
16378 // When transforming the replacement expression previously, all Sema
16379 // specific annotations, such as implicit casts, are discarded. Calling the
16380 // corresponding sema action is necessary to recover those. Otherwise,
16381 // equivalency of the result would be lost.
16382 TemplateArgument SugaredConverted, CanonicalConverted;
16383 Replacement = SemaRef.CheckTemplateArgument(
16384 Param, ParamType, Replacement.get(), SugaredConverted,
16385 CanonicalConverted,
16386 /*StrictCheck=*/false, Sema::CTAK_Specified);
16387 if (Replacement.isInvalid())
16388 return true;
16389 } else {
16390 // Otherwise, the same expression would have been produced.
16391 Replacement = E->getReplacement();
16392 }
16393
16394 return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
16395 Replacement.get()->getType(), Replacement.get()->getValueKind(),
16396 E->getNameLoc(), Replacement.get(), AssociatedDecl, E->getIndex(),
16397 E->getPackIndex(), E->isReferenceParameter(), E->getFinal());
16398}
16399
16400template<typename Derived>
16403 // Default behavior is to do nothing with this transformation.
16404 return E;
16405}
16406
16407template<typename Derived>
16411 return getDerived().TransformExpr(E->getSubExpr());
16412}
16413
16414template<typename Derived>
16417 UnresolvedLookupExpr *Callee = nullptr;
16418 if (Expr *OldCallee = E->getCallee()) {
16419 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16420 if (CalleeResult.isInvalid())
16421 return ExprError();
16422 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16423 }
16424
16425 Expr *Pattern = E->getPattern();
16426
16428 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16429 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16430
16431 // Determine whether the set of unexpanded parameter packs can and should
16432 // be expanded.
16433 bool Expand = true;
16434 bool RetainExpansion = false;
16435 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
16436 NumExpansions = OrigNumExpansions;
16437 if (getDerived().TryExpandParameterPacks(
16438 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16439 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16440 NumExpansions))
16441 return true;
16442
16443 if (!Expand) {
16444 // Do not expand any packs here, just transform and rebuild a fold
16445 // expression.
16446 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16447
16448 ExprResult LHS =
16449 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16450 if (LHS.isInvalid())
16451 return true;
16452
16453 ExprResult RHS =
16454 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16455 if (RHS.isInvalid())
16456 return true;
16457
16458 if (!getDerived().AlwaysRebuild() &&
16459 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16460 return E;
16461
16462 return getDerived().RebuildCXXFoldExpr(
16463 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16464 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16465 }
16466
16467 // Formally a fold expression expands to nested parenthesized expressions.
16468 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16469 // them.
16470 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
16471 SemaRef.Diag(E->getEllipsisLoc(),
16472 clang::diag::err_fold_expression_limit_exceeded)
16473 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16474 << E->getSourceRange();
16475 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16476 return ExprError();
16477 }
16478
16479 // The transform has determined that we should perform an elementwise
16480 // expansion of the pattern. Do so.
16481 ExprResult Result = getDerived().TransformExpr(E->getInit());
16482 if (Result.isInvalid())
16483 return true;
16484 bool LeftFold = E->isLeftFold();
16485
16486 // If we're retaining an expansion for a right fold, it is the innermost
16487 // component and takes the init (if any).
16488 if (!LeftFold && RetainExpansion) {
16489 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16490
16491 ExprResult Out = getDerived().TransformExpr(Pattern);
16492 if (Out.isInvalid())
16493 return true;
16494
16495 Result = getDerived().RebuildCXXFoldExpr(
16496 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16497 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16498 if (Result.isInvalid())
16499 return true;
16500 }
16501
16502 bool WarnedOnComparison = false;
16503 for (unsigned I = 0; I != *NumExpansions; ++I) {
16504 Sema::ArgPackSubstIndexRAII SubstIndex(
16505 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16506 ExprResult Out = getDerived().TransformExpr(Pattern);
16507 if (Out.isInvalid())
16508 return true;
16509
16510 if (Out.get()->containsUnexpandedParameterPack()) {
16511 // We still have a pack; retain a pack expansion for this slice.
16512 Result = getDerived().RebuildCXXFoldExpr(
16513 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16514 E->getOperator(), E->getEllipsisLoc(),
16515 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16516 OrigNumExpansions);
16517 } else if (Result.isUsable()) {
16518 // We've got down to a single element; build a binary operator.
16519 Expr *LHS = LeftFold ? Result.get() : Out.get();
16520 Expr *RHS = LeftFold ? Out.get() : Result.get();
16521 if (Callee) {
16522 UnresolvedSet<16> Functions;
16523 Functions.append(Callee->decls_begin(), Callee->decls_end());
16524 Result = getDerived().RebuildCXXOperatorCallExpr(
16525 BinaryOperator::getOverloadedOperator(E->getOperator()),
16526 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16527 Functions, LHS, RHS);
16528 } else {
16529 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16530 E->getOperator(), LHS, RHS,
16531 /*ForFoldExpresion=*/true);
16532 if (!WarnedOnComparison && Result.isUsable()) {
16533 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
16534 BO && BO->isComparisonOp()) {
16535 WarnedOnComparison = true;
16536 SemaRef.Diag(BO->getBeginLoc(),
16537 diag::warn_comparison_in_fold_expression)
16538 << BO->getOpcodeStr();
16539 }
16540 }
16541 }
16542 } else
16543 Result = Out;
16544
16545 if (Result.isInvalid())
16546 return true;
16547 }
16548
16549 // If we're retaining an expansion for a left fold, it is the outermost
16550 // component and takes the complete expansion so far as its init (if any).
16551 if (LeftFold && RetainExpansion) {
16552 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16553
16554 ExprResult Out = getDerived().TransformExpr(Pattern);
16555 if (Out.isInvalid())
16556 return true;
16557
16558 Result = getDerived().RebuildCXXFoldExpr(
16559 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16560 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16561 if (Result.isInvalid())
16562 return true;
16563 }
16564
16565 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16566 PE->setIsProducedByFoldExpansion();
16567
16568 // If we had no init and an empty pack, and we're not retaining an expansion,
16569 // then produce a fallback value or error.
16570 if (Result.isUnset())
16571 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16572 E->getOperator());
16573 return Result;
16574}
16575
16576template <typename Derived>
16579 SmallVector<Expr *, 4> TransformedInits;
16580 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16581
16582 QualType T = getDerived().TransformType(E->getType());
16583
16584 bool ArgChanged = false;
16585
16586 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
16587 TransformedInits, &ArgChanged))
16588 return ExprError();
16589
16590 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
16591 return E;
16592
16593 return getDerived().RebuildCXXParenListInitExpr(
16594 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
16595 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
16596}
16597
16598template<typename Derived>
16602 return getDerived().TransformExpr(E->getSubExpr());
16603}
16604
16605template<typename Derived>
16608 return SemaRef.MaybeBindToTemporary(E);
16609}
16610
16611template<typename Derived>
16614 return E;
16615}
16616
16617template<typename Derived>
16620 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16621 if (SubExpr.isInvalid())
16622 return ExprError();
16623
16624 if (!getDerived().AlwaysRebuild() &&
16625 SubExpr.get() == E->getSubExpr())
16626 return E;
16627
16628 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16629}
16630
16631template<typename Derived>
16634 // Transform each of the elements.
16635 SmallVector<Expr *, 8> Elements;
16636 bool ArgChanged = false;
16637 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16638 /*IsCall=*/false, Elements, &ArgChanged))
16639 return ExprError();
16640
16641 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16642 return SemaRef.MaybeBindToTemporary(E);
16643
16644 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16645 Elements.data(),
16646 Elements.size());
16647}
16648
16649template<typename Derived>
16653 // Transform each of the elements.
16655 bool ArgChanged = false;
16656 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16657 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16658
16659 if (OrigElement.isPackExpansion()) {
16660 // This key/value element is a pack expansion.
16662 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16663 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16664 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16665
16666 // Determine whether the set of unexpanded parameter packs can
16667 // and should be expanded.
16668 bool Expand = true;
16669 bool RetainExpansion = false;
16670 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
16671 UnsignedOrNone NumExpansions = OrigNumExpansions;
16672 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16673 OrigElement.Value->getEndLoc());
16674 if (getDerived().TryExpandParameterPacks(
16675 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
16676 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16677 NumExpansions))
16678 return ExprError();
16679
16680 if (!Expand) {
16681 // The transform has determined that we should perform a simple
16682 // transformation on the pack expansion, producing another pack
16683 // expansion.
16684 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16685 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16686 if (Key.isInvalid())
16687 return ExprError();
16688
16689 if (Key.get() != OrigElement.Key)
16690 ArgChanged = true;
16691
16692 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16693 if (Value.isInvalid())
16694 return ExprError();
16695
16696 if (Value.get() != OrigElement.Value)
16697 ArgChanged = true;
16698
16699 ObjCDictionaryElement Expansion = {
16700 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16701 };
16702 Elements.push_back(Expansion);
16703 continue;
16704 }
16705
16706 // Record right away that the argument was changed. This needs
16707 // to happen even if the array expands to nothing.
16708 ArgChanged = true;
16709
16710 // The transform has determined that we should perform an elementwise
16711 // expansion of the pattern. Do so.
16712 for (unsigned I = 0; I != *NumExpansions; ++I) {
16713 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16714 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16715 if (Key.isInvalid())
16716 return ExprError();
16717
16718 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16719 if (Value.isInvalid())
16720 return ExprError();
16721
16722 ObjCDictionaryElement Element = {
16723 Key.get(), Value.get(), SourceLocation(), NumExpansions
16724 };
16725
16726 // If any unexpanded parameter packs remain, we still have a
16727 // pack expansion.
16728 // FIXME: Can this really happen?
16729 if (Key.get()->containsUnexpandedParameterPack() ||
16730 Value.get()->containsUnexpandedParameterPack())
16731 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16732
16733 Elements.push_back(Element);
16734 }
16735
16736 // FIXME: Retain a pack expansion if RetainExpansion is true.
16737
16738 // We've finished with this pack expansion.
16739 continue;
16740 }
16741
16742 // Transform and check key.
16743 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16744 if (Key.isInvalid())
16745 return ExprError();
16746
16747 if (Key.get() != OrigElement.Key)
16748 ArgChanged = true;
16749
16750 // Transform and check value.
16752 = getDerived().TransformExpr(OrigElement.Value);
16753 if (Value.isInvalid())
16754 return ExprError();
16755
16756 if (Value.get() != OrigElement.Value)
16757 ArgChanged = true;
16758
16759 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16760 std::nullopt};
16761 Elements.push_back(Element);
16762 }
16763
16764 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16765 return SemaRef.MaybeBindToTemporary(E);
16766
16767 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16768 Elements);
16769}
16770
16771template<typename Derived>
16774 TypeSourceInfo *EncodedTypeInfo
16775 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16776 if (!EncodedTypeInfo)
16777 return ExprError();
16778
16779 if (!getDerived().AlwaysRebuild() &&
16780 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16781 return E;
16782
16783 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16784 EncodedTypeInfo,
16785 E->getRParenLoc());
16786}
16787
16788template<typename Derived>
16791 // This is a kind of implicit conversion, and it needs to get dropped
16792 // and recomputed for the same general reasons that ImplicitCastExprs
16793 // do, as well a more specific one: this expression is only valid when
16794 // it appears *immediately* as an argument expression.
16795 return getDerived().TransformExpr(E->getSubExpr());
16796}
16797
16798template<typename Derived>
16801 TypeSourceInfo *TSInfo
16802 = getDerived().TransformType(E->getTypeInfoAsWritten());
16803 if (!TSInfo)
16804 return ExprError();
16805
16806 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16807 if (Result.isInvalid())
16808 return ExprError();
16809
16810 if (!getDerived().AlwaysRebuild() &&
16811 TSInfo == E->getTypeInfoAsWritten() &&
16812 Result.get() == E->getSubExpr())
16813 return E;
16814
16815 return SemaRef.ObjC().BuildObjCBridgedCast(
16816 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16817 Result.get());
16818}
16819
16820template <typename Derived>
16823 return E;
16824}
16825
16826template<typename Derived>
16829 // Transform arguments.
16830 bool ArgChanged = false;
16832 Args.reserve(E->getNumArgs());
16833 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16834 &ArgChanged))
16835 return ExprError();
16836
16837 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16838 // Class message: transform the receiver type.
16839 TypeSourceInfo *ReceiverTypeInfo
16840 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16841 if (!ReceiverTypeInfo)
16842 return ExprError();
16843
16844 // If nothing changed, just retain the existing message send.
16845 if (!getDerived().AlwaysRebuild() &&
16846 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16847 return SemaRef.MaybeBindToTemporary(E);
16848
16849 // Build a new class message send.
16851 E->getSelectorLocs(SelLocs);
16852 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16853 E->getSelector(),
16854 SelLocs,
16855 E->getMethodDecl(),
16856 E->getLeftLoc(),
16857 Args,
16858 E->getRightLoc());
16859 }
16860 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16861 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16862 if (!E->getMethodDecl())
16863 return ExprError();
16864
16865 // Build a new class message send to 'super'.
16867 E->getSelectorLocs(SelLocs);
16868 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16869 E->getSelector(),
16870 SelLocs,
16871 E->getReceiverType(),
16872 E->getMethodDecl(),
16873 E->getLeftLoc(),
16874 Args,
16875 E->getRightLoc());
16876 }
16877
16878 // Instance message: transform the receiver
16879 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16880 "Only class and instance messages may be instantiated");
16881 ExprResult Receiver
16882 = getDerived().TransformExpr(E->getInstanceReceiver());
16883 if (Receiver.isInvalid())
16884 return ExprError();
16885
16886 // If nothing changed, just retain the existing message send.
16887 if (!getDerived().AlwaysRebuild() &&
16888 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16889 return SemaRef.MaybeBindToTemporary(E);
16890
16891 // Build a new instance message send.
16893 E->getSelectorLocs(SelLocs);
16894 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16895 E->getSelector(),
16896 SelLocs,
16897 E->getMethodDecl(),
16898 E->getLeftLoc(),
16899 Args,
16900 E->getRightLoc());
16901}
16902
16903template<typename Derived>
16906 return E;
16907}
16908
16909template<typename Derived>
16912 return E;
16913}
16914
16915template<typename Derived>
16918 // Transform the base expression.
16919 ExprResult Base = getDerived().TransformExpr(E->getBase());
16920 if (Base.isInvalid())
16921 return ExprError();
16922
16923 // We don't need to transform the ivar; it will never change.
16924
16925 // If nothing changed, just retain the existing expression.
16926 if (!getDerived().AlwaysRebuild() &&
16927 Base.get() == E->getBase())
16928 return E;
16929
16930 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16931 E->getLocation(),
16932 E->isArrow(), E->isFreeIvar());
16933}
16934
16935template<typename Derived>
16938 // 'super' and types never change. Property never changes. Just
16939 // retain the existing expression.
16940 if (!E->isObjectReceiver())
16941 return E;
16942
16943 // Transform the base expression.
16944 ExprResult Base = getDerived().TransformExpr(E->getBase());
16945 if (Base.isInvalid())
16946 return ExprError();
16947
16948 // We don't need to transform the property; it will never change.
16949
16950 // If nothing changed, just retain the existing expression.
16951 if (!getDerived().AlwaysRebuild() &&
16952 Base.get() == E->getBase())
16953 return E;
16954
16955 if (E->isExplicitProperty())
16956 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16957 E->getExplicitProperty(),
16958 E->getLocation());
16959
16960 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16961 SemaRef.Context.PseudoObjectTy,
16962 E->getImplicitPropertyGetter(),
16963 E->getImplicitPropertySetter(),
16964 E->getLocation());
16965}
16966
16967template<typename Derived>
16970 // Transform the base expression.
16971 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16972 if (Base.isInvalid())
16973 return ExprError();
16974
16975 // Transform the key expression.
16976 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16977 if (Key.isInvalid())
16978 return ExprError();
16979
16980 // If nothing changed, just retain the existing expression.
16981 if (!getDerived().AlwaysRebuild() &&
16982 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16983 return E;
16984
16985 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16986 Base.get(), Key.get(),
16987 E->getAtIndexMethodDecl(),
16988 E->setAtIndexMethodDecl());
16989}
16990
16991template<typename Derived>
16994 // Transform the base expression.
16995 ExprResult Base = getDerived().TransformExpr(E->getBase());
16996 if (Base.isInvalid())
16997 return ExprError();
16998
16999 // If nothing changed, just retain the existing expression.
17000 if (!getDerived().AlwaysRebuild() &&
17001 Base.get() == E->getBase())
17002 return E;
17003
17004 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17005 E->getOpLoc(),
17006 E->isArrow());
17007}
17008
17009template<typename Derived>
17012 bool ArgumentChanged = false;
17013 SmallVector<Expr*, 8> SubExprs;
17014 SubExprs.reserve(E->getNumSubExprs());
17015 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17016 SubExprs, &ArgumentChanged))
17017 return ExprError();
17018
17019 if (!getDerived().AlwaysRebuild() &&
17020 !ArgumentChanged)
17021 return E;
17022
17023 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17024 SubExprs,
17025 E->getRParenLoc());
17026}
17027
17028template<typename Derived>
17031 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17032 if (SrcExpr.isInvalid())
17033 return ExprError();
17034
17035 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17036 if (!Type)
17037 return ExprError();
17038
17039 if (!getDerived().AlwaysRebuild() &&
17040 Type == E->getTypeSourceInfo() &&
17041 SrcExpr.get() == E->getSrcExpr())
17042 return E;
17043
17044 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17045 SrcExpr.get(), Type,
17046 E->getRParenLoc());
17047}
17048
17049template<typename Derived>
17052 BlockDecl *oldBlock = E->getBlockDecl();
17053
17054 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17055 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17056
17057 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17058 blockScope->TheDecl->setBlockMissingReturnType(
17059 oldBlock->blockMissingReturnType());
17060
17062 SmallVector<QualType, 4> paramTypes;
17063
17064 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17065
17066 // Parameter substitution.
17067 Sema::ExtParameterInfoBuilder extParamInfos;
17068 if (getDerived().TransformFunctionTypeParams(
17069 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17070 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17071 extParamInfos)) {
17072 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17073 return ExprError();
17074 }
17075
17076 QualType exprResultType =
17077 getDerived().TransformType(exprFunctionType->getReturnType());
17078
17079 auto epi = exprFunctionType->getExtProtoInfo();
17080 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17081
17083 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17084 blockScope->FunctionType = functionType;
17085
17086 // Set the parameters on the block decl.
17087 if (!params.empty())
17088 blockScope->TheDecl->setParams(params);
17089
17090 if (!oldBlock->blockMissingReturnType()) {
17091 blockScope->HasImplicitReturnType = false;
17092 blockScope->ReturnType = exprResultType;
17093 }
17094
17095 // Transform the body
17096 StmtResult body = getDerived().TransformStmt(E->getBody());
17097 if (body.isInvalid()) {
17098 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17099 return ExprError();
17100 }
17101
17102#ifndef NDEBUG
17103 // In builds with assertions, make sure that we captured everything we
17104 // captured before.
17105 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17106 for (const auto &I : oldBlock->captures()) {
17107 VarDecl *oldCapture = I.getVariable();
17108
17109 // Ignore parameter packs.
17110 if (oldCapture->isParameterPack())
17111 continue;
17112
17113 VarDecl *newCapture =
17114 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17115 oldCapture));
17116 assert(blockScope->CaptureMap.count(newCapture));
17117 }
17118
17119 // The this pointer may not be captured by the instantiated block, even when
17120 // it's captured by the original block, if the expression causing the
17121 // capture is in the discarded branch of a constexpr if statement.
17122 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17123 "this pointer isn't captured in the old block");
17124 }
17125#endif
17126
17127 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17128 /*Scope=*/nullptr);
17129}
17130
17131template<typename Derived>
17134 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17135 if (SrcExpr.isInvalid())
17136 return ExprError();
17137
17138 QualType Type = getDerived().TransformType(E->getType());
17139
17140 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17141 E->getRParenLoc());
17142}
17143
17144template<typename Derived>
17147 bool ArgumentChanged = false;
17148 SmallVector<Expr*, 8> SubExprs;
17149 SubExprs.reserve(E->getNumSubExprs());
17150 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17151 SubExprs, &ArgumentChanged))
17152 return ExprError();
17153
17154 if (!getDerived().AlwaysRebuild() &&
17155 !ArgumentChanged)
17156 return E;
17157
17158 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17159 E->getOp(), E->getRParenLoc());
17160}
17161
17162//===----------------------------------------------------------------------===//
17163// Type reconstruction
17164//===----------------------------------------------------------------------===//
17165
17166template<typename Derived>
17169 return SemaRef.BuildPointerType(PointeeType, Star,
17171}
17172
17173template<typename Derived>
17176 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17178}
17179
17180template<typename Derived>
17183 bool WrittenAsLValue,
17184 SourceLocation Sigil) {
17185 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17186 Sigil, getDerived().getBaseEntity());
17187}
17188
17189template <typename Derived>
17191 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17192 SourceLocation Sigil) {
17193 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17195}
17196
17197template<typename Derived>
17199 const ObjCTypeParamDecl *Decl,
17200 SourceLocation ProtocolLAngleLoc,
17202 ArrayRef<SourceLocation> ProtocolLocs,
17203 SourceLocation ProtocolRAngleLoc) {
17204 return SemaRef.ObjC().BuildObjCTypeParamType(
17205 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17206 /*FailOnError=*/true);
17207}
17208
17209template<typename Derived>
17211 QualType BaseType,
17212 SourceLocation Loc,
17213 SourceLocation TypeArgsLAngleLoc,
17215 SourceLocation TypeArgsRAngleLoc,
17216 SourceLocation ProtocolLAngleLoc,
17218 ArrayRef<SourceLocation> ProtocolLocs,
17219 SourceLocation ProtocolRAngleLoc) {
17220 return SemaRef.ObjC().BuildObjCObjectType(
17221 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17222 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17223 /*FailOnError=*/true,
17224 /*Rebuilding=*/true);
17225}
17226
17227template<typename Derived>
17229 QualType PointeeType,
17231 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17232}
17233
17234template <typename Derived>
17236 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17237 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17238 if (SizeExpr || !Size)
17239 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17240 IndexTypeQuals, BracketsRange,
17242
17243 QualType Types[] = {
17244 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17245 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17246 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17247 };
17248 QualType SizeType;
17249 for (const auto &T : Types)
17250 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17251 SizeType = T;
17252 break;
17253 }
17254
17255 // Note that we can return a VariableArrayType here in the case where
17256 // the element type was a dependent VariableArrayType.
17257 IntegerLiteral *ArraySize
17258 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17259 /*FIXME*/BracketsRange.getBegin());
17260 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17261 IndexTypeQuals, BracketsRange,
17263}
17264
17265template <typename Derived>
17267 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17268 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17269 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17270 IndexTypeQuals, BracketsRange);
17271}
17272
17273template <typename Derived>
17275 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17276 SourceRange BracketsRange) {
17277 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17278 IndexTypeQuals, BracketsRange);
17279}
17280
17281template <typename Derived>
17283 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17284 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17285 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17286 SizeExpr,
17287 IndexTypeQuals, BracketsRange);
17288}
17289
17290template <typename Derived>
17292 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17293 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17294 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17295 SizeExpr,
17296 IndexTypeQuals, BracketsRange);
17297}
17298
17299template <typename Derived>
17301 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17302 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17303 AttributeLoc);
17304}
17305
17306template <typename Derived>
17308 unsigned NumElements,
17309 VectorKind VecKind) {
17310 // FIXME: semantic checking!
17311 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17312}
17313
17314template <typename Derived>
17316 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17317 VectorKind VecKind) {
17318 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17319}
17320
17321template<typename Derived>
17323 unsigned NumElements,
17324 SourceLocation AttributeLoc) {
17325 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17326 NumElements, true);
17327 IntegerLiteral *VectorSize
17328 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17329 AttributeLoc);
17330 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17331}
17332
17333template<typename Derived>
17336 Expr *SizeExpr,
17337 SourceLocation AttributeLoc) {
17338 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17339}
17340
17341template <typename Derived>
17343 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17344 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17345 NumColumns);
17346}
17347
17348template <typename Derived>
17350 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17351 SourceLocation AttributeLoc) {
17352 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17353 AttributeLoc);
17354}
17355
17356template <typename Derived>
17360 return SemaRef.BuildFunctionType(T, ParamTypes,
17363 EPI);
17364}
17365
17366template<typename Derived>
17368 return SemaRef.Context.getFunctionNoProtoType(T);
17369}
17370
17371template <typename Derived>
17374 SourceLocation NameLoc, Decl *D) {
17375 assert(D && "no decl found");
17376 if (D->isInvalidDecl()) return QualType();
17377
17378 // FIXME: Doesn't account for ObjCInterfaceDecl!
17379 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17380 // A valid resolved using typename pack expansion decl can have multiple
17381 // UsingDecls, but they must each have exactly one type, and it must be
17382 // the same type in every case. But we must have at least one expansion!
17383 if (UPD->expansions().empty()) {
17384 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17385 << UPD->isCXXClassMember() << UPD;
17386 return QualType();
17387 }
17388
17389 // We might still have some unresolved types. Try to pick a resolved type
17390 // if we can. The final instantiation will check that the remaining
17391 // unresolved types instantiate to the type we pick.
17392 QualType FallbackT;
17393 QualType T;
17394 for (auto *E : UPD->expansions()) {
17395 QualType ThisT =
17396 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17397 if (ThisT.isNull())
17398 continue;
17399 if (ThisT->getAs<UnresolvedUsingType>())
17400 FallbackT = ThisT;
17401 else if (T.isNull())
17402 T = ThisT;
17403 else
17404 assert(getSema().Context.hasSameType(ThisT, T) &&
17405 "mismatched resolved types in using pack expansion");
17406 }
17407 return T.isNull() ? FallbackT : T;
17408 }
17409 if (auto *Using = dyn_cast<UsingDecl>(D)) {
17410 assert(Using->hasTypename() &&
17411 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17412
17413 // A valid resolved using typename decl points to exactly one type decl.
17414 assert(++Using->shadow_begin() == Using->shadow_end());
17415
17416 UsingShadowDecl *Shadow = *Using->shadow_begin();
17417 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
17418 return QualType();
17419 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
17420 }
17422 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17423 return SemaRef.Context.getUnresolvedUsingType(
17425}
17426
17427template <typename Derived>
17429 TypeOfKind Kind) {
17430 return SemaRef.BuildTypeofExprType(E, Kind);
17431}
17432
17433template<typename Derived>
17435 TypeOfKind Kind) {
17436 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17437}
17438
17439template <typename Derived>
17441 return SemaRef.BuildDecltypeType(E);
17442}
17443
17444template <typename Derived>
17446 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17447 SourceLocation EllipsisLoc, bool FullySubstituted,
17448 ArrayRef<QualType> Expansions) {
17449 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17450 FullySubstituted, Expansions);
17451}
17452
17453template<typename Derived>
17455 UnaryTransformType::UTTKind UKind,
17456 SourceLocation Loc) {
17457 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17458}
17459
17460template <typename Derived>
17463 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
17464 return SemaRef.CheckTemplateIdType(
17465 Keyword, Template, TemplateNameLoc, TemplateArgs,
17466 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
17467}
17468
17469template<typename Derived>
17471 SourceLocation KWLoc) {
17472 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17473}
17474
17475template<typename Derived>
17477 SourceLocation KWLoc,
17478 bool isReadPipe) {
17479 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17480 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17481}
17482
17483template <typename Derived>
17485 unsigned NumBits,
17486 SourceLocation Loc) {
17487 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17488 NumBits, true);
17489 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17490 SemaRef.Context.IntTy, Loc);
17491 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17492}
17493
17494template <typename Derived>
17496 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17497 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17498}
17499
17500template <typename Derived>
17502 bool TemplateKW,
17503 TemplateName Name) {
17504 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17505 Name);
17506}
17507
17508template <typename Derived>
17510 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
17511 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
17513 TemplateName.setIdentifier(&Name, NameLoc);
17515 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17516 TemplateName, ParsedType::make(ObjectType),
17517 /*EnteringContext=*/false, Template,
17518 AllowInjectedClassName);
17519 return Template.get();
17520}
17521
17522template<typename Derived>
17525 SourceLocation TemplateKWLoc,
17526 OverloadedOperatorKind Operator,
17527 SourceLocation NameLoc,
17528 QualType ObjectType,
17529 bool AllowInjectedClassName) {
17530 UnqualifiedId Name;
17531 // FIXME: Bogus location information.
17532 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17533 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17535 getSema().ActOnTemplateName(
17536 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17537 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17538 return Template.get();
17539}
17540
17541template <typename Derived>
17544 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17545 Expr *Second) {
17546 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17547
17548 if (First->getObjectKind() == OK_ObjCProperty) {
17551 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17552 Opc, First, Second);
17553 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
17554 if (Result.isInvalid())
17555 return ExprError();
17556 First = Result.get();
17557 }
17558
17559 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17560 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17561 if (Result.isInvalid())
17562 return ExprError();
17563 Second = Result.get();
17564 }
17565
17566 // Determine whether this should be a builtin operation.
17567 if (Op == OO_Subscript) {
17568 if (!First->getType()->isOverloadableType() &&
17569 !Second->getType()->isOverloadableType())
17570 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17571 OpLoc);
17572 } else if (Op == OO_Arrow) {
17573 // It is possible that the type refers to a RecoveryExpr created earlier
17574 // in the tree transformation.
17575 if (First->getType()->isDependentType())
17576 return ExprError();
17577 // -> is never a builtin operation.
17578 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17579 } else if (Second == nullptr || isPostIncDec) {
17580 if (!First->getType()->isOverloadableType() ||
17581 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17582 // The argument is not of overloadable type, or this is an expression
17583 // of the form &Class::member, so try to create a built-in unary
17584 // operation.
17586 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17587
17588 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17589 }
17590 } else {
17591 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17592 !First->getType()->isOverloadableType() &&
17593 !Second->getType()->isOverloadableType()) {
17594 // Neither of the arguments is type-dependent or has an overloadable
17595 // type, so try to create a built-in binary operation.
17598 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17599 if (Result.isInvalid())
17600 return ExprError();
17601
17602 return Result;
17603 }
17604 }
17605
17606 // Create the overloaded operator invocation for unary operators.
17607 if (!Second || isPostIncDec) {
17609 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17610 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17611 RequiresADL);
17612 }
17613
17614 // Create the overloaded operator invocation for binary operators.
17616 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17617 First, Second, RequiresADL);
17618 if (Result.isInvalid())
17619 return ExprError();
17620
17621 return Result;
17622}
17623
17624template<typename Derived>
17627 SourceLocation OperatorLoc,
17628 bool isArrow,
17629 CXXScopeSpec &SS,
17630 TypeSourceInfo *ScopeType,
17631 SourceLocation CCLoc,
17632 SourceLocation TildeLoc,
17633 PseudoDestructorTypeStorage Destroyed) {
17634 QualType CanonicalBaseType = Base->getType().getCanonicalType();
17635 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17636 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
17637 (isArrow && isa<PointerType>(CanonicalBaseType) &&
17638 !cast<PointerType>(CanonicalBaseType)
17639 ->getPointeeType()
17640 ->getAsCanonical<RecordType>())) {
17641 // This pseudo-destructor expression is still a pseudo-destructor.
17642 return SemaRef.BuildPseudoDestructorExpr(
17643 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17644 CCLoc, TildeLoc, Destroyed);
17645 }
17646
17647 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17648 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
17649 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17650 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17651 NameInfo.setNamedTypeInfo(DestroyedType);
17652
17653 // The scope type is now known to be a valid nested name specifier
17654 // component. Tack it on to the nested name specifier.
17655 if (ScopeType) {
17656 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
17657 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17658 diag::err_expected_class_or_namespace)
17659 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17660 return ExprError();
17661 }
17662 SS.clear();
17663 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
17664 }
17665
17666 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17667 return getSema().BuildMemberReferenceExpr(
17668 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
17669 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
17670 /*TemplateArgs*/ nullptr,
17671 /*S*/ nullptr);
17672}
17673
17674template<typename Derived>
17677 SourceLocation Loc = S->getBeginLoc();
17678 CapturedDecl *CD = S->getCapturedDecl();
17679 unsigned NumParams = CD->getNumParams();
17680 unsigned ContextParamPos = CD->getContextParamPosition();
17682 for (unsigned I = 0; I < NumParams; ++I) {
17683 if (I != ContextParamPos) {
17684 Params.push_back(
17685 std::make_pair(
17686 CD->getParam(I)->getName(),
17687 getDerived().TransformType(CD->getParam(I)->getType())));
17688 } else {
17689 Params.push_back(std::make_pair(StringRef(), QualType()));
17690 }
17691 }
17692 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17693 S->getCapturedRegionKind(), Params);
17694 StmtResult Body;
17695 {
17696 Sema::CompoundScopeRAII CompoundScope(getSema());
17697 Body = getDerived().TransformStmt(S->getCapturedStmt());
17698 }
17699
17700 if (Body.isInvalid()) {
17701 getSema().ActOnCapturedRegionError();
17702 return StmtError();
17703 }
17704
17705 return getSema().ActOnCapturedRegionEnd(Body.get());
17706}
17707
17708template <typename Derived>
17711 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
17712 // function definition or instantiation of a function template specialization
17713 // and will therefore never appear in a dependent context.
17714 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
17715 "context");
17716}
17717
17718template <typename Derived>
17720 // We can transform the base expression and allow argument resolution to fill
17721 // in the rest.
17722 return getDerived().TransformExpr(E->getArgLValue());
17723}
17724
17725} // end namespace clang
17726
17727#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:2990
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3028
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3030
Expr * getDimensionExpression() const
Definition ExprCXX.h:3040
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3036
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3027
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h: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:8139
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4651
void setIsVariadic(bool value)
Definition Decl.h:4727
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:5470
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5489
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5488
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h: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:2620
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3864
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:481
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5026
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition ExprCXX.h:1833
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:375
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:406
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:413
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:409
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2349
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4303
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:768
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5135
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2739
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1854
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:526
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:286
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2198
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:73
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition DeclSpec.cpp:51
char * location_data() const
Retrieve the data associated with the source-location information.
Definition DeclSpec.h:206
SourceRange getRange() const
Definition DeclSpec.h:79
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition DeclSpec.cpp:75
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition DeclSpec.h:94
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition DeclSpec.cpp:123
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition DeclSpec.h:210
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition DeclSpec.cpp:62
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition DeclSpec.cpp:85
bool isEmpty() const
No scope specifier.
Definition DeclSpec.h:178
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition DeclSpec.cpp:103
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:800
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1901
Represents the this expression in C++.
Definition ExprCXX.h:1155
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:848
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3738
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3782
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3793
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3776
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3787
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3796
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1069
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h: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:4923
unsigned getNumParams() const
Definition Decl.h:4961
unsigned getContextParamPosition() const
Definition Decl.h:4990
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:4963
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:5363
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:5444
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h:1454
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2109
DeclContextLookupResult lookup_result
Definition DeclBase.h:2577
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
void addDecl(Decl *D)
Add the declaration D into this context.
A reference to a declared variable, function, enum, etc.
Definition Expr.h: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:821
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:808
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1874
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2268
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2493
void setAttrOperandParensRange(SourceRange range)
Definition TypeLoc.h:1978
Represents an extended address space qualifier where the input address space value is dependent.
Definition TypeBase.h:4061
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5395
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2561
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3504
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3578
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3552
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3570
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3588
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3562
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3605
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3543
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3598
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3540
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h: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:3655
This represents one expression.
Definition Expr.h:112
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:451
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:3063
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:3157
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2888
Represents a function declaration or definition.
Definition Decl.h:1999
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2771
SmallVector< Conflict > Conflicts
Definition TypeBase.h: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:4835
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:523
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2146
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1970
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1363
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1358
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1367
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2035
Represents the results of name lookup.
Definition Lookup.h:147
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition Lookup.h:607
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition Lookup.h:475
bool empty() const
Return true if no decls were found.
Definition Lookup.h:362
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition Lookup.h:666
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition Lookup.h:576
DeclarationName getLookupName() const
Gets the name to look up.
Definition Lookup.h:265
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3614
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Definition StmtCXX.h:253
An instance of this class represents the declaration of a property member.
Definition DeclCXX.h: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:4914
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:273
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:486
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:294
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:300
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:339
Represents C++ namespaces and their aliases.
Definition Decl.h:572
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h: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:3122
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3274
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3256
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3235
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3248
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3244
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3318
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3221
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3324
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3232
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3264
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3271
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4357
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2613
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2609
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2625
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2296
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h: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:1789
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1849
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1822
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.cpp:2946
unsigned getFunctionScopeDepth() const
Definition Decl.h:1839
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2705
PipeType - OpenCL20.
Definition TypeBase.h:8105
bool isReadOnly() const
Definition TypeBase.h:8135
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:2688
const IdentifierInfo * getIdentifier() const
Definition ExprCXX.h:2708
SourceLocation getLocation() const
Definition ExprCXX.h:2712
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2704
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h: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:8287
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8327
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8381
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8319
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:13518
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8400
A RAII object to enter scope of a compound statement.
Definition Sema.h:1289
A RAII object to temporarily push a declaration context.
Definition Sema.h:3475
A helper class for building up ExtParameterInfos.
Definition Sema.h:12931
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:12950
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:12938
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:13903
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:853
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:9290
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9298
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9293
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:1504
void ActOnStartStmtExpr()
void ActOnStmtExprError()
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt={})
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
VarDecl * buildCoroutinePromise(SourceLocation Loc)
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
Definition Sema.h:7796
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7798
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7797
ExprResult 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:1529
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:11919
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:1282
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:921
SemaObjC & ObjC()
Definition Sema.h:1489
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:924
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *LHS, Expr *RHS, bool RequiresADL=true, bool AllowRewrittenCandidates=true, FunctionDecl *DefaultedFn=nullptr)
Create a binary operation that may resolve to an overloaded operator.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
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:917
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1494
@ ReuseLambdaContextDecl
Definition Sema.h:6977
bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, bool IsAddressOfOperand)
Check whether an expression might be an implicit class member access.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11722
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:1313
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:11717
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:1417
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:13512
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Definition Sema.h:6695
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6705
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6674
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6700
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition SemaStmt.cpp:75
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition Sema.h:8269
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc)
Complete a lambda-expression having processed and attached the lambda body.
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition Sema.h:11010
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs)
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:563
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParen)
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition SemaCast.cpp:337
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition SemaStmt.cpp:950
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, SourceLocation RParenLoc, MultiExprArg Args, AtomicExpr::AtomicOp Op, AtomicArgumentOrder ArgOrder=AtomicArgumentOrder::API)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
OpaquePtr< TemplateName > TemplateTy
Definition Sema.h:1274
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:7782
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:436
SemaPseudoObject & PseudoObject()
Definition Sema.h:1514
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:1273
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:8608
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:4435
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4497
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4520
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1709
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4525
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4494
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4500
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4503
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h: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:4658
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4748
A structure for storing an already-substituted template template parameter pack.
A structure for storing the information associated with a substituted template template parameter.
Wrapper for substituted template type parameters.
Definition TypeLoc.h:1001
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2509
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
SourceLocation getNameLoc() const
Definition TypeLoc.h:827
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:806
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:814
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition TypeLoc.h:821
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:829
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:810
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
const TemplateArgumentLoc * operator->() const
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
TemplateArgumentLocContainerIterator operator++(int)
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator & operator++()
const TemplateArgumentLoc * operator->() const
Iterator adaptor that invents template argument location information for each of the template argumen...
TemplateArgumentLocInventIterator & operator++()
std::iterator_traits< InputIterator >::difference_type difference_type
TemplateArgumentLocInventIterator operator++(int)
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DeducedTemplateStorage * getAsDeducedTemplateName() const
Retrieve the deduced template info, if any.
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NestedNameSpecifier getQualifier() const
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceLocation getLAngleLoc() const
Definition TypeLoc.h:1887
SourceLocation getRAngleLoc() const
Definition TypeLoc.h:1902
SourceLocation getTemplateNameLoc() const
Definition TypeLoc.h:1885
SourceLocation getTemplateKeywordLoc() const
Definition TypeLoc.h:1881
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:1871
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:1867
Wrapper for template type parameters.
Definition TypeLoc.h:890
The top declaration context.
Definition Decl.h:104
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
TemplateArgument TransformNamedTemplateTemplateArgument(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, TemplateName Name, SourceLocation NameLoc)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
StmtResult RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TagDecl *Tag)
Build a new class/struct/union/enum type.
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
OMPClause * RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'use' clause.
StmtResult RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL)
Transform the given type-with-location into a new type, collecting location information in the given ...
ExprResult RebuildCXXRewrittenBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opcode, const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS)
Build a new rewritten operator expression.
QualType RebuildDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new expression pack expansion.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
OMPClause * RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'message' clause.
ExprResult RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth)
Build a new GNU statement expression.
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
QualType TransformType(QualType T)
Transforms the given type into another type.
UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(ArrayRef< TemplateArgument > PackArgs)
OMPClause * RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc)
Build a new OpenMP 'order' clause.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
ExprResult TransformRequiresTypeParams(SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > Params, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > &TransParams, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a requires expresison into the given vectors.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc)
Build a new initializer list expression.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
StmtResult RebuildOpenACCWaitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
OMPClause * RebuildOMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
OMPClause * RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nocontext' clause.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorKind VecKind)
Build a new vector type given the element type and number of elements.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
QualType RebuildMemberPointerType(QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the qualifier it refers into.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
Build a new Objective-C boxed expression.
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCCacheConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation EndLoc)
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed)
Transforms the parameters of a function type into the given vectors.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Build a new inline asm statement.
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateName Name)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool SuppressObjCLifetime)
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
StmtResult TransformSEHHandler(Stmt *Handler)
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, OverloadedOperatorKind Operator, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the overloaded operator name that is refe...
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_ptr' clause.
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation.
concepts::TypeRequirement * TransformTypeRequirement(concepts::TypeRequirement *Req)
const Derived & getDerived() const
Retrieves a reference to the derived class.
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS, bool ForFoldExpression=false)
Build a new binary operator expression.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs, QualType Type)
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, LambdaScopeInfo *LSI)
QualType RebuildIncompleteArrayType(QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers.
CXXRecordDecl::LambdaDependencyKind ComputeLambdaDependency(LambdaScopeInfo *LSI)
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool FullySubstituted=false)
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc, bool ListInitialization)
Build a new C++ functional-style cast expression.
QualType RebuildCanonicalTagType(TagDecl *Tag)
TypeSourceInfo * TransformType(TypeSourceInfo *DI)
Transforms the given type-with-location into a new type-with-location.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
OMPClause * RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocator' clause.
QualType RebuildDependentSizedArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression,...
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPClause * RebuildOMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'inclusive' clause.
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S)
This is mostly the same as above, but allows 'informational' class directives when rebuilding the stm...
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
Build a new C++1z fold-expression.
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
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:8258
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:8269
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:556
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2890
The base class of the type hierarchy.
Definition TypeBase.h:1833
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2782
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2405
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9023
bool isObjCObjectPointerType() const
Definition TypeBase.h:8693
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9100
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3559
Wrapper for source info for typedefs.
Definition TypeLoc.h:782
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2180
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h: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:3384
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3458
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3453
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4120
A set of unresolved declarations.
void append(iterator I, iterator E)
A set of unresolved declarations.
Wrapper for source info for unresolved typename using decls.
Definition TypeLoc.h:787
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h: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:711
QualType getType() const
Definition Decl.h:722
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5465
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:925
@ CInit
C-style initialization with assignment.
Definition Decl.h:930
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:933
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1167
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h: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:650
@ 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:601
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:235
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:918
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Expr * Cond
};
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition TypeTraits.h:51
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
ExprResult ExprEmpty()
Definition Ownership.h:272
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
StmtResult StmtError()
Definition Ownership.h:266
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h: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:559
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:797
@ Exists
The symbol exists.
Definition Sema.h:790
@ Error
An error occurred.
Definition Sema.h:800
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:793
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:88
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h: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:12977
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13008
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1302
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3275
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions