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.
63
64 bool Expand = false;
65 bool RetainExpansion = false;
68};
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.
320 return TemplateArgument();
321 }
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.
394 enum class StmtDiscardKind {
395 Discarded,
398 };
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.
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, NamedDecl *UnqualLookup,
750 bool AllowInjectedClassName);
751
753
754 /// Transforms the parameters of a function type into the
755 /// given vectors.
756 ///
757 /// The result vectors should be kept in sync; null entries in the
758 /// variables vector are acceptable.
759 ///
760 /// LastParamTransformed, if non-null, will be set to the index of the last
761 /// parameter on which transformation was started. In the event of an error,
762 /// this will contain the parameter which failed to instantiate.
763 ///
764 /// Return true on error.
767 const QualType *ParamTypes,
768 const FunctionProtoType::ExtParameterInfo *ParamInfos,
770 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
771
774 const QualType *ParamTypes,
775 const FunctionProtoType::ExtParameterInfo *ParamInfos,
778 return getDerived().TransformFunctionTypeParams(
779 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
780 }
781
782 /// Transforms the parameters of a requires expresison into the given vectors.
783 ///
784 /// The result vectors should be kept in sync; null entries in the
785 /// variables vector are acceptable.
786 ///
787 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
788 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
789 /// which are cases where transformation shouldn't continue.
791 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
797 KWLoc, Params, /*ParamTypes=*/nullptr,
798 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
799 return ExprError();
800
801 return ExprResult{};
802 }
803
804 /// Transforms a single function-type parameter. Return null
805 /// on error.
806 ///
807 /// \param indexAdjustment - A number to add to the parameter's
808 /// scope index; can be negative
810 int indexAdjustment,
811 UnsignedOrNone NumExpansions,
812 bool ExpectParameterPack);
813
814 /// Transform the body of a lambda-expression.
816 /// Alternative implementation of TransformLambdaBody that skips transforming
817 /// the body.
819
822 return static_cast<CXXRecordDecl::LambdaDependencyKind>(
824 }
825
827
830
833 return TPL;
834 }
835
837
839 bool IsAddressOfOperand,
840 TypeSourceInfo **RecoveryTSI);
841
843 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
844 TypeSourceInfo **RecoveryTSI);
845
847 bool IsAddressOfOperand);
848
850
852
853// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
854// amount of stack usage with clang.
855#define STMT(Node, Parent) \
856 LLVM_ATTRIBUTE_NOINLINE \
857 StmtResult Transform##Node(Node *S);
858#define VALUESTMT(Node, Parent) \
859 LLVM_ATTRIBUTE_NOINLINE \
860 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
861#define EXPR(Node, Parent) \
862 LLVM_ATTRIBUTE_NOINLINE \
863 ExprResult Transform##Node(Node *E);
864#define ABSTRACT_STMT(Stmt)
865#include "clang/AST/StmtNodes.inc"
866
867#define GEN_CLANG_CLAUSE_CLASS
868#define CLAUSE_CLASS(Enum, Str, Class) \
869 LLVM_ATTRIBUTE_NOINLINE \
870 OMPClause *Transform##Class(Class *S);
871#include "llvm/Frontend/OpenMP/OMP.inc"
872
873 /// Build a new qualified type given its unqualified type and type location.
874 ///
875 /// By default, this routine adds type qualifiers only to types that can
876 /// have qualifiers, and silently suppresses those qualifiers that are not
877 /// permitted. Subclasses may override this routine to provide different
878 /// behavior.
880
881 /// Build a new pointer type given its pointee type.
882 ///
883 /// By default, performs semantic analysis when building the pointer type.
884 /// Subclasses may override this routine to provide different behavior.
886
887 /// Build a new block pointer type given its pointee type.
888 ///
889 /// By default, performs semantic analysis when building the block pointer
890 /// type. Subclasses may override this routine to provide different behavior.
892
893 /// Build a new reference type given the type it references.
894 ///
895 /// By default, performs semantic analysis when building the
896 /// reference type. Subclasses may override this routine to provide
897 /// different behavior.
898 ///
899 /// \param LValue whether the type was written with an lvalue sigil
900 /// or an rvalue sigil.
902 bool LValue,
903 SourceLocation Sigil);
904
905 /// Build a new member pointer type given the pointee type and the
906 /// qualifier it refers into.
907 ///
908 /// By default, performs semantic analysis when building the member pointer
909 /// type. Subclasses may override this routine to provide different behavior.
911 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
912 SourceLocation Sigil);
913
915 SourceLocation ProtocolLAngleLoc,
917 ArrayRef<SourceLocation> ProtocolLocs,
918 SourceLocation ProtocolRAngleLoc);
919
920 /// Build an Objective-C object type.
921 ///
922 /// By default, performs semantic analysis when building the object type.
923 /// Subclasses may override this routine to provide different behavior.
926 SourceLocation TypeArgsLAngleLoc,
928 SourceLocation TypeArgsRAngleLoc,
929 SourceLocation ProtocolLAngleLoc,
931 ArrayRef<SourceLocation> ProtocolLocs,
932 SourceLocation ProtocolRAngleLoc);
933
934 /// Build a new Objective-C object pointer type given the pointee type.
935 ///
936 /// By default, directly builds the pointer type, with no additional semantic
937 /// analysis.
940
941 /// Build a new array type given the element type, size
942 /// modifier, size of the array (if known), size expression, and index type
943 /// qualifiers.
944 ///
945 /// By default, performs semantic analysis when building the array type.
946 /// Subclasses may override this routine to provide different behavior.
947 /// Also by default, all of the other Rebuild*Array
949 const llvm::APInt *Size, Expr *SizeExpr,
950 unsigned IndexTypeQuals, SourceRange BracketsRange);
951
952 /// Build a new constant array type given the element type, size
953 /// modifier, (known) size of the array, and index type qualifiers.
954 ///
955 /// By default, performs semantic analysis when building the array type.
956 /// Subclasses may override this routine to provide different behavior.
958 ArraySizeModifier SizeMod,
959 const llvm::APInt &Size, Expr *SizeExpr,
960 unsigned IndexTypeQuals,
961 SourceRange BracketsRange);
962
963 /// Build a new incomplete array type given the element type, size
964 /// modifier, and index type qualifiers.
965 ///
966 /// By default, performs semantic analysis when building the array type.
967 /// Subclasses may override this routine to provide different behavior.
969 ArraySizeModifier SizeMod,
970 unsigned IndexTypeQuals,
971 SourceRange BracketsRange);
972
973 /// Build a new variable-length array type given the element type,
974 /// size modifier, size expression, and index type qualifiers.
975 ///
976 /// By default, performs semantic analysis when building the array type.
977 /// Subclasses may override this routine to provide different behavior.
979 ArraySizeModifier SizeMod, Expr *SizeExpr,
980 unsigned IndexTypeQuals,
981 SourceRange BracketsRange);
982
983 /// Build a new dependent-sized array type given the element type,
984 /// size modifier, size expression, and index type qualifiers.
985 ///
986 /// By default, performs semantic analysis when building the array type.
987 /// Subclasses may override this routine to provide different behavior.
989 ArraySizeModifier SizeMod,
990 Expr *SizeExpr,
991 unsigned IndexTypeQuals,
992 SourceRange BracketsRange);
993
994 /// Build a new vector type given the element type and
995 /// number of elements.
996 ///
997 /// By default, performs semantic analysis when building the vector type.
998 /// Subclasses may override this routine to provide different behavior.
999 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1000 VectorKind VecKind);
1001
1002 /// Build a new potentially dependently-sized extended vector type
1003 /// given the element type and number of elements.
1004 ///
1005 /// By default, performs semantic analysis when building the vector type.
1006 /// Subclasses may override this routine to provide different behavior.
1008 SourceLocation AttributeLoc, VectorKind);
1009
1010 /// Build a new extended vector type given the element type and
1011 /// number of elements.
1012 ///
1013 /// By default, performs semantic analysis when building the vector type.
1014 /// Subclasses may override this routine to provide different behavior.
1015 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1016 SourceLocation AttributeLoc);
1017
1018 /// Build a new potentially dependently-sized extended vector type
1019 /// given the element type and number of elements.
1020 ///
1021 /// By default, performs semantic analysis when building the vector type.
1022 /// Subclasses may override this routine to provide different behavior.
1024 Expr *SizeExpr,
1025 SourceLocation AttributeLoc);
1026
1027 /// Build a new matrix type given the element type and dimensions.
1028 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1029 unsigned NumColumns);
1030
1031 /// Build a new matrix type given the type and dependently-defined
1032 /// dimensions.
1034 Expr *ColumnExpr,
1035 SourceLocation AttributeLoc);
1036
1037 /// Build a new DependentAddressSpaceType or return the pointee
1038 /// type variable with the correct address space (retrieved from
1039 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1040 /// where the address space remains dependent.
1041 ///
1042 /// By default, performs semantic analysis when building the type with address
1043 /// space applied. Subclasses may override this routine to provide different
1044 /// behavior.
1046 Expr *AddrSpaceExpr,
1047 SourceLocation AttributeLoc);
1048
1049 /// Build a new function type.
1050 ///
1051 /// By default, performs semantic analysis when building the function type.
1052 /// Subclasses may override this routine to provide different behavior.
1054 MutableArrayRef<QualType> ParamTypes,
1056
1057 /// Build a new unprototyped function type.
1059
1060 /// Rebuild an unresolved typename type, given the decl that
1061 /// the UnresolvedUsingTypenameDecl was transformed to.
1063 NestedNameSpecifier Qualifier,
1064 SourceLocation NameLoc, Decl *D);
1065
1066 /// Build a new type found via an alias.
1069 QualType UnderlyingType) {
1070 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1071 }
1072
1073 /// Build a new typedef type.
1075 NestedNameSpecifier Qualifier,
1077 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1078 }
1079
1080 /// Build a new MacroDefined type.
1082 const IdentifierInfo *MacroII) {
1083 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1084 }
1085
1086 /// Build a new class/struct/union/enum type.
1088 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1089 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1090 /*OwnsTag=*/false);
1091 }
1094 }
1095
1096 /// Build a new typeof(expr) type.
1097 ///
1098 /// By default, performs semantic analysis when building the typeof type.
1099 /// Subclasses may override this routine to provide different behavior.
1101 TypeOfKind Kind);
1102
1103 /// Build a new typeof(type) type.
1104 ///
1105 /// By default, builds a new TypeOfType with the given underlying type.
1107
1108 /// Build a new unary transform type.
1112
1113 /// Build a new C++11 decltype type.
1114 ///
1115 /// By default, performs semantic analysis when building the decltype type.
1116 /// Subclasses may override this routine to provide different behavior.
1118
1121 SourceLocation EllipsisLoc,
1122 bool FullySubstituted,
1123 ArrayRef<QualType> Expansions = {});
1124
1125 /// Build a new C++11 auto type.
1126 ///
1127 /// By default, builds a new AutoType with the given deduced type.
1129 ConceptDecl *TypeConstraintConcept,
1130 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1131 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1132 // which has been deduced to a dependent type into an undeduced 'auto', so
1133 // that we'll retry deduction after the transformation.
1134 return SemaRef.Context.getAutoType(Deduced, Keyword,
1135 /*IsDependent*/ false, /*IsPack=*/false,
1136 TypeConstraintConcept,
1137 TypeConstraintArgs);
1138 }
1139
1140 /// By default, builds a new DeducedTemplateSpecializationType with the given
1141 /// deduced type.
1145 Keyword, Template, Deduced, /*IsDependent*/ false);
1146 }
1147
1148 /// Build a new template specialization type.
1149 ///
1150 /// By default, performs semantic analysis when building the template
1151 /// specialization type. Subclasses may override this routine to provide
1152 /// different behavior.
1155 SourceLocation TemplateLoc,
1157
1158 /// Build a new parenthesized type.
1159 ///
1160 /// By default, builds a new ParenType type from the inner type.
1161 /// Subclasses may override this routine to provide different behavior.
1163 return SemaRef.BuildParenType(InnerType);
1164 }
1165
1166 /// Build a new typename type that refers to a template-id.
1167 ///
1168 /// By default, builds a new DependentNameType type from the
1169 /// nested-name-specifier and the given type. Subclasses may override
1170 /// this routine to provide different behavior.
1174 bool AllowInjectedClassName) {
1175 // If it's still dependent, make a dependent specialization.
1176 if (const DependentTemplateStorage *S = Name.getAsDependentTemplateName())
1178 Keyword, *S, Args.arguments());
1179
1180 return getDerived().RebuildTemplateSpecializationType(Keyword, Name,
1181 NameLoc, Args);
1182 }
1183
1184 /// Build a new typename type that refers to an identifier.
1185 ///
1186 /// By default, performs semantic analysis when building the typename type
1187 /// (or elaborated type). Subclasses may override this routine to provide
1188 /// different behavior.
1190 SourceLocation KeywordLoc,
1191 NestedNameSpecifierLoc QualifierLoc,
1192 const IdentifierInfo *Id,
1193 SourceLocation IdLoc,
1194 bool DeducedTSTContext) {
1195 CXXScopeSpec SS;
1196 SS.Adopt(QualifierLoc);
1197
1198 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1199 // If the name is still dependent, just build a new dependent name type.
1200 if (!SemaRef.computeDeclContext(SS))
1202 QualifierLoc.getNestedNameSpecifier(),
1203 Id);
1204 }
1205
1208 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1209 *Id, IdLoc, DeducedTSTContext);
1210 }
1211
1213
1214 // We had a dependent elaborated-type-specifier that has been transformed
1215 // into a non-dependent elaborated-type-specifier. Find the tag we're
1216 // referring to.
1218 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1219 if (!DC)
1220 return QualType();
1221
1223 return QualType();
1224
1225 TagDecl *Tag = nullptr;
1227 switch (Result.getResultKind()) {
1230 break;
1231
1233 Tag = Result.getAsSingle<TagDecl>();
1234 break;
1235
1238 llvm_unreachable("Tag lookup cannot find non-tags");
1239
1241 // Let the LookupResult structure handle ambiguities.
1242 return QualType();
1243 }
1244
1245 if (!Tag) {
1246 // Check where the name exists but isn't a tag type and use that to emit
1247 // better diagnostics.
1250 switch (Result.getResultKind()) {
1254 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1255 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1256 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1257 << SomeDecl << NTK << Kind;
1258 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1259 break;
1260 }
1261 default:
1262 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1263 << Kind << Id << DC << QualifierLoc.getSourceRange();
1264 break;
1265 }
1266 return QualType();
1267 }
1268 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1269 IdLoc, Id)) {
1270 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1271 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1272 return QualType();
1273 }
1274 return getDerived().RebuildTagType(
1275 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1276 }
1277
1278 /// Build a new pack expansion type.
1279 ///
1280 /// By default, builds a new PackExpansionType type from the given pattern.
1281 /// Subclasses may override this routine to provide different behavior.
1283 SourceLocation EllipsisLoc,
1284 UnsignedOrNone NumExpansions) {
1285 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1286 NumExpansions);
1287 }
1288
1289 /// Build a new atomic type given its value type.
1290 ///
1291 /// By default, performs semantic analysis when building the atomic type.
1292 /// Subclasses may override this routine to provide different behavior.
1294
1295 /// Build a new pipe type given its value type.
1297 bool isReadPipe);
1298
1299 /// Build a bit-precise int given its value type.
1300 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1302
1303 /// Build a dependent bit-precise int given its value type.
1304 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1306
1307 /// Build a new template name given a nested name specifier, a flag
1308 /// indicating whether the "template" keyword was provided, and the template
1309 /// that the template name refers to.
1310 ///
1311 /// By default, builds the new template name directly. Subclasses may override
1312 /// this routine to provide different behavior.
1314 TemplateName Name);
1315
1316 /// Build a new template name given a nested name specifier and the
1317 /// name that is referred to as a template.
1318 ///
1319 /// By default, performs semantic analysis to determine whether the name can
1320 /// be resolved to a specific template, then builds the appropriate kind of
1321 /// template name. Subclasses may override this routine to provide different
1322 /// behavior.
1324 SourceLocation TemplateKWLoc,
1325 const IdentifierInfo &Name,
1326 SourceLocation NameLoc, QualType ObjectType,
1327 bool AllowInjectedClassName);
1328
1329 /// Build a new template name given a nested name specifier and the
1330 /// overloaded operator name that is referred to as a template.
1331 ///
1332 /// By default, performs semantic analysis to determine whether the name can
1333 /// be resolved to a specific template, then builds the appropriate kind of
1334 /// template name. Subclasses may override this routine to provide different
1335 /// behavior.
1337 SourceLocation TemplateKWLoc,
1338 OverloadedOperatorKind Operator,
1339 SourceLocation NameLoc, QualType ObjectType,
1340 bool AllowInjectedClassName);
1341
1343 SourceLocation TemplateKWLoc,
1345 SourceLocation NameLoc, QualType ObjectType,
1346 bool AllowInjectedClassName);
1347
1348 /// Build a new template name given a template template parameter pack
1349 /// and the
1350 ///
1351 /// By default, performs semantic analysis to determine whether the name can
1352 /// be resolved to a specific template, then builds the appropriate kind of
1353 /// template name. Subclasses may override this routine to provide different
1354 /// behavior.
1356 Decl *AssociatedDecl, unsigned Index,
1357 bool Final) {
1359 ArgPack, AssociatedDecl, Index, Final);
1360 }
1361
1362 /// Build a new compound statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
1367 MultiStmtArg Statements,
1368 SourceLocation RBraceLoc,
1369 bool IsStmtExpr) {
1370 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1371 IsStmtExpr);
1372 }
1373
1374 /// Build a new case statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
1379 Expr *LHS,
1380 SourceLocation EllipsisLoc,
1381 Expr *RHS,
1382 SourceLocation ColonLoc) {
1383 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1384 ColonLoc);
1385 }
1386
1387 /// Attach the body to a new case statement.
1388 ///
1389 /// By default, performs semantic analysis to build the new statement.
1390 /// Subclasses may override this routine to provide different behavior.
1392 getSema().ActOnCaseStmtBody(S, Body);
1393 return S;
1394 }
1395
1396 /// Build a new default statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
1401 SourceLocation ColonLoc,
1402 Stmt *SubStmt) {
1403 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1404 /*CurScope=*/nullptr);
1405 }
1406
1407 /// Build a new label statement.
1408 ///
1409 /// By default, performs semantic analysis to build the new statement.
1410 /// Subclasses may override this routine to provide different behavior.
1412 SourceLocation ColonLoc, Stmt *SubStmt) {
1413 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1414 }
1415
1416 /// Build a new attributed statement.
1417 ///
1418 /// By default, performs semantic analysis to build the new statement.
1419 /// Subclasses may override this routine to provide different behavior.
1422 Stmt *SubStmt) {
1424 return StmtError();
1425 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1426 }
1427
1428 /// Build a new "if" statement.
1429 ///
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
1433 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1434 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1435 SourceLocation ElseLoc, Stmt *Else) {
1436 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1437 Then, ElseLoc, Else);
1438 }
1439
1440 /// Start building a new switch statement.
1441 ///
1442 /// By default, performs semantic analysis to build the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1445 SourceLocation LParenLoc, Stmt *Init,
1447 SourceLocation RParenLoc) {
1448 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1449 RParenLoc);
1450 }
1451
1452 /// Attach the body to the switch statement.
1453 ///
1454 /// By default, performs semantic analysis to build the new statement.
1455 /// Subclasses may override this routine to provide different behavior.
1457 Stmt *Switch, Stmt *Body) {
1458 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1459 }
1460
1461 /// Build a new while statement.
1462 ///
1463 /// By default, performs semantic analysis to build the new statement.
1464 /// Subclasses may override this routine to provide different behavior.
1467 SourceLocation RParenLoc, Stmt *Body) {
1468 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1469 }
1470
1471 /// Build a new do-while statement.
1472 ///
1473 /// By default, performs semantic analysis to build the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
1476 SourceLocation WhileLoc, SourceLocation LParenLoc,
1477 Expr *Cond, SourceLocation RParenLoc) {
1478 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1479 Cond, RParenLoc);
1480 }
1481
1482 /// Build a new for statement.
1483 ///
1484 /// By default, performs semantic analysis to build the new statement.
1485 /// Subclasses may override this routine to provide different behavior.
1488 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1489 Stmt *Body) {
1490 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1491 Inc, RParenLoc, Body);
1492 }
1493
1494 /// Build a new goto statement.
1495 ///
1496 /// By default, performs semantic analysis to build the new statement.
1497 /// Subclasses may override this routine to provide different behavior.
1499 LabelDecl *Label) {
1500 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1501 }
1502
1503 /// Build a new indirect goto statement.
1504 ///
1505 /// By default, performs semantic analysis to build the new statement.
1506 /// Subclasses may override this routine to provide different behavior.
1508 SourceLocation StarLoc,
1509 Expr *Target) {
1510 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1511 }
1512
1513 /// Build a new return statement.
1514 ///
1515 /// By default, performs semantic analysis to build the new statement.
1516 /// Subclasses may override this routine to provide different behavior.
1518 return getSema().BuildReturnStmt(ReturnLoc, Result);
1519 }
1520
1521 /// Build a new declaration statement.
1522 ///
1523 /// By default, performs semantic analysis to build the new statement.
1524 /// Subclasses may override this routine to provide different behavior.
1526 SourceLocation StartLoc, SourceLocation EndLoc) {
1528 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1529 }
1530
1531 /// Build a new inline asm statement.
1532 ///
1533 /// By default, performs semantic analysis to build the new statement.
1534 /// Subclasses may override this routine to provide different behavior.
1536 bool IsVolatile, unsigned NumOutputs,
1537 unsigned NumInputs, IdentifierInfo **Names,
1538 MultiExprArg Constraints, MultiExprArg Exprs,
1539 Expr *AsmString, MultiExprArg Clobbers,
1540 unsigned NumLabels,
1541 SourceLocation RParenLoc) {
1542 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1543 NumInputs, Names, Constraints, Exprs,
1544 AsmString, Clobbers, NumLabels, RParenLoc);
1545 }
1546
1547 /// Build a new MS style inline asm statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
1552 ArrayRef<Token> AsmToks,
1553 StringRef AsmString,
1554 unsigned NumOutputs, unsigned NumInputs,
1555 ArrayRef<StringRef> Constraints,
1556 ArrayRef<StringRef> Clobbers,
1557 ArrayRef<Expr*> Exprs,
1558 SourceLocation EndLoc) {
1559 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1560 NumOutputs, NumInputs,
1561 Constraints, Clobbers, Exprs, EndLoc);
1562 }
1563
1564 /// Build a new co_return statement.
1565 ///
1566 /// By default, performs semantic analysis to build the new statement.
1567 /// Subclasses may override this routine to provide different behavior.
1569 bool IsImplicit) {
1570 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1571 }
1572
1573 /// Build a new co_await expression.
1574 ///
1575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
1578 UnresolvedLookupExpr *OpCoawaitLookup,
1579 bool IsImplicit) {
1580 // This function rebuilds a coawait-expr given its operator.
1581 // For an explicit coawait-expr, the rebuild involves the full set
1582 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1583 // including calling await_transform().
1584 // For an implicit coawait-expr, we need to rebuild the "operator
1585 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1586 // This mirrors how the implicit CoawaitExpr is originally created
1587 // in Sema::ActOnCoroutineBodyStart().
1588 if (IsImplicit) {
1590 CoawaitLoc, Operand, OpCoawaitLookup);
1591 if (Suspend.isInvalid())
1592 return ExprError();
1593 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1594 Suspend.get(), true);
1595 }
1596
1597 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1598 OpCoawaitLookup);
1599 }
1600
1601 /// Build a new co_await expression.
1602 ///
1603 /// By default, performs semantic analysis to build the new expression.
1604 /// Subclasses may override this routine to provide different behavior.
1606 Expr *Result,
1607 UnresolvedLookupExpr *Lookup) {
1608 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1609 }
1610
1611 /// Build a new co_yield expression.
1612 ///
1613 /// By default, performs semantic analysis to build the new expression.
1614 /// Subclasses may override this routine to provide different behavior.
1616 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1617 }
1618
1620 return getSema().BuildCoroutineBodyStmt(Args);
1621 }
1622
1623 /// Build a new Objective-C \@try statement.
1624 ///
1625 /// By default, performs semantic analysis to build the new statement.
1626 /// Subclasses may override this routine to provide different behavior.
1628 Stmt *TryBody,
1629 MultiStmtArg CatchStmts,
1630 Stmt *Finally) {
1631 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1632 Finally);
1633 }
1634
1635 /// Rebuild an Objective-C exception declaration.
1636 ///
1637 /// By default, performs semantic analysis to build the new declaration.
1638 /// Subclasses may override this routine to provide different behavior.
1640 TypeSourceInfo *TInfo, QualType T) {
1642 TInfo, T, ExceptionDecl->getInnerLocStart(),
1643 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1644 }
1645
1646 /// Build a new Objective-C \@catch statement.
1647 ///
1648 /// By default, performs semantic analysis to build the new statement.
1649 /// Subclasses may override this routine to provide different behavior.
1651 SourceLocation RParenLoc,
1652 VarDecl *Var,
1653 Stmt *Body) {
1654 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1655 }
1656
1657 /// Build a new Objective-C \@finally statement.
1658 ///
1659 /// By default, performs semantic analysis to build the new statement.
1660 /// Subclasses may override this routine to provide different behavior.
1662 Stmt *Body) {
1663 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1664 }
1665
1666 /// Build a new Objective-C \@throw statement.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1671 Expr *Operand) {
1672 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1673 }
1674
1675 /// Build a new OpenMP Canonical loop.
1676 ///
1677 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1678 /// OMPCanonicalLoop.
1680 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1681 }
1682
1683 /// Build a new OpenMP executable directive.
1684 ///
1685 /// By default, performs semantic analysis to build the new statement.
1686 /// Subclasses may override this routine to provide different behavior.
1688 DeclarationNameInfo DirName,
1689 OpenMPDirectiveKind CancelRegion,
1690 ArrayRef<OMPClause *> Clauses,
1691 Stmt *AStmt, SourceLocation StartLoc,
1692 SourceLocation EndLoc) {
1693
1695 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1696 }
1697
1698 /// Build a new OpenMP informational directive.
1700 DeclarationNameInfo DirName,
1701 ArrayRef<OMPClause *> Clauses,
1702 Stmt *AStmt,
1703 SourceLocation StartLoc,
1704 SourceLocation EndLoc) {
1705
1707 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1708 }
1709
1710 /// Build a new OpenMP 'if' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1715 Expr *Condition, SourceLocation StartLoc,
1716 SourceLocation LParenLoc,
1717 SourceLocation NameModifierLoc,
1718 SourceLocation ColonLoc,
1719 SourceLocation EndLoc) {
1721 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1722 EndLoc);
1723 }
1724
1725 /// Build a new OpenMP 'final' clause.
1726 ///
1727 /// By default, performs semantic analysis to build the new OpenMP clause.
1728 /// Subclasses may override this routine to provide different behavior.
1730 SourceLocation LParenLoc,
1731 SourceLocation EndLoc) {
1732 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1733 LParenLoc, EndLoc);
1734 }
1735
1736 /// Build a new OpenMP 'num_threads' clause.
1737 ///
1738 /// By default, performs semantic analysis to build the new OpenMP clause.
1739 /// Subclasses may override this routine to provide different behavior.
1741 Expr *NumThreads,
1742 SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation ModifierLoc,
1745 SourceLocation EndLoc) {
1747 Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc);
1748 }
1749
1750 /// Build a new OpenMP 'safelen' clause.
1751 ///
1752 /// By default, performs semantic analysis to build the new OpenMP clause.
1753 /// Subclasses may override this routine to provide different behavior.
1755 SourceLocation LParenLoc,
1756 SourceLocation EndLoc) {
1757 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1758 EndLoc);
1759 }
1760
1761 /// Build a new OpenMP 'simdlen' clause.
1762 ///
1763 /// By default, performs semantic analysis to build the new OpenMP clause.
1764 /// Subclasses may override this routine to provide different behavior.
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1769 EndLoc);
1770 }
1771
1773 SourceLocation StartLoc,
1774 SourceLocation LParenLoc,
1775 SourceLocation EndLoc) {
1776 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1777 EndLoc);
1778 }
1779
1780 /// Build a new OpenMP 'permutation' clause.
1782 SourceLocation StartLoc,
1783 SourceLocation LParenLoc,
1784 SourceLocation EndLoc) {
1785 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1786 LParenLoc, EndLoc);
1787 }
1788
1789 /// Build a new OpenMP 'full' clause.
1791 SourceLocation EndLoc) {
1792 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1793 }
1794
1795 /// Build a new OpenMP 'partial' clause.
1797 SourceLocation LParenLoc,
1798 SourceLocation EndLoc) {
1799 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1800 LParenLoc, EndLoc);
1801 }
1802
1803 /// Build a new OpenMP 'allocator' clause.
1804 ///
1805 /// By default, performs semantic analysis to build the new OpenMP clause.
1806 /// Subclasses may override this routine to provide different behavior.
1808 SourceLocation LParenLoc,
1809 SourceLocation EndLoc) {
1810 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1811 EndLoc);
1812 }
1813
1814 /// Build a new OpenMP 'collapse' clause.
1815 ///
1816 /// By default, performs semantic analysis to build the new OpenMP clause.
1817 /// Subclasses may override this routine to provide different behavior.
1819 SourceLocation LParenLoc,
1820 SourceLocation EndLoc) {
1821 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1822 LParenLoc, EndLoc);
1823 }
1824
1825 /// Build a new OpenMP 'default' clause.
1826 ///
1827 /// By default, performs semantic analysis to build the new OpenMP clause.
1828 /// Subclasses may override this routine to provide different behavior.
1830 SourceLocation StartLoc,
1831 SourceLocation LParenLoc,
1832 SourceLocation EndLoc) {
1834 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1835 }
1836
1837 /// Build a new OpenMP 'proc_bind' clause.
1838 ///
1839 /// By default, performs semantic analysis to build the new OpenMP clause.
1840 /// Subclasses may override this routine to provide different behavior.
1842 SourceLocation KindKwLoc,
1843 SourceLocation StartLoc,
1844 SourceLocation LParenLoc,
1845 SourceLocation EndLoc) {
1847 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1848 }
1849
1850 /// Build a new OpenMP 'schedule' clause.
1851 ///
1852 /// By default, performs semantic analysis to build the new OpenMP clause.
1853 /// Subclasses may override this routine to provide different behavior.
1856 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1857 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1858 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1860 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1861 CommaLoc, EndLoc);
1862 }
1863
1864 /// Build a new OpenMP 'ordered' clause.
1865 ///
1866 /// By default, performs semantic analysis to build the new OpenMP clause.
1867 /// Subclasses may override this routine to provide different behavior.
1869 SourceLocation EndLoc,
1870 SourceLocation LParenLoc, Expr *Num) {
1871 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1872 LParenLoc, Num);
1873 }
1874
1875 /// Build a new OpenMP 'private' clause.
1876 ///
1877 /// By default, performs semantic analysis to build the new OpenMP clause.
1878 /// Subclasses may override this routine to provide different behavior.
1880 SourceLocation StartLoc,
1881 SourceLocation LParenLoc,
1882 SourceLocation EndLoc) {
1883 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1884 LParenLoc, EndLoc);
1885 }
1886
1887 /// Build a new OpenMP 'firstprivate' clause.
1888 ///
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1892 SourceLocation StartLoc,
1893 SourceLocation LParenLoc,
1894 SourceLocation EndLoc) {
1895 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1896 LParenLoc, EndLoc);
1897 }
1898
1899 /// Build a new OpenMP 'lastprivate' clause.
1900 ///
1901 /// By default, performs semantic analysis to build the new OpenMP clause.
1902 /// Subclasses may override this routine to provide different behavior.
1905 SourceLocation LPKindLoc,
1906 SourceLocation ColonLoc,
1907 SourceLocation StartLoc,
1908 SourceLocation LParenLoc,
1909 SourceLocation EndLoc) {
1911 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1912 }
1913
1914 /// Build a new OpenMP 'shared' clause.
1915 ///
1916 /// By default, performs semantic analysis to build the new OpenMP clause.
1917 /// Subclasses may override this routine to provide different behavior.
1919 SourceLocation StartLoc,
1920 SourceLocation LParenLoc,
1921 SourceLocation EndLoc) {
1922 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1923 LParenLoc, EndLoc);
1924 }
1925
1926 /// Build a new OpenMP 'reduction' clause.
1927 ///
1928 /// By default, performs semantic analysis to build the new statement.
1929 /// Subclasses may override this routine to provide different behavior.
1932 OpenMPOriginalSharingModifier OriginalSharingModifier,
1933 SourceLocation StartLoc, SourceLocation LParenLoc,
1934 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1935 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1936 const DeclarationNameInfo &ReductionId,
1937 ArrayRef<Expr *> UnresolvedReductions) {
1939 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1940 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1941 UnresolvedReductions);
1942 }
1943
1944 /// Build a new OpenMP 'task_reduction' clause.
1945 ///
1946 /// By default, performs semantic analysis to build the new statement.
1947 /// Subclasses may override this routine to provide different behavior.
1949 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1950 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1951 CXXScopeSpec &ReductionIdScopeSpec,
1952 const DeclarationNameInfo &ReductionId,
1953 ArrayRef<Expr *> UnresolvedReductions) {
1955 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1956 ReductionId, UnresolvedReductions);
1957 }
1958
1959 /// Build a new OpenMP 'in_reduction' clause.
1960 ///
1961 /// By default, performs semantic analysis to build the new statement.
1962 /// Subclasses may override this routine to provide different behavior.
1963 OMPClause *
1965 SourceLocation LParenLoc, SourceLocation ColonLoc,
1966 SourceLocation EndLoc,
1967 CXXScopeSpec &ReductionIdScopeSpec,
1968 const DeclarationNameInfo &ReductionId,
1969 ArrayRef<Expr *> UnresolvedReductions) {
1971 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1972 ReductionId, UnresolvedReductions);
1973 }
1974
1975 /// Build a new OpenMP 'linear' clause.
1976 ///
1977 /// By default, performs semantic analysis to build the new OpenMP clause.
1978 /// Subclasses may override this routine to provide different behavior.
1980 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1981 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1982 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1983 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1985 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1986 StepModifierLoc, EndLoc);
1987 }
1988
1989 /// Build a new OpenMP 'aligned' clause.
1990 ///
1991 /// By default, performs semantic analysis to build the new OpenMP clause.
1992 /// Subclasses may override this routine to provide different behavior.
1994 SourceLocation StartLoc,
1995 SourceLocation LParenLoc,
1996 SourceLocation ColonLoc,
1997 SourceLocation EndLoc) {
1999 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2000 }
2001
2002 /// Build a new OpenMP 'copyin' clause.
2003 ///
2004 /// By default, performs semantic analysis to build the new OpenMP clause.
2005 /// Subclasses may override this routine to provide different behavior.
2007 SourceLocation StartLoc,
2008 SourceLocation LParenLoc,
2009 SourceLocation EndLoc) {
2010 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2011 LParenLoc, EndLoc);
2012 }
2013
2014 /// Build a new OpenMP 'copyprivate' clause.
2015 ///
2016 /// By default, performs semantic analysis to build the new OpenMP clause.
2017 /// Subclasses may override this routine to provide different behavior.
2019 SourceLocation StartLoc,
2020 SourceLocation LParenLoc,
2021 SourceLocation EndLoc) {
2022 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2023 LParenLoc, EndLoc);
2024 }
2025
2026 /// Build a new OpenMP 'flush' pseudo clause.
2027 ///
2028 /// By default, performs semantic analysis to build the new OpenMP clause.
2029 /// Subclasses may override this routine to provide different behavior.
2031 SourceLocation StartLoc,
2032 SourceLocation LParenLoc,
2033 SourceLocation EndLoc) {
2034 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2035 LParenLoc, EndLoc);
2036 }
2037
2038 /// Build a new OpenMP 'depobj' pseudo clause.
2039 ///
2040 /// By default, performs semantic analysis to build the new OpenMP clause.
2041 /// Subclasses may override this routine to provide different behavior.
2043 SourceLocation LParenLoc,
2044 SourceLocation EndLoc) {
2045 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2046 LParenLoc, EndLoc);
2047 }
2048
2049 /// Build a new OpenMP 'depend' pseudo clause.
2050 ///
2051 /// By default, performs semantic analysis to build the new OpenMP clause.
2052 /// Subclasses may override this routine to provide different behavior.
2054 Expr *DepModifier, ArrayRef<Expr *> VarList,
2055 SourceLocation StartLoc,
2056 SourceLocation LParenLoc,
2057 SourceLocation EndLoc) {
2059 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2060 }
2061
2062 /// Build a new OpenMP 'device' clause.
2063 ///
2064 /// By default, performs semantic analysis to build the new statement.
2065 /// Subclasses may override this routine to provide different behavior.
2067 Expr *Device, SourceLocation StartLoc,
2068 SourceLocation LParenLoc,
2069 SourceLocation ModifierLoc,
2070 SourceLocation EndLoc) {
2072 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2073 }
2074
2075 /// Build a new OpenMP 'map' clause.
2076 ///
2077 /// By default, performs semantic analysis to build the new OpenMP clause.
2078 /// Subclasses may override this routine to provide different behavior.
2080 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2081 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2082 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2083 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2084 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2085 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2087 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2088 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2089 ColonLoc, VarList, Locs,
2090 /*NoDiagnose=*/false, UnresolvedMappers);
2091 }
2092
2093 /// Build a new OpenMP 'allocate' clause.
2094 ///
2095 /// By default, performs semantic analysis to build the new OpenMP clause.
2096 /// Subclasses may override this routine to provide different behavior.
2097 OMPClause *
2098 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2099 OpenMPAllocateClauseModifier FirstModifier,
2100 SourceLocation FirstModifierLoc,
2101 OpenMPAllocateClauseModifier SecondModifier,
2102 SourceLocation SecondModifierLoc,
2103 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2104 SourceLocation LParenLoc, SourceLocation ColonLoc,
2105 SourceLocation EndLoc) {
2107 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2108 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2109 }
2110
2111 /// Build a new OpenMP 'num_teams' clause.
2112 ///
2113 /// By default, performs semantic analysis to build the new statement.
2114 /// Subclasses may override this routine to provide different behavior.
2116 SourceLocation StartLoc,
2117 SourceLocation LParenLoc,
2118 SourceLocation EndLoc) {
2119 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2120 LParenLoc, EndLoc);
2121 }
2122
2123 /// Build a new OpenMP 'thread_limit' clause.
2124 ///
2125 /// By default, performs semantic analysis to build the new statement.
2126 /// Subclasses may override this routine to provide different behavior.
2128 SourceLocation StartLoc,
2129 SourceLocation LParenLoc,
2130 SourceLocation EndLoc) {
2131 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2132 LParenLoc, EndLoc);
2133 }
2134
2135 /// Build a new OpenMP 'priority' clause.
2136 ///
2137 /// By default, performs semantic analysis to build the new statement.
2138 /// Subclasses may override this routine to provide different behavior.
2140 SourceLocation LParenLoc,
2141 SourceLocation EndLoc) {
2142 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2143 LParenLoc, EndLoc);
2144 }
2145
2146 /// Build a new OpenMP 'grainsize' clause.
2147 ///
2148 /// By default, performs semantic analysis to build the new statement.
2149 /// Subclasses may override this routine to provide different behavior.
2151 Expr *Device, SourceLocation StartLoc,
2152 SourceLocation LParenLoc,
2153 SourceLocation ModifierLoc,
2154 SourceLocation EndLoc) {
2156 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2157 }
2158
2159 /// Build a new OpenMP 'num_tasks' clause.
2160 ///
2161 /// By default, performs semantic analysis to build the new statement.
2162 /// Subclasses may override this routine to provide different behavior.
2164 Expr *NumTasks, SourceLocation StartLoc,
2165 SourceLocation LParenLoc,
2166 SourceLocation ModifierLoc,
2167 SourceLocation EndLoc) {
2169 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2170 }
2171
2172 /// Build a new OpenMP 'hint' clause.
2173 ///
2174 /// By default, performs semantic analysis to build the new statement.
2175 /// Subclasses may override this routine to provide different behavior.
2177 SourceLocation LParenLoc,
2178 SourceLocation EndLoc) {
2179 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2180 EndLoc);
2181 }
2182
2183 /// Build a new OpenMP 'detach' clause.
2184 ///
2185 /// By default, performs semantic analysis to build the new statement.
2186 /// Subclasses may override this routine to provide different behavior.
2188 SourceLocation LParenLoc,
2189 SourceLocation EndLoc) {
2190 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2191 EndLoc);
2192 }
2193
2194 /// Build a new OpenMP 'dist_schedule' clause.
2195 ///
2196 /// By default, performs semantic analysis to build the new OpenMP clause.
2197 /// Subclasses may override this routine to provide different behavior.
2198 OMPClause *
2200 Expr *ChunkSize, SourceLocation StartLoc,
2201 SourceLocation LParenLoc, SourceLocation KindLoc,
2202 SourceLocation CommaLoc, SourceLocation EndLoc) {
2204 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2205 }
2206
2207 /// Build a new OpenMP 'to' clause.
2208 ///
2209 /// By default, performs semantic analysis to build the new statement.
2210 /// Subclasses may override this routine to provide different behavior.
2211 OMPClause *
2213 ArrayRef<SourceLocation> MotionModifiersLoc,
2214 CXXScopeSpec &MapperIdScopeSpec,
2215 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2216 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2217 ArrayRef<Expr *> UnresolvedMappers) {
2219 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2220 ColonLoc, VarList, Locs, UnresolvedMappers);
2221 }
2222
2223 /// Build a new OpenMP 'from' clause.
2224 ///
2225 /// By default, performs semantic analysis to build the new statement.
2226 /// Subclasses may override this routine to provide different behavior.
2227 OMPClause *
2229 ArrayRef<SourceLocation> MotionModifiersLoc,
2230 CXXScopeSpec &MapperIdScopeSpec,
2231 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2232 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2233 ArrayRef<Expr *> UnresolvedMappers) {
2235 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2236 ColonLoc, VarList, Locs, UnresolvedMappers);
2237 }
2238
2239 /// Build a new OpenMP 'use_device_ptr' clause.
2240 ///
2241 /// By default, performs semantic analysis to build the new OpenMP clause.
2242 /// Subclasses may override this routine to provide different behavior.
2244 const OMPVarListLocTy &Locs) {
2245 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2246 }
2247
2248 /// Build a new OpenMP 'use_device_addr' clause.
2249 ///
2250 /// By default, performs semantic analysis to build the new OpenMP clause.
2251 /// Subclasses may override this routine to provide different behavior.
2253 const OMPVarListLocTy &Locs) {
2254 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2255 }
2256
2257 /// Build a new OpenMP 'is_device_ptr' clause.
2258 ///
2259 /// By default, performs semantic analysis to build the new OpenMP clause.
2260 /// Subclasses may override this routine to provide different behavior.
2262 const OMPVarListLocTy &Locs) {
2263 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2264 }
2265
2266 /// Build a new OpenMP 'has_device_addr' clause.
2267 ///
2268 /// By default, performs semantic analysis to build the new OpenMP clause.
2269 /// Subclasses may override this routine to provide different behavior.
2271 const OMPVarListLocTy &Locs) {
2272 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2273 }
2274
2275 /// Build a new OpenMP 'defaultmap' clause.
2276 ///
2277 /// By default, performs semantic analysis to build the new OpenMP clause.
2278 /// Subclasses may override this routine to provide different behavior.
2281 SourceLocation StartLoc,
2282 SourceLocation LParenLoc,
2283 SourceLocation MLoc,
2284 SourceLocation KindLoc,
2285 SourceLocation EndLoc) {
2287 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2288 }
2289
2290 /// Build a new OpenMP 'nontemporal' clause.
2291 ///
2292 /// By default, performs semantic analysis to build the new OpenMP clause.
2293 /// Subclasses may override this routine to provide different behavior.
2295 SourceLocation StartLoc,
2296 SourceLocation LParenLoc,
2297 SourceLocation EndLoc) {
2298 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2299 LParenLoc, EndLoc);
2300 }
2301
2302 /// Build a new OpenMP 'inclusive' clause.
2303 ///
2304 /// By default, performs semantic analysis to build the new OpenMP clause.
2305 /// Subclasses may override this routine to provide different behavior.
2307 SourceLocation StartLoc,
2308 SourceLocation LParenLoc,
2309 SourceLocation EndLoc) {
2310 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2311 LParenLoc, EndLoc);
2312 }
2313
2314 /// Build a new OpenMP 'exclusive' clause.
2315 ///
2316 /// By default, performs semantic analysis to build the new OpenMP clause.
2317 /// Subclasses may override this routine to provide different behavior.
2319 SourceLocation StartLoc,
2320 SourceLocation LParenLoc,
2321 SourceLocation EndLoc) {
2322 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2323 LParenLoc, EndLoc);
2324 }
2325
2326 /// Build a new OpenMP 'uses_allocators' clause.
2327 ///
2328 /// By default, performs semantic analysis to build the new OpenMP clause.
2329 /// Subclasses may override this routine to provide different behavior.
2332 SourceLocation LParenLoc, SourceLocation EndLoc) {
2334 StartLoc, LParenLoc, EndLoc, Data);
2335 }
2336
2337 /// Build a new OpenMP 'affinity' clause.
2338 ///
2339 /// By default, performs semantic analysis to build the new OpenMP clause.
2340 /// Subclasses may override this routine to provide different behavior.
2342 SourceLocation LParenLoc,
2343 SourceLocation ColonLoc,
2344 SourceLocation EndLoc, Expr *Modifier,
2345 ArrayRef<Expr *> Locators) {
2347 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2348 }
2349
2350 /// Build a new OpenMP 'order' clause.
2351 ///
2352 /// By default, performs semantic analysis to build the new OpenMP clause.
2353 /// Subclasses may override this routine to provide different behavior.
2355 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2356 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2357 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2359 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2360 }
2361
2362 /// Build a new OpenMP 'init' clause.
2363 ///
2364 /// By default, performs semantic analysis to build the new OpenMP clause.
2365 /// Subclasses may override this routine to provide different behavior.
2367 SourceLocation StartLoc,
2368 SourceLocation LParenLoc,
2369 SourceLocation VarLoc,
2370 SourceLocation EndLoc) {
2372 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2373 }
2374
2375 /// Build a new OpenMP 'use' clause.
2376 ///
2377 /// By default, performs semantic analysis to build the new OpenMP clause.
2378 /// Subclasses may override this routine to provide different behavior.
2380 SourceLocation LParenLoc,
2381 SourceLocation VarLoc, SourceLocation EndLoc) {
2382 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2383 LParenLoc, VarLoc, EndLoc);
2384 }
2385
2386 /// Build a new OpenMP 'destroy' clause.
2387 ///
2388 /// By default, performs semantic analysis to build the new OpenMP clause.
2389 /// Subclasses may override this routine to provide different behavior.
2391 SourceLocation LParenLoc,
2392 SourceLocation VarLoc,
2393 SourceLocation EndLoc) {
2395 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2396 }
2397
2398 /// Build a new OpenMP 'novariants' clause.
2399 ///
2400 /// By default, performs semantic analysis to build the new OpenMP clause.
2401 /// Subclasses may override this routine to provide different behavior.
2403 SourceLocation StartLoc,
2404 SourceLocation LParenLoc,
2405 SourceLocation EndLoc) {
2407 LParenLoc, EndLoc);
2408 }
2409
2410 /// Build a new OpenMP 'nocontext' clause.
2411 ///
2412 /// By default, performs semantic analysis to build the new OpenMP clause.
2413 /// Subclasses may override this routine to provide different behavior.
2415 SourceLocation LParenLoc,
2416 SourceLocation EndLoc) {
2418 LParenLoc, EndLoc);
2419 }
2420
2421 /// Build a new OpenMP 'filter' clause.
2422 ///
2423 /// By default, performs semantic analysis to build the new OpenMP clause.
2424 /// Subclasses may override this routine to provide different behavior.
2426 SourceLocation LParenLoc,
2427 SourceLocation EndLoc) {
2428 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2429 LParenLoc, EndLoc);
2430 }
2431
2432 /// Build a new OpenMP 'bind' clause.
2433 ///
2434 /// By default, performs semantic analysis to build the new OpenMP clause.
2435 /// Subclasses may override this routine to provide different behavior.
2437 SourceLocation KindLoc,
2438 SourceLocation StartLoc,
2439 SourceLocation LParenLoc,
2440 SourceLocation EndLoc) {
2441 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2442 LParenLoc, EndLoc);
2443 }
2444
2445 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2446 ///
2447 /// By default, performs semantic analysis to build the new OpenMP clause.
2448 /// Subclasses may override this routine to provide different behavior.
2450 SourceLocation LParenLoc,
2451 SourceLocation EndLoc) {
2452 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2453 LParenLoc, EndLoc);
2454 }
2455
2456 /// Build a new OpenMP 'ompx_attribute' clause.
2457 ///
2458 /// By default, performs semantic analysis to build the new OpenMP clause.
2459 /// Subclasses may override this routine to provide different behavior.
2461 SourceLocation StartLoc,
2462 SourceLocation LParenLoc,
2463 SourceLocation EndLoc) {
2464 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2465 LParenLoc, EndLoc);
2466 }
2467
2468 /// Build a new OpenMP 'ompx_bare' clause.
2469 ///
2470 /// By default, performs semantic analysis to build the new OpenMP clause.
2471 /// Subclasses may override this routine to provide different behavior.
2473 SourceLocation EndLoc) {
2474 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2475 }
2476
2477 /// Build a new OpenMP 'align' clause.
2478 ///
2479 /// By default, performs semantic analysis to build the new OpenMP clause.
2480 /// Subclasses may override this routine to provide different behavior.
2482 SourceLocation LParenLoc,
2483 SourceLocation EndLoc) {
2484 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2485 EndLoc);
2486 }
2487
2488 /// Build a new OpenMP 'at' clause.
2489 ///
2490 /// By default, performs semantic analysis to build the new OpenMP clause.
2491 /// Subclasses may override this routine to provide different behavior.
2493 SourceLocation StartLoc,
2494 SourceLocation LParenLoc,
2495 SourceLocation EndLoc) {
2496 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2497 LParenLoc, EndLoc);
2498 }
2499
2500 /// Build a new OpenMP 'severity' clause.
2501 ///
2502 /// By default, performs semantic analysis to build the new OpenMP clause.
2503 /// Subclasses may override this routine to provide different behavior.
2505 SourceLocation KwLoc,
2506 SourceLocation StartLoc,
2507 SourceLocation LParenLoc,
2508 SourceLocation EndLoc) {
2509 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2510 LParenLoc, EndLoc);
2511 }
2512
2513 /// Build a new OpenMP 'message' clause.
2514 ///
2515 /// By default, performs semantic analysis to build the new OpenMP clause.
2516 /// Subclasses may override this routine to provide different behavior.
2518 SourceLocation LParenLoc,
2519 SourceLocation EndLoc) {
2520 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2521 EndLoc);
2522 }
2523
2524 /// Build a new OpenMP 'doacross' clause.
2525 ///
2526 /// By default, performs semantic analysis to build the new OpenMP clause.
2527 /// Subclasses may override this routine to provide different behavior.
2528 OMPClause *
2530 SourceLocation DepLoc, SourceLocation ColonLoc,
2531 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2532 SourceLocation LParenLoc, SourceLocation EndLoc) {
2534 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2535 }
2536
2537 /// Build a new OpenMP 'holds' clause.
2539 SourceLocation LParenLoc,
2540 SourceLocation EndLoc) {
2541 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2542 EndLoc);
2543 }
2544
2545 /// Rebuild the operand to an Objective-C \@synchronized statement.
2546 ///
2547 /// By default, performs semantic analysis to build the new statement.
2548 /// Subclasses may override this routine to provide different behavior.
2550 Expr *object) {
2551 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2552 }
2553
2554 /// Build a new Objective-C \@synchronized statement.
2555 ///
2556 /// By default, performs semantic analysis to build the new statement.
2557 /// Subclasses may override this routine to provide different behavior.
2559 Expr *Object, Stmt *Body) {
2560 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2561 }
2562
2563 /// Build a new Objective-C \@autoreleasepool statement.
2564 ///
2565 /// By default, performs semantic analysis to build the new statement.
2566 /// Subclasses may override this routine to provide different behavior.
2568 Stmt *Body) {
2569 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2570 }
2571
2572 /// Build a new Objective-C fast enumeration statement.
2573 ///
2574 /// By default, performs semantic analysis to build the new statement.
2575 /// Subclasses may override this routine to provide different behavior.
2577 Stmt *Element,
2578 Expr *Collection,
2579 SourceLocation RParenLoc,
2580 Stmt *Body) {
2582 ForLoc, Element, Collection, RParenLoc);
2583 if (ForEachStmt.isInvalid())
2584 return StmtError();
2585
2586 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2587 Body);
2588 }
2589
2590 /// Build a new C++ exception declaration.
2591 ///
2592 /// By default, performs semantic analysis to build the new decaration.
2593 /// Subclasses may override this routine to provide different behavior.
2596 SourceLocation StartLoc,
2597 SourceLocation IdLoc,
2598 IdentifierInfo *Id) {
2600 StartLoc, IdLoc, Id);
2601 if (Var)
2602 getSema().CurContext->addDecl(Var);
2603 return Var;
2604 }
2605
2606 /// Build a new C++ catch statement.
2607 ///
2608 /// By default, performs semantic analysis to build the new statement.
2609 /// Subclasses may override this routine to provide different behavior.
2611 VarDecl *ExceptionDecl,
2612 Stmt *Handler) {
2613 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2614 Handler));
2615 }
2616
2617 /// Build a new C++ try statement.
2618 ///
2619 /// By default, performs semantic analysis to build the new statement.
2620 /// Subclasses may override this routine to provide different behavior.
2622 ArrayRef<Stmt *> Handlers) {
2623 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2624 }
2625
2626 /// Build a new C++0x range-based for statement.
2627 ///
2628 /// By default, performs semantic analysis to build the new statement.
2629 /// Subclasses may override this routine to provide different behavior.
2631 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2632 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2633 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2634 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2635 // If we've just learned that the range is actually an Objective-C
2636 // collection, treat this as an Objective-C fast enumeration loop.
2637 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2638 if (RangeStmt->isSingleDecl()) {
2639 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2640 if (RangeVar->isInvalidDecl())
2641 return StmtError();
2642
2643 Expr *RangeExpr = RangeVar->getInit();
2644 if (!RangeExpr->isTypeDependent() &&
2645 RangeExpr->getType()->isObjCObjectPointerType()) {
2646 // FIXME: Support init-statements in Objective-C++20 ranged for
2647 // statement.
2648 if (Init) {
2649 return SemaRef.Diag(Init->getBeginLoc(),
2650 diag::err_objc_for_range_init_stmt)
2651 << Init->getSourceRange();
2652 }
2654 ForLoc, LoopVar, RangeExpr, RParenLoc);
2655 }
2656 }
2657 }
2658 }
2659
2661 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2662 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2663 }
2664
2665 /// Build a new C++0x range-based for statement.
2666 ///
2667 /// By default, performs semantic analysis to build the new statement.
2668 /// Subclasses may override this routine to provide different behavior.
2670 bool IsIfExists,
2671 NestedNameSpecifierLoc QualifierLoc,
2672 DeclarationNameInfo NameInfo,
2673 Stmt *Nested) {
2674 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2675 QualifierLoc, NameInfo, Nested);
2676 }
2677
2678 /// Attach body to a C++0x range-based for statement.
2679 ///
2680 /// By default, performs semantic analysis to finish the new statement.
2681 /// Subclasses may override this routine to provide different behavior.
2683 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2684 }
2685
2687 Stmt *TryBlock, Stmt *Handler) {
2688 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2689 }
2690
2692 Stmt *Block) {
2693 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2694 }
2695
2697 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2698 }
2699
2701 SourceLocation LParen,
2702 SourceLocation RParen,
2703 TypeSourceInfo *TSI) {
2704 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2705 TSI);
2706 }
2707
2708 /// Build a new predefined expression.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2713 return getSema().BuildPredefinedExpr(Loc, IK);
2714 }
2715
2716 /// Build a new expression that references a declaration.
2717 ///
2718 /// By default, performs semantic analysis to build the new expression.
2719 /// Subclasses may override this routine to provide different behavior.
2721 LookupResult &R,
2722 bool RequiresADL) {
2723 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2724 }
2725
2726
2727 /// Build a new expression that references a declaration.
2728 ///
2729 /// By default, performs semantic analysis to build the new expression.
2730 /// Subclasses may override this routine to provide different behavior.
2732 ValueDecl *VD,
2733 const DeclarationNameInfo &NameInfo,
2735 TemplateArgumentListInfo *TemplateArgs) {
2736 CXXScopeSpec SS;
2737 SS.Adopt(QualifierLoc);
2738 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2739 TemplateArgs);
2740 }
2741
2742 /// Build a new expression in parentheses.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
2747 SourceLocation RParen) {
2748 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2749 }
2750
2751 /// Build a new pseudo-destructor expression.
2752 ///
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
2756 SourceLocation OperatorLoc,
2757 bool isArrow,
2758 CXXScopeSpec &SS,
2759 TypeSourceInfo *ScopeType,
2760 SourceLocation CCLoc,
2761 SourceLocation TildeLoc,
2762 PseudoDestructorTypeStorage Destroyed);
2763
2764 /// Build a new unary operator expression.
2765 ///
2766 /// By default, performs semantic analysis to build the new expression.
2767 /// Subclasses may override this routine to provide different behavior.
2770 Expr *SubExpr) {
2771 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2772 }
2773
2774 /// Build a new builtin offsetof expression.
2775 ///
2776 /// By default, performs semantic analysis to build the new expression.
2777 /// Subclasses may override this routine to provide different behavior.
2781 SourceLocation RParenLoc) {
2782 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2783 RParenLoc);
2784 }
2785
2786 /// Build a new sizeof, alignof or vec_step expression with a
2787 /// type argument.
2788 ///
2789 /// By default, performs semantic analysis to build the new expression.
2790 /// Subclasses may override this routine to provide different behavior.
2792 SourceLocation OpLoc,
2793 UnaryExprOrTypeTrait ExprKind,
2794 SourceRange R) {
2795 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2796 }
2797
2798 /// Build a new sizeof, alignof or vec step expression with an
2799 /// expression argument.
2800 ///
2801 /// By default, performs semantic analysis to build the new expression.
2802 /// Subclasses may override this routine to provide different behavior.
2804 UnaryExprOrTypeTrait ExprKind,
2805 SourceRange R) {
2807 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2808 if (Result.isInvalid())
2809 return ExprError();
2810
2811 return Result;
2812 }
2813
2814 /// Build a new array subscript expression.
2815 ///
2816 /// By default, performs semantic analysis to build the new expression.
2817 /// Subclasses may override this routine to provide different behavior.
2819 SourceLocation LBracketLoc,
2820 Expr *RHS,
2821 SourceLocation RBracketLoc) {
2822 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2823 LBracketLoc, RHS,
2824 RBracketLoc);
2825 }
2826
2827 /// Build a new matrix subscript expression.
2828 ///
2829 /// By default, performs semantic analysis to build the new expression.
2830 /// Subclasses may override this routine to provide different behavior.
2832 Expr *ColumnIdx,
2833 SourceLocation RBracketLoc) {
2834 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2835 RBracketLoc);
2836 }
2837
2838 /// Build a new array section expression.
2839 ///
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
2843 SourceLocation LBracketLoc,
2844 Expr *LowerBound,
2845 SourceLocation ColonLocFirst,
2846 SourceLocation ColonLocSecond,
2847 Expr *Length, Expr *Stride,
2848 SourceLocation RBracketLoc) {
2849 if (IsOMPArraySection)
2851 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2852 Stride, RBracketLoc);
2853
2854 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2855 "Stride/second colon not allowed for OpenACC");
2856
2858 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2859 }
2860
2861 /// Build a new array shaping expression.
2862 ///
2863 /// By default, performs semantic analysis to build the new expression.
2864 /// Subclasses may override this routine to provide different behavior.
2866 SourceLocation RParenLoc,
2867 ArrayRef<Expr *> Dims,
2868 ArrayRef<SourceRange> BracketsRanges) {
2870 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2871 }
2872
2873 /// Build a new iterator expression.
2874 ///
2875 /// By default, performs semantic analysis to build the new expression.
2876 /// Subclasses may override this routine to provide different behavior.
2879 SourceLocation RLoc,
2882 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2883 }
2884
2885 /// Build a new call expression.
2886 ///
2887 /// By default, performs semantic analysis to build the new expression.
2888 /// Subclasses may override this routine to provide different behavior.
2890 MultiExprArg Args,
2891 SourceLocation RParenLoc,
2892 Expr *ExecConfig = nullptr) {
2893 return getSema().ActOnCallExpr(
2894 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2895 }
2896
2898 MultiExprArg Args,
2899 SourceLocation RParenLoc) {
2901 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2902 }
2903
2904 /// Build a new member access expression.
2905 ///
2906 /// By default, performs semantic analysis to build the new expression.
2907 /// Subclasses may override this routine to provide different behavior.
2909 bool isArrow,
2910 NestedNameSpecifierLoc QualifierLoc,
2911 SourceLocation TemplateKWLoc,
2912 const DeclarationNameInfo &MemberNameInfo,
2914 NamedDecl *FoundDecl,
2915 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2916 NamedDecl *FirstQualifierInScope) {
2918 isArrow);
2919 if (!Member->getDeclName()) {
2920 // We have a reference to an unnamed field. This is always the
2921 // base of an anonymous struct/union member access, i.e. the
2922 // field is always of record type.
2923 assert(Member->getType()->isRecordType() &&
2924 "unnamed member not of record type?");
2925
2926 BaseResult =
2928 QualifierLoc.getNestedNameSpecifier(),
2929 FoundDecl, Member);
2930 if (BaseResult.isInvalid())
2931 return ExprError();
2932 Base = BaseResult.get();
2933
2934 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2935 // from the AST, so we need to re-insert them if needed (since
2936 // `BuildFieldRefereneExpr()` doesn't do this).
2937 if (!isArrow && Base->isPRValue()) {
2939 if (BaseResult.isInvalid())
2940 return ExprError();
2941 Base = BaseResult.get();
2942 }
2943
2944 CXXScopeSpec EmptySS;
2946 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2947 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2948 MemberNameInfo);
2949 }
2950
2951 CXXScopeSpec SS;
2952 SS.Adopt(QualifierLoc);
2953
2954 Base = BaseResult.get();
2955 if (Base->containsErrors())
2956 return ExprError();
2957
2958 QualType BaseType = Base->getType();
2959
2960 if (isArrow && !BaseType->isPointerType())
2961 return ExprError();
2962
2963 // FIXME: this involves duplicating earlier analysis in a lot of
2964 // cases; we should avoid this when possible.
2965 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2966 R.addDecl(FoundDecl);
2967 R.resolveKind();
2968
2969 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2970 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2971 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2972 ->getType()
2973 ->getPointeeType()
2974 ->getAsCXXRecordDecl()) {
2975 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2976 // In unevaluated contexts, an expression supposed to be a member access
2977 // might reference a member in an unrelated class.
2978 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2979 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2980 VK_LValue, Member->getLocation());
2981 }
2982 }
2983
2984 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2985 SS, TemplateKWLoc,
2986 FirstQualifierInScope,
2987 R, ExplicitTemplateArgs,
2988 /*S*/nullptr);
2989 }
2990
2991 /// Build a new binary operator expression.
2992 ///
2993 /// By default, performs semantic analysis to build the new expression.
2994 /// Subclasses may override this routine to provide different behavior.
2996 Expr *LHS, Expr *RHS,
2997 bool ForFoldExpression = false) {
2998 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
2999 ForFoldExpression);
3000 }
3001
3002 /// Build a new rewritten operator expression.
3003 ///
3004 /// By default, performs semantic analysis to build the new expression.
3005 /// Subclasses may override this routine to provide different behavior.
3007 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3008 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3009 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3010 RHS, /*RequiresADL*/false);
3011 }
3012
3013 /// Build a new conditional operator expression.
3014 ///
3015 /// By default, performs semantic analysis to build the new expression.
3016 /// Subclasses may override this routine to provide different behavior.
3018 SourceLocation QuestionLoc,
3019 Expr *LHS,
3020 SourceLocation ColonLoc,
3021 Expr *RHS) {
3022 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3023 LHS, RHS);
3024 }
3025
3026 /// Build a new C-style cast expression.
3027 ///
3028 /// By default, performs semantic analysis to build the new expression.
3029 /// Subclasses may override this routine to provide different behavior.
3031 TypeSourceInfo *TInfo,
3032 SourceLocation RParenLoc,
3033 Expr *SubExpr) {
3034 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3035 SubExpr);
3036 }
3037
3038 /// Build a new compound literal expression.
3039 ///
3040 /// By default, performs semantic analysis to build the new expression.
3041 /// Subclasses may override this routine to provide different behavior.
3043 TypeSourceInfo *TInfo,
3044 SourceLocation RParenLoc,
3045 Expr *Init) {
3046 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3047 Init);
3048 }
3049
3050 /// Build a new extended vector element access expression.
3051 ///
3052 /// By default, performs semantic analysis to build the new expression.
3053 /// Subclasses may override this routine to provide different behavior.
3055 bool IsArrow,
3056 SourceLocation AccessorLoc,
3057 IdentifierInfo &Accessor) {
3058
3059 CXXScopeSpec SS;
3060 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3062 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3063 /*FirstQualifierInScope*/ nullptr, NameInfo,
3064 /* TemplateArgs */ nullptr,
3065 /*S*/ nullptr);
3066 }
3067
3068 /// Build a new initializer list expression.
3069 ///
3070 /// By default, performs semantic analysis to build the new expression.
3071 /// Subclasses may override this routine to provide different behavior.
3073 MultiExprArg Inits,
3074 SourceLocation RBraceLoc) {
3075 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3076 }
3077
3078 /// Build a new designated initializer expression.
3079 ///
3080 /// By default, performs semantic analysis to build the new expression.
3081 /// Subclasses may override this routine to provide different behavior.
3083 MultiExprArg ArrayExprs,
3084 SourceLocation EqualOrColonLoc,
3085 bool GNUSyntax,
3086 Expr *Init) {
3088 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3089 Init);
3090 if (Result.isInvalid())
3091 return ExprError();
3092
3093 return Result;
3094 }
3095
3096 /// Build a new value-initialized expression.
3097 ///
3098 /// By default, builds the implicit value initialization without performing
3099 /// any semantic analysis. Subclasses may override this routine to provide
3100 /// different behavior.
3102 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3103 }
3104
3105 /// Build a new \c va_arg expression.
3106 ///
3107 /// By default, performs semantic analysis to build the new expression.
3108 /// Subclasses may override this routine to provide different behavior.
3110 Expr *SubExpr, TypeSourceInfo *TInfo,
3111 SourceLocation RParenLoc) {
3112 return getSema().BuildVAArgExpr(BuiltinLoc,
3113 SubExpr, TInfo,
3114 RParenLoc);
3115 }
3116
3117 /// Build a new expression list in parentheses.
3118 ///
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
3122 MultiExprArg SubExprs,
3123 SourceLocation RParenLoc) {
3124 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3125 }
3126
3128 unsigned NumUserSpecifiedExprs,
3129 SourceLocation InitLoc,
3130 SourceLocation LParenLoc,
3131 SourceLocation RParenLoc) {
3132 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3133 InitLoc, LParenLoc, RParenLoc);
3134 }
3135
3136 /// Build a new address-of-label expression.
3137 ///
3138 /// By default, performs semantic analysis, using the name of the label
3139 /// rather than attempting to map the label statement itself.
3140 /// Subclasses may override this routine to provide different behavior.
3142 SourceLocation LabelLoc, LabelDecl *Label) {
3143 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3144 }
3145
3146 /// Build a new GNU statement expression.
3147 ///
3148 /// By default, performs semantic analysis to build the new expression.
3149 /// Subclasses may override this routine to provide different behavior.
3151 SourceLocation RParenLoc, unsigned TemplateDepth) {
3152 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3153 TemplateDepth);
3154 }
3155
3156 /// Build a new __builtin_choose_expr expression.
3157 ///
3158 /// By default, performs semantic analysis to build the new expression.
3159 /// Subclasses may override this routine to provide different behavior.
3161 Expr *Cond, Expr *LHS, Expr *RHS,
3162 SourceLocation RParenLoc) {
3163 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3164 Cond, LHS, RHS,
3165 RParenLoc);
3166 }
3167
3168 /// Build a new generic selection expression with an expression predicate.
3169 ///
3170 /// By default, performs semantic analysis to build the new expression.
3171 /// Subclasses may override this routine to provide different behavior.
3173 SourceLocation DefaultLoc,
3174 SourceLocation RParenLoc,
3175 Expr *ControllingExpr,
3177 ArrayRef<Expr *> Exprs) {
3178 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3179 /*PredicateIsExpr=*/true,
3180 ControllingExpr, Types, Exprs);
3181 }
3182
3183 /// Build a new generic selection expression with a type predicate.
3184 ///
3185 /// By default, performs semantic analysis to build the new expression.
3186 /// Subclasses may override this routine to provide different behavior.
3188 SourceLocation DefaultLoc,
3189 SourceLocation RParenLoc,
3190 TypeSourceInfo *ControllingType,
3192 ArrayRef<Expr *> Exprs) {
3193 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3194 /*PredicateIsExpr=*/false,
3195 ControllingType, Types, Exprs);
3196 }
3197
3198 /// Build a new overloaded operator call expression.
3199 ///
3200 /// By default, performs semantic analysis to build the new expression.
3201 /// The semantic analysis provides the behavior of template instantiation,
3202 /// copying with transformations that turn what looks like an overloaded
3203 /// operator call into a use of a builtin operator, performing
3204 /// argument-dependent lookup, etc. Subclasses may override this routine to
3205 /// provide different behavior.
3207 SourceLocation OpLoc,
3208 SourceLocation CalleeLoc,
3209 bool RequiresADL,
3210 const UnresolvedSetImpl &Functions,
3211 Expr *First, Expr *Second);
3212
3213 /// Build a new C++ "named" cast expression, such as static_cast or
3214 /// reinterpret_cast.
3215 ///
3216 /// By default, this routine dispatches to one of the more-specific routines
3217 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3218 /// Subclasses may override this routine to provide different behavior.
3221 SourceLocation LAngleLoc,
3222 TypeSourceInfo *TInfo,
3223 SourceLocation RAngleLoc,
3224 SourceLocation LParenLoc,
3225 Expr *SubExpr,
3226 SourceLocation RParenLoc) {
3227 switch (Class) {
3228 case Stmt::CXXStaticCastExprClass:
3229 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3230 RAngleLoc, LParenLoc,
3231 SubExpr, RParenLoc);
3232
3233 case Stmt::CXXDynamicCastExprClass:
3234 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3235 RAngleLoc, LParenLoc,
3236 SubExpr, RParenLoc);
3237
3238 case Stmt::CXXReinterpretCastExprClass:
3239 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3240 RAngleLoc, LParenLoc,
3241 SubExpr,
3242 RParenLoc);
3243
3244 case Stmt::CXXConstCastExprClass:
3245 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3246 RAngleLoc, LParenLoc,
3247 SubExpr, RParenLoc);
3248
3249 case Stmt::CXXAddrspaceCastExprClass:
3250 return getDerived().RebuildCXXAddrspaceCastExpr(
3251 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3252
3253 default:
3254 llvm_unreachable("Invalid C++ named cast");
3255 }
3256 }
3257
3258 /// Build a new C++ static_cast expression.
3259 ///
3260 /// By default, performs semantic analysis to build the new expression.
3261 /// Subclasses may override this routine to provide different behavior.
3263 SourceLocation LAngleLoc,
3264 TypeSourceInfo *TInfo,
3265 SourceLocation RAngleLoc,
3266 SourceLocation LParenLoc,
3267 Expr *SubExpr,
3268 SourceLocation RParenLoc) {
3269 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3270 TInfo, SubExpr,
3271 SourceRange(LAngleLoc, RAngleLoc),
3272 SourceRange(LParenLoc, RParenLoc));
3273 }
3274
3275 /// Build a new C++ dynamic_cast expression.
3276 ///
3277 /// By default, performs semantic analysis to build the new expression.
3278 /// Subclasses may override this routine to provide different behavior.
3280 SourceLocation LAngleLoc,
3281 TypeSourceInfo *TInfo,
3282 SourceLocation RAngleLoc,
3283 SourceLocation LParenLoc,
3284 Expr *SubExpr,
3285 SourceLocation RParenLoc) {
3286 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3287 TInfo, SubExpr,
3288 SourceRange(LAngleLoc, RAngleLoc),
3289 SourceRange(LParenLoc, RParenLoc));
3290 }
3291
3292 /// Build a new C++ reinterpret_cast expression.
3293 ///
3294 /// By default, performs semantic analysis to build the new expression.
3295 /// Subclasses may override this routine to provide different behavior.
3297 SourceLocation LAngleLoc,
3298 TypeSourceInfo *TInfo,
3299 SourceLocation RAngleLoc,
3300 SourceLocation LParenLoc,
3301 Expr *SubExpr,
3302 SourceLocation RParenLoc) {
3303 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3304 TInfo, SubExpr,
3305 SourceRange(LAngleLoc, RAngleLoc),
3306 SourceRange(LParenLoc, RParenLoc));
3307 }
3308
3309 /// Build a new C++ const_cast expression.
3310 ///
3311 /// By default, performs semantic analysis to build the new expression.
3312 /// Subclasses may override this routine to provide different behavior.
3314 SourceLocation LAngleLoc,
3315 TypeSourceInfo *TInfo,
3316 SourceLocation RAngleLoc,
3317 SourceLocation LParenLoc,
3318 Expr *SubExpr,
3319 SourceLocation RParenLoc) {
3320 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3321 TInfo, SubExpr,
3322 SourceRange(LAngleLoc, RAngleLoc),
3323 SourceRange(LParenLoc, RParenLoc));
3324 }
3325
3328 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3329 SourceLocation LParenLoc, Expr *SubExpr,
3330 SourceLocation RParenLoc) {
3331 return getSema().BuildCXXNamedCast(
3332 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3333 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3334 }
3335
3336 /// Build a new C++ functional-style cast expression.
3337 ///
3338 /// By default, performs semantic analysis to build the new expression.
3339 /// Subclasses may override this routine to provide different behavior.
3341 SourceLocation LParenLoc,
3342 Expr *Sub,
3343 SourceLocation RParenLoc,
3344 bool ListInitialization) {
3345 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3346 // CXXParenListInitExpr. Pass its expanded arguments so that the
3347 // CXXParenListInitExpr can be rebuilt.
3348 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3350 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3351 RParenLoc, ListInitialization);
3352
3353 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3355 TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
3356
3357 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3358 MultiExprArg(&Sub, 1), RParenLoc,
3359 ListInitialization);
3360 }
3361
3362 /// Build a new C++ __builtin_bit_cast expression.
3363 ///
3364 /// By default, performs semantic analysis to build the new expression.
3365 /// Subclasses may override this routine to provide different behavior.
3367 TypeSourceInfo *TSI, Expr *Sub,
3368 SourceLocation RParenLoc) {
3369 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3370 }
3371
3372 /// Build a new C++ typeid(type) expression.
3373 ///
3374 /// By default, performs semantic analysis to build the new expression.
3375 /// Subclasses may override this routine to provide different behavior.
3377 SourceLocation TypeidLoc,
3378 TypeSourceInfo *Operand,
3379 SourceLocation RParenLoc) {
3380 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3381 RParenLoc);
3382 }
3383
3384
3385 /// Build a new C++ typeid(expr) expression.
3386 ///
3387 /// By default, performs semantic analysis to build the new expression.
3388 /// Subclasses may override this routine to provide different behavior.
3390 SourceLocation TypeidLoc,
3391 Expr *Operand,
3392 SourceLocation RParenLoc) {
3393 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3394 RParenLoc);
3395 }
3396
3397 /// Build a new C++ __uuidof(type) expression.
3398 ///
3399 /// By default, performs semantic analysis to build the new expression.
3400 /// Subclasses may override this routine to provide different behavior.
3402 TypeSourceInfo *Operand,
3403 SourceLocation RParenLoc) {
3404 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3405 }
3406
3407 /// Build a new C++ __uuidof(expr) expression.
3408 ///
3409 /// By default, performs semantic analysis to build the new expression.
3410 /// Subclasses may override this routine to provide different behavior.
3412 Expr *Operand, SourceLocation RParenLoc) {
3413 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3414 }
3415
3416 /// Build a new C++ "this" expression.
3417 ///
3418 /// By default, performs semantic analysis to build a new "this" expression.
3419 /// Subclasses may override this routine to provide different behavior.
3421 QualType ThisType,
3422 bool isImplicit) {
3423 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3424 return ExprError();
3425 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3426 }
3427
3428 /// Build a new C++ throw expression.
3429 ///
3430 /// By default, performs semantic analysis to build the new expression.
3431 /// Subclasses may override this routine to provide different behavior.
3433 bool IsThrownVariableInScope) {
3434 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3435 }
3436
3437 /// Build a new C++ default-argument expression.
3438 ///
3439 /// By default, builds a new default-argument expression, which does not
3440 /// require any semantic analysis. Subclasses may override this routine to
3441 /// provide different behavior.
3443 Expr *RewrittenExpr) {
3444 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3445 RewrittenExpr, getSema().CurContext);
3446 }
3447
3448 /// Build a new C++11 default-initialization expression.
3449 ///
3450 /// By default, builds a new default field initialization expression, which
3451 /// does not require any semantic analysis. Subclasses may override this
3452 /// routine to provide different behavior.
3454 FieldDecl *Field) {
3455 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3456 }
3457
3458 /// Build a new C++ zero-initialization expression.
3459 ///
3460 /// By default, performs semantic analysis to build the new expression.
3461 /// Subclasses may override this routine to provide different behavior.
3463 SourceLocation LParenLoc,
3464 SourceLocation RParenLoc) {
3465 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3466 /*ListInitialization=*/false);
3467 }
3468
3469 /// Build a new C++ "new" expression.
3470 ///
3471 /// By default, performs semantic analysis to build the new expression.
3472 /// Subclasses may override this routine to provide different behavior.
3474 SourceLocation PlacementLParen,
3475 MultiExprArg PlacementArgs,
3476 SourceLocation PlacementRParen,
3477 SourceRange TypeIdParens, QualType AllocatedType,
3478 TypeSourceInfo *AllocatedTypeInfo,
3479 std::optional<Expr *> ArraySize,
3480 SourceRange DirectInitRange, Expr *Initializer) {
3481 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3482 PlacementLParen,
3483 PlacementArgs,
3484 PlacementRParen,
3485 TypeIdParens,
3486 AllocatedType,
3487 AllocatedTypeInfo,
3488 ArraySize,
3489 DirectInitRange,
3490 Initializer);
3491 }
3492
3493 /// Build a new C++ "delete" expression.
3494 ///
3495 /// By default, performs semantic analysis to build the new expression.
3496 /// Subclasses may override this routine to provide different behavior.
3498 bool IsGlobalDelete,
3499 bool IsArrayForm,
3500 Expr *Operand) {
3501 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3502 Operand);
3503 }
3504
3505 /// Build a new type trait expression.
3506 ///
3507 /// By default, performs semantic analysis to build the new expression.
3508 /// Subclasses may override this routine to provide different behavior.
3510 SourceLocation StartLoc,
3512 SourceLocation RParenLoc) {
3513 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3514 }
3515
3516 /// Build a new array type trait expression.
3517 ///
3518 /// By default, performs semantic analysis to build the new expression.
3519 /// Subclasses may override this routine to provide different behavior.
3521 SourceLocation StartLoc,
3522 TypeSourceInfo *TSInfo,
3523 Expr *DimExpr,
3524 SourceLocation RParenLoc) {
3525 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3526 }
3527
3528 /// Build a new expression trait expression.
3529 ///
3530 /// By default, performs semantic analysis to build the new expression.
3531 /// Subclasses may override this routine to provide different behavior.
3533 SourceLocation StartLoc,
3534 Expr *Queried,
3535 SourceLocation RParenLoc) {
3536 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3537 }
3538
3539 /// Build a new (previously unresolved) declaration reference
3540 /// expression.
3541 ///
3542 /// By default, performs semantic analysis to build the new expression.
3543 /// Subclasses may override this routine to provide different behavior.
3545 NestedNameSpecifierLoc QualifierLoc,
3546 SourceLocation TemplateKWLoc,
3547 const DeclarationNameInfo &NameInfo,
3548 const TemplateArgumentListInfo *TemplateArgs,
3549 bool IsAddressOfOperand,
3550 TypeSourceInfo **RecoveryTSI) {
3551 CXXScopeSpec SS;
3552 SS.Adopt(QualifierLoc);
3553
3554 if (TemplateArgs || TemplateKWLoc.isValid())
3556 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3557
3559 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3560 }
3561
3562 /// Build a new template-id expression.
3563 ///
3564 /// By default, performs semantic analysis to build the new expression.
3565 /// Subclasses may override this routine to provide different behavior.
3567 SourceLocation TemplateKWLoc,
3568 LookupResult &R,
3569 bool RequiresADL,
3570 const TemplateArgumentListInfo *TemplateArgs) {
3571 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3572 TemplateArgs);
3573 }
3574
3575 /// Build a new object-construction expression.
3576 ///
3577 /// By default, performs semantic analysis to build the new expression.
3578 /// Subclasses may override this routine to provide different behavior.
3581 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3582 bool ListInitialization, bool StdInitListInitialization,
3583 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3584 SourceRange ParenRange) {
3585 // Reconstruct the constructor we originally found, which might be
3586 // different if this is a call to an inherited constructor.
3587 CXXConstructorDecl *FoundCtor = Constructor;
3588 if (Constructor->isInheritingConstructor())
3589 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3590
3591 SmallVector<Expr *, 8> ConvertedArgs;
3592 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3593 ConvertedArgs))
3594 return ExprError();
3595
3597 IsElidable,
3598 ConvertedArgs,
3599 HadMultipleCandidates,
3600 ListInitialization,
3601 StdInitListInitialization,
3602 RequiresZeroInit, ConstructKind,
3603 ParenRange);
3604 }
3605
3606 /// Build a new implicit construction via inherited constructor
3607 /// expression.
3610 bool ConstructsVBase,
3611 bool InheritedFromVBase) {
3613 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3614 }
3615
3616 /// Build a new object-construction expression.
3617 ///
3618 /// By default, performs semantic analysis to build the new expression.
3619 /// Subclasses may override this routine to provide different behavior.
3621 SourceLocation LParenOrBraceLoc,
3622 MultiExprArg Args,
3623 SourceLocation RParenOrBraceLoc,
3624 bool ListInitialization) {
3626 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3627 }
3628
3629 /// Build a new object-construction expression.
3630 ///
3631 /// By default, performs semantic analysis to build the new expression.
3632 /// Subclasses may override this routine to provide different behavior.
3634 SourceLocation LParenLoc,
3635 MultiExprArg Args,
3636 SourceLocation RParenLoc,
3637 bool ListInitialization) {
3638 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3639 RParenLoc, ListInitialization);
3640 }
3641
3642 /// Build a new member reference expression.
3643 ///
3644 /// By default, performs semantic analysis to build the new expression.
3645 /// Subclasses may override this routine to provide different behavior.
3647 QualType BaseType,
3648 bool IsArrow,
3649 SourceLocation OperatorLoc,
3650 NestedNameSpecifierLoc QualifierLoc,
3651 SourceLocation TemplateKWLoc,
3652 NamedDecl *FirstQualifierInScope,
3653 const DeclarationNameInfo &MemberNameInfo,
3654 const TemplateArgumentListInfo *TemplateArgs) {
3655 CXXScopeSpec SS;
3656 SS.Adopt(QualifierLoc);
3657
3658 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3659 OperatorLoc, IsArrow,
3660 SS, TemplateKWLoc,
3661 FirstQualifierInScope,
3662 MemberNameInfo,
3663 TemplateArgs, /*S*/nullptr);
3664 }
3665
3666 /// Build a new member reference expression.
3667 ///
3668 /// By default, performs semantic analysis to build the new expression.
3669 /// Subclasses may override this routine to provide different behavior.
3671 SourceLocation OperatorLoc,
3672 bool IsArrow,
3673 NestedNameSpecifierLoc QualifierLoc,
3674 SourceLocation TemplateKWLoc,
3675 NamedDecl *FirstQualifierInScope,
3676 LookupResult &R,
3677 const TemplateArgumentListInfo *TemplateArgs) {
3678 CXXScopeSpec SS;
3679 SS.Adopt(QualifierLoc);
3680
3681 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3682 OperatorLoc, IsArrow,
3683 SS, TemplateKWLoc,
3684 FirstQualifierInScope,
3685 R, TemplateArgs, /*S*/nullptr);
3686 }
3687
3688 /// Build a new noexcept expression.
3689 ///
3690 /// By default, performs semantic analysis to build the new expression.
3691 /// Subclasses may override this routine to provide different behavior.
3693 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3694 }
3695
3698
3699 /// Build a new expression to compute the length of a parameter pack.
3701 SourceLocation PackLoc,
3702 SourceLocation RParenLoc,
3703 UnsignedOrNone Length,
3704 ArrayRef<TemplateArgument> PartialArgs) {
3705 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3706 RParenLoc, Length, PartialArgs);
3707 }
3708
3710 SourceLocation RSquareLoc,
3711 Expr *PackIdExpression, Expr *IndexExpr,
3712 ArrayRef<Expr *> ExpandedExprs,
3713 bool FullySubstituted = false) {
3714 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3715 IndexExpr, RSquareLoc, ExpandedExprs,
3716 FullySubstituted);
3717 }
3718
3719 /// Build a new expression representing a call to a source location
3720 /// builtin.
3721 ///
3722 /// By default, performs semantic analysis to build the new expression.
3723 /// Subclasses may override this routine to provide different behavior.
3725 SourceLocation BuiltinLoc,
3726 SourceLocation RPLoc,
3727 DeclContext *ParentContext) {
3728 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3729 ParentContext);
3730 }
3731
3732 /// Build a new Objective-C boxed expression.
3733 ///
3734 /// By default, performs semantic analysis to build the new expression.
3735 /// Subclasses may override this routine to provide different behavior.
3737 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3738 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3740 CXXScopeSpec SS;
3741 SS.Adopt(NNS);
3742 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3743 ConceptNameInfo,
3744 FoundDecl,
3745 NamedConcept, TALI);
3746 if (Result.isInvalid())
3747 return ExprError();
3748 return Result;
3749 }
3750
3751 /// \brief Build a new requires expression.
3752 ///
3753 /// By default, performs semantic analysis to build the new expression.
3754 /// Subclasses may override this routine to provide different behavior.
3757 SourceLocation LParenLoc,
3758 ArrayRef<ParmVarDecl *> LocalParameters,
3759 SourceLocation RParenLoc,
3761 SourceLocation ClosingBraceLoc) {
3762 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3763 LocalParameters, RParenLoc, Requirements,
3764 ClosingBraceLoc);
3765 }
3766
3770 return SemaRef.BuildTypeRequirement(SubstDiag);
3771 }
3772
3775 }
3776
3779 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3780 SourceLocation NoexceptLoc,
3782 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3783 std::move(Ret));
3784 }
3785
3787 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3789 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3790 std::move(Ret));
3791 }
3792
3794 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3795 const ASTConstraintSatisfaction &Satisfaction) {
3796 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3797 Satisfaction);
3798 }
3799
3801 return SemaRef.BuildNestedRequirement(Constraint);
3802 }
3803
3804 /// \brief Build a new Objective-C boxed expression.
3805 ///
3806 /// By default, performs semantic analysis to build the new expression.
3807 /// Subclasses may override this routine to provide different behavior.
3809 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3810 }
3811
3812 /// Build a new Objective-C array literal.
3813 ///
3814 /// By default, performs semantic analysis to build the new expression.
3815 /// Subclasses may override this routine to provide different behavior.
3817 Expr **Elements, unsigned NumElements) {
3819 Range, MultiExprArg(Elements, NumElements));
3820 }
3821
3823 Expr *Base, Expr *Key,
3824 ObjCMethodDecl *getterMethod,
3825 ObjCMethodDecl *setterMethod) {
3827 RB, Base, Key, getterMethod, setterMethod);
3828 }
3829
3830 /// Build a new Objective-C dictionary literal.
3831 ///
3832 /// By default, performs semantic analysis to build the new expression.
3833 /// Subclasses may override this routine to provide different behavior.
3836 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3837 }
3838
3839 /// Build a new Objective-C \@encode expression.
3840 ///
3841 /// By default, performs semantic analysis to build the new expression.
3842 /// Subclasses may override this routine to provide different behavior.
3844 TypeSourceInfo *EncodeTypeInfo,
3845 SourceLocation RParenLoc) {
3846 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3847 RParenLoc);
3848 }
3849
3850 /// Build a new Objective-C class message.
3852 Selector Sel,
3853 ArrayRef<SourceLocation> SelectorLocs,
3855 SourceLocation LBracLoc,
3856 MultiExprArg Args,
3857 SourceLocation RBracLoc) {
3859 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3860 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3861 RBracLoc, Args);
3862 }
3863
3864 /// Build a new Objective-C instance message.
3866 Selector Sel,
3867 ArrayRef<SourceLocation> SelectorLocs,
3869 SourceLocation LBracLoc,
3870 MultiExprArg Args,
3871 SourceLocation RBracLoc) {
3872 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3873 /*SuperLoc=*/SourceLocation(),
3874 Sel, Method, LBracLoc,
3875 SelectorLocs, RBracLoc, Args);
3876 }
3877
3878 /// Build a new Objective-C instance/class message to 'super'.
3880 Selector Sel,
3881 ArrayRef<SourceLocation> SelectorLocs,
3882 QualType SuperType,
3884 SourceLocation LBracLoc,
3885 MultiExprArg Args,
3886 SourceLocation RBracLoc) {
3887 return Method->isInstanceMethod()
3889 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3890 SelectorLocs, RBracLoc, Args)
3891 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3892 Sel, Method, LBracLoc,
3893 SelectorLocs, RBracLoc, Args);
3894 }
3895
3896 /// Build a new Objective-C ivar reference expression.
3897 ///
3898 /// By default, performs semantic analysis to build the new expression.
3899 /// Subclasses may override this routine to provide different behavior.
3901 SourceLocation IvarLoc,
3902 bool IsArrow, bool IsFreeIvar) {
3903 CXXScopeSpec SS;
3904 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3906 BaseArg, BaseArg->getType(),
3907 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3908 /*FirstQualifierInScope=*/nullptr, NameInfo,
3909 /*TemplateArgs=*/nullptr,
3910 /*S=*/nullptr);
3911 if (IsFreeIvar && Result.isUsable())
3912 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3913 return Result;
3914 }
3915
3916 /// Build a new Objective-C property reference expression.
3917 ///
3918 /// By default, performs semantic analysis to build the new expression.
3919 /// Subclasses may override this routine to provide different behavior.
3922 SourceLocation PropertyLoc) {
3923 CXXScopeSpec SS;
3924 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3925 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3926 /*FIXME:*/PropertyLoc,
3927 /*IsArrow=*/false,
3928 SS, SourceLocation(),
3929 /*FirstQualifierInScope=*/nullptr,
3930 NameInfo,
3931 /*TemplateArgs=*/nullptr,
3932 /*S=*/nullptr);
3933 }
3934
3935 /// Build a new Objective-C property reference expression.
3936 ///
3937 /// By default, performs semantic analysis to build the new expression.
3938 /// Subclasses may override this routine to provide different behavior.
3940 ObjCMethodDecl *Getter,
3941 ObjCMethodDecl *Setter,
3942 SourceLocation PropertyLoc) {
3943 // Since these expressions can only be value-dependent, we do not
3944 // need to perform semantic analysis again.
3945 return Owned(
3946 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3948 PropertyLoc, Base));
3949 }
3950
3951 /// Build a new Objective-C "isa" expression.
3952 ///
3953 /// By default, performs semantic analysis to build the new expression.
3954 /// Subclasses may override this routine to provide different behavior.
3956 SourceLocation OpLoc, bool IsArrow) {
3957 CXXScopeSpec SS;
3958 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3959 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3960 OpLoc, IsArrow,
3961 SS, SourceLocation(),
3962 /*FirstQualifierInScope=*/nullptr,
3963 NameInfo,
3964 /*TemplateArgs=*/nullptr,
3965 /*S=*/nullptr);
3966 }
3967
3968 /// Build a new shuffle vector expression.
3969 ///
3970 /// By default, performs semantic analysis to build the new expression.
3971 /// Subclasses may override this routine to provide different behavior.
3973 MultiExprArg SubExprs,
3974 SourceLocation RParenLoc) {
3975 // Find the declaration for __builtin_shufflevector
3976 const IdentifierInfo &Name
3977 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3979 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3980 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3981
3982 // Build a reference to the __builtin_shufflevector builtin
3983 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3984 Expr *Callee = new (SemaRef.Context)
3986 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3987 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3988 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3989 CK_BuiltinFnToFnPtr).get();
3990
3991 // Build the CallExpr
3992 ExprResult TheCall = CallExpr::Create(
3993 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3994 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3996
3997 // Type-check the __builtin_shufflevector expression.
3998 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3999 }
4000
4001 /// Build a new convert vector expression.
4003 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4004 SourceLocation RParenLoc) {
4005 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4006 }
4007
4008 /// Build a new template argument pack expansion.
4009 ///
4010 /// By default, performs semantic analysis to build a new pack expansion
4011 /// for a template argument. Subclasses may override this routine to provide
4012 /// different behavior.
4014 SourceLocation EllipsisLoc,
4015 UnsignedOrNone NumExpansions) {
4016 switch (Pattern.getArgument().getKind()) {
4020 EllipsisLoc, NumExpansions);
4021 if (Result.isInvalid())
4022 return TemplateArgumentLoc();
4023
4025 /*IsCanonical=*/false),
4026 Result.get());
4027 }
4028
4030 return TemplateArgumentLoc(
4033 NumExpansions),
4034 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4035 Pattern.getTemplateNameLoc(), EllipsisLoc);
4036
4044 llvm_unreachable("Pack expansion pattern has no parameter packs");
4045
4047 if (TypeSourceInfo *Expansion
4048 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4049 EllipsisLoc,
4050 NumExpansions))
4051 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4052 Expansion);
4053 break;
4054 }
4055
4056 return TemplateArgumentLoc();
4057 }
4058
4059 /// Build a new expression pack expansion.
4060 ///
4061 /// By default, performs semantic analysis to build a new pack expansion
4062 /// for an expression. Subclasses may override this routine to provide
4063 /// different behavior.
4065 UnsignedOrNone NumExpansions) {
4066 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4067 }
4068
4069 /// Build a new C++1z fold-expression.
4070 ///
4071 /// By default, performs semantic analysis in order to build a new fold
4072 /// expression.
4074 SourceLocation LParenLoc, Expr *LHS,
4075 BinaryOperatorKind Operator,
4076 SourceLocation EllipsisLoc, Expr *RHS,
4077 SourceLocation RParenLoc,
4078 UnsignedOrNone NumExpansions) {
4079 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4080 EllipsisLoc, RHS, RParenLoc,
4081 NumExpansions);
4082 }
4083
4085 LambdaScopeInfo *LSI) {
4086 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4087 if (Expr *Init = PVD->getInit())
4089 Init->containsUnexpandedParameterPack();
4090 else if (PVD->hasUninstantiatedDefaultArg())
4092 PVD->getUninstantiatedDefaultArg()
4093 ->containsUnexpandedParameterPack();
4094 }
4095 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4096 }
4097
4098 /// Build an empty C++1z fold-expression with the given operator.
4099 ///
4100 /// By default, produces the fallback value for the fold-expression, or
4101 /// produce an error if there is no fallback value.
4103 BinaryOperatorKind Operator) {
4104 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4105 }
4106
4107 /// Build a new atomic operation expression.
4108 ///
4109 /// By default, performs semantic analysis to build the new expression.
4110 /// Subclasses may override this routine to provide different behavior.
4113 SourceLocation RParenLoc) {
4114 // Use this for all of the locations, since we don't know the difference
4115 // between the call and the expr at this point.
4116 SourceRange Range{BuiltinLoc, RParenLoc};
4117 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4119 }
4120
4122 ArrayRef<Expr *> SubExprs, QualType Type) {
4123 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4124 }
4125
4127 SourceLocation BeginLoc,
4128 SourceLocation DirLoc,
4129 SourceLocation EndLoc,
4131 StmtResult StrBlock) {
4133 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4134 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4135 }
4136
4138 SourceLocation DirLoc,
4139 SourceLocation EndLoc,
4141 StmtResult Loop) {
4143 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4145 Clauses, Loop);
4146 }
4147
4149 SourceLocation BeginLoc,
4150 SourceLocation DirLoc,
4151 SourceLocation EndLoc,
4153 StmtResult Loop) {
4155 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4156 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4157 }
4158
4160 SourceLocation DirLoc,
4161 SourceLocation EndLoc,
4163 StmtResult StrBlock) {
4165 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4167 Clauses, StrBlock);
4168 }
4169
4172 SourceLocation DirLoc, SourceLocation EndLoc,
4173 ArrayRef<OpenACCClause *> Clauses) {
4177 Clauses, {});
4178 }
4179
4182 SourceLocation DirLoc, SourceLocation EndLoc,
4183 ArrayRef<OpenACCClause *> Clauses) {
4187 Clauses, {});
4188 }
4189
4191 SourceLocation DirLoc,
4192 SourceLocation EndLoc,
4194 StmtResult StrBlock) {
4198 Clauses, StrBlock);
4199 }
4200
4202 SourceLocation DirLoc,
4203 SourceLocation EndLoc,
4204 ArrayRef<OpenACCClause *> Clauses) {
4206 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4208 Clauses, {});
4209 }
4210
4213 SourceLocation DirLoc, SourceLocation EndLoc,
4214 ArrayRef<OpenACCClause *> Clauses) {
4218 Clauses, {});
4219 }
4220
4222 SourceLocation DirLoc,
4223 SourceLocation EndLoc,
4224 ArrayRef<OpenACCClause *> Clauses) {
4226 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4228 Clauses, {});
4229 }
4230
4232 SourceLocation DirLoc,
4233 SourceLocation EndLoc,
4234 ArrayRef<OpenACCClause *> Clauses) {
4236 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4238 Clauses, {});
4239 }
4240
4242 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4243 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4244 SourceLocation RParenLoc, SourceLocation EndLoc,
4245 ArrayRef<OpenACCClause *> Clauses) {
4247 Exprs.push_back(DevNumExpr);
4248 llvm::append_range(Exprs, QueueIdExprs);
4250 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4251 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4252 }
4253
4255 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4256 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4257 SourceLocation RParenLoc, SourceLocation EndLoc) {
4259 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4260 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4261 }
4262
4264 SourceLocation DirLoc,
4265 OpenACCAtomicKind AtKind,
4266 SourceLocation EndLoc,
4268 StmtResult AssociatedStmt) {
4270 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4271 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4272 AssociatedStmt);
4273 }
4274
4276 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4277 }
4278
4279private:
4280 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4281 QualType ObjectType,
4282 NamedDecl *FirstQualifierInScope);
4283
4284 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4285 QualType ObjectType,
4286 NamedDecl *FirstQualifierInScope) {
4287 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4288 return TSInfo;
4289
4290 TypeLocBuilder TLB;
4291 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4292 ObjectType, FirstQualifierInScope);
4293 if (T.isNull())
4294 return nullptr;
4295 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4296 }
4297
4298 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4299 DependentNameTypeLoc TL,
4300 bool DeducibleTSTContext,
4301 QualType ObjectType = QualType(),
4302 NamedDecl *UnqualLookup = nullptr);
4303
4305 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4307
4308 OpenACCClause *
4309 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4310 OpenACCDirectiveKind DirKind,
4311 const OpenACCClause *OldClause);
4312};
4313
4314template <typename Derived>
4316 if (!S)
4317 return S;
4318
4319 switch (S->getStmtClass()) {
4320 case Stmt::NoStmtClass: break;
4321
4322 // Transform individual statement nodes
4323 // Pass SDK into statements that can produce a value
4324#define STMT(Node, Parent) \
4325 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4326#define VALUESTMT(Node, Parent) \
4327 case Stmt::Node##Class: \
4328 return getDerived().Transform##Node(cast<Node>(S), SDK);
4329#define ABSTRACT_STMT(Node)
4330#define EXPR(Node, Parent)
4331#include "clang/AST/StmtNodes.inc"
4332
4333 // Transform expressions by calling TransformExpr.
4334#define STMT(Node, Parent)
4335#define ABSTRACT_STMT(Stmt)
4336#define EXPR(Node, Parent) case Stmt::Node##Class:
4337#include "clang/AST/StmtNodes.inc"
4338 {
4339 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4340
4341 if (SDK == StmtDiscardKind::StmtExprResult)
4342 E = getSema().ActOnStmtExprResult(E);
4343 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4344 }
4345 }
4346
4347 return S;
4348}
4349
4350template<typename Derived>
4352 if (!S)
4353 return S;
4354
4355 switch (S->getClauseKind()) {
4356 default: break;
4357 // Transform individual clause nodes
4358#define GEN_CLANG_CLAUSE_CLASS
4359#define CLAUSE_CLASS(Enum, Str, Class) \
4360 case Enum: \
4361 return getDerived().Transform##Class(cast<Class>(S));
4362#include "llvm/Frontend/OpenMP/OMP.inc"
4363 }
4364
4365 return S;
4366}
4367
4368
4369template<typename Derived>
4371 if (!E)
4372 return E;
4373
4374 switch (E->getStmtClass()) {
4375 case Stmt::NoStmtClass: break;
4376#define STMT(Node, Parent) case Stmt::Node##Class: break;
4377#define ABSTRACT_STMT(Stmt)
4378#define EXPR(Node, Parent) \
4379 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4380#include "clang/AST/StmtNodes.inc"
4381 }
4382
4383 return E;
4384}
4385
4386template<typename Derived>
4388 bool NotCopyInit) {
4389 // Initializers are instantiated like expressions, except that various outer
4390 // layers are stripped.
4391 if (!Init)
4392 return Init;
4393
4394 if (auto *FE = dyn_cast<FullExpr>(Init))
4395 Init = FE->getSubExpr();
4396
4397 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4398 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4399 Init = OVE->getSourceExpr();
4400 }
4401
4402 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4403 Init = MTE->getSubExpr();
4404
4405 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4406 Init = Binder->getSubExpr();
4407
4408 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4409 Init = ICE->getSubExprAsWritten();
4410
4411 if (CXXStdInitializerListExpr *ILE =
4412 dyn_cast<CXXStdInitializerListExpr>(Init))
4413 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4414
4415 // If this is copy-initialization, we only need to reconstruct
4416 // InitListExprs. Other forms of copy-initialization will be a no-op if
4417 // the initializer is already the right type.
4418 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4419 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4420 return getDerived().TransformExpr(Init);
4421
4422 // Revert value-initialization back to empty parens.
4423 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4424 SourceRange Parens = VIE->getSourceRange();
4425 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4426 Parens.getEnd());
4427 }
4428
4429 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4430 if (isa<ImplicitValueInitExpr>(Init))
4431 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4432 SourceLocation());
4433
4434 // Revert initialization by constructor back to a parenthesized or braced list
4435 // of expressions. Any other form of initializer can just be reused directly.
4436 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4437 return getDerived().TransformExpr(Init);
4438
4439 // If the initialization implicitly converted an initializer list to a
4440 // std::initializer_list object, unwrap the std::initializer_list too.
4441 if (Construct && Construct->isStdInitListInitialization())
4442 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4443
4444 // Enter a list-init context if this was list initialization.
4447 Construct->isListInitialization());
4448
4449 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4450 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4451 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4452 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4453 SmallVector<Expr*, 8> NewArgs;
4454 bool ArgChanged = false;
4455 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4456 /*IsCall*/true, NewArgs, &ArgChanged))
4457 return ExprError();
4458
4459 // If this was list initialization, revert to syntactic list form.
4460 if (Construct->isListInitialization())
4461 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4462 Construct->getEndLoc());
4463
4464 // Build a ParenListExpr to represent anything else.
4466 if (Parens.isInvalid()) {
4467 // This was a variable declaration's initialization for which no initializer
4468 // was specified.
4469 assert(NewArgs.empty() &&
4470 "no parens or braces but have direct init with arguments?");
4471 return ExprEmpty();
4472 }
4473 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4474 Parens.getEnd());
4475}
4476
4477template<typename Derived>
4479 unsigned NumInputs,
4480 bool IsCall,
4481 SmallVectorImpl<Expr *> &Outputs,
4482 bool *ArgChanged) {
4483 for (unsigned I = 0; I != NumInputs; ++I) {
4484 // If requested, drop call arguments that need to be dropped.
4485 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4486 if (ArgChanged)
4487 *ArgChanged = true;
4488
4489 break;
4490 }
4491
4492 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4493 Expr *Pattern = Expansion->getPattern();
4494
4496 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4497 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4498
4499 // Determine whether the set of unexpanded parameter packs can and should
4500 // be expanded.
4501 bool Expand = true;
4502 bool RetainExpansion = false;
4503 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4504 UnsignedOrNone NumExpansions = OrigNumExpansions;
4505 if (getDerived().TryExpandParameterPacks(
4506 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4507 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4508 RetainExpansion, NumExpansions))
4509 return true;
4510
4511 if (!Expand) {
4512 // The transform has determined that we should perform a simple
4513 // transformation on the pack expansion, producing another pack
4514 // expansion.
4515 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4516 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4517 if (OutPattern.isInvalid())
4518 return true;
4519
4520 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4521 Expansion->getEllipsisLoc(),
4522 NumExpansions);
4523 if (Out.isInvalid())
4524 return true;
4525
4526 if (ArgChanged)
4527 *ArgChanged = true;
4528 Outputs.push_back(Out.get());
4529 continue;
4530 }
4531
4532 // Record right away that the argument was changed. This needs
4533 // to happen even if the array expands to nothing.
4534 if (ArgChanged) *ArgChanged = true;
4535
4536 // The transform has determined that we should perform an elementwise
4537 // expansion of the pattern. Do so.
4538 for (unsigned I = 0; I != *NumExpansions; ++I) {
4539 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4540 ExprResult Out = getDerived().TransformExpr(Pattern);
4541 if (Out.isInvalid())
4542 return true;
4543
4544 if (Out.get()->containsUnexpandedParameterPack()) {
4545 Out = getDerived().RebuildPackExpansion(
4546 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4547 if (Out.isInvalid())
4548 return true;
4549 }
4550
4551 Outputs.push_back(Out.get());
4552 }
4553
4554 // If we're supposed to retain a pack expansion, do so by temporarily
4555 // forgetting the partially-substituted parameter pack.
4556 if (RetainExpansion) {
4557 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4558
4559 ExprResult Out = getDerived().TransformExpr(Pattern);
4560 if (Out.isInvalid())
4561 return true;
4562
4563 Out = getDerived().RebuildPackExpansion(
4564 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4565 if (Out.isInvalid())
4566 return true;
4567
4568 Outputs.push_back(Out.get());
4569 }
4570
4571 continue;
4572 }
4573
4575 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4576 : getDerived().TransformExpr(Inputs[I]);
4577 if (Result.isInvalid())
4578 return true;
4579
4580 if (Result.get() != Inputs[I] && ArgChanged)
4581 *ArgChanged = true;
4582
4583 Outputs.push_back(Result.get());
4584 }
4585
4586 return false;
4587}
4588
4589template <typename Derived>
4592
4595 /*LambdaContextDecl=*/nullptr,
4597 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4598
4599 if (Var) {
4600 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4601 getDerived().TransformDefinition(Var->getLocation(), Var));
4602
4603 if (!ConditionVar)
4604 return Sema::ConditionError();
4605
4606 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4607 }
4608
4609 if (Expr) {
4610 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4611
4612 if (CondExpr.isInvalid())
4613 return Sema::ConditionError();
4614
4615 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4616 /*MissingOK=*/true);
4617 }
4618
4619 return Sema::ConditionResult();
4620}
4621
4622template <typename Derived>
4624 NestedNameSpecifierLoc NNS, QualType ObjectType,
4625 NamedDecl *FirstQualifierInScope) {
4627
4628 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4629 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4630 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4631 Qualifiers.push_back(Qualifier);
4632 };
4633 insertNNS(NNS);
4634
4635 CXXScopeSpec SS;
4636 while (!Qualifiers.empty()) {
4637 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4639
4640 switch (QNNS.getKind()) {
4642 llvm_unreachable("unexpected null nested name specifier");
4643
4645 auto *NS = cast<NamespaceBaseDecl>(getDerived().TransformDecl(
4646 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4648 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4649 break;
4650 }
4651
4653 // There is no meaningful transformation that one could perform on the
4654 // global scope.
4655 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4656 break;
4657
4659 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4660 getDerived().TransformDecl(SourceLocation(), QNNS.getAsRecordDecl()));
4661 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4662 Q.getEndLoc());
4663 break;
4664 }
4665
4667 assert(SS.isEmpty());
4668 TypeLoc TL = Q.castAsTypeLoc();
4669
4670 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4671 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4672 if (QualifierLoc) {
4673 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4674 QualifierLoc, ObjectType, FirstQualifierInScope);
4675 if (!QualifierLoc)
4676 return NestedNameSpecifierLoc();
4677 ObjectType = QualType();
4678 FirstQualifierInScope = nullptr;
4679 }
4680 SS.Adopt(QualifierLoc);
4682 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4683 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4684 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4685 false, SS,
4686 FirstQualifierInScope, false))
4687 return NestedNameSpecifierLoc();
4688 return SS.getWithLocInContext(SemaRef.Context);
4689 }
4690
4691 QualType T = TL.getType();
4692 TypeLocBuilder TLB;
4693 if (!getDerived().AlreadyTransformed(T)) {
4694 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4695 FirstQualifierInScope);
4696 if (T.isNull())
4697 return NestedNameSpecifierLoc();
4698 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4699 }
4700
4701 if (T->isDependentType() || T->isRecordType() ||
4702 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4703 if (T->isEnumeralType())
4704 SemaRef.Diag(TL.getBeginLoc(),
4705 diag::warn_cxx98_compat_enum_nested_name_spec);
4706 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4707 break;
4708 }
4709 // If the nested-name-specifier is an invalid type def, don't emit an
4710 // error because a previous error should have already been emitted.
4712 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4713 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4714 << T << SS.getRange();
4715 }
4716 return NestedNameSpecifierLoc();
4717 }
4718 }
4719 }
4720
4721 // Don't rebuild the nested-name-specifier if we don't have to.
4722 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4723 !getDerived().AlwaysRebuild())
4724 return NNS;
4725
4726 // If we can re-use the source-location data from the original
4727 // nested-name-specifier, do so.
4728 if (SS.location_size() == NNS.getDataLength() &&
4729 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4731
4732 // Allocate new nested-name-specifier location information.
4733 return SS.getWithLocInContext(SemaRef.Context);
4734}
4735
4736template<typename Derived>
4740 DeclarationName Name = NameInfo.getName();
4741 if (!Name)
4742 return DeclarationNameInfo();
4743
4744 switch (Name.getNameKind()) {
4752 return NameInfo;
4753
4755 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4756 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4757 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4758 if (!NewTemplate)
4759 return DeclarationNameInfo();
4760
4761 DeclarationNameInfo NewNameInfo(NameInfo);
4762 NewNameInfo.setName(
4764 return NewNameInfo;
4765 }
4766
4770 TypeSourceInfo *NewTInfo;
4771 CanQualType NewCanTy;
4772 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4773 NewTInfo = getDerived().TransformType(OldTInfo);
4774 if (!NewTInfo)
4775 return DeclarationNameInfo();
4776 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4777 }
4778 else {
4779 NewTInfo = nullptr;
4780 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4781 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4782 if (NewT.isNull())
4783 return DeclarationNameInfo();
4784 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4785 }
4786
4787 DeclarationName NewName
4788 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4789 NewCanTy);
4790 DeclarationNameInfo NewNameInfo(NameInfo);
4791 NewNameInfo.setName(NewName);
4792 NewNameInfo.setNamedTypeInfo(NewTInfo);
4793 return NewNameInfo;
4794 }
4795 }
4796
4797 llvm_unreachable("Unknown name kind.");
4798}
4799
4800template <typename Derived>
4802 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4804 QualType ObjectType, bool AllowInjectedClassName) {
4805 if (const IdentifierInfo *II = IO.getIdentifier())
4806 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4807 ObjectType, AllowInjectedClassName);
4808 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4809 NameLoc, ObjectType,
4810 AllowInjectedClassName);
4811}
4812
4813template <typename Derived>
4815 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4816 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4817 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4819 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4820
4821 if (QualifierLoc) {
4822 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4823 QualifierLoc, ObjectType, FirstQualifierInScope);
4824 if (!QualifierLoc)
4825 return TemplateName();
4826 }
4827
4828 NestedNameSpecifierLoc UnderlyingQualifier;
4829 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4830 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4831 FirstQualifierInScope, AllowInjectedClassName);
4832 if (NewUnderlyingName.isNull())
4833 return TemplateName();
4834 assert(!UnderlyingQualifier && "unexpected qualifier");
4835
4836 if (!getDerived().AlwaysRebuild() &&
4837 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4838 NewUnderlyingName == UnderlyingName)
4839 return Name;
4840 CXXScopeSpec SS;
4841 SS.Adopt(QualifierLoc);
4842 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4843 NewUnderlyingName);
4844 }
4845
4846 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4847 if (QualifierLoc) {
4848 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4849 QualifierLoc, ObjectType, FirstQualifierInScope);
4850 if (!QualifierLoc)
4851 return TemplateName();
4852 // The qualifier-in-scope and object type only apply to the leftmost
4853 // entity.
4854 ObjectType = QualType();
4855 }
4856
4857 if (!getDerived().AlwaysRebuild() &&
4858 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4859 ObjectType.isNull())
4860 return Name;
4861
4862 CXXScopeSpec SS;
4863 SS.Adopt(QualifierLoc);
4864 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4865 NameLoc, ObjectType,
4866 AllowInjectedClassName);
4867 }
4868
4870 Name.getAsSubstTemplateTemplateParm()) {
4871 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4872
4873 NestedNameSpecifierLoc ReplacementQualifierLoc;
4874 TemplateName ReplacementName = S->getReplacement();
4875 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4877 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4878 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4879 }
4880
4881 TemplateName NewName = getDerived().TransformTemplateName(
4882 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4883 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4884 if (NewName.isNull())
4885 return TemplateName();
4886 Decl *AssociatedDecl =
4887 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4888 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4889 AssociatedDecl == S->getAssociatedDecl())
4890 return Name;
4892 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4893 S->getFinal());
4894 }
4895
4896 assert(!Name.getAsDeducedTemplateName() &&
4897 "DeducedTemplateName should not escape partial ordering");
4898
4899 // FIXME: Preserve UsingTemplateName.
4900 if (auto *Template = Name.getAsTemplateDecl()) {
4901 assert(!QualifierLoc && "Unexpected qualifier");
4902 return TemplateName(cast_or_null<TemplateDecl>(
4903 getDerived().TransformDecl(NameLoc, Template)));
4904 }
4905
4907 = Name.getAsSubstTemplateTemplateParmPack()) {
4908 assert(!QualifierLoc &&
4909 "Unexpected qualified SubstTemplateTemplateParmPack");
4910 return getDerived().RebuildTemplateName(
4911 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4912 SubstPack->getIndex(), SubstPack->getFinal());
4913 }
4914
4915 // These should be getting filtered out before they reach the AST.
4916 llvm_unreachable("overloaded function decl survived to here");
4917}
4918
4919template <typename Derived>
4921 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4922 TemplateName Name, SourceLocation NameLoc) {
4923 TemplateName TN = getDerived().TransformTemplateName(
4924 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
4925 if (TN.isNull())
4926 return TemplateArgument();
4927 return TemplateArgument(TN);
4928}
4929
4930template<typename Derived>
4932 const TemplateArgument &Arg,
4933 TemplateArgumentLoc &Output) {
4934 Output = getSema().getTrivialTemplateArgumentLoc(
4935 Arg, QualType(), getDerived().getBaseLocation());
4936}
4937
4938template <typename Derived>
4940 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4941 bool Uneval) {
4942 const TemplateArgument &Arg = Input.getArgument();
4943 switch (Arg.getKind()) {
4946 llvm_unreachable("Unexpected TemplateArgument");
4947
4952 // Transform a resolved template argument straight to a resolved template
4953 // argument. We get here when substituting into an already-substituted
4954 // template type argument during concept satisfaction checking.
4956 QualType NewT = getDerived().TransformType(T);
4957 if (NewT.isNull())
4958 return true;
4959
4961 ? Arg.getAsDecl()
4962 : nullptr;
4963 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4964 getDerived().getBaseLocation(), D))
4965 : nullptr;
4966 if (D && !NewD)
4967 return true;
4968
4969 if (NewT == T && D == NewD)
4970 Output = Input;
4971 else if (Arg.getKind() == TemplateArgument::Integral)
4972 Output = TemplateArgumentLoc(
4973 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4975 else if (Arg.getKind() == TemplateArgument::NullPtr)
4976 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4978 else if (Arg.getKind() == TemplateArgument::Declaration)
4979 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4982 Output = TemplateArgumentLoc(
4983 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4985 else
4986 llvm_unreachable("unexpected template argument kind");
4987
4988 return false;
4989 }
4990
4992 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4993 if (!DI)
4994 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4995
4996 DI = getDerived().TransformType(DI);
4997 if (!DI)
4998 return true;
4999
5000 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
5001 return false;
5002 }
5003
5005 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5006
5007 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5008 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5009 Input.getTemplateNameLoc());
5010 if (Out.isNull())
5011 return true;
5012 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5013 QualifierLoc, Input.getTemplateNameLoc());
5014 return false;
5015 }
5016
5018 llvm_unreachable("Caller should expand pack expansions");
5019
5021 // Template argument expressions are constant expressions.
5023 getSema(),
5026 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5028
5029 Expr *InputExpr = Input.getSourceExpression();
5030 if (!InputExpr)
5031 InputExpr = Input.getArgument().getAsExpr();
5032
5033 ExprResult E = getDerived().TransformExpr(InputExpr);
5034 E = SemaRef.ActOnConstantExpression(E);
5035 if (E.isInvalid())
5036 return true;
5037 Output = TemplateArgumentLoc(
5038 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5039 return false;
5040 }
5041 }
5042
5043 // Work around bogus GCC warning
5044 return true;
5045}
5046
5047/// Iterator adaptor that invents template argument location information
5048/// for each of the template arguments in its underlying iterator.
5049template<typename Derived, typename InputIterator>
5052 InputIterator Iter;
5053
5054public:
5057 typedef typename std::iterator_traits<InputIterator>::difference_type
5059 typedef std::input_iterator_tag iterator_category;
5060
5061 class pointer {
5063
5064 public:
5065 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5066
5067 const TemplateArgumentLoc *operator->() const { return &Arg; }
5068 };
5069
5071 InputIterator Iter)
5072 : Self(Self), Iter(Iter) { }
5073
5075 ++Iter;
5076 return *this;
5077 }
5078
5081 ++(*this);
5082 return Old;
5083 }
5084
5087 Self.InventTemplateArgumentLoc(*Iter, Result);
5088 return Result;
5089 }
5090
5091 pointer operator->() const { return pointer(**this); }
5092
5095 return X.Iter == Y.Iter;
5096 }
5097
5100 return X.Iter != Y.Iter;
5101 }
5102};
5103
5104template<typename Derived>
5105template<typename InputIterator>
5107 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5108 bool Uneval) {
5109 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5111 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5112 // Unpack argument packs, which we translate them into separate
5113 // arguments.
5114 // FIXME: We could do much better if we could guarantee that the
5115 // TemplateArgumentLocInfo for the pack expansion would be usable for
5116 // all of the template arguments in the argument pack.
5117 typedef TemplateArgumentLocInventIterator<Derived,
5119 PackLocIterator;
5120 if (TransformTemplateArguments(
5121 PackLocIterator(*this, In.getArgument().pack_begin()),
5122 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5123 Uneval))
5124 return true;
5125
5126 continue;
5127 }
5128
5129 if (In.getArgument().isPackExpansion()) {
5130 UnexpandedInfo Info;
5131 TemplateArgumentLoc Prepared;
5132 if (PreparePackForExpansion(In, Uneval, Prepared, Info))
5133 return true;
5134 if (!Info.Expand) {
5135 Outputs.addArgument(Prepared);
5136 continue;
5137 }
5138
5139 // The transform has determined that we should perform an elementwise
5140 // expansion of the pattern. Do so.
5141 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5143 ForgetSubst.emplace(getDerived());
5144 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5145 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5146
5148 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5149 return true;
5150
5151 if (Out.getArgument().containsUnexpandedParameterPack()) {
5152 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5153 Info.OrigNumExpansions);
5154 if (Out.getArgument().isNull())
5155 return true;
5156 }
5157
5158 Outputs.addArgument(Out);
5159 }
5160
5161 // If we're supposed to retain a pack expansion, do so by temporarily
5162 // forgetting the partially-substituted parameter pack.
5163 if (Info.RetainExpansion) {
5164 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5165
5167 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5168 return true;
5169
5170 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5171 Info.OrigNumExpansions);
5172 if (Out.getArgument().isNull())
5173 return true;
5174
5175 Outputs.addArgument(Out);
5176 }
5177
5178 continue;
5179 }
5180
5181 // The simple case:
5182 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5183 return true;
5184
5185 Outputs.addArgument(Out);
5186 }
5187
5188 return false;
5189
5190}
5191
5192// FIXME: Find ways to reduce code duplication for pack expansions.
5193template <typename Derived>
5195 bool Uneval,
5197 UnexpandedInfo &Info) {
5198 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5199 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5200 TemplateArgumentLoc &Pattern) {
5201 assert(Arg.getArgument().isPackExpansion());
5202 // We have a pack expansion, for which we will be substituting into the
5203 // pattern.
5204 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5205 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5207 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5208 if (IsLateExpansionAttempt) {
5209 // Request expansion only when there is an opportunity to expand a pack
5210 // that required a substituion first.
5211 bool SawPackTypes =
5212 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5213 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5214 });
5215 if (!SawPackTypes) {
5216 Info.Expand = false;
5217 return false;
5218 }
5219 }
5220 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5221
5222 // Determine whether the set of unexpanded parameter packs can and
5223 // should be expanded.
5224 Info.Expand = true;
5225 Info.RetainExpansion = false;
5226 Info.NumExpansions = Info.OrigNumExpansions;
5227 return getDerived().TryExpandParameterPacks(
5228 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5229 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5230 Info.RetainExpansion, Info.NumExpansions);
5231 };
5232
5233 TemplateArgumentLoc Pattern;
5234 if (ComputeInfo(In, false, Info, Pattern))
5235 return true;
5236
5237 if (Info.Expand) {
5238 Out = Pattern;
5239 return false;
5240 }
5241
5242 // The transform has determined that we should perform a simple
5243 // transformation on the pack expansion, producing another pack
5244 // expansion.
5245 TemplateArgumentLoc OutPattern;
5246 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5247 std::in_place, getSema(), std::nullopt);
5248 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5249 return true;
5250
5251 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5252 Info.NumExpansions);
5253 if (Out.getArgument().isNull())
5254 return true;
5255 SubstIndex.reset();
5256
5257 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5258 return false;
5259
5260 // Some packs will learn their length after substitution, e.g.
5261 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5262 // value of `T`.
5263 //
5264 // We only expand after we know sizes of all packs, check if this is the case
5265 // or not. However, we avoid a full template substitution and only do
5266 // expanstions after this point.
5267
5268 // E.g. when substituting template arguments of tuple with {T -> int} in the
5269 // following example:
5270 // template <class T>
5271 // struct TupleWithInt {
5272 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5273 // };
5274 // TupleWithInt<int>::type y;
5275 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5276 // lenght and run `ComputeInfo()` to provide the necessary information to our
5277 // caller.
5278 //
5279 // Note that we may still have situations where builtin is not going to be
5280 // expanded. For example:
5281 // template <class T>
5282 // struct Foo {
5283 // template <class U> using tuple_with_t =
5284 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5285 // tuple_with_t<short>;
5286 // }
5287 // Because the substitution into `type` happens in dependent context, `type`
5288 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5289 // and the caller will not be able to expand it.
5290 ForgetSubstitutionRAII ForgetSubst(getDerived());
5291 if (ComputeInfo(Out, true, Info, OutPattern))
5292 return true;
5293 if (!Info.Expand)
5294 return false;
5295 Out = OutPattern;
5296 Info.ExpandUnderForgetSubstitions = true;
5297 return false;
5298}
5299
5300//===----------------------------------------------------------------------===//
5301// Type transformation
5302//===----------------------------------------------------------------------===//
5303
5304template<typename Derived>
5306 if (getDerived().AlreadyTransformed(T))
5307 return T;
5308
5309 // Temporary workaround. All of these transformations should
5310 // eventually turn into transformations on TypeLocs.
5311 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5312 getDerived().getBaseLocation());
5313
5314 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5315
5316 if (!NewDI)
5317 return QualType();
5318
5319 return NewDI->getType();
5320}
5321
5322template<typename Derived>
5324 // Refine the base location to the type's location.
5325 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5326 getDerived().getBaseEntity());
5327 if (getDerived().AlreadyTransformed(DI->getType()))
5328 return DI;
5329
5330 TypeLocBuilder TLB;
5331
5332 TypeLoc TL = DI->getTypeLoc();
5333 TLB.reserve(TL.getFullDataSize());
5334
5335 QualType Result = getDerived().TransformType(TLB, TL);
5336 if (Result.isNull())
5337 return nullptr;
5338
5339 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5340}
5341
5342template<typename Derived>
5345 switch (T.getTypeLocClass()) {
5346#define ABSTRACT_TYPELOC(CLASS, PARENT)
5347#define TYPELOC(CLASS, PARENT) \
5348 case TypeLoc::CLASS: \
5349 return getDerived().Transform##CLASS##Type(TLB, \
5350 T.castAs<CLASS##TypeLoc>());
5351#include "clang/AST/TypeLocNodes.def"
5352 }
5353
5354 llvm_unreachable("unhandled type loc!");
5355}
5356
5357template<typename Derived>
5359 if (!isa<DependentNameType>(T))
5360 return TransformType(T);
5361
5362 if (getDerived().AlreadyTransformed(T))
5363 return T;
5364 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5365 getDerived().getBaseLocation());
5366 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5367 return NewDI ? NewDI->getType() : QualType();
5368}
5369
5370template<typename Derived>
5373 if (!isa<DependentNameType>(DI->getType()))
5374 return TransformType(DI);
5375
5376 // Refine the base location to the type's location.
5377 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5378 getDerived().getBaseEntity());
5379 if (getDerived().AlreadyTransformed(DI->getType()))
5380 return DI;
5381
5382 TypeLocBuilder TLB;
5383
5384 TypeLoc TL = DI->getTypeLoc();
5385 TLB.reserve(TL.getFullDataSize());
5386
5387 auto QTL = TL.getAs<QualifiedTypeLoc>();
5388 if (QTL)
5389 TL = QTL.getUnqualifiedLoc();
5390
5391 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5392
5393 QualType Result = getDerived().TransformDependentNameType(
5394 TLB, DNTL, /*DeducedTSTContext*/true);
5395 if (Result.isNull())
5396 return nullptr;
5397
5398 if (QTL) {
5399 Result = getDerived().RebuildQualifiedType(Result, QTL);
5400 if (Result.isNull())
5401 return nullptr;
5403 }
5404
5405 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5406}
5407
5408template<typename Derived>
5413 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5414 auto SuppressObjCLifetime =
5415 T.getType().getLocalQualifiers().hasObjCLifetime();
5416 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5417 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5418 SuppressObjCLifetime);
5419 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5420 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5421 TLB, STTP, SuppressObjCLifetime);
5422 } else {
5423 Result = getDerived().TransformType(TLB, UnqualTL);
5424 }
5425
5426 if (Result.isNull())
5427 return QualType();
5428
5429 Result = getDerived().RebuildQualifiedType(Result, T);
5430
5431 if (Result.isNull())
5432 return QualType();
5433
5434 // RebuildQualifiedType might have updated the type, but not in a way
5435 // that invalidates the TypeLoc. (There's no location information for
5436 // qualifiers.)
5438
5439 return Result;
5440}
5441
5442template <typename Derived>
5444 QualifiedTypeLoc TL) {
5445
5447 Qualifiers Quals = TL.getType().getLocalQualifiers();
5448
5449 if ((T.getAddressSpace() != LangAS::Default &&
5450 Quals.getAddressSpace() != LangAS::Default) &&
5451 T.getAddressSpace() != Quals.getAddressSpace()) {
5452 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5453 << TL.getType() << T;
5454 return QualType();
5455 }
5456
5457 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5458 if (LocalPointerAuth.isPresent()) {
5459 if (T.getPointerAuth().isPresent()) {
5460 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5461 return QualType();
5462 }
5463 if (!T->isDependentType()) {
5464 if (!T->isSignableType(SemaRef.getASTContext())) {
5465 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5466 return QualType();
5467 }
5468 }
5469 }
5470 // C++ [dcl.fct]p7:
5471 // [When] adding cv-qualifications on top of the function type [...] the
5472 // cv-qualifiers are ignored.
5473 if (T->isFunctionType()) {
5475 Quals.getAddressSpace());
5476 return T;
5477 }
5478
5479 // C++ [dcl.ref]p1:
5480 // when the cv-qualifiers are introduced through the use of a typedef-name
5481 // or decltype-specifier [...] the cv-qualifiers are ignored.
5482 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5483 // applied to a reference type.
5484 if (T->isReferenceType()) {
5485 // The only qualifier that applies to a reference type is restrict.
5486 if (!Quals.hasRestrict())
5487 return T;
5489 }
5490
5491 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5492 // resulting type.
5493 if (Quals.hasObjCLifetime()) {
5494 if (!T->isObjCLifetimeType() && !T->isDependentType())
5495 Quals.removeObjCLifetime();
5496 else if (T.getObjCLifetime()) {
5497 // Objective-C ARC:
5498 // A lifetime qualifier applied to a substituted template parameter
5499 // overrides the lifetime qualifier from the template argument.
5500 const AutoType *AutoTy;
5501 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5502 // 'auto' types behave the same way as template parameters.
5503 QualType Deduced = AutoTy->getDeducedType();
5504 Qualifiers Qs = Deduced.getQualifiers();
5505 Qs.removeObjCLifetime();
5506 Deduced =
5507 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5508 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5509 AutoTy->isDependentType(),
5510 /*isPack=*/false,
5511 AutoTy->getTypeConstraintConcept(),
5512 AutoTy->getTypeConstraintArguments());
5513 } else {
5514 // Otherwise, complain about the addition of a qualifier to an
5515 // already-qualified type.
5516 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5517 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5518 Quals.removeObjCLifetime();
5519 }
5520 }
5521 }
5522
5523 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5524}
5525
5526template <typename Derived>
5528 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5529 NamedDecl *UnqualLookup) {
5530 assert(!getDerived().AlreadyTransformed(TL.getType()));
5531
5532 switch (TL.getTypeLocClass()) {
5533 case TypeLoc::DependentTemplateSpecialization:
5534 return getDerived().TransformDependentTemplateSpecializationType(
5535 TLB, TL.castAs<DependentTemplateSpecializationTypeLoc>(), ObjectType,
5536 UnqualLookup, /*AllowInjectedClassName=*/true);
5537 case TypeLoc::DependentName: {
5538 return getDerived().TransformDependentNameType(
5539 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5540 ObjectType, UnqualLookup);
5541 }
5542 default:
5543 // Any dependent canonical type can appear here, through type alias
5544 // templates.
5545 return getDerived().TransformType(TLB, TL);
5546 }
5547}
5548
5549template <class TyLoc> static inline
5551 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5552 NewT.setNameLoc(T.getNameLoc());
5553 return T.getType();
5554}
5555
5556template<typename Derived>
5557QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5558 BuiltinTypeLoc T) {
5559 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5560 NewT.setBuiltinLoc(T.getBuiltinLoc());
5561 if (T.needsExtraLocalData())
5562 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5563 return T.getType();
5564}
5565
5566template<typename Derived>
5567QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5568 ComplexTypeLoc T) {
5569 // FIXME: recurse?
5570 return TransformTypeSpecType(TLB, T);
5571}
5572
5573template <typename Derived>
5574QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5575 AdjustedTypeLoc TL) {
5576 // Adjustments applied during transformation are handled elsewhere.
5577 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5578}
5579
5580template<typename Derived>
5581QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5582 DecayedTypeLoc TL) {
5583 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5584 if (OriginalType.isNull())
5585 return QualType();
5586
5587 QualType Result = TL.getType();
5588 if (getDerived().AlwaysRebuild() ||
5589 OriginalType != TL.getOriginalLoc().getType())
5590 Result = SemaRef.Context.getDecayedType(OriginalType);
5591 TLB.push<DecayedTypeLoc>(Result);
5592 // Nothing to set for DecayedTypeLoc.
5593 return Result;
5594}
5595
5596template <typename Derived>
5597QualType
5598TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5599 ArrayParameterTypeLoc TL) {
5600 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5601 if (OriginalType.isNull())
5602 return QualType();
5603
5604 QualType Result = TL.getType();
5605 if (getDerived().AlwaysRebuild() ||
5606 OriginalType != TL.getElementLoc().getType())
5607 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5608 TLB.push<ArrayParameterTypeLoc>(Result);
5609 // Nothing to set for ArrayParameterTypeLoc.
5610 return Result;
5611}
5612
5613template<typename Derived>
5614QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5615 PointerTypeLoc TL) {
5616 QualType PointeeType
5617 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5618 if (PointeeType.isNull())
5619 return QualType();
5620
5621 QualType Result = TL.getType();
5622 if (PointeeType->getAs<ObjCObjectType>()) {
5623 // A dependent pointer type 'T *' has is being transformed such
5624 // that an Objective-C class type is being replaced for 'T'. The
5625 // resulting pointer type is an ObjCObjectPointerType, not a
5626 // PointerType.
5627 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5628
5629 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5630 NewT.setStarLoc(TL.getStarLoc());
5631 return Result;
5632 }
5633
5634 if (getDerived().AlwaysRebuild() ||
5635 PointeeType != TL.getPointeeLoc().getType()) {
5636 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5637 if (Result.isNull())
5638 return QualType();
5639 }
5640
5641 // Objective-C ARC can add lifetime qualifiers to the type that we're
5642 // pointing to.
5643 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5644
5645 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5646 NewT.setSigilLoc(TL.getSigilLoc());
5647 return Result;
5648}
5649
5650template<typename Derived>
5651QualType
5652TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5653 BlockPointerTypeLoc TL) {
5654 QualType PointeeType
5655 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5656 if (PointeeType.isNull())
5657 return QualType();
5658
5659 QualType Result = TL.getType();
5660 if (getDerived().AlwaysRebuild() ||
5661 PointeeType != TL.getPointeeLoc().getType()) {
5662 Result = getDerived().RebuildBlockPointerType(PointeeType,
5663 TL.getSigilLoc());
5664 if (Result.isNull())
5665 return QualType();
5666 }
5667
5668 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5669 NewT.setSigilLoc(TL.getSigilLoc());
5670 return Result;
5671}
5672
5673/// Transforms a reference type. Note that somewhat paradoxically we
5674/// don't care whether the type itself is an l-value type or an r-value
5675/// type; we only care if the type was *written* as an l-value type
5676/// or an r-value type.
5677template<typename Derived>
5678QualType
5680 ReferenceTypeLoc TL) {
5681 const ReferenceType *T = TL.getTypePtr();
5682
5683 // Note that this works with the pointee-as-written.
5684 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5685 if (PointeeType.isNull())
5686 return QualType();
5687
5688 QualType Result = TL.getType();
5689 if (getDerived().AlwaysRebuild() ||
5690 PointeeType != T->getPointeeTypeAsWritten()) {
5691 Result = getDerived().RebuildReferenceType(PointeeType,
5692 T->isSpelledAsLValue(),
5693 TL.getSigilLoc());
5694 if (Result.isNull())
5695 return QualType();
5696 }
5697
5698 // Objective-C ARC can add lifetime qualifiers to the type that we're
5699 // referring to.
5702
5703 // r-value references can be rebuilt as l-value references.
5704 ReferenceTypeLoc NewTL;
5705 if (isa<LValueReferenceType>(Result))
5706 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5707 else
5708 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5709 NewTL.setSigilLoc(TL.getSigilLoc());
5710
5711 return Result;
5712}
5713
5714template<typename Derived>
5718 return TransformReferenceType(TLB, TL);
5719}
5720
5721template<typename Derived>
5722QualType
5723TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5724 RValueReferenceTypeLoc TL) {
5725 return TransformReferenceType(TLB, TL);
5726}
5727
5728template<typename Derived>
5729QualType
5730TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5731 MemberPointerTypeLoc TL) {
5732 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5733 if (PointeeType.isNull())
5734 return QualType();
5735
5736 const MemberPointerType *T = TL.getTypePtr();
5737
5738 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5739 NestedNameSpecifierLoc NewQualifierLoc =
5740 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5741 if (!NewQualifierLoc)
5742 return QualType();
5743
5744 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5745 if (OldCls) {
5746 NewCls = cast_or_null<CXXRecordDecl>(
5747 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5748 if (!NewCls)
5749 return QualType();
5750 }
5751
5752 QualType Result = TL.getType();
5753 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5754 NewQualifierLoc.getNestedNameSpecifier() !=
5755 OldQualifierLoc.getNestedNameSpecifier() ||
5756 NewCls != OldCls) {
5757 CXXScopeSpec SS;
5758 SS.Adopt(NewQualifierLoc);
5759 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5760 TL.getStarLoc());
5761 if (Result.isNull())
5762 return QualType();
5763 }
5764
5765 // If we had to adjust the pointee type when building a member pointer, make
5766 // sure to push TypeLoc info for it.
5767 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5768 if (MPT && PointeeType != MPT->getPointeeType()) {
5769 assert(isa<AdjustedType>(MPT->getPointeeType()));
5770 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5771 }
5772
5773 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5774 NewTL.setSigilLoc(TL.getSigilLoc());
5775 NewTL.setQualifierLoc(NewQualifierLoc);
5776
5777 return Result;
5778}
5779
5780template<typename Derived>
5781QualType
5782TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5783 ConstantArrayTypeLoc TL) {
5784 const ConstantArrayType *T = TL.getTypePtr();
5785 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5786 if (ElementType.isNull())
5787 return QualType();
5788
5789 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5790 Expr *OldSize = TL.getSizeExpr();
5791 if (!OldSize)
5792 OldSize = const_cast<Expr*>(T->getSizeExpr());
5793 Expr *NewSize = nullptr;
5794 if (OldSize) {
5795 EnterExpressionEvaluationContext Unevaluated(
5797 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5798 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5799 }
5800
5801 QualType Result = TL.getType();
5802 if (getDerived().AlwaysRebuild() ||
5803 ElementType != T->getElementType() ||
5804 (T->getSizeExpr() && NewSize != OldSize)) {
5805 Result = getDerived().RebuildConstantArrayType(ElementType,
5806 T->getSizeModifier(),
5807 T->getSize(), NewSize,
5808 T->getIndexTypeCVRQualifiers(),
5809 TL.getBracketsRange());
5810 if (Result.isNull())
5811 return QualType();
5812 }
5813
5814 // We might have either a ConstantArrayType or a VariableArrayType now:
5815 // a ConstantArrayType is allowed to have an element type which is a
5816 // VariableArrayType if the type is dependent. Fortunately, all array
5817 // types have the same location layout.
5818 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5819 NewTL.setLBracketLoc(TL.getLBracketLoc());
5820 NewTL.setRBracketLoc(TL.getRBracketLoc());
5821 NewTL.setSizeExpr(NewSize);
5822
5823 return Result;
5824}
5825
5826template<typename Derived>
5827QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5828 TypeLocBuilder &TLB,
5829 IncompleteArrayTypeLoc TL) {
5830 const IncompleteArrayType *T = TL.getTypePtr();
5831 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5832 if (ElementType.isNull())
5833 return QualType();
5834
5835 QualType Result = TL.getType();
5836 if (getDerived().AlwaysRebuild() ||
5837 ElementType != T->getElementType()) {
5838 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5839 T->getSizeModifier(),
5840 T->getIndexTypeCVRQualifiers(),
5841 TL.getBracketsRange());
5842 if (Result.isNull())
5843 return QualType();
5844 }
5845
5846 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5847 NewTL.setLBracketLoc(TL.getLBracketLoc());
5848 NewTL.setRBracketLoc(TL.getRBracketLoc());
5849 NewTL.setSizeExpr(nullptr);
5850
5851 return Result;
5852}
5853
5854template<typename Derived>
5855QualType
5856TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5857 VariableArrayTypeLoc TL) {
5858 const VariableArrayType *T = TL.getTypePtr();
5859 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5860 if (ElementType.isNull())
5861 return QualType();
5862
5863 ExprResult SizeResult;
5864 {
5865 EnterExpressionEvaluationContext Context(
5867 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5868 }
5869 if (SizeResult.isInvalid())
5870 return QualType();
5871 SizeResult =
5872 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5873 if (SizeResult.isInvalid())
5874 return QualType();
5875
5876 Expr *Size = SizeResult.get();
5877
5878 QualType Result = TL.getType();
5879 if (getDerived().AlwaysRebuild() ||
5880 ElementType != T->getElementType() ||
5881 Size != T->getSizeExpr()) {
5882 Result = getDerived().RebuildVariableArrayType(ElementType,
5883 T->getSizeModifier(),
5884 Size,
5885 T->getIndexTypeCVRQualifiers(),
5886 TL.getBracketsRange());
5887 if (Result.isNull())
5888 return QualType();
5889 }
5890
5891 // We might have constant size array now, but fortunately it has the same
5892 // location layout.
5893 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5894 NewTL.setLBracketLoc(TL.getLBracketLoc());
5895 NewTL.setRBracketLoc(TL.getRBracketLoc());
5896 NewTL.setSizeExpr(Size);
5897
5898 return Result;
5899}
5900
5901template<typename Derived>
5902QualType
5903TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5904 DependentSizedArrayTypeLoc TL) {
5905 const DependentSizedArrayType *T = TL.getTypePtr();
5906 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5907 if (ElementType.isNull())
5908 return QualType();
5909
5910 // Array bounds are constant expressions.
5911 EnterExpressionEvaluationContext Unevaluated(
5913
5914 // If we have a VLA then it won't be a constant.
5915 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5916
5917 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5918 Expr *origSize = TL.getSizeExpr();
5919 if (!origSize) origSize = T->getSizeExpr();
5920
5921 ExprResult sizeResult
5922 = getDerived().TransformExpr(origSize);
5923 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5924 if (sizeResult.isInvalid())
5925 return QualType();
5926
5927 Expr *size = sizeResult.get();
5928
5929 QualType Result = TL.getType();
5930 if (getDerived().AlwaysRebuild() ||
5931 ElementType != T->getElementType() ||
5932 size != origSize) {
5933 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5934 T->getSizeModifier(),
5935 size,
5936 T->getIndexTypeCVRQualifiers(),
5937 TL.getBracketsRange());
5938 if (Result.isNull())
5939 return QualType();
5940 }
5941
5942 // We might have any sort of array type now, but fortunately they
5943 // all have the same location layout.
5944 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5945 NewTL.setLBracketLoc(TL.getLBracketLoc());
5946 NewTL.setRBracketLoc(TL.getRBracketLoc());
5947 NewTL.setSizeExpr(size);
5948
5949 return Result;
5950}
5951
5952template <typename Derived>
5953QualType TreeTransform<Derived>::TransformDependentVectorType(
5954 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5955 const DependentVectorType *T = TL.getTypePtr();
5956 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5957 if (ElementType.isNull())
5958 return QualType();
5959
5960 EnterExpressionEvaluationContext Unevaluated(
5962
5963 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5964 Size = SemaRef.ActOnConstantExpression(Size);
5965 if (Size.isInvalid())
5966 return QualType();
5967
5968 QualType Result = TL.getType();
5969 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5970 Size.get() != T->getSizeExpr()) {
5971 Result = getDerived().RebuildDependentVectorType(
5972 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5973 if (Result.isNull())
5974 return QualType();
5975 }
5976
5977 // Result might be dependent or not.
5978 if (isa<DependentVectorType>(Result)) {
5979 DependentVectorTypeLoc NewTL =
5980 TLB.push<DependentVectorTypeLoc>(Result);
5981 NewTL.setNameLoc(TL.getNameLoc());
5982 } else {
5983 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5984 NewTL.setNameLoc(TL.getNameLoc());
5985 }
5986
5987 return Result;
5988}
5989
5990template<typename Derived>
5991QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5992 TypeLocBuilder &TLB,
5993 DependentSizedExtVectorTypeLoc TL) {
5994 const DependentSizedExtVectorType *T = TL.getTypePtr();
5995
5996 // FIXME: ext vector locs should be nested
5997 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5998 if (ElementType.isNull())
5999 return QualType();
6000
6001 // Vector sizes are constant expressions.
6002 EnterExpressionEvaluationContext Unevaluated(
6004
6005 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6006 Size = SemaRef.ActOnConstantExpression(Size);
6007 if (Size.isInvalid())
6008 return QualType();
6009
6010 QualType Result = TL.getType();
6011 if (getDerived().AlwaysRebuild() ||
6012 ElementType != T->getElementType() ||
6013 Size.get() != T->getSizeExpr()) {
6014 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6015 Size.get(),
6016 T->getAttributeLoc());
6017 if (Result.isNull())
6018 return QualType();
6019 }
6020
6021 // Result might be dependent or not.
6022 if (isa<DependentSizedExtVectorType>(Result)) {
6023 DependentSizedExtVectorTypeLoc NewTL
6024 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
6025 NewTL.setNameLoc(TL.getNameLoc());
6026 } else {
6027 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6028 NewTL.setNameLoc(TL.getNameLoc());
6029 }
6030
6031 return Result;
6032}
6033
6034template <typename Derived>
6035QualType
6036TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
6037 ConstantMatrixTypeLoc TL) {
6038 const ConstantMatrixType *T = TL.getTypePtr();
6039 QualType ElementType = getDerived().TransformType(T->getElementType());
6040 if (ElementType.isNull())
6041 return QualType();
6042
6043 QualType Result = TL.getType();
6044 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6045 Result = getDerived().RebuildConstantMatrixType(
6046 ElementType, T->getNumRows(), T->getNumColumns());
6047 if (Result.isNull())
6048 return QualType();
6049 }
6050
6051 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
6052 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6053 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6054 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6055 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6056
6057 return Result;
6058}
6059
6060template <typename Derived>
6061QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
6062 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
6063 const DependentSizedMatrixType *T = TL.getTypePtr();
6064
6065 QualType ElementType = getDerived().TransformType(T->getElementType());
6066 if (ElementType.isNull()) {
6067 return QualType();
6068 }
6069
6070 // Matrix dimensions are constant expressions.
6071 EnterExpressionEvaluationContext Unevaluated(
6073
6074 Expr *origRows = TL.getAttrRowOperand();
6075 if (!origRows)
6076 origRows = T->getRowExpr();
6077 Expr *origColumns = TL.getAttrColumnOperand();
6078 if (!origColumns)
6079 origColumns = T->getColumnExpr();
6080
6081 ExprResult rowResult = getDerived().TransformExpr(origRows);
6082 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6083 if (rowResult.isInvalid())
6084 return QualType();
6085
6086 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6087 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6088 if (columnResult.isInvalid())
6089 return QualType();
6090
6091 Expr *rows = rowResult.get();
6092 Expr *columns = columnResult.get();
6093
6094 QualType Result = TL.getType();
6095 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6096 rows != origRows || columns != origColumns) {
6097 Result = getDerived().RebuildDependentSizedMatrixType(
6098 ElementType, rows, columns, T->getAttributeLoc());
6099
6100 if (Result.isNull())
6101 return QualType();
6102 }
6103
6104 // We might have any sort of matrix type now, but fortunately they
6105 // all have the same location layout.
6106 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6107 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6108 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6109 NewTL.setAttrRowOperand(rows);
6110 NewTL.setAttrColumnOperand(columns);
6111 return Result;
6112}
6113
6114template <typename Derived>
6115QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
6116 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
6117 const DependentAddressSpaceType *T = TL.getTypePtr();
6118
6119 QualType pointeeType =
6120 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6121
6122 if (pointeeType.isNull())
6123 return QualType();
6124
6125 // Address spaces are constant expressions.
6126 EnterExpressionEvaluationContext Unevaluated(
6128
6129 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6130 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6131 if (AddrSpace.isInvalid())
6132 return QualType();
6133
6134 QualType Result = TL.getType();
6135 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6136 AddrSpace.get() != T->getAddrSpaceExpr()) {
6137 Result = getDerived().RebuildDependentAddressSpaceType(
6138 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6139 if (Result.isNull())
6140 return QualType();
6141 }
6142
6143 // Result might be dependent or not.
6144 if (isa<DependentAddressSpaceType>(Result)) {
6145 DependentAddressSpaceTypeLoc NewTL =
6146 TLB.push<DependentAddressSpaceTypeLoc>(Result);
6147
6148 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6149 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6150 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6151
6152 } else {
6153 TLB.TypeWasModifiedSafely(Result);
6154 }
6155
6156 return Result;
6157}
6158
6159template <typename Derived>
6160QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
6161 VectorTypeLoc TL) {
6162 const VectorType *T = TL.getTypePtr();
6163 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6164 if (ElementType.isNull())
6165 return QualType();
6166
6167 QualType Result = TL.getType();
6168 if (getDerived().AlwaysRebuild() ||
6169 ElementType != T->getElementType()) {
6170 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6171 T->getVectorKind());
6172 if (Result.isNull())
6173 return QualType();
6174 }
6175
6176 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6177 NewTL.setNameLoc(TL.getNameLoc());
6178
6179 return Result;
6180}
6181
6182template<typename Derived>
6183QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
6184 ExtVectorTypeLoc TL) {
6185 const VectorType *T = TL.getTypePtr();
6186 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6187 if (ElementType.isNull())
6188 return QualType();
6189
6190 QualType Result = TL.getType();
6191 if (getDerived().AlwaysRebuild() ||
6192 ElementType != T->getElementType()) {
6193 Result = getDerived().RebuildExtVectorType(ElementType,
6194 T->getNumElements(),
6195 /*FIXME*/ SourceLocation());
6196 if (Result.isNull())
6197 return QualType();
6198 }
6199
6200 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6201 NewTL.setNameLoc(TL.getNameLoc());
6202
6203 return Result;
6204}
6205
6206template <typename Derived>
6208 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6209 bool ExpectParameterPack) {
6210 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6211 TypeSourceInfo *NewDI = nullptr;
6212
6213 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6214 // If we're substituting into a pack expansion type and we know the
6215 // length we want to expand to, just substitute for the pattern.
6216 TypeLoc OldTL = OldDI->getTypeLoc();
6217 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6218
6219 TypeLocBuilder TLB;
6220 TypeLoc NewTL = OldDI->getTypeLoc();
6221 TLB.reserve(NewTL.getFullDataSize());
6222
6223 QualType Result = getDerived().TransformType(TLB,
6224 OldExpansionTL.getPatternLoc());
6225 if (Result.isNull())
6226 return nullptr;
6227
6228 Result = RebuildPackExpansionType(Result,
6229 OldExpansionTL.getPatternLoc().getSourceRange(),
6230 OldExpansionTL.getEllipsisLoc(),
6231 NumExpansions);
6232 if (Result.isNull())
6233 return nullptr;
6234
6235 PackExpansionTypeLoc NewExpansionTL
6236 = TLB.push<PackExpansionTypeLoc>(Result);
6237 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6238 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6239 } else
6240 NewDI = getDerived().TransformType(OldDI);
6241 if (!NewDI)
6242 return nullptr;
6243
6244 if (NewDI == OldDI && indexAdjustment == 0)
6245 return OldParm;
6246
6247 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6248 OldParm->getDeclContext(),
6249 OldParm->getInnerLocStart(),
6250 OldParm->getLocation(),
6251 OldParm->getIdentifier(),
6252 NewDI->getType(),
6253 NewDI,
6254 OldParm->getStorageClass(),
6255 /* DefArg */ nullptr);
6256 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6257 OldParm->getFunctionScopeIndex() + indexAdjustment);
6258 transformedLocalDecl(OldParm, {newParm});
6259 return newParm;
6260}
6261
6262template <typename Derived>
6265 const QualType *ParamTypes,
6266 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6267 SmallVectorImpl<QualType> &OutParamTypes,
6270 unsigned *LastParamTransformed) {
6271 int indexAdjustment = 0;
6272
6273 unsigned NumParams = Params.size();
6274 for (unsigned i = 0; i != NumParams; ++i) {
6275 if (LastParamTransformed)
6276 *LastParamTransformed = i;
6277 if (ParmVarDecl *OldParm = Params[i]) {
6278 assert(OldParm->getFunctionScopeIndex() == i);
6279
6280 UnsignedOrNone NumExpansions = std::nullopt;
6281 ParmVarDecl *NewParm = nullptr;
6282 if (OldParm->isParameterPack()) {
6283 // We have a function parameter pack that may need to be expanded.
6285
6286 // Find the parameter packs that could be expanded.
6287 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6289 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6290 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6291
6292 // Determine whether we should expand the parameter packs.
6293 bool ShouldExpand = false;
6294 bool RetainExpansion = false;
6295 UnsignedOrNone OrigNumExpansions = std::nullopt;
6296 if (Unexpanded.size() > 0) {
6297 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6298 NumExpansions = OrigNumExpansions;
6299 if (getDerived().TryExpandParameterPacks(
6300 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6301 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6302 ShouldExpand, RetainExpansion, NumExpansions)) {
6303 return true;
6304 }
6305 } else {
6306#ifndef NDEBUG
6307 const AutoType *AT =
6308 Pattern.getType().getTypePtr()->getContainedAutoType();
6309 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6310 "Could not find parameter packs or undeduced auto type!");
6311#endif
6312 }
6313
6314 if (ShouldExpand) {
6315 // Expand the function parameter pack into multiple, separate
6316 // parameters.
6317 getDerived().ExpandingFunctionParameterPack(OldParm);
6318 for (unsigned I = 0; I != *NumExpansions; ++I) {
6319 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6320 ParmVarDecl *NewParm
6321 = getDerived().TransformFunctionTypeParam(OldParm,
6322 indexAdjustment++,
6323 OrigNumExpansions,
6324 /*ExpectParameterPack=*/false);
6325 if (!NewParm)
6326 return true;
6327
6328 if (ParamInfos)
6329 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6330 OutParamTypes.push_back(NewParm->getType());
6331 if (PVars)
6332 PVars->push_back(NewParm);
6333 }
6334
6335 // If we're supposed to retain a pack expansion, do so by temporarily
6336 // forgetting the partially-substituted parameter pack.
6337 if (RetainExpansion) {
6338 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6339 ParmVarDecl *NewParm
6340 = getDerived().TransformFunctionTypeParam(OldParm,
6341 indexAdjustment++,
6342 OrigNumExpansions,
6343 /*ExpectParameterPack=*/false);
6344 if (!NewParm)
6345 return true;
6346
6347 if (ParamInfos)
6348 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6349 OutParamTypes.push_back(NewParm->getType());
6350 if (PVars)
6351 PVars->push_back(NewParm);
6352 }
6353
6354 // The next parameter should have the same adjustment as the
6355 // last thing we pushed, but we post-incremented indexAdjustment
6356 // on every push. Also, if we push nothing, the adjustment should
6357 // go down by one.
6358 indexAdjustment--;
6359
6360 // We're done with the pack expansion.
6361 continue;
6362 }
6363
6364 // We'll substitute the parameter now without expanding the pack
6365 // expansion.
6366 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6367 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6368 indexAdjustment,
6369 NumExpansions,
6370 /*ExpectParameterPack=*/true);
6371 assert(NewParm->isParameterPack() &&
6372 "Parameter pack no longer a parameter pack after "
6373 "transformation.");
6374 } else {
6375 NewParm = getDerived().TransformFunctionTypeParam(
6376 OldParm, indexAdjustment, std::nullopt,
6377 /*ExpectParameterPack=*/false);
6378 }
6379
6380 if (!NewParm)
6381 return true;
6382
6383 if (ParamInfos)
6384 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6385 OutParamTypes.push_back(NewParm->getType());
6386 if (PVars)
6387 PVars->push_back(NewParm);
6388 continue;
6389 }
6390
6391 // Deal with the possibility that we don't have a parameter
6392 // declaration for this parameter.
6393 assert(ParamTypes);
6394 QualType OldType = ParamTypes[i];
6395 bool IsPackExpansion = false;
6396 UnsignedOrNone NumExpansions = std::nullopt;
6397 QualType NewType;
6398 if (const PackExpansionType *Expansion
6399 = dyn_cast<PackExpansionType>(OldType)) {
6400 // We have a function parameter pack that may need to be expanded.
6401 QualType Pattern = Expansion->getPattern();
6403 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6404
6405 // Determine whether we should expand the parameter packs.
6406 bool ShouldExpand = false;
6407 bool RetainExpansion = false;
6408 if (getDerived().TryExpandParameterPacks(
6409 Loc, SourceRange(), Unexpanded,
6410 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6411 RetainExpansion, NumExpansions)) {
6412 return true;
6413 }
6414
6415 if (ShouldExpand) {
6416 // Expand the function parameter pack into multiple, separate
6417 // parameters.
6418 for (unsigned I = 0; I != *NumExpansions; ++I) {
6419 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6420 QualType NewType = getDerived().TransformType(Pattern);
6421 if (NewType.isNull())
6422 return true;
6423
6424 if (NewType->containsUnexpandedParameterPack()) {
6425 NewType = getSema().getASTContext().getPackExpansionType(
6426 NewType, std::nullopt);
6427
6428 if (NewType.isNull())
6429 return true;
6430 }
6431
6432 if (ParamInfos)
6433 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6434 OutParamTypes.push_back(NewType);
6435 if (PVars)
6436 PVars->push_back(nullptr);
6437 }
6438
6439 // We're done with the pack expansion.
6440 continue;
6441 }
6442
6443 // If we're supposed to retain a pack expansion, do so by temporarily
6444 // forgetting the partially-substituted parameter pack.
6445 if (RetainExpansion) {
6446 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6447 QualType NewType = getDerived().TransformType(Pattern);
6448 if (NewType.isNull())
6449 return true;
6450
6451 if (ParamInfos)
6452 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6453 OutParamTypes.push_back(NewType);
6454 if (PVars)
6455 PVars->push_back(nullptr);
6456 }
6457
6458 // We'll substitute the parameter now without expanding the pack
6459 // expansion.
6460 OldType = Expansion->getPattern();
6461 IsPackExpansion = true;
6462 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6463 NewType = getDerived().TransformType(OldType);
6464 } else {
6465 NewType = getDerived().TransformType(OldType);
6466 }
6467
6468 if (NewType.isNull())
6469 return true;
6470
6471 if (IsPackExpansion)
6472 NewType = getSema().Context.getPackExpansionType(NewType,
6473 NumExpansions);
6474
6475 if (ParamInfos)
6476 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6477 OutParamTypes.push_back(NewType);
6478 if (PVars)
6479 PVars->push_back(nullptr);
6480 }
6481
6482#ifndef NDEBUG
6483 if (PVars) {
6484 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6485 if (ParmVarDecl *parm = (*PVars)[i])
6486 assert(parm->getFunctionScopeIndex() == i);
6487 }
6488#endif
6489
6490 return false;
6491}
6492
6493template<typename Derived>
6497 SmallVector<QualType, 4> ExceptionStorage;
6498 return getDerived().TransformFunctionProtoType(
6499 TLB, TL, nullptr, Qualifiers(),
6500 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6501 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6502 ExceptionStorage, Changed);
6503 });
6504}
6505
6506template<typename Derived> template<typename Fn>
6508 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6509 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6510
6511 // Transform the parameters and return type.
6512 //
6513 // We are required to instantiate the params and return type in source order.
6514 // When the function has a trailing return type, we instantiate the
6515 // parameters before the return type, since the return type can then refer
6516 // to the parameters themselves (via decltype, sizeof, etc.).
6517 //
6518 SmallVector<QualType, 4> ParamTypes;
6520 Sema::ExtParameterInfoBuilder ExtParamInfos;
6521 const FunctionProtoType *T = TL.getTypePtr();
6522
6523 QualType ResultType;
6524
6525 if (T->hasTrailingReturn()) {
6526 if (getDerived().TransformFunctionTypeParams(
6527 TL.getBeginLoc(), TL.getParams(),
6530 ParamTypes, &ParamDecls, ExtParamInfos))
6531 return QualType();
6532
6533 {
6534 // C++11 [expr.prim.general]p3:
6535 // If a declaration declares a member function or member function
6536 // template of a class X, the expression this is a prvalue of type
6537 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6538 // and the end of the function-definition, member-declarator, or
6539 // declarator.
6540 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6541 Sema::CXXThisScopeRAII ThisScope(
6542 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6543
6544 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6545 if (ResultType.isNull())
6546 return QualType();
6547 }
6548 }
6549 else {
6550 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6551 if (ResultType.isNull())
6552 return QualType();
6553
6554 if (getDerived().TransformFunctionTypeParams(
6555 TL.getBeginLoc(), TL.getParams(),
6558 ParamTypes, &ParamDecls, ExtParamInfos))
6559 return QualType();
6560 }
6561
6563
6564 bool EPIChanged = false;
6565 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6566 return QualType();
6567
6568 // Handle extended parameter information.
6569 if (auto NewExtParamInfos =
6570 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6571 if (!EPI.ExtParameterInfos ||
6573 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6574 EPIChanged = true;
6575 }
6576 EPI.ExtParameterInfos = NewExtParamInfos;
6577 } else if (EPI.ExtParameterInfos) {
6578 EPIChanged = true;
6579 EPI.ExtParameterInfos = nullptr;
6580 }
6581
6582 // Transform any function effects with unevaluated conditions.
6583 // Hold this set in a local for the rest of this function, since EPI
6584 // may need to hold a FunctionEffectsRef pointing into it.
6585 std::optional<FunctionEffectSet> NewFX;
6586 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6587 NewFX.emplace();
6590
6591 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6592 FunctionEffectWithCondition NewEC = PrevEC;
6593 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6594 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6595 if (NewExpr.isInvalid())
6596 return QualType();
6597 std::optional<FunctionEffectMode> Mode =
6598 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6599 if (!Mode)
6600 return QualType();
6601
6602 // The condition expression has been transformed, and re-evaluated.
6603 // It may or may not have become constant.
6604 switch (*Mode) {
6606 NewEC.Cond = {};
6607 break;
6609 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6610 NewEC.Cond = {};
6611 break;
6613 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6614 break;
6616 llvm_unreachable(
6617 "FunctionEffectMode::None shouldn't be possible here");
6618 }
6619 }
6620 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6621 TL.getBeginLoc())) {
6623 NewFX->insert(NewEC, Errs);
6624 assert(Errs.empty());
6625 }
6626 }
6627 EPI.FunctionEffects = *NewFX;
6628 EPIChanged = true;
6629 }
6630
6631 QualType Result = TL.getType();
6632 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6633 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6634 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6635 if (Result.isNull())
6636 return QualType();
6637 }
6638
6641 NewTL.setLParenLoc(TL.getLParenLoc());
6642 NewTL.setRParenLoc(TL.getRParenLoc());
6645 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6646 NewTL.setParam(i, ParamDecls[i]);
6647
6648 return Result;
6649}
6650
6651template<typename Derived>
6654 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6655 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6656
6657 // Instantiate a dynamic noexcept expression, if any.
6658 if (isComputedNoexcept(ESI.Type)) {
6659 // Update this scrope because ContextDecl in Sema will be used in
6660 // TransformExpr.
6661 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6662 Sema::CXXThisScopeRAII ThisScope(
6663 SemaRef, Method ? Method->getParent() : nullptr,
6664 Method ? Method->getMethodQualifiers() : Qualifiers{},
6665 Method != nullptr);
6668 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6669 if (NoexceptExpr.isInvalid())
6670 return true;
6671
6673 NoexceptExpr =
6674 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6675 if (NoexceptExpr.isInvalid())
6676 return true;
6677
6678 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6679 Changed = true;
6680 ESI.NoexceptExpr = NoexceptExpr.get();
6681 ESI.Type = EST;
6682 }
6683
6684 if (ESI.Type != EST_Dynamic)
6685 return false;
6686
6687 // Instantiate a dynamic exception specification's type.
6688 for (QualType T : ESI.Exceptions) {
6689 if (const PackExpansionType *PackExpansion =
6691 Changed = true;
6692
6693 // We have a pack expansion. Instantiate it.
6695 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6696 Unexpanded);
6697 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6698
6699 // Determine whether the set of unexpanded parameter packs can and
6700 // should
6701 // be expanded.
6702 bool Expand = false;
6703 bool RetainExpansion = false;
6704 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6705 // FIXME: Track the location of the ellipsis (and track source location
6706 // information for the types in the exception specification in general).
6707 if (getDerived().TryExpandParameterPacks(
6708 Loc, SourceRange(), Unexpanded,
6709 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6710 NumExpansions))
6711 return true;
6712
6713 if (!Expand) {
6714 // We can't expand this pack expansion into separate arguments yet;
6715 // just substitute into the pattern and create a new pack expansion
6716 // type.
6717 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6718 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6719 if (U.isNull())
6720 return true;
6721
6722 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6723 Exceptions.push_back(U);
6724 continue;
6725 }
6726
6727 // Substitute into the pack expansion pattern for each slice of the
6728 // pack.
6729 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6730 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6731
6732 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6733 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6734 return true;
6735
6736 Exceptions.push_back(U);
6737 }
6738 } else {
6739 QualType U = getDerived().TransformType(T);
6740 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6741 return true;
6742 if (T != U)
6743 Changed = true;
6744
6745 Exceptions.push_back(U);
6746 }
6747 }
6748
6749 ESI.Exceptions = Exceptions;
6750 if (ESI.Exceptions.empty())
6751 ESI.Type = EST_DynamicNone;
6752 return false;
6753}
6754
6755template<typename Derived>
6757 TypeLocBuilder &TLB,
6759 const FunctionNoProtoType *T = TL.getTypePtr();
6760 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6761 if (ResultType.isNull())
6762 return QualType();
6763
6764 QualType Result = TL.getType();
6765 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6766 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6767
6770 NewTL.setLParenLoc(TL.getLParenLoc());
6771 NewTL.setRParenLoc(TL.getRParenLoc());
6773
6774 return Result;
6775}
6776
6777template <typename Derived>
6778QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6779 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6780
6781 const UnresolvedUsingType *T = TL.getTypePtr();
6782 bool Changed = false;
6783
6784 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6785 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6786 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6787 if (!QualifierLoc)
6788 return QualType();
6789 Changed |= QualifierLoc != OldQualifierLoc;
6790 }
6791
6792 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6793 if (!D)
6794 return QualType();
6795 Changed |= D != T->getDecl();
6796
6797 QualType Result = TL.getType();
6798 if (getDerived().AlwaysRebuild() || Changed) {
6799 Result = getDerived().RebuildUnresolvedUsingType(
6800 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6801 D);
6802 if (Result.isNull())
6803 return QualType();
6804 }
6805
6806 if (isa<UsingType>(Result))
6807 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6808 QualifierLoc, TL.getNameLoc());
6809 else
6810 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6811 QualifierLoc, TL.getNameLoc());
6812 return Result;
6813}
6814
6815template <typename Derived>
6816QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6817 UsingTypeLoc TL) {
6818 const UsingType *T = TL.getTypePtr();
6819 bool Changed = false;
6820
6821 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6822 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6823 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6824 if (!QualifierLoc)
6825 return QualType();
6826 Changed |= QualifierLoc != OldQualifierLoc;
6827 }
6828
6829 auto *D = cast_or_null<UsingShadowDecl>(
6830 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6831 if (!D)
6832 return QualType();
6833 Changed |= D != T->getDecl();
6834
6835 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6836 if (UnderlyingType.isNull())
6837 return QualType();
6838 Changed |= UnderlyingType != T->desugar();
6839
6840 QualType Result = TL.getType();
6841 if (getDerived().AlwaysRebuild() || Changed) {
6842 Result = getDerived().RebuildUsingType(
6843 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6844 UnderlyingType);
6845 if (Result.isNull())
6846 return QualType();
6847 }
6848 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6849 TL.getNameLoc());
6850 return Result;
6851}
6852
6853template<typename Derived>
6854QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6855 TypedefTypeLoc TL) {
6856 const TypedefType *T = TL.getTypePtr();
6857 bool Changed = false;
6858
6859 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6860 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6861 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6862 if (!QualifierLoc)
6863 return QualType();
6864 Changed |= QualifierLoc != OldQualifierLoc;
6865 }
6866
6867 auto *Typedef = cast_or_null<TypedefNameDecl>(
6868 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6869 if (!Typedef)
6870 return QualType();
6871 Changed |= Typedef != T->getDecl();
6872
6873 // FIXME: Transform the UnderlyingType if different from decl.
6874
6875 QualType Result = TL.getType();
6876 if (getDerived().AlwaysRebuild() || Changed) {
6877 Result = getDerived().RebuildTypedefType(
6878 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6879 if (Result.isNull())
6880 return QualType();
6881 }
6882
6883 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6884 QualifierLoc, TL.getNameLoc());
6885 return Result;
6886}
6887
6888template<typename Derived>
6889QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6890 TypeOfExprTypeLoc TL) {
6891 // typeof expressions are not potentially evaluated contexts
6892 EnterExpressionEvaluationContext Unevaluated(
6895
6896 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6897 if (E.isInvalid())
6898 return QualType();
6899
6900 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6901 if (E.isInvalid())
6902 return QualType();
6903
6904 QualType Result = TL.getType();
6905 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6906 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6907 Result =
6908 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6909 if (Result.isNull())
6910 return QualType();
6911 }
6912
6913 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6914 NewTL.setTypeofLoc(TL.getTypeofLoc());
6915 NewTL.setLParenLoc(TL.getLParenLoc());
6916 NewTL.setRParenLoc(TL.getRParenLoc());
6917
6918 return Result;
6919}
6920
6921template<typename Derived>
6922QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6923 TypeOfTypeLoc TL) {
6924 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6925 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6926 if (!New_Under_TI)
6927 return QualType();
6928
6929 QualType Result = TL.getType();
6930 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6931 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6932 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6933 if (Result.isNull())
6934 return QualType();
6935 }
6936
6937 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6938 NewTL.setTypeofLoc(TL.getTypeofLoc());
6939 NewTL.setLParenLoc(TL.getLParenLoc());
6940 NewTL.setRParenLoc(TL.getRParenLoc());
6941 NewTL.setUnmodifiedTInfo(New_Under_TI);
6942
6943 return Result;
6944}
6945
6946template<typename Derived>
6947QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6948 DecltypeTypeLoc TL) {
6949 const DecltypeType *T = TL.getTypePtr();
6950
6951 // decltype expressions are not potentially evaluated contexts
6952 EnterExpressionEvaluationContext Unevaluated(
6955
6956 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6957 if (E.isInvalid())
6958 return QualType();
6959
6960 E = getSema().ActOnDecltypeExpression(E.get());
6961 if (E.isInvalid())
6962 return QualType();
6963
6964 QualType Result = TL.getType();
6965 if (getDerived().AlwaysRebuild() ||
6966 E.get() != T->getUnderlyingExpr()) {
6967 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6968 if (Result.isNull())
6969 return QualType();
6970 }
6971 else E.get();
6972
6973 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6974 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6975 NewTL.setRParenLoc(TL.getRParenLoc());
6976 return Result;
6977}
6978
6979template <typename Derived>
6980QualType
6981TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6982 PackIndexingTypeLoc TL) {
6983 // Transform the index
6984 ExprResult IndexExpr;
6985 {
6986 EnterExpressionEvaluationContext ConstantContext(
6988
6989 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6990 if (IndexExpr.isInvalid())
6991 return QualType();
6992 }
6993 QualType Pattern = TL.getPattern();
6994
6995 const PackIndexingType *PIT = TL.getTypePtr();
6996 SmallVector<QualType, 5> SubtitutedTypes;
6997 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6998
6999 bool NotYetExpanded = Types.empty();
7000 bool FullySubstituted = true;
7001
7002 if (Types.empty() && !PIT->expandsToEmptyPack())
7003 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7004
7005 for (QualType T : Types) {
7007 QualType Transformed = getDerived().TransformType(T);
7008 if (Transformed.isNull())
7009 return QualType();
7010 SubtitutedTypes.push_back(Transformed);
7011 continue;
7012 }
7013
7015 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7016 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7017 // Determine whether the set of unexpanded parameter packs can and should
7018 // be expanded.
7019 bool ShouldExpand = true;
7020 bool RetainExpansion = false;
7021 UnsignedOrNone NumExpansions = std::nullopt;
7022 if (getDerived().TryExpandParameterPacks(
7023 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7024 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7025 RetainExpansion, NumExpansions))
7026 return QualType();
7027 if (!ShouldExpand) {
7028 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7029 // FIXME: should we keep TypeLoc for individual expansions in
7030 // PackIndexingTypeLoc?
7031 TypeSourceInfo *TI =
7032 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7033 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7034 if (Pack.isNull())
7035 return QualType();
7036 if (NotYetExpanded) {
7037 FullySubstituted = false;
7038 QualType Out = getDerived().RebuildPackIndexingType(
7039 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7040 FullySubstituted);
7041 if (Out.isNull())
7042 return QualType();
7043
7044 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
7045 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7046 return Out;
7047 }
7048 SubtitutedTypes.push_back(Pack);
7049 continue;
7050 }
7051 for (unsigned I = 0; I != *NumExpansions; ++I) {
7052 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7053 QualType Out = getDerived().TransformType(T);
7054 if (Out.isNull())
7055 return QualType();
7056 SubtitutedTypes.push_back(Out);
7057 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7058 }
7059 // If we're supposed to retain a pack expansion, do so by temporarily
7060 // forgetting the partially-substituted parameter pack.
7061 if (RetainExpansion) {
7062 FullySubstituted = false;
7063 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7064 QualType Out = getDerived().TransformType(T);
7065 if (Out.isNull())
7066 return QualType();
7067 SubtitutedTypes.push_back(Out);
7068 }
7069 }
7070
7071 // A pack indexing type can appear in a larger pack expansion,
7072 // e.g. `Pack...[pack_of_indexes]...`
7073 // so we need to temporarily disable substitution of pack elements
7074 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7075 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7076
7077 QualType Out = getDerived().RebuildPackIndexingType(
7078 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7079 FullySubstituted, SubtitutedTypes);
7080 if (Out.isNull())
7081 return Out;
7082
7083 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
7084 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7085 return Out;
7086}
7087
7088template<typename Derived>
7089QualType TreeTransform<Derived>::TransformUnaryTransformType(
7090 TypeLocBuilder &TLB,
7091 UnaryTransformTypeLoc TL) {
7092 QualType Result = TL.getType();
7093 if (Result->isDependentType()) {
7094 const UnaryTransformType *T = TL.getTypePtr();
7095
7096 TypeSourceInfo *NewBaseTSI =
7097 getDerived().TransformType(TL.getUnderlyingTInfo());
7098 if (!NewBaseTSI)
7099 return QualType();
7100 QualType NewBase = NewBaseTSI->getType();
7101
7102 Result = getDerived().RebuildUnaryTransformType(NewBase,
7103 T->getUTTKind(),
7104 TL.getKWLoc());
7105 if (Result.isNull())
7106 return QualType();
7107 }
7108
7109 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
7110 NewTL.setKWLoc(TL.getKWLoc());
7111 NewTL.setParensRange(TL.getParensRange());
7112 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
7113 return Result;
7114}
7115
7116template<typename Derived>
7117QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
7118 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
7119 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7120
7121 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7122 TemplateName TemplateName = getDerived().TransformTemplateName(
7123 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7124 TL.getTemplateNameLoc());
7125 if (TemplateName.isNull())
7126 return QualType();
7127
7128 QualType OldDeduced = T->getDeducedType();
7129 QualType NewDeduced;
7130 if (!OldDeduced.isNull()) {
7131 NewDeduced = getDerived().TransformType(OldDeduced);
7132 if (NewDeduced.isNull())
7133 return QualType();
7134 }
7135
7136 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7137 T->getKeyword(), TemplateName, NewDeduced);
7138 if (Result.isNull())
7139 return QualType();
7140
7141 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7142 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7143 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7144 NewTL.setQualifierLoc(QualifierLoc);
7145 return Result;
7146}
7147
7148template <typename Derived>
7150 TagTypeLoc TL) {
7151 const TagType *T = TL.getTypePtr();
7152
7153 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7154 if (QualifierLoc) {
7155 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7156 if (!QualifierLoc)
7157 return QualType();
7158 }
7159
7160 auto *TD = cast_or_null<TagDecl>(
7161 getDerived().TransformDecl(TL.getNameLoc(), T->getOriginalDecl()));
7162 if (!TD)
7163 return QualType();
7164
7165 QualType Result = TL.getType();
7166 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7167 TD != T->getOriginalDecl()) {
7169 Result = getDerived().RebuildCanonicalTagType(TD);
7170 else
7171 Result = getDerived().RebuildTagType(
7172 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7173 if (Result.isNull())
7174 return QualType();
7175 }
7176
7177 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7179 NewTL.setQualifierLoc(QualifierLoc);
7180 NewTL.setNameLoc(TL.getNameLoc());
7181
7182 return Result;
7183}
7184
7185template <typename Derived>
7187 EnumTypeLoc TL) {
7188 return getDerived().TransformTagType(TLB, TL);
7189}
7190
7191template <typename Derived>
7192QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7193 RecordTypeLoc TL) {
7194 return getDerived().TransformTagType(TLB, TL);
7195}
7196
7197template<typename Derived>
7198QualType TreeTransform<Derived>::TransformInjectedClassNameType(
7199 TypeLocBuilder &TLB,
7200 InjectedClassNameTypeLoc TL) {
7201 return getDerived().TransformTagType(TLB, TL);
7202}
7203
7204template<typename Derived>
7206 TypeLocBuilder &TLB,
7208 return getDerived().TransformTemplateTypeParmType(
7209 TLB, TL,
7210 /*SuppressObjCLifetime=*/false);
7211}
7212
7213template <typename Derived>
7215 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7216 return TransformTypeSpecType(TLB, TL);
7217}
7218
7219template<typename Derived>
7220QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7221 TypeLocBuilder &TLB,
7222 SubstTemplateTypeParmTypeLoc TL) {
7223 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7224
7225 Decl *NewReplaced =
7226 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7227
7228 // Substitute into the replacement type, which itself might involve something
7229 // that needs to be transformed. This only tends to occur with default
7230 // template arguments of template template parameters.
7231 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7232 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7233 if (Replacement.isNull())
7234 return QualType();
7235
7236 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7237 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7238 T->getFinal());
7239
7240 // Propagate type-source information.
7241 SubstTemplateTypeParmTypeLoc NewTL
7242 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7243 NewTL.setNameLoc(TL.getNameLoc());
7244 return Result;
7245
7246}
7247template <typename Derived>
7248QualType TreeTransform<Derived>::TransformSubstBuiltinTemplatePackType(
7249 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
7250 return TransformTypeSpecType(TLB, TL);
7251}
7252
7253template<typename Derived>
7255 TypeLocBuilder &TLB,
7257 return getDerived().TransformSubstTemplateTypeParmPackType(
7258 TLB, TL, /*SuppressObjCLifetime=*/false);
7259}
7260
7261template <typename Derived>
7264 return TransformTypeSpecType(TLB, TL);
7265}
7266
7267template<typename Derived>
7268QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7269 AtomicTypeLoc TL) {
7270 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7271 if (ValueType.isNull())
7272 return QualType();
7273
7274 QualType Result = TL.getType();
7275 if (getDerived().AlwaysRebuild() ||
7276 ValueType != TL.getValueLoc().getType()) {
7277 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7278 if (Result.isNull())
7279 return QualType();
7280 }
7281
7282 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7283 NewTL.setKWLoc(TL.getKWLoc());
7284 NewTL.setLParenLoc(TL.getLParenLoc());
7285 NewTL.setRParenLoc(TL.getRParenLoc());
7286
7287 return Result;
7288}
7289
7290template <typename Derived>
7291QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
7292 PipeTypeLoc TL) {
7293 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7294 if (ValueType.isNull())
7295 return QualType();
7296
7297 QualType Result = TL.getType();
7298 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7299 const PipeType *PT = Result->castAs<PipeType>();
7300 bool isReadPipe = PT->isReadOnly();
7301 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7302 if (Result.isNull())
7303 return QualType();
7304 }
7305
7306 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7307 NewTL.setKWLoc(TL.getKWLoc());
7308
7309 return Result;
7310}
7311
7312template <typename Derived>
7313QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
7314 BitIntTypeLoc TL) {
7315 const BitIntType *EIT = TL.getTypePtr();
7316 QualType Result = TL.getType();
7317
7318 if (getDerived().AlwaysRebuild()) {
7319 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7320 EIT->getNumBits(), TL.getNameLoc());
7321 if (Result.isNull())
7322 return QualType();
7323 }
7324
7325 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7326 NewTL.setNameLoc(TL.getNameLoc());
7327 return Result;
7328}
7329
7330template <typename Derived>
7331QualType TreeTransform<Derived>::TransformDependentBitIntType(
7332 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
7333 const DependentBitIntType *EIT = TL.getTypePtr();
7334
7335 EnterExpressionEvaluationContext Unevaluated(
7337 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7338 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7339
7340 if (BitsExpr.isInvalid())
7341 return QualType();
7342
7343 QualType Result = TL.getType();
7344
7345 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7346 Result = getDerived().RebuildDependentBitIntType(
7347 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7348
7349 if (Result.isNull())
7350 return QualType();
7351 }
7352
7353 if (isa<DependentBitIntType>(Result)) {
7354 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7355 NewTL.setNameLoc(TL.getNameLoc());
7356 } else {
7357 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7358 NewTL.setNameLoc(TL.getNameLoc());
7359 }
7360 return Result;
7361}
7362
7363template <typename Derived>
7364QualType TreeTransform<Derived>::TransformPredefinedSugarType(
7365 TypeLocBuilder &TLB, PredefinedSugarTypeLoc TL) {
7366 llvm_unreachable("This type does not need to be transformed.");
7367}
7368
7369 /// Simple iterator that traverses the template arguments in a
7370 /// container that provides a \c getArgLoc() member function.
7371 ///
7372 /// This iterator is intended to be used with the iterator form of
7373 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7374 template<typename ArgLocContainer>
7376 ArgLocContainer *Container;
7377 unsigned Index;
7378
7379 public:
7382 typedef int difference_type;
7383 typedef std::input_iterator_tag iterator_category;
7384
7385 class pointer {
7387
7388 public:
7389 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7390
7392 return &Arg;
7393 }
7394 };
7395
7396
7398
7399 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7400 unsigned Index)
7401 : Container(&Container), Index(Index) { }
7402
7404 ++Index;
7405 return *this;
7406 }
7407
7410 ++(*this);
7411 return Old;
7412 }
7413
7415 return Container->getArgLoc(Index);
7416 }
7417
7419 return pointer(Container->getArgLoc(Index));
7420 }
7421
7424 return X.Container == Y.Container && X.Index == Y.Index;
7425 }
7426
7429 return !(X == Y);
7430 }
7431 };
7432
7433template<typename Derived>
7434QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7435 AutoTypeLoc TL) {
7436 const AutoType *T = TL.getTypePtr();
7437 QualType OldDeduced = T->getDeducedType();
7438 QualType NewDeduced;
7439 if (!OldDeduced.isNull()) {
7440 NewDeduced = getDerived().TransformType(OldDeduced);
7441 if (NewDeduced.isNull())
7442 return QualType();
7443 }
7444
7445 ConceptDecl *NewCD = nullptr;
7446 TemplateArgumentListInfo NewTemplateArgs;
7447 NestedNameSpecifierLoc NewNestedNameSpec;
7448 if (T->isConstrained()) {
7449 assert(TL.getConceptReference());
7450 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7451 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7452
7453 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7454 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7455 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7456 if (getDerived().TransformTemplateArguments(
7457 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7458 NewTemplateArgs))
7459 return QualType();
7460
7461 if (TL.getNestedNameSpecifierLoc()) {
7462 NewNestedNameSpec
7463 = getDerived().TransformNestedNameSpecifierLoc(
7464 TL.getNestedNameSpecifierLoc());
7465 if (!NewNestedNameSpec)
7466 return QualType();
7467 }
7468 }
7469
7470 QualType Result = TL.getType();
7471 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7472 T->isDependentType() || T->isConstrained()) {
7473 // FIXME: Maybe don't rebuild if all template arguments are the same.
7475 NewArgList.reserve(NewTemplateArgs.size());
7476 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7477 NewArgList.push_back(ArgLoc.getArgument());
7478 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7479 NewArgList);
7480 if (Result.isNull())
7481 return QualType();
7482 }
7483
7484 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7485 NewTL.setNameLoc(TL.getNameLoc());
7486 NewTL.setRParenLoc(TL.getRParenLoc());
7487 NewTL.setConceptReference(nullptr);
7488
7489 if (T->isConstrained()) {
7490 DeclarationNameInfo DNI = DeclarationNameInfo(
7491 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7492 TL.getConceptNameLoc(),
7493 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7494 auto *CR = ConceptReference::Create(
7495 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7496 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7497 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7498 NewTL.setConceptReference(CR);
7499 }
7500
7501 return Result;
7502}
7503
7504template <typename Derived>
7505QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
7506 TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL) {
7507 const TemplateSpecializationType *T = TL.getTypePtr();
7508
7509 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7510 TemplateName Template = getDerived().TransformTemplateName(
7511 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7512 TL.getTemplateNameLoc());
7513 if (Template.isNull())
7514 return QualType();
7515
7516 TemplateArgumentListInfo NewTemplateArgs;
7517 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7518 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7519 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7520 ArgIterator;
7521 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7522 ArgIterator(TL, TL.getNumArgs()),
7523 NewTemplateArgs))
7524 return QualType();
7525
7526 // This needs to be rebuilt if either the arguments changed, or if the
7527 // original template changed. If the template changed, and even if the
7528 // arguments didn't change, these arguments might not correspond to their
7529 // respective parameters, therefore needing conversions.
7530 QualType Result = getDerived().RebuildTemplateSpecializationType(
7531 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7532 NewTemplateArgs);
7533
7534 if (!Result.isNull()) {
7535 // Specializations of template template parameters are represented as
7536 // TemplateSpecializationTypes, and substitution of type alias templates
7537 // within a dependent context can transform them into
7538 // DependentTemplateSpecializationTypes.
7539 if (isa<DependentTemplateSpecializationType>(Result)) {
7540 DependentTemplateSpecializationTypeLoc NewTL
7541 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7542 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7543 NewTL.setQualifierLoc(QualifierLoc);
7544 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7545 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7546 NewTL.setLAngleLoc(TL.getLAngleLoc());
7547 NewTL.setRAngleLoc(TL.getRAngleLoc());
7548 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7549 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7550 return Result;
7551 }
7552 TLB.push<TemplateSpecializationTypeLoc>(Result).set(
7553 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7554 TL.getTemplateNameLoc(), NewTemplateArgs);
7555 }
7556
7557 return Result;
7558}
7559
7560template <typename Derived>
7561QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB,
7562 AttributedTypeLoc TL) {
7563 const AttributedType *oldType = TL.getTypePtr();
7564 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7565 if (modifiedType.isNull())
7566 return QualType();
7567
7568 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7569 const Attr *oldAttr = TL.getAttr();
7570 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7571 if (oldAttr && !newAttr)
7572 return QualType();
7573
7574 QualType result = TL.getType();
7575
7576 // FIXME: dependent operand expressions?
7577 if (getDerived().AlwaysRebuild() ||
7578 modifiedType != oldType->getModifiedType()) {
7579 // If the equivalent type is equal to the modified type, we don't want to
7580 // transform it as well because:
7581 //
7582 // 1. The transformation would yield the same result and is therefore
7583 // superfluous, and
7584 //
7585 // 2. Transforming the same type twice can cause problems, e.g. if it
7586 // is a FunctionProtoType, we may end up instantiating the function
7587 // parameters twice, which causes an assertion since the parameters
7588 // are already bound to their counterparts in the template for this
7589 // instantiation.
7590 //
7591 QualType equivalentType = modifiedType;
7592 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7593 TypeLocBuilder AuxiliaryTLB;
7594 AuxiliaryTLB.reserve(TL.getFullDataSize());
7595 equivalentType =
7596 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7597 if (equivalentType.isNull())
7598 return QualType();
7599 }
7600
7601 // Check whether we can add nullability; it is only represented as
7602 // type sugar, and therefore cannot be diagnosed in any other way.
7603 if (auto nullability = oldType->getImmediateNullability()) {
7604 if (!modifiedType->canHaveNullability()) {
7605 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7606 : TL.getModifiedLoc().getBeginLoc()),
7607 diag::err_nullability_nonpointer)
7608 << DiagNullabilityKind(*nullability, false) << modifiedType;
7609 return QualType();
7610 }
7611 }
7612
7613 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7614 modifiedType,
7615 equivalentType,
7616 TL.getAttr());
7617 }
7618
7619 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7620 newTL.setAttr(newAttr);
7621 return result;
7622}
7623
7624template <typename Derived>
7625QualType TreeTransform<Derived>::TransformCountAttributedType(
7626 TypeLocBuilder &TLB, CountAttributedTypeLoc TL) {
7627 const CountAttributedType *OldTy = TL.getTypePtr();
7628 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7629 if (InnerTy.isNull())
7630 return QualType();
7631
7632 Expr *OldCount = TL.getCountExpr();
7633 Expr *NewCount = nullptr;
7634 if (OldCount) {
7635 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7636 if (CountResult.isInvalid())
7637 return QualType();
7638 NewCount = CountResult.get();
7639 }
7640
7641 QualType Result = TL.getType();
7642 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7643 OldCount != NewCount) {
7644 // Currently, CountAttributedType can only wrap incomplete array types.
7646 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7647 }
7648
7649 TLB.push<CountAttributedTypeLoc>(Result);
7650 return Result;
7651}
7652
7653template <typename Derived>
7654QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7655 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7656 // The BTFTagAttributedType is available for C only.
7657 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7658}
7659
7660template <typename Derived>
7661QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
7662 TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
7663
7664 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7665
7666 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7667 if (WrappedTy.isNull())
7668 return QualType();
7669
7670 QualType ContainedTy = QualType();
7671 QualType OldContainedTy = oldType->getContainedType();
7672 if (!OldContainedTy.isNull()) {
7673 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7674 if (!oldContainedTSI)
7675 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7676 OldContainedTy, SourceLocation());
7677 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7678 if (!ContainedTSI)
7679 return QualType();
7680 ContainedTy = ContainedTSI->getType();
7681 }
7682
7683 QualType Result = TL.getType();
7684 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7685 ContainedTy != oldType->getContainedType()) {
7687 WrappedTy, ContainedTy, oldType->getAttrs());
7688 }
7689
7690 TLB.push<HLSLAttributedResourceTypeLoc>(Result);
7691 return Result;
7692}
7693
7694template <typename Derived>
7695QualType TreeTransform<Derived>::TransformHLSLInlineSpirvType(
7696 TypeLocBuilder &TLB, HLSLInlineSpirvTypeLoc TL) {
7697 // No transformations needed.
7698 return TL.getType();
7699}
7700
7701template<typename Derived>
7702QualType
7703TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7704 ParenTypeLoc TL) {
7705 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7706 if (Inner.isNull())
7707 return QualType();
7708
7709 QualType Result = TL.getType();
7710 if (getDerived().AlwaysRebuild() ||
7711 Inner != TL.getInnerLoc().getType()) {
7712 Result = getDerived().RebuildParenType(Inner);
7713 if (Result.isNull())
7714 return QualType();
7715 }
7716
7717 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7718 NewTL.setLParenLoc(TL.getLParenLoc());
7719 NewTL.setRParenLoc(TL.getRParenLoc());
7720 return Result;
7721}
7722
7723template <typename Derived>
7724QualType
7725TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7726 MacroQualifiedTypeLoc TL) {
7727 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7728 if (Inner.isNull())
7729 return QualType();
7730
7731 QualType Result = TL.getType();
7732 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7733 Result =
7734 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7735 if (Result.isNull())
7736 return QualType();
7737 }
7738
7739 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7740 NewTL.setExpansionLoc(TL.getExpansionLoc());
7741 return Result;
7742}
7743
7744template<typename Derived>
7745QualType TreeTransform<Derived>::TransformDependentNameType(
7746 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7747 return TransformDependentNameType(TLB, TL, false);
7748}
7749
7750template <typename Derived>
7751QualType TreeTransform<Derived>::TransformDependentNameType(
7752 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7753 QualType ObjectType, NamedDecl *UnqualLookup) {
7754 const DependentNameType *T = TL.getTypePtr();
7755
7756 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7757 if (QualifierLoc) {
7758 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7759 QualifierLoc, ObjectType, UnqualLookup);
7760 if (!QualifierLoc)
7761 return QualType();
7762 } else {
7763 assert((ObjectType.isNull() && !UnqualLookup) &&
7764 "must be transformed by TransformNestedNameSpecifierLoc");
7765 }
7766
7767 QualType Result
7768 = getDerived().RebuildDependentNameType(T->getKeyword(),
7769 TL.getElaboratedKeywordLoc(),
7770 QualifierLoc,
7771 T->getIdentifier(),
7772 TL.getNameLoc(),
7773 DeducedTSTContext);
7774 if (Result.isNull())
7775 return QualType();
7776
7777 if (isa<TagType>(Result)) {
7778 auto NewTL = TLB.push<TagTypeLoc>(Result);
7779 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7780 NewTL.setQualifierLoc(QualifierLoc);
7781 NewTL.setNameLoc(TL.getNameLoc());
7782 } else if (isa<DeducedTemplateSpecializationType>(Result)) {
7783 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7784 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7785 NewTL.setTemplateNameLoc(TL.getNameLoc());
7786 NewTL.setQualifierLoc(QualifierLoc);
7787 } else if (isa<TypedefType>(Result)) {
7788 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7789 QualifierLoc, TL.getNameLoc());
7790 } else if (isa<UnresolvedUsingType>(Result)) {
7791 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7792 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7793 } else {
7794 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7795 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7796 NewTL.setQualifierLoc(QualifierLoc);
7797 NewTL.setNameLoc(TL.getNameLoc());
7798 }
7799 return Result;
7800}
7801
7802template <typename Derived>
7805 return getDerived().TransformDependentTemplateSpecializationType(
7806 TLB, TL, QualType(), nullptr, false);
7807}
7808
7809template <typename Derived>
7812 QualType ObjectType, NamedDecl *UnqualLookup, bool AllowInjectedClassName) {
7814
7815 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7816 if (QualifierLoc) {
7817 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7818 QualifierLoc, ObjectType, UnqualLookup);
7819 if (!QualifierLoc)
7820 return QualType();
7821 // These only apply to the leftmost prefix.
7822 ObjectType = QualType();
7823 UnqualLookup = nullptr;
7824 }
7825 CXXScopeSpec SS;
7826 SS.Adopt(QualifierLoc);
7827
7828 TemplateArgumentListInfo NewTemplateArgs(TL.getLAngleLoc(),
7829 TL.getRAngleLoc());
7830 auto ArgsRange = llvm::make_range<TemplateArgumentLocContainerIterator<
7831 DependentTemplateSpecializationTypeLoc>>({TL, 0}, {TL, TL.getNumArgs()});
7832
7833 if (getDerived().TransformTemplateArguments(ArgsRange.begin(),
7834 ArgsRange.end(), NewTemplateArgs))
7835 return QualType();
7836 bool TemplateArgumentsChanged = !llvm::equal(
7837 ArgsRange, NewTemplateArgs.arguments(),
7838 [](const TemplateArgumentLoc &A, const TemplateArgumentLoc &B) {
7839 return A.getArgument().structurallyEquals(B.getArgument());
7840 });
7841
7842 const DependentTemplateStorage &DTN = T->getDependentTemplateName();
7843
7844 QualType Result = TL.getType();
7845 if (getDerived().AlwaysRebuild() || SS.getScopeRep() != DTN.getQualifier() ||
7846 TemplateArgumentsChanged || !ObjectType.isNull()) {
7847 TemplateName Name = getDerived().RebuildTemplateName(
7848 SS, TL.getTemplateKeywordLoc(), DTN.getName(), TL.getTemplateNameLoc(),
7849 ObjectType, AllowInjectedClassName);
7850 if (Name.isNull())
7851 return QualType();
7852 Result = getDerived().RebuildDependentTemplateSpecializationType(
7853 T->getKeyword(), TL.getTemplateKeywordLoc(), Name,
7854 TL.getTemplateNameLoc(), NewTemplateArgs,
7855 /*AllowInjectedClassName=*/false);
7856 if (Result.isNull())
7857 return QualType();
7858 }
7859
7860 QualifierLoc = SS.getWithLocInContext(SemaRef.Context);
7861 if (isa<TemplateSpecializationType>(Result)) {
7862 TLB.push<TemplateSpecializationTypeLoc>(Result).set(
7863 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7864 TL.getTemplateNameLoc(), NewTemplateArgs);
7865 } else {
7866 auto SpecTL = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7867 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7868 SpecTL.setQualifierLoc(QualifierLoc);
7869 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7870 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7871 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7872 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7873 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7874 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7875 }
7876 return Result;
7877}
7878
7879template<typename Derived>
7880QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
7881 PackExpansionTypeLoc TL) {
7882 QualType Pattern
7883 = getDerived().TransformType(TLB, TL.getPatternLoc());
7884 if (Pattern.isNull())
7885 return QualType();
7886
7887 QualType Result = TL.getType();
7888 if (getDerived().AlwaysRebuild() ||
7889 Pattern != TL.getPatternLoc().getType()) {
7890 Result = getDerived().RebuildPackExpansionType(Pattern,
7891 TL.getPatternLoc().getSourceRange(),
7892 TL.getEllipsisLoc(),
7893 TL.getTypePtr()->getNumExpansions());
7894 if (Result.isNull())
7895 return QualType();
7896 }
7897
7898 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7899 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7900 return Result;
7901}
7902
7903template<typename Derived>
7904QualType
7905TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7906 ObjCInterfaceTypeLoc TL) {
7907 // ObjCInterfaceType is never dependent.
7908 TLB.pushFullCopy(TL);
7909 return TL.getType();
7910}
7911
7912template<typename Derived>
7913QualType
7914TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7915 ObjCTypeParamTypeLoc TL) {
7916 const ObjCTypeParamType *T = TL.getTypePtr();
7917 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7918 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7919 if (!OTP)
7920 return QualType();
7921
7922 QualType Result = TL.getType();
7923 if (getDerived().AlwaysRebuild() ||
7924 OTP != T->getDecl()) {
7925 Result = getDerived().RebuildObjCTypeParamType(
7926 OTP, TL.getProtocolLAngleLoc(),
7927 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7928 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7929 if (Result.isNull())
7930 return QualType();
7931 }
7932
7933 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7934 if (TL.getNumProtocols()) {
7935 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7936 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7937 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7938 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7939 }
7940 return Result;
7941}
7942
7943template<typename Derived>
7944QualType
7945TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7946 ObjCObjectTypeLoc TL) {
7947 // Transform base type.
7948 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7949 if (BaseType.isNull())
7950 return QualType();
7951
7952 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7953
7954 // Transform type arguments.
7955 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7956 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7957 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7958 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7959 QualType TypeArg = TypeArgInfo->getType();
7960 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7961 AnyChanged = true;
7962
7963 // We have a pack expansion. Instantiate it.
7964 const auto *PackExpansion = PackExpansionLoc.getType()
7965 ->castAs<PackExpansionType>();
7967 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7968 Unexpanded);
7969 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7970
7971 // Determine whether the set of unexpanded parameter packs can
7972 // and should be expanded.
7973 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7974 bool Expand = false;
7975 bool RetainExpansion = false;
7976 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
7977 if (getDerived().TryExpandParameterPacks(
7978 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7979 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
7980 RetainExpansion, NumExpansions))
7981 return QualType();
7982
7983 if (!Expand) {
7984 // We can't expand this pack expansion into separate arguments yet;
7985 // just substitute into the pattern and create a new pack expansion
7986 // type.
7987 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7988
7989 TypeLocBuilder TypeArgBuilder;
7990 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7991 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7992 PatternLoc);
7993 if (NewPatternType.isNull())
7994 return QualType();
7995
7996 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7997 NewPatternType, NumExpansions);
7998 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7999 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
8000 NewTypeArgInfos.push_back(
8001 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
8002 continue;
8003 }
8004
8005 // Substitute into the pack expansion pattern for each slice of the
8006 // pack.
8007 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
8008 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
8009
8010 TypeLocBuilder TypeArgBuilder;
8011 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8012
8013 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
8014 PatternLoc);
8015 if (NewTypeArg.isNull())
8016 return QualType();
8017
8018 NewTypeArgInfos.push_back(
8019 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8020 }
8021
8022 continue;
8023 }
8024
8025 TypeLocBuilder TypeArgBuilder;
8026 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
8027 QualType NewTypeArg =
8028 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
8029 if (NewTypeArg.isNull())
8030 return QualType();
8031
8032 // If nothing changed, just keep the old TypeSourceInfo.
8033 if (NewTypeArg == TypeArg) {
8034 NewTypeArgInfos.push_back(TypeArgInfo);
8035 continue;
8036 }
8037
8038 NewTypeArgInfos.push_back(
8039 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8040 AnyChanged = true;
8041 }
8042
8043 QualType Result = TL.getType();
8044 if (getDerived().AlwaysRebuild() || AnyChanged) {
8045 // Rebuild the type.
8046 Result = getDerived().RebuildObjCObjectType(
8047 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8048 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8049 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8050 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8051
8052 if (Result.isNull())
8053 return QualType();
8054 }
8055
8056 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8057 NewT.setHasBaseTypeAsWritten(true);
8058 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8059 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8060 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8061 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8062 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8063 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8064 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8065 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8066 return Result;
8067}
8068
8069template<typename Derived>
8070QualType
8071TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
8072 ObjCObjectPointerTypeLoc TL) {
8073 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8074 if (PointeeType.isNull())
8075 return QualType();
8076
8077 QualType Result = TL.getType();
8078 if (getDerived().AlwaysRebuild() ||
8079 PointeeType != TL.getPointeeLoc().getType()) {
8080 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8081 TL.getStarLoc());
8082 if (Result.isNull())
8083 return QualType();
8084 }
8085
8086 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
8087 NewT.setStarLoc(TL.getStarLoc());
8088 return Result;
8089}
8090
8091//===----------------------------------------------------------------------===//
8092// Statement transformation
8093//===----------------------------------------------------------------------===//
8094template<typename Derived>
8096TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
8097 return S;
8098}
8099
8100template<typename Derived>
8103 return getDerived().TransformCompoundStmt(S, false);
8104}
8105
8106template<typename Derived>
8109 bool IsStmtExpr) {
8110 Sema::CompoundScopeRAII CompoundScope(getSema());
8111 Sema::FPFeaturesStateRAII FPSave(getSema());
8112 if (S->hasStoredFPFeatures())
8113 getSema().resetFPOptions(
8114 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8115
8116 const Stmt *ExprResult = S->getStmtExprResult();
8117 bool SubStmtInvalid = false;
8118 bool SubStmtChanged = false;
8119 SmallVector<Stmt*, 8> Statements;
8120 for (auto *B : S->body()) {
8121 StmtResult Result = getDerived().TransformStmt(
8122 B, IsStmtExpr && B == ExprResult ? StmtDiscardKind::StmtExprResult
8123 : StmtDiscardKind::Discarded);
8124
8125 if (Result.isInvalid()) {
8126 // Immediately fail if this was a DeclStmt, since it's very
8127 // likely that this will cause problems for future statements.
8128 if (isa<DeclStmt>(B))
8129 return StmtError();
8130
8131 // Otherwise, just keep processing substatements and fail later.
8132 SubStmtInvalid = true;
8133 continue;
8134 }
8135
8136 SubStmtChanged = SubStmtChanged || Result.get() != B;
8137 Statements.push_back(Result.getAs<Stmt>());
8138 }
8139
8140 if (SubStmtInvalid)
8141 return StmtError();
8142
8143 if (!getDerived().AlwaysRebuild() &&
8144 !SubStmtChanged)
8145 return S;
8146
8147 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8148 Statements,
8149 S->getRBracLoc(),
8150 IsStmtExpr);
8151}
8152
8153template<typename Derived>
8155TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
8156 ExprResult LHS, RHS;
8157 {
8158 EnterExpressionEvaluationContext Unevaluated(
8160
8161 // Transform the left-hand case value.
8162 LHS = getDerived().TransformExpr(S->getLHS());
8163 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8164 if (LHS.isInvalid())
8165 return StmtError();
8166
8167 // Transform the right-hand case value (for the GNU case-range extension).
8168 RHS = getDerived().TransformExpr(S->getRHS());
8169 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8170 if (RHS.isInvalid())
8171 return StmtError();
8172 }
8173
8174 // Build the case statement.
8175 // Case statements are always rebuilt so that they will attached to their
8176 // transformed switch statement.
8177 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8178 LHS.get(),
8179 S->getEllipsisLoc(),
8180 RHS.get(),
8181 S->getColonLoc());
8182 if (Case.isInvalid())
8183 return StmtError();
8184
8185 // Transform the statement following the case
8186 StmtResult SubStmt =
8187 getDerived().TransformStmt(S->getSubStmt());
8188 if (SubStmt.isInvalid())
8189 return StmtError();
8190
8191 // Attach the body to the case statement
8192 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8193}
8194
8195template <typename Derived>
8196StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
8197 // Transform the statement following the default case
8198 StmtResult SubStmt =
8199 getDerived().TransformStmt(S->getSubStmt());
8200 if (SubStmt.isInvalid())
8201 return StmtError();
8202
8203 // Default statements are always rebuilt
8204 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8205 SubStmt.get());
8206}
8207
8208template<typename Derived>
8210TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
8211 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8212 if (SubStmt.isInvalid())
8213 return StmtError();
8214
8215 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8216 S->getDecl());
8217 if (!LD)
8218 return StmtError();
8219
8220 // If we're transforming "in-place" (we're not creating new local
8221 // declarations), assume we're replacing the old label statement
8222 // and clear out the reference to it.
8223 if (LD == S->getDecl())
8224 S->getDecl()->setStmt(nullptr);
8225
8226 // FIXME: Pass the real colon location in.
8227 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8228 cast<LabelDecl>(LD), SourceLocation(),
8229 SubStmt.get());
8230}
8231
8232template <typename Derived>
8234 if (!R)
8235 return R;
8236
8237 switch (R->getKind()) {
8238// Transform attributes by calling TransformXXXAttr.
8239#define ATTR(X) \
8240 case attr::X: \
8241 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8242#include "clang/Basic/AttrList.inc"
8243 }
8244 return R;
8245}
8246
8247template <typename Derived>
8249 const Stmt *InstS,
8250 const Attr *R) {
8251 if (!R)
8252 return R;
8253
8254 switch (R->getKind()) {
8255// Transform attributes by calling TransformStmtXXXAttr.
8256#define ATTR(X) \
8257 case attr::X: \
8258 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8259#include "clang/Basic/AttrList.inc"
8260 }
8261 return TransformAttr(R);
8262}
8263
8264template <typename Derived>
8267 StmtDiscardKind SDK) {
8268 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8269 if (SubStmt.isInvalid())
8270 return StmtError();
8271
8272 bool AttrsChanged = false;
8274
8275 // Visit attributes and keep track if any are transformed.
8276 for (const auto *I : S->getAttrs()) {
8277 const Attr *R =
8278 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8279 AttrsChanged |= (I != R);
8280 if (R)
8281 Attrs.push_back(R);
8282 }
8283
8284 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8285 return S;
8286
8287 // If transforming the attributes failed for all of the attributes in the
8288 // statement, don't make an AttributedStmt without attributes.
8289 if (Attrs.empty())
8290 return SubStmt;
8291
8292 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8293 SubStmt.get());
8294}
8295
8296template<typename Derived>
8298TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8299 // Transform the initialization statement
8300 StmtResult Init = getDerived().TransformStmt(S->getInit());
8301 if (Init.isInvalid())
8302 return StmtError();
8303
8304 Sema::ConditionResult Cond;
8305 if (!S->isConsteval()) {
8306 // Transform the condition
8307 Cond = getDerived().TransformCondition(
8308 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8309 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8311 if (Cond.isInvalid())
8312 return StmtError();
8313 }
8314
8315 // If this is a constexpr if, determine which arm we should instantiate.
8316 std::optional<bool> ConstexprConditionValue;
8317 if (S->isConstexpr())
8318 ConstexprConditionValue = Cond.getKnownValue();
8319
8320 // Transform the "then" branch.
8321 StmtResult Then;
8322 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8323 EnterExpressionEvaluationContext Ctx(
8326 S->isNonNegatedConsteval());
8327
8328 Then = getDerived().TransformStmt(S->getThen());
8329 if (Then.isInvalid())
8330 return StmtError();
8331 } else {
8332 // Discarded branch is replaced with empty CompoundStmt so we can keep
8333 // proper source location for start and end of original branch, so
8334 // subsequent transformations like CoverageMapping work properly
8335 Then = new (getSema().Context)
8336 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8337 }
8338
8339 // Transform the "else" branch.
8340 StmtResult Else;
8341 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8342 EnterExpressionEvaluationContext Ctx(
8345 S->isNegatedConsteval());
8346
8347 Else = getDerived().TransformStmt(S->getElse());
8348 if (Else.isInvalid())
8349 return StmtError();
8350 } else if (S->getElse() && ConstexprConditionValue &&
8351 *ConstexprConditionValue) {
8352 // Same thing here as with <then> branch, we are discarding it, we can't
8353 // replace it with NULL nor NullStmt as we need to keep for source location
8354 // range, for CoverageMapping
8355 Else = new (getSema().Context)
8356 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8357 }
8358
8359 if (!getDerived().AlwaysRebuild() &&
8360 Init.get() == S->getInit() &&
8361 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8362 Then.get() == S->getThen() &&
8363 Else.get() == S->getElse())
8364 return S;
8365
8366 return getDerived().RebuildIfStmt(
8367 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8368 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8369}
8370
8371template<typename Derived>
8373TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8374 // Transform the initialization statement
8375 StmtResult Init = getDerived().TransformStmt(S->getInit());
8376 if (Init.isInvalid())
8377 return StmtError();
8378
8379 // Transform the condition.
8380 Sema::ConditionResult Cond = getDerived().TransformCondition(
8381 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8383 if (Cond.isInvalid())
8384 return StmtError();
8385
8386 // Rebuild the switch statement.
8388 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8389 Init.get(), Cond, S->getRParenLoc());
8390 if (Switch.isInvalid())
8391 return StmtError();
8392
8393 // Transform the body of the switch statement.
8394 StmtResult Body = getDerived().TransformStmt(S->getBody());
8395 if (Body.isInvalid())
8396 return StmtError();
8397
8398 // Complete the switch statement.
8399 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8400 Body.get());
8401}
8402
8403template<typename Derived>
8405TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8406 // Transform the condition
8407 Sema::ConditionResult Cond = getDerived().TransformCondition(
8408 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8410 if (Cond.isInvalid())
8411 return StmtError();
8412
8413 // OpenACC Restricts a while-loop inside of certain construct/clause
8414 // combinations, so diagnose that here in OpenACC mode.
8415 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8416 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8417
8418 // Transform the body
8419 StmtResult Body = getDerived().TransformStmt(S->getBody());
8420 if (Body.isInvalid())
8421 return StmtError();
8422
8423 if (!getDerived().AlwaysRebuild() &&
8424 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8425 Body.get() == S->getBody())
8426 return Owned(S);
8427
8428 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8429 Cond, S->getRParenLoc(), Body.get());
8430}
8431
8432template<typename Derived>
8434TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8435 // OpenACC Restricts a do-loop inside of certain construct/clause
8436 // combinations, so diagnose that here in OpenACC mode.
8437 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8438 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8439
8440 // Transform the body
8441 StmtResult Body = getDerived().TransformStmt(S->getBody());
8442 if (Body.isInvalid())
8443 return StmtError();
8444
8445 // Transform the condition
8446 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8447 if (Cond.isInvalid())
8448 return StmtError();
8449
8450 if (!getDerived().AlwaysRebuild() &&
8451 Cond.get() == S->getCond() &&
8452 Body.get() == S->getBody())
8453 return S;
8454
8455 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8456 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8457 S->getRParenLoc());
8458}
8459
8460template<typename Derived>
8462TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8463 if (getSema().getLangOpts().OpenMP)
8464 getSema().OpenMP().startOpenMPLoop();
8465
8466 // Transform the initialization statement
8467 StmtResult Init = getDerived().TransformStmt(S->getInit());
8468 if (Init.isInvalid())
8469 return StmtError();
8470
8471 // In OpenMP loop region loop control variable must be captured and be
8472 // private. Perform analysis of first part (if any).
8473 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8474 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8475 Init.get());
8476
8477 // Transform the condition
8478 Sema::ConditionResult Cond = getDerived().TransformCondition(
8479 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8481 if (Cond.isInvalid())
8482 return StmtError();
8483
8484 // Transform the increment
8485 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8486 if (Inc.isInvalid())
8487 return StmtError();
8488
8489 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8490 if (S->getInc() && !FullInc.get())
8491 return StmtError();
8492
8493 // OpenACC Restricts a for-loop inside of certain construct/clause
8494 // combinations, so diagnose that here in OpenACC mode.
8495 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8496 SemaRef.OpenACC().ActOnForStmtBegin(
8497 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8498 Cond.get().second, S->getInc(), Inc.get());
8499
8500 // Transform the body
8501 StmtResult Body = getDerived().TransformStmt(S->getBody());
8502 if (Body.isInvalid())
8503 return StmtError();
8504
8505 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8506
8507 if (!getDerived().AlwaysRebuild() &&
8508 Init.get() == S->getInit() &&
8509 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8510 Inc.get() == S->getInc() &&
8511 Body.get() == S->getBody())
8512 return S;
8513
8514 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8515 Init.get(), Cond, FullInc,
8516 S->getRParenLoc(), Body.get());
8517}
8518
8519template<typename Derived>
8521TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8522 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8523 S->getLabel());
8524 if (!LD)
8525 return StmtError();
8526
8527 // Goto statements must always be rebuilt, to resolve the label.
8528 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8529 cast<LabelDecl>(LD));
8530}
8531
8532template<typename Derived>
8534TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8535 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8536 if (Target.isInvalid())
8537 return StmtError();
8538 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8539
8540 if (!getDerived().AlwaysRebuild() &&
8541 Target.get() == S->getTarget())
8542 return S;
8543
8544 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8545 Target.get());
8546}
8547
8548template<typename Derived>
8550TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8551 if (!S->hasLabelTarget())
8552 return S;
8553
8554 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8555 S->getLabelDecl());
8556 if (!LD)
8557 return StmtError();
8558
8559 return new (SemaRef.Context)
8560 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8561}
8562
8563template<typename Derived>
8565TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8566 if (!S->hasLabelTarget())
8567 return S;
8568
8569 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8570 S->getLabelDecl());
8571 if (!LD)
8572 return StmtError();
8573
8574 return new (SemaRef.Context)
8575 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8576}
8577
8578template<typename Derived>
8580TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8581 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8582 /*NotCopyInit*/false);
8583 if (Result.isInvalid())
8584 return StmtError();
8585
8586 // FIXME: We always rebuild the return statement because there is no way
8587 // to tell whether the return type of the function has changed.
8588 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8589}
8590
8591template<typename Derived>
8593TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8594 bool DeclChanged = false;
8596 LambdaScopeInfo *LSI = getSema().getCurLambda();
8597 for (auto *D : S->decls()) {
8598 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8599 if (!Transformed)
8600 return StmtError();
8601
8602 if (Transformed != D)
8603 DeclChanged = true;
8604
8605 if (LSI) {
8606 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8607 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8608 LSI->ContainsUnexpandedParameterPack |=
8609 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8610 } else {
8611 LSI->ContainsUnexpandedParameterPack |=
8612 getSema()
8613 .getASTContext()
8614 .getTypeDeclType(TD)
8615 ->containsUnexpandedParameterPack();
8616 }
8617 }
8618 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8619 LSI->ContainsUnexpandedParameterPack |=
8620 VD->getType()->containsUnexpandedParameterPack();
8621 }
8622
8623 Decls.push_back(Transformed);
8624 }
8625
8626 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8627 return S;
8628
8629 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8630}
8631
8632template<typename Derived>
8634TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8635
8636 SmallVector<Expr*, 8> Constraints;
8639
8640 SmallVector<Expr*, 8> Clobbers;
8641
8642 bool ExprsChanged = false;
8643
8644 auto RebuildString = [&](Expr *E) {
8645 ExprResult Result = getDerived().TransformExpr(E);
8646 if (!Result.isUsable())
8647 return Result;
8648 if (Result.get() != E) {
8649 ExprsChanged = true;
8650 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8651 }
8652 return Result;
8653 };
8654
8655 // Go through the outputs.
8656 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8657 Names.push_back(S->getOutputIdentifier(I));
8658
8659 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8660 if (Result.isInvalid())
8661 return StmtError();
8662
8663 Constraints.push_back(Result.get());
8664
8665 // Transform the output expr.
8666 Expr *OutputExpr = S->getOutputExpr(I);
8667 Result = getDerived().TransformExpr(OutputExpr);
8668 if (Result.isInvalid())
8669 return StmtError();
8670
8671 ExprsChanged |= Result.get() != OutputExpr;
8672
8673 Exprs.push_back(Result.get());
8674 }
8675
8676 // Go through the inputs.
8677 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8678 Names.push_back(S->getInputIdentifier(I));
8679
8680 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8681 if (Result.isInvalid())
8682 return StmtError();
8683
8684 Constraints.push_back(Result.get());
8685
8686 // Transform the input expr.
8687 Expr *InputExpr = S->getInputExpr(I);
8688 Result = getDerived().TransformExpr(InputExpr);
8689 if (Result.isInvalid())
8690 return StmtError();
8691
8692 ExprsChanged |= Result.get() != InputExpr;
8693
8694 Exprs.push_back(Result.get());
8695 }
8696
8697 // Go through the Labels.
8698 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8699 Names.push_back(S->getLabelIdentifier(I));
8700
8701 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8702 if (Result.isInvalid())
8703 return StmtError();
8704 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8705 Exprs.push_back(Result.get());
8706 }
8707
8708 // Go through the clobbers.
8709 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8710 ExprResult Result = RebuildString(S->getClobberExpr(I));
8711 if (Result.isInvalid())
8712 return StmtError();
8713 Clobbers.push_back(Result.get());
8714 }
8715
8716 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8717 if (AsmString.isInvalid())
8718 return StmtError();
8719
8720 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8721 return S;
8722
8723 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8724 S->isVolatile(), S->getNumOutputs(),
8725 S->getNumInputs(), Names.data(),
8726 Constraints, Exprs, AsmString.get(),
8727 Clobbers, S->getNumLabels(),
8728 S->getRParenLoc());
8729}
8730
8731template<typename Derived>
8733TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8734 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8735
8736 bool HadError = false, HadChange = false;
8737
8738 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8739 SmallVector<Expr*, 8> TransformedExprs;
8740 TransformedExprs.reserve(SrcExprs.size());
8741 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8742 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8743 if (!Result.isUsable()) {
8744 HadError = true;
8745 } else {
8746 HadChange |= (Result.get() != SrcExprs[i]);
8747 TransformedExprs.push_back(Result.get());
8748 }
8749 }
8750
8751 if (HadError) return StmtError();
8752 if (!HadChange && !getDerived().AlwaysRebuild())
8753 return Owned(S);
8754
8755 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8756 AsmToks, S->getAsmString(),
8757 S->getNumOutputs(), S->getNumInputs(),
8758 S->getAllConstraints(), S->getClobbers(),
8759 TransformedExprs, S->getEndLoc());
8760}
8761
8762// C++ Coroutines
8763template<typename Derived>
8765TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8766 auto *ScopeInfo = SemaRef.getCurFunction();
8767 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8768 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8769 ScopeInfo->NeedsCoroutineSuspends &&
8770 ScopeInfo->CoroutineSuspends.first == nullptr &&
8771 ScopeInfo->CoroutineSuspends.second == nullptr &&
8772 "expected clean scope info");
8773
8774 // Set that we have (possibly-invalid) suspend points before we do anything
8775 // that may fail.
8776 ScopeInfo->setNeedsCoroutineSuspends(false);
8777
8778 // We re-build the coroutine promise object (and the coroutine parameters its
8779 // type and constructor depend on) based on the types used in our current
8780 // function. We must do so, and set it on the current FunctionScopeInfo,
8781 // before attempting to transform the other parts of the coroutine body
8782 // statement, such as the implicit suspend statements (because those
8783 // statements reference the FunctionScopeInfo::CoroutinePromise).
8784 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8785 return StmtError();
8786 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8787 if (!Promise)
8788 return StmtError();
8789 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8790 ScopeInfo->CoroutinePromise = Promise;
8791
8792 // Transform the implicit coroutine statements constructed using dependent
8793 // types during the previous parse: initial and final suspensions, the return
8794 // object, and others. We also transform the coroutine function's body.
8795 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8796 if (InitSuspend.isInvalid())
8797 return StmtError();
8798 StmtResult FinalSuspend =
8799 getDerived().TransformStmt(S->getFinalSuspendStmt());
8800 if (FinalSuspend.isInvalid() ||
8801 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8802 return StmtError();
8803 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8804 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8805
8806 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8807 if (BodyRes.isInvalid())
8808 return StmtError();
8809
8810 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8811 if (Builder.isInvalid())
8812 return StmtError();
8813
8814 Expr *ReturnObject = S->getReturnValueInit();
8815 assert(ReturnObject && "the return object is expected to be valid");
8816 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8817 /*NoCopyInit*/ false);
8818 if (Res.isInvalid())
8819 return StmtError();
8820 Builder.ReturnValue = Res.get();
8821
8822 // If during the previous parse the coroutine still had a dependent promise
8823 // statement, we may need to build some implicit coroutine statements
8824 // (such as exception and fallthrough handlers) for the first time.
8825 if (S->hasDependentPromiseType()) {
8826 // We can only build these statements, however, if the current promise type
8827 // is not dependent.
8828 if (!Promise->getType()->isDependentType()) {
8829 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8830 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8831 "these nodes should not have been built yet");
8832 if (!Builder.buildDependentStatements())
8833 return StmtError();
8834 }
8835 } else {
8836 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8837 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8838 if (Res.isInvalid())
8839 return StmtError();
8840 Builder.OnFallthrough = Res.get();
8841 }
8842
8843 if (auto *OnException = S->getExceptionHandler()) {
8844 StmtResult Res = getDerived().TransformStmt(OnException);
8845 if (Res.isInvalid())
8846 return StmtError();
8847 Builder.OnException = Res.get();
8848 }
8849
8850 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8851 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8852 if (Res.isInvalid())
8853 return StmtError();
8854 Builder.ReturnStmtOnAllocFailure = Res.get();
8855 }
8856
8857 // Transform any additional statements we may have already built
8858 assert(S->getAllocate() && S->getDeallocate() &&
8859 "allocation and deallocation calls must already be built");
8860 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8861 if (AllocRes.isInvalid())
8862 return StmtError();
8863 Builder.Allocate = AllocRes.get();
8864
8865 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8866 if (DeallocRes.isInvalid())
8867 return StmtError();
8868 Builder.Deallocate = DeallocRes.get();
8869
8870 if (auto *ResultDecl = S->getResultDecl()) {
8871 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8872 if (Res.isInvalid())
8873 return StmtError();
8874 Builder.ResultDecl = Res.get();
8875 }
8876
8877 if (auto *ReturnStmt = S->getReturnStmt()) {
8878 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8879 if (Res.isInvalid())
8880 return StmtError();
8881 Builder.ReturnStmt = Res.get();
8882 }
8883 }
8884
8885 return getDerived().RebuildCoroutineBodyStmt(Builder);
8886}
8887
8888template<typename Derived>
8890TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8891 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8892 /*NotCopyInit*/false);
8893 if (Result.isInvalid())
8894 return StmtError();
8895
8896 // Always rebuild; we don't know if this needs to be injected into a new
8897 // context or if the promise type has changed.
8898 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8899 S->isImplicit());
8900}
8901
8902template <typename Derived>
8903ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8904 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8905 /*NotCopyInit*/ false);
8906 if (Operand.isInvalid())
8907 return ExprError();
8908
8909 // Rebuild the common-expr from the operand rather than transforming it
8910 // separately.
8911
8912 // FIXME: getCurScope() should not be used during template instantiation.
8913 // We should pick up the set of unqualified lookup results for operator
8914 // co_await during the initial parse.
8915 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8916 getSema().getCurScope(), E->getKeywordLoc());
8917
8918 // Always rebuild; we don't know if this needs to be injected into a new
8919 // context or if the promise type has changed.
8920 return getDerived().RebuildCoawaitExpr(
8921 E->getKeywordLoc(), Operand.get(),
8922 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8923}
8924
8925template <typename Derived>
8927TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8928 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8929 /*NotCopyInit*/ false);
8930 if (OperandResult.isInvalid())
8931 return ExprError();
8932
8933 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8934 E->getOperatorCoawaitLookup());
8935
8936 if (LookupResult.isInvalid())
8937 return ExprError();
8938
8939 // Always rebuild; we don't know if this needs to be injected into a new
8940 // context or if the promise type has changed.
8941 return getDerived().RebuildDependentCoawaitExpr(
8942 E->getKeywordLoc(), OperandResult.get(),
8943 cast<UnresolvedLookupExpr>(LookupResult.get()));
8944}
8945
8946template<typename Derived>
8948TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8949 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8950 /*NotCopyInit*/false);
8951 if (Result.isInvalid())
8952 return ExprError();
8953
8954 // Always rebuild; we don't know if this needs to be injected into a new
8955 // context or if the promise type has changed.
8956 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8957}
8958
8959// Objective-C Statements.
8960
8961template<typename Derived>
8963TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8964 // Transform the body of the @try.
8965 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8966 if (TryBody.isInvalid())
8967 return StmtError();
8968
8969 // Transform the @catch statements (if present).
8970 bool AnyCatchChanged = false;
8971 SmallVector<Stmt*, 8> CatchStmts;
8972 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8973 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8974 if (Catch.isInvalid())
8975 return StmtError();
8976 if (Catch.get() != S->getCatchStmt(I))
8977 AnyCatchChanged = true;
8978 CatchStmts.push_back(Catch.get());
8979 }
8980
8981 // Transform the @finally statement (if present).
8982 StmtResult Finally;
8983 if (S->getFinallyStmt()) {
8984 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8985 if (Finally.isInvalid())
8986 return StmtError();
8987 }
8988
8989 // If nothing changed, just retain this statement.
8990 if (!getDerived().AlwaysRebuild() &&
8991 TryBody.get() == S->getTryBody() &&
8992 !AnyCatchChanged &&
8993 Finally.get() == S->getFinallyStmt())
8994 return S;
8995
8996 // Build a new statement.
8997 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8998 CatchStmts, Finally.get());
8999}
9000
9001template<typename Derived>
9003TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
9004 // Transform the @catch parameter, if there is one.
9005 VarDecl *Var = nullptr;
9006 if (VarDecl *FromVar = S->getCatchParamDecl()) {
9007 TypeSourceInfo *TSInfo = nullptr;
9008 if (FromVar->getTypeSourceInfo()) {
9009 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
9010 if (!TSInfo)
9011 return StmtError();
9012 }
9013
9014 QualType T;
9015 if (TSInfo)
9016 T = TSInfo->getType();
9017 else {
9018 T = getDerived().TransformType(FromVar->getType());
9019 if (T.isNull())
9020 return StmtError();
9021 }
9022
9023 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
9024 if (!Var)
9025 return StmtError();
9026 }
9027
9028 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
9029 if (Body.isInvalid())
9030 return StmtError();
9031
9032 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9033 S->getRParenLoc(),
9034 Var, Body.get());
9035}
9036
9037template<typename Derived>
9039TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
9040 // Transform the body.
9041 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9042 if (Body.isInvalid())
9043 return StmtError();
9044
9045 // If nothing changed, just retain this statement.
9046 if (!getDerived().AlwaysRebuild() &&
9047 Body.get() == S->getFinallyBody())
9048 return S;
9049
9050 // Build a new statement.
9051 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9052 Body.get());
9053}
9054
9055template<typename Derived>
9057TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
9059 if (S->getThrowExpr()) {
9060 Operand = getDerived().TransformExpr(S->getThrowExpr());
9061 if (Operand.isInvalid())
9062 return StmtError();
9063 }
9064
9065 if (!getDerived().AlwaysRebuild() &&
9066 Operand.get() == S->getThrowExpr())
9067 return S;
9068
9069 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9070}
9071
9072template<typename Derived>
9074TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
9075 ObjCAtSynchronizedStmt *S) {
9076 // Transform the object we are locking.
9077 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9078 if (Object.isInvalid())
9079 return StmtError();
9080 Object =
9081 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9082 Object.get());
9083 if (Object.isInvalid())
9084 return StmtError();
9085
9086 // Transform the body.
9087 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9088 if (Body.isInvalid())
9089 return StmtError();
9090
9091 // If nothing change, just retain the current statement.
9092 if (!getDerived().AlwaysRebuild() &&
9093 Object.get() == S->getSynchExpr() &&
9094 Body.get() == S->getSynchBody())
9095 return S;
9096
9097 // Build a new statement.
9098 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9099 Object.get(), Body.get());
9100}
9101
9102template<typename Derived>
9104TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
9105 ObjCAutoreleasePoolStmt *S) {
9106 // Transform the body.
9107 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9108 if (Body.isInvalid())
9109 return StmtError();
9110
9111 // If nothing changed, just retain this statement.
9112 if (!getDerived().AlwaysRebuild() &&
9113 Body.get() == S->getSubStmt())
9114 return S;
9115
9116 // Build a new statement.
9117 return getDerived().RebuildObjCAutoreleasePoolStmt(
9118 S->getAtLoc(), Body.get());
9119}
9120
9121template<typename Derived>
9123TreeTransform<Derived>::TransformObjCForCollectionStmt(
9124 ObjCForCollectionStmt *S) {
9125 // Transform the element statement.
9126 StmtResult Element = getDerived().TransformStmt(
9127 S->getElement(), StmtDiscardKind::NotDiscarded);
9128 if (Element.isInvalid())
9129 return StmtError();
9130
9131 // Transform the collection expression.
9132 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9133 if (Collection.isInvalid())
9134 return StmtError();
9135
9136 // Transform the body.
9137 StmtResult Body = getDerived().TransformStmt(S->getBody());
9138 if (Body.isInvalid())
9139 return StmtError();
9140
9141 // If nothing changed, just retain this statement.
9142 if (!getDerived().AlwaysRebuild() &&
9143 Element.get() == S->getElement() &&
9144 Collection.get() == S->getCollection() &&
9145 Body.get() == S->getBody())
9146 return S;
9147
9148 // Build a new statement.
9149 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9150 Element.get(),
9151 Collection.get(),
9152 S->getRParenLoc(),
9153 Body.get());
9154}
9155
9156template <typename Derived>
9157StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
9158 // Transform the exception declaration, if any.
9159 VarDecl *Var = nullptr;
9160 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9161 TypeSourceInfo *T =
9162 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9163 if (!T)
9164 return StmtError();
9165
9166 Var = getDerived().RebuildExceptionDecl(
9167 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9168 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9169 if (!Var || Var->isInvalidDecl())
9170 return StmtError();
9171 }
9172
9173 // Transform the actual exception handler.
9174 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9175 if (Handler.isInvalid())
9176 return StmtError();
9177
9178 if (!getDerived().AlwaysRebuild() && !Var &&
9179 Handler.get() == S->getHandlerBlock())
9180 return S;
9181
9182 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9183}
9184
9185template <typename Derived>
9186StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
9187 // Transform the try block itself.
9188 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9189 if (TryBlock.isInvalid())
9190 return StmtError();
9191
9192 // Transform the handlers.
9193 bool HandlerChanged = false;
9194 SmallVector<Stmt *, 8> Handlers;
9195 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9196 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9197 if (Handler.isInvalid())
9198 return StmtError();
9199
9200 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9201 Handlers.push_back(Handler.getAs<Stmt>());
9202 }
9203
9204 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9205
9206 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9207 !HandlerChanged)
9208 return S;
9209
9210 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9211 Handlers);
9212}
9213
9214template<typename Derived>
9216TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
9217 EnterExpressionEvaluationContext ForRangeInitContext(
9219 /*LambdaContextDecl=*/nullptr,
9221 getSema().getLangOpts().CPlusPlus23);
9222
9223 // P2718R0 - Lifetime extension in range-based for loops.
9224 if (getSema().getLangOpts().CPlusPlus23) {
9225 auto &LastRecord = getSema().currentEvaluationContext();
9226 LastRecord.InLifetimeExtendingContext = true;
9227 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9228 }
9230 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9231 if (Init.isInvalid())
9232 return StmtError();
9233
9234 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9235 if (Range.isInvalid())
9236 return StmtError();
9237
9238 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9239 assert(getSema().getLangOpts().CPlusPlus23 ||
9240 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9241 auto ForRangeLifetimeExtendTemps =
9242 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9243
9244 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9245 if (Begin.isInvalid())
9246 return StmtError();
9247 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9248 if (End.isInvalid())
9249 return StmtError();
9250
9251 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9252 if (Cond.isInvalid())
9253 return StmtError();
9254 if (Cond.get())
9255 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9256 if (Cond.isInvalid())
9257 return StmtError();
9258 if (Cond.get())
9259 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9260
9261 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9262 if (Inc.isInvalid())
9263 return StmtError();
9264 if (Inc.get())
9265 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9266
9267 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9268 if (LoopVar.isInvalid())
9269 return StmtError();
9270
9271 StmtResult NewStmt = S;
9272 if (getDerived().AlwaysRebuild() ||
9273 Init.get() != S->getInit() ||
9274 Range.get() != S->getRangeStmt() ||
9275 Begin.get() != S->getBeginStmt() ||
9276 End.get() != S->getEndStmt() ||
9277 Cond.get() != S->getCond() ||
9278 Inc.get() != S->getInc() ||
9279 LoopVar.get() != S->getLoopVarStmt()) {
9280 NewStmt = getDerived().RebuildCXXForRangeStmt(
9281 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9282 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9283 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9284 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9285 // Might not have attached any initializer to the loop variable.
9286 getSema().ActOnInitializerError(
9287 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9288 return StmtError();
9289 }
9290 }
9291
9292 // OpenACC Restricts a while-loop inside of certain construct/clause
9293 // combinations, so diagnose that here in OpenACC mode.
9294 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
9295 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9296
9297 StmtResult Body = getDerived().TransformStmt(S->getBody());
9298 if (Body.isInvalid())
9299 return StmtError();
9300
9301 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9302
9303 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9304 // it now so we have a new statement to attach the body to.
9305 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9306 NewStmt = getDerived().RebuildCXXForRangeStmt(
9307 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9308 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9309 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9310 if (NewStmt.isInvalid())
9311 return StmtError();
9312 }
9313
9314 if (NewStmt.get() == S)
9315 return S;
9316
9317 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9318}
9319
9320template<typename Derived>
9322TreeTransform<Derived>::TransformMSDependentExistsStmt(
9323 MSDependentExistsStmt *S) {
9324 // Transform the nested-name-specifier, if any.
9325 NestedNameSpecifierLoc QualifierLoc;
9326 if (S->getQualifierLoc()) {
9327 QualifierLoc
9328 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9329 if (!QualifierLoc)
9330 return StmtError();
9331 }
9332
9333 // Transform the declaration name.
9334 DeclarationNameInfo NameInfo = S->getNameInfo();
9335 if (NameInfo.getName()) {
9336 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9337 if (!NameInfo.getName())
9338 return StmtError();
9339 }
9340
9341 // Check whether anything changed.
9342 if (!getDerived().AlwaysRebuild() &&
9343 QualifierLoc == S->getQualifierLoc() &&
9344 NameInfo.getName() == S->getNameInfo().getName())
9345 return S;
9346
9347 // Determine whether this name exists, if we can.
9348 CXXScopeSpec SS;
9349 SS.Adopt(QualifierLoc);
9350 bool Dependent = false;
9351 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9353 if (S->isIfExists())
9354 break;
9355
9356 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9357
9359 if (S->isIfNotExists())
9360 break;
9361
9362 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9363
9365 Dependent = true;
9366 break;
9367
9369 return StmtError();
9370 }
9371
9372 // We need to continue with the instantiation, so do so now.
9373 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9374 if (SubStmt.isInvalid())
9375 return StmtError();
9376
9377 // If we have resolved the name, just transform to the substatement.
9378 if (!Dependent)
9379 return SubStmt;
9380
9381 // The name is still dependent, so build a dependent expression again.
9382 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9383 S->isIfExists(),
9384 QualifierLoc,
9385 NameInfo,
9386 SubStmt.get());
9387}
9388
9389template<typename Derived>
9391TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9392 NestedNameSpecifierLoc QualifierLoc;
9393 if (E->getQualifierLoc()) {
9394 QualifierLoc
9395 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9396 if (!QualifierLoc)
9397 return ExprError();
9398 }
9399
9400 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9401 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9402 if (!PD)
9403 return ExprError();
9404
9405 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9406 if (Base.isInvalid())
9407 return ExprError();
9408
9409 return new (SemaRef.getASTContext())
9410 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9412 QualifierLoc, E->getMemberLoc());
9413}
9414
9415template <typename Derived>
9416ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9417 MSPropertySubscriptExpr *E) {
9418 auto BaseRes = getDerived().TransformExpr(E->getBase());
9419 if (BaseRes.isInvalid())
9420 return ExprError();
9421 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9422 if (IdxRes.isInvalid())
9423 return ExprError();
9424
9425 if (!getDerived().AlwaysRebuild() &&
9426 BaseRes.get() == E->getBase() &&
9427 IdxRes.get() == E->getIdx())
9428 return E;
9429
9430 return getDerived().RebuildArraySubscriptExpr(
9431 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9432}
9433
9434template <typename Derived>
9435StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9436 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9437 if (TryBlock.isInvalid())
9438 return StmtError();
9439
9440 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9441 if (Handler.isInvalid())
9442 return StmtError();
9443
9444 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9445 Handler.get() == S->getHandler())
9446 return S;
9447
9448 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9449 TryBlock.get(), Handler.get());
9450}
9451
9452template <typename Derived>
9453StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9454 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9455 if (Block.isInvalid())
9456 return StmtError();
9457
9458 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9459}
9460
9461template <typename Derived>
9462StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9463 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9464 if (FilterExpr.isInvalid())
9465 return StmtError();
9466
9467 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9468 if (Block.isInvalid())
9469 return StmtError();
9470
9471 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9472 Block.get());
9473}
9474
9475template <typename Derived>
9477 if (isa<SEHFinallyStmt>(Handler))
9478 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9479 else
9480 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9481}
9482
9483template<typename Derived>
9486 return S;
9487}
9488
9489//===----------------------------------------------------------------------===//
9490// OpenMP directive transformation
9491//===----------------------------------------------------------------------===//
9492
9493template <typename Derived>
9495TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9496 // OMPCanonicalLoops are eliminated during transformation, since they will be
9497 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9498 // after transformation.
9499 return getDerived().TransformStmt(L->getLoopStmt());
9500}
9501
9502template <typename Derived>
9505
9506 // Transform the clauses
9508 ArrayRef<OMPClause *> Clauses = D->clauses();
9509 TClauses.reserve(Clauses.size());
9510 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9511 I != E; ++I) {
9512 if (*I) {
9513 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9514 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9515 getDerived().getSema().OpenMP().EndOpenMPClause();
9516 if (Clause)
9517 TClauses.push_back(Clause);
9518 } else {
9519 TClauses.push_back(nullptr);
9520 }
9521 }
9522 StmtResult AssociatedStmt;
9523 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9524 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9525 D->getDirectiveKind(),
9526 /*CurScope=*/nullptr);
9527 StmtResult Body;
9528 {
9529 Sema::CompoundScopeRAII CompoundScope(getSema());
9530 Stmt *CS;
9531 if (D->getDirectiveKind() == OMPD_atomic ||
9532 D->getDirectiveKind() == OMPD_critical ||
9533 D->getDirectiveKind() == OMPD_section ||
9534 D->getDirectiveKind() == OMPD_master)
9535 CS = D->getAssociatedStmt();
9536 else
9537 CS = D->getRawStmt();
9538 Body = getDerived().TransformStmt(CS);
9539 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9540 getSema().getLangOpts().OpenMPIRBuilder)
9541 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9542 }
9543 AssociatedStmt =
9544 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9545 if (AssociatedStmt.isInvalid()) {
9546 return StmtError();
9547 }
9548 }
9549 if (TClauses.size() != Clauses.size()) {
9550 return StmtError();
9551 }
9552
9553 // Transform directive name for 'omp critical' directive.
9554 DeclarationNameInfo DirName;
9555 if (D->getDirectiveKind() == OMPD_critical) {
9556 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9557 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9558 }
9559 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9560 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9561 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9562 } else if (D->getDirectiveKind() == OMPD_cancel) {
9563 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9564 }
9565
9566 return getDerived().RebuildOMPExecutableDirective(
9567 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9568 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9569}
9570
9571/// This is mostly the same as above, but allows 'informational' class
9572/// directives when rebuilding the stmt. It still takes an
9573/// OMPExecutableDirective-type argument because we're reusing that as the
9574/// superclass for the 'assume' directive at present, instead of defining a
9575/// mostly-identical OMPInformationalDirective parent class.
9576template <typename Derived>
9579
9580 // Transform the clauses
9582 ArrayRef<OMPClause *> Clauses = D->clauses();
9583 TClauses.reserve(Clauses.size());
9584 for (OMPClause *C : Clauses) {
9585 if (C) {
9586 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9587 OMPClause *Clause = getDerived().TransformOMPClause(C);
9588 getDerived().getSema().OpenMP().EndOpenMPClause();
9589 if (Clause)
9590 TClauses.push_back(Clause);
9591 } else {
9592 TClauses.push_back(nullptr);
9593 }
9594 }
9595 StmtResult AssociatedStmt;
9596 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9597 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9598 D->getDirectiveKind(),
9599 /*CurScope=*/nullptr);
9600 StmtResult Body;
9601 {
9602 Sema::CompoundScopeRAII CompoundScope(getSema());
9603 assert(D->getDirectiveKind() == OMPD_assume &&
9604 "Unexpected informational directive");
9605 Stmt *CS = D->getAssociatedStmt();
9606 Body = getDerived().TransformStmt(CS);
9607 }
9608 AssociatedStmt =
9609 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9610 if (AssociatedStmt.isInvalid())
9611 return StmtError();
9612 }
9613 if (TClauses.size() != Clauses.size())
9614 return StmtError();
9615
9616 DeclarationNameInfo DirName;
9617
9618 return getDerived().RebuildOMPInformationalDirective(
9619 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9620 D->getBeginLoc(), D->getEndLoc());
9621}
9622
9623template <typename Derived>
9626 // TODO: Fix This
9627 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9628 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9629 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9630 return StmtError();
9631}
9632
9633template <typename Derived>
9635TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9636 DeclarationNameInfo DirName;
9637 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9638 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9640 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9641 return Res;
9642}
9643
9644template <typename Derived>
9646TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9647 DeclarationNameInfo DirName;
9648 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9649 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9651 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9652 return Res;
9653}
9654
9655template <typename Derived>
9657TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9658 DeclarationNameInfo DirName;
9659 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9660 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9661 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9662 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9663 return Res;
9664}
9665
9666template <typename Derived>
9668TreeTransform<Derived>::TransformOMPStripeDirective(OMPStripeDirective *D) {
9669 DeclarationNameInfo DirName;
9670 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9671 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9672 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9673 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9674 return Res;
9675}
9676
9677template <typename Derived>
9679TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9680 DeclarationNameInfo DirName;
9681 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9682 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9683 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9684 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9685 return Res;
9686}
9687
9688template <typename Derived>
9690TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9691 DeclarationNameInfo DirName;
9692 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9693 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9694 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9695 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9696 return Res;
9697}
9698
9699template <typename Derived>
9700StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9701 OMPInterchangeDirective *D) {
9702 DeclarationNameInfo DirName;
9703 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9704 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9705 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9706 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9707 return Res;
9708}
9709
9710template <typename Derived>
9712TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9713 DeclarationNameInfo DirName;
9714 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9715 OMPD_for, DirName, nullptr, D->getBeginLoc());
9716 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9717 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9718 return Res;
9719}
9720
9721template <typename Derived>
9723TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9724 DeclarationNameInfo DirName;
9725 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9726 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9727 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9728 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9729 return Res;
9730}
9731
9732template <typename Derived>
9734TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9735 DeclarationNameInfo DirName;
9736 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9737 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9738 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9739 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9740 return Res;
9741}
9742
9743template <typename Derived>
9745TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9746 DeclarationNameInfo DirName;
9747 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9748 OMPD_section, DirName, nullptr, D->getBeginLoc());
9749 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9750 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9751 return Res;
9752}
9753
9754template <typename Derived>
9756TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9757 DeclarationNameInfo DirName;
9758 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9759 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9760 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9761 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9762 return Res;
9763}
9764
9765template <typename Derived>
9767TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9768 DeclarationNameInfo DirName;
9769 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9770 OMPD_single, DirName, nullptr, D->getBeginLoc());
9771 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9772 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9773 return Res;
9774}
9775
9776template <typename Derived>
9778TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9779 DeclarationNameInfo DirName;
9780 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9781 OMPD_master, DirName, nullptr, D->getBeginLoc());
9782 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9783 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9784 return Res;
9785}
9786
9787template <typename Derived>
9789TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9790 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9791 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9792 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9793 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9794 return Res;
9795}
9796
9797template <typename Derived>
9798StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9799 OMPParallelForDirective *D) {
9800 DeclarationNameInfo DirName;
9801 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9802 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9803 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9804 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9805 return Res;
9806}
9807
9808template <typename Derived>
9809StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9810 OMPParallelForSimdDirective *D) {
9811 DeclarationNameInfo DirName;
9812 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9813 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9814 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9815 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9816 return Res;
9817}
9818
9819template <typename Derived>
9820StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9821 OMPParallelMasterDirective *D) {
9822 DeclarationNameInfo DirName;
9823 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9824 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9825 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9826 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9827 return Res;
9828}
9829
9830template <typename Derived>
9831StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9832 OMPParallelMaskedDirective *D) {
9833 DeclarationNameInfo DirName;
9834 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9835 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9836 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9837 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9838 return Res;
9839}
9840
9841template <typename Derived>
9842StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9843 OMPParallelSectionsDirective *D) {
9844 DeclarationNameInfo DirName;
9845 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9846 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9847 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9848 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9849 return Res;
9850}
9851
9852template <typename Derived>
9854TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9855 DeclarationNameInfo DirName;
9856 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9857 OMPD_task, DirName, nullptr, D->getBeginLoc());
9858 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9859 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9860 return Res;
9861}
9862
9863template <typename Derived>
9864StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9865 OMPTaskyieldDirective *D) {
9866 DeclarationNameInfo DirName;
9867 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9868 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9869 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9870 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9871 return Res;
9872}
9873
9874template <typename Derived>
9876TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9877 DeclarationNameInfo DirName;
9878 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9879 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9880 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9881 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9882 return Res;
9883}
9884
9885template <typename Derived>
9887TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9888 DeclarationNameInfo DirName;
9889 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9890 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9891 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9892 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9893 return Res;
9894}
9895
9896template <typename Derived>
9898TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) {
9899 DeclarationNameInfo DirName;
9900 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9901 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9902 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9903 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9904 return Res;
9905}
9906
9907template <typename Derived>
9909TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9910 DeclarationNameInfo DirName;
9911 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9912 OMPD_error, DirName, nullptr, D->getBeginLoc());
9913 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9914 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9915 return Res;
9916}
9917
9918template <typename Derived>
9919StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9920 OMPTaskgroupDirective *D) {
9921 DeclarationNameInfo DirName;
9922 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9923 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9924 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9925 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9926 return Res;
9927}
9928
9929template <typename Derived>
9931TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9932 DeclarationNameInfo DirName;
9933 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9934 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9935 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9936 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9937 return Res;
9938}
9939
9940template <typename Derived>
9942TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9943 DeclarationNameInfo DirName;
9944 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9945 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9946 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9947 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9948 return Res;
9949}
9950
9951template <typename Derived>
9953TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9954 DeclarationNameInfo DirName;
9955 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9956 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9957 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9958 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9959 return Res;
9960}
9961
9962template <typename Derived>
9964TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9965 DeclarationNameInfo DirName;
9966 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9967 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9968 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9969 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9970 return Res;
9971}
9972
9973template <typename Derived>
9975TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9976 DeclarationNameInfo DirName;
9977 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9978 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9979 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9980 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9981 return Res;
9982}
9983
9984template <typename Derived>
9986TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9987 DeclarationNameInfo DirName;
9988 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9989 OMPD_target, DirName, nullptr, D->getBeginLoc());
9990 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9991 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9992 return Res;
9993}
9994
9995template <typename Derived>
9996StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9997 OMPTargetDataDirective *D) {
9998 DeclarationNameInfo DirName;
9999 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10000 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
10001 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10002 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10003 return Res;
10004}
10005
10006template <typename Derived>
10007StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
10008 OMPTargetEnterDataDirective *D) {
10009 DeclarationNameInfo DirName;
10010 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10011 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
10012 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10013 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10014 return Res;
10015}
10016
10017template <typename Derived>
10018StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
10019 OMPTargetExitDataDirective *D) {
10020 DeclarationNameInfo DirName;
10021 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10022 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
10023 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10024 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10025 return Res;
10026}
10027
10028template <typename Derived>
10029StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
10030 OMPTargetParallelDirective *D) {
10031 DeclarationNameInfo DirName;
10032 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10033 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10034 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10035 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10036 return Res;
10037}
10038
10039template <typename Derived>
10040StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
10041 OMPTargetParallelForDirective *D) {
10042 DeclarationNameInfo DirName;
10043 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10044 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10045 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10046 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10047 return Res;
10048}
10049
10050template <typename Derived>
10051StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
10052 OMPTargetUpdateDirective *D) {
10053 DeclarationNameInfo DirName;
10054 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10055 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10056 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10057 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10058 return Res;
10059}
10060
10061template <typename Derived>
10063TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
10064 DeclarationNameInfo DirName;
10065 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10066 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10067 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10068 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10069 return Res;
10070}
10071
10072template <typename Derived>
10073StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
10074 OMPCancellationPointDirective *D) {
10075 DeclarationNameInfo DirName;
10076 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10077 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10078 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10079 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10080 return Res;
10081}
10082
10083template <typename Derived>
10085TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
10086 DeclarationNameInfo DirName;
10087 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10088 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10089 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10090 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10091 return Res;
10092}
10093
10094template <typename Derived>
10096TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
10097 DeclarationNameInfo DirName;
10098 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10099 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10100 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10101 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10102 return Res;
10103}
10104
10105template <typename Derived>
10106StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
10107 OMPTaskLoopSimdDirective *D) {
10108 DeclarationNameInfo DirName;
10109 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10110 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10111 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10112 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10113 return Res;
10114}
10115
10116template <typename Derived>
10117StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
10118 OMPMasterTaskLoopDirective *D) {
10119 DeclarationNameInfo DirName;
10120 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10121 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10122 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10123 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10124 return Res;
10125}
10126
10127template <typename Derived>
10128StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
10129 OMPMaskedTaskLoopDirective *D) {
10130 DeclarationNameInfo DirName;
10131 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10132 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10133 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10134 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10135 return Res;
10136}
10137
10138template <typename Derived>
10139StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
10140 OMPMasterTaskLoopSimdDirective *D) {
10141 DeclarationNameInfo DirName;
10142 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10143 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10144 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10145 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10146 return Res;
10147}
10148
10149template <typename Derived>
10150StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
10151 OMPMaskedTaskLoopSimdDirective *D) {
10152 DeclarationNameInfo DirName;
10153 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10154 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10155 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10156 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10157 return Res;
10158}
10159
10160template <typename Derived>
10161StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
10162 OMPParallelMasterTaskLoopDirective *D) {
10163 DeclarationNameInfo DirName;
10164 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10165 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10166 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10167 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10168 return Res;
10169}
10170
10171template <typename Derived>
10172StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
10173 OMPParallelMaskedTaskLoopDirective *D) {
10174 DeclarationNameInfo DirName;
10175 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10176 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10177 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10178 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10179 return Res;
10180}
10181
10182template <typename Derived>
10184TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
10185 OMPParallelMasterTaskLoopSimdDirective *D) {
10186 DeclarationNameInfo DirName;
10187 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10188 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10189 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10190 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10191 return Res;
10192}
10193
10194template <typename Derived>
10196TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
10197 OMPParallelMaskedTaskLoopSimdDirective *D) {
10198 DeclarationNameInfo DirName;
10199 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10200 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10201 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10202 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10203 return Res;
10204}
10205
10206template <typename Derived>
10207StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
10208 OMPDistributeDirective *D) {
10209 DeclarationNameInfo DirName;
10210 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10211 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10212 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10213 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10214 return Res;
10215}
10216
10217template <typename Derived>
10218StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
10219 OMPDistributeParallelForDirective *D) {
10220 DeclarationNameInfo DirName;
10221 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10222 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10223 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10224 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10225 return Res;
10226}
10227
10228template <typename Derived>
10230TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
10231 OMPDistributeParallelForSimdDirective *D) {
10232 DeclarationNameInfo DirName;
10233 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10234 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10235 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10236 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10237 return Res;
10238}
10239
10240template <typename Derived>
10241StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
10242 OMPDistributeSimdDirective *D) {
10243 DeclarationNameInfo DirName;
10244 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10245 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10246 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10247 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10248 return Res;
10249}
10250
10251template <typename Derived>
10252StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
10253 OMPTargetParallelForSimdDirective *D) {
10254 DeclarationNameInfo DirName;
10255 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10256 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10257 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10258 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10259 return Res;
10260}
10261
10262template <typename Derived>
10263StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
10264 OMPTargetSimdDirective *D) {
10265 DeclarationNameInfo DirName;
10266 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10267 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10269 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10270 return Res;
10271}
10272
10273template <typename Derived>
10274StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
10275 OMPTeamsDistributeDirective *D) {
10276 DeclarationNameInfo DirName;
10277 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10278 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10279 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10280 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10281 return Res;
10282}
10283
10284template <typename Derived>
10285StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
10286 OMPTeamsDistributeSimdDirective *D) {
10287 DeclarationNameInfo DirName;
10288 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10289 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10290 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10291 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10292 return Res;
10293}
10294
10295template <typename Derived>
10296StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
10297 OMPTeamsDistributeParallelForSimdDirective *D) {
10298 DeclarationNameInfo DirName;
10299 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10300 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10301 D->getBeginLoc());
10302 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10303 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10304 return Res;
10305}
10306
10307template <typename Derived>
10308StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
10309 OMPTeamsDistributeParallelForDirective *D) {
10310 DeclarationNameInfo DirName;
10311 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10312 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10313 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10314 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10315 return Res;
10316}
10317
10318template <typename Derived>
10319StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
10320 OMPTargetTeamsDirective *D) {
10321 DeclarationNameInfo DirName;
10322 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10323 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10324 auto Res = getDerived().TransformOMPExecutableDirective(D);
10325 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10326 return Res;
10327}
10328
10329template <typename Derived>
10330StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
10331 OMPTargetTeamsDistributeDirective *D) {
10332 DeclarationNameInfo DirName;
10333 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10334 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10335 auto Res = getDerived().TransformOMPExecutableDirective(D);
10336 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10337 return Res;
10338}
10339
10340template <typename Derived>
10342TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
10343 OMPTargetTeamsDistributeParallelForDirective *D) {
10344 DeclarationNameInfo DirName;
10345 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10346 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10347 D->getBeginLoc());
10348 auto Res = getDerived().TransformOMPExecutableDirective(D);
10349 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10350 return Res;
10351}
10352
10353template <typename Derived>
10354StmtResult TreeTransform<Derived>::
10355 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
10356 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10357 DeclarationNameInfo DirName;
10358 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10359 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10360 D->getBeginLoc());
10361 auto Res = getDerived().TransformOMPExecutableDirective(D);
10362 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10363 return Res;
10364}
10365
10366template <typename Derived>
10368TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
10369 OMPTargetTeamsDistributeSimdDirective *D) {
10370 DeclarationNameInfo DirName;
10371 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10372 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10373 auto Res = getDerived().TransformOMPExecutableDirective(D);
10374 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10375 return Res;
10376}
10377
10378template <typename Derived>
10380TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
10381 DeclarationNameInfo DirName;
10382 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10383 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10384 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10385 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10386 return Res;
10387}
10388
10389template <typename Derived>
10391TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
10392 DeclarationNameInfo DirName;
10393 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10394 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10395 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10396 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10397 return Res;
10398}
10399
10400template <typename Derived>
10402TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
10403 DeclarationNameInfo DirName;
10404 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10405 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10406 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10407 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10408 return Res;
10409}
10410
10411template <typename Derived>
10412StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
10413 OMPGenericLoopDirective *D) {
10414 DeclarationNameInfo DirName;
10415 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10416 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10417 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10418 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10419 return Res;
10420}
10421
10422template <typename Derived>
10423StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
10424 OMPTeamsGenericLoopDirective *D) {
10425 DeclarationNameInfo DirName;
10426 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10427 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10428 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10429 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10430 return Res;
10431}
10432
10433template <typename Derived>
10434StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
10435 OMPTargetTeamsGenericLoopDirective *D) {
10436 DeclarationNameInfo DirName;
10437 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10438 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10439 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10440 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10441 return Res;
10442}
10443
10444template <typename Derived>
10445StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
10446 OMPParallelGenericLoopDirective *D) {
10447 DeclarationNameInfo DirName;
10448 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10449 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10450 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10451 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10452 return Res;
10453}
10454
10455template <typename Derived>
10457TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10458 OMPTargetParallelGenericLoopDirective *D) {
10459 DeclarationNameInfo DirName;
10460 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10461 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10462 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10463 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10464 return Res;
10465}
10466
10467//===----------------------------------------------------------------------===//
10468// OpenMP clause transformation
10469//===----------------------------------------------------------------------===//
10470template <typename Derived>
10471OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10472 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10473 if (Cond.isInvalid())
10474 return nullptr;
10475 return getDerived().RebuildOMPIfClause(
10476 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10477 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10478}
10479
10480template <typename Derived>
10481OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10482 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10483 if (Cond.isInvalid())
10484 return nullptr;
10485 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10486 C->getLParenLoc(), C->getEndLoc());
10487}
10488
10489template <typename Derived>
10490OMPClause *
10491TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10492 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10493 if (NumThreads.isInvalid())
10494 return nullptr;
10495 return getDerived().RebuildOMPNumThreadsClause(
10496 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10497 C->getModifierLoc(), C->getEndLoc());
10498}
10499
10500template <typename Derived>
10501OMPClause *
10502TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10503 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10504 if (E.isInvalid())
10505 return nullptr;
10506 return getDerived().RebuildOMPSafelenClause(
10507 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10508}
10509
10510template <typename Derived>
10511OMPClause *
10512TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10513 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10514 if (E.isInvalid())
10515 return nullptr;
10516 return getDerived().RebuildOMPAllocatorClause(
10517 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10518}
10519
10520template <typename Derived>
10521OMPClause *
10522TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10523 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10524 if (E.isInvalid())
10525 return nullptr;
10526 return getDerived().RebuildOMPSimdlenClause(
10527 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10528}
10529
10530template <typename Derived>
10531OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10532 SmallVector<Expr *, 4> TransformedSizes;
10533 TransformedSizes.reserve(C->getNumSizes());
10534 bool Changed = false;
10535 for (Expr *E : C->getSizesRefs()) {
10536 if (!E) {
10537 TransformedSizes.push_back(nullptr);
10538 continue;
10539 }
10540
10541 ExprResult T = getDerived().TransformExpr(E);
10542 if (T.isInvalid())
10543 return nullptr;
10544 if (E != T.get())
10545 Changed = true;
10546 TransformedSizes.push_back(T.get());
10547 }
10548
10549 if (!Changed && !getDerived().AlwaysRebuild())
10550 return C;
10551 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10552 C->getLParenLoc(), C->getEndLoc());
10553}
10554
10555template <typename Derived>
10556OMPClause *
10557TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) {
10558 SmallVector<Expr *> TransformedArgs;
10559 TransformedArgs.reserve(C->getNumLoops());
10560 bool Changed = false;
10561 for (Expr *E : C->getArgsRefs()) {
10562 if (!E) {
10563 TransformedArgs.push_back(nullptr);
10564 continue;
10565 }
10566
10567 ExprResult T = getDerived().TransformExpr(E);
10568 if (T.isInvalid())
10569 return nullptr;
10570 if (E != T.get())
10571 Changed = true;
10572 TransformedArgs.push_back(T.get());
10573 }
10574
10575 if (!Changed && !getDerived().AlwaysRebuild())
10576 return C;
10577 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10578 C->getLParenLoc(), C->getEndLoc());
10579}
10580
10581template <typename Derived>
10582OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10583 if (!getDerived().AlwaysRebuild())
10584 return C;
10585 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10586}
10587
10588template <typename Derived>
10589OMPClause *
10590TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10591 ExprResult T = getDerived().TransformExpr(C->getFactor());
10592 if (T.isInvalid())
10593 return nullptr;
10594 Expr *Factor = T.get();
10595 bool Changed = Factor != C->getFactor();
10596
10597 if (!Changed && !getDerived().AlwaysRebuild())
10598 return C;
10599 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10600 C->getEndLoc());
10601}
10602
10603template <typename Derived>
10604OMPClause *
10605TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10606 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10607 if (E.isInvalid())
10608 return nullptr;
10609 return getDerived().RebuildOMPCollapseClause(
10610 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10611}
10612
10613template <typename Derived>
10614OMPClause *
10615TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10616 return getDerived().RebuildOMPDefaultClause(
10617 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10618 C->getLParenLoc(), C->getEndLoc());
10619}
10620
10621template <typename Derived>
10622OMPClause *
10623TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10624 return getDerived().RebuildOMPProcBindClause(
10625 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10626 C->getLParenLoc(), C->getEndLoc());
10627}
10628
10629template <typename Derived>
10630OMPClause *
10631TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10632 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10633 if (E.isInvalid())
10634 return nullptr;
10635 return getDerived().RebuildOMPScheduleClause(
10636 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10637 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10638 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10639 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10640}
10641
10642template <typename Derived>
10643OMPClause *
10644TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10645 ExprResult E;
10646 if (auto *Num = C->getNumForLoops()) {
10647 E = getDerived().TransformExpr(Num);
10648 if (E.isInvalid())
10649 return nullptr;
10650 }
10651 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10652 C->getLParenLoc(), E.get());
10653}
10654
10655template <typename Derived>
10656OMPClause *
10657TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10658 ExprResult E;
10659 if (Expr *Evt = C->getEventHandler()) {
10660 E = getDerived().TransformExpr(Evt);
10661 if (E.isInvalid())
10662 return nullptr;
10663 }
10664 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10665 C->getLParenLoc(), C->getEndLoc());
10666}
10667
10668template <typename Derived>
10669OMPClause *
10670TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10671 // No need to rebuild this clause, no template-dependent parameters.
10672 return C;
10673}
10674
10675template <typename Derived>
10676OMPClause *
10677TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10678 // No need to rebuild this clause, no template-dependent parameters.
10679 return C;
10680}
10681
10682template <typename Derived>
10683OMPClause *
10684TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10685 // No need to rebuild this clause, no template-dependent parameters.
10686 return C;
10687}
10688
10689template <typename Derived>
10690OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10691 // No need to rebuild this clause, no template-dependent parameters.
10692 return C;
10693}
10694
10695template <typename Derived>
10696OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10697 // No need to rebuild this clause, no template-dependent parameters.
10698 return C;
10699}
10700
10701template <typename Derived>
10702OMPClause *
10703TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10704 // No need to rebuild this clause, no template-dependent parameters.
10705 return C;
10706}
10707
10708template <typename Derived>
10709OMPClause *
10710TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10711 // No need to rebuild this clause, no template-dependent parameters.
10712 return C;
10713}
10714
10715template <typename Derived>
10716OMPClause *
10717TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10718 // No need to rebuild this clause, no template-dependent parameters.
10719 return C;
10720}
10721
10722template <typename Derived>
10723OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10724 // No need to rebuild this clause, no template-dependent parameters.
10725 return C;
10726}
10727
10728template <typename Derived>
10729OMPClause *
10730TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) {
10731 return C;
10732}
10733
10734template <typename Derived>
10735OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) {
10736 ExprResult E = getDerived().TransformExpr(C->getExpr());
10737 if (E.isInvalid())
10738 return nullptr;
10739 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10740 C->getLParenLoc(), C->getEndLoc());
10741}
10742
10743template <typename Derived>
10744OMPClause *
10745TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) {
10746 return C;
10747}
10748
10749template <typename Derived>
10750OMPClause *
10751TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) {
10752 return C;
10753}
10754template <typename Derived>
10755OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause(
10756 OMPNoOpenMPRoutinesClause *C) {
10757 return C;
10758}
10759template <typename Derived>
10760OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPConstructsClause(
10761 OMPNoOpenMPConstructsClause *C) {
10762 return C;
10763}
10764template <typename Derived>
10765OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause(
10766 OMPNoParallelismClause *C) {
10767 return C;
10768}
10769
10770template <typename Derived>
10771OMPClause *
10772TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10773 // No need to rebuild this clause, no template-dependent parameters.
10774 return C;
10775}
10776
10777template <typename Derived>
10778OMPClause *
10779TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10780 // No need to rebuild this clause, no template-dependent parameters.
10781 return C;
10782}
10783
10784template <typename Derived>
10785OMPClause *
10786TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10787 // No need to rebuild this clause, no template-dependent parameters.
10788 return C;
10789}
10790
10791template <typename Derived>
10792OMPClause *
10793TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10794 // No need to rebuild this clause, no template-dependent parameters.
10795 return C;
10796}
10797
10798template <typename Derived>
10799OMPClause *
10800TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10801 // No need to rebuild this clause, no template-dependent parameters.
10802 return C;
10803}
10804
10805template <typename Derived>
10806OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10807 // No need to rebuild this clause, no template-dependent parameters.
10808 return C;
10809}
10810
10811template <typename Derived>
10812OMPClause *
10813TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10814 // No need to rebuild this clause, no template-dependent parameters.
10815 return C;
10816}
10817
10818template <typename Derived>
10819OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10820 // No need to rebuild this clause, no template-dependent parameters.
10821 return C;
10822}
10823
10824template <typename Derived>
10825OMPClause *
10826TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10827 // No need to rebuild this clause, no template-dependent parameters.
10828 return C;
10829}
10830
10831template <typename Derived>
10832OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10833 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10834 if (IVR.isInvalid())
10835 return nullptr;
10836
10837 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10838 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10839 for (Expr *E : llvm::drop_begin(C->varlist())) {
10840 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10841 if (ER.isInvalid())
10842 return nullptr;
10843 InteropInfo.PreferTypes.push_back(ER.get());
10844 }
10845 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10846 C->getBeginLoc(), C->getLParenLoc(),
10847 C->getVarLoc(), C->getEndLoc());
10848}
10849
10850template <typename Derived>
10851OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10852 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10853 if (ER.isInvalid())
10854 return nullptr;
10855 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10856 C->getLParenLoc(), C->getVarLoc(),
10857 C->getEndLoc());
10858}
10859
10860template <typename Derived>
10861OMPClause *
10862TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10863 ExprResult ER;
10864 if (Expr *IV = C->getInteropVar()) {
10865 ER = getDerived().TransformExpr(IV);
10866 if (ER.isInvalid())
10867 return nullptr;
10868 }
10869 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10870 C->getLParenLoc(), C->getVarLoc(),
10871 C->getEndLoc());
10872}
10873
10874template <typename Derived>
10875OMPClause *
10876TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10877 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10878 if (Cond.isInvalid())
10879 return nullptr;
10880 return getDerived().RebuildOMPNovariantsClause(
10881 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10882}
10883
10884template <typename Derived>
10885OMPClause *
10886TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10887 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10888 if (Cond.isInvalid())
10889 return nullptr;
10890 return getDerived().RebuildOMPNocontextClause(
10891 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10892}
10893
10894template <typename Derived>
10895OMPClause *
10896TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10897 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10898 if (ThreadID.isInvalid())
10899 return nullptr;
10900 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10901 C->getLParenLoc(), C->getEndLoc());
10902}
10903
10904template <typename Derived>
10905OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10906 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10907 if (E.isInvalid())
10908 return nullptr;
10909 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10910 C->getLParenLoc(), C->getEndLoc());
10911}
10912
10913template <typename Derived>
10914OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10915 OMPUnifiedAddressClause *C) {
10916 llvm_unreachable("unified_address clause cannot appear in dependent context");
10917}
10918
10919template <typename Derived>
10920OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10921 OMPUnifiedSharedMemoryClause *C) {
10922 llvm_unreachable(
10923 "unified_shared_memory clause cannot appear in dependent context");
10924}
10925
10926template <typename Derived>
10927OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10928 OMPReverseOffloadClause *C) {
10929 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10930}
10931
10932template <typename Derived>
10933OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10934 OMPDynamicAllocatorsClause *C) {
10935 llvm_unreachable(
10936 "dynamic_allocators clause cannot appear in dependent context");
10937}
10938
10939template <typename Derived>
10940OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10941 OMPAtomicDefaultMemOrderClause *C) {
10942 llvm_unreachable(
10943 "atomic_default_mem_order clause cannot appear in dependent context");
10944}
10945
10946template <typename Derived>
10947OMPClause *
10948TreeTransform<Derived>::TransformOMPSelfMapsClause(OMPSelfMapsClause *C) {
10949 llvm_unreachable("self_maps clause cannot appear in dependent context");
10950}
10951
10952template <typename Derived>
10953OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10954 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10955 C->getBeginLoc(), C->getLParenLoc(),
10956 C->getEndLoc());
10957}
10958
10959template <typename Derived>
10960OMPClause *
10961TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10962 return getDerived().RebuildOMPSeverityClause(
10963 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10964 C->getLParenLoc(), C->getEndLoc());
10965}
10966
10967template <typename Derived>
10968OMPClause *
10969TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10970 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10971 if (E.isInvalid())
10972 return nullptr;
10973 return getDerived().RebuildOMPMessageClause(
10974 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10975}
10976
10977template <typename Derived>
10978OMPClause *
10979TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10981 Vars.reserve(C->varlist_size());
10982 for (auto *VE : C->varlist()) {
10983 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10984 if (EVar.isInvalid())
10985 return nullptr;
10986 Vars.push_back(EVar.get());
10987 }
10988 return getDerived().RebuildOMPPrivateClause(
10989 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10990}
10991
10992template <typename Derived>
10993OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10994 OMPFirstprivateClause *C) {
10996 Vars.reserve(C->varlist_size());
10997 for (auto *VE : C->varlist()) {
10998 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10999 if (EVar.isInvalid())
11000 return nullptr;
11001 Vars.push_back(EVar.get());
11002 }
11003 return getDerived().RebuildOMPFirstprivateClause(
11004 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11005}
11006
11007template <typename Derived>
11008OMPClause *
11009TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
11011 Vars.reserve(C->varlist_size());
11012 for (auto *VE : C->varlist()) {
11013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11014 if (EVar.isInvalid())
11015 return nullptr;
11016 Vars.push_back(EVar.get());
11017 }
11018 return getDerived().RebuildOMPLastprivateClause(
11019 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11020 C->getLParenLoc(), C->getEndLoc());
11021}
11022
11023template <typename Derived>
11024OMPClause *
11025TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
11027 Vars.reserve(C->varlist_size());
11028 for (auto *VE : C->varlist()) {
11029 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11030 if (EVar.isInvalid())
11031 return nullptr;
11032 Vars.push_back(EVar.get());
11033 }
11034 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11035 C->getLParenLoc(), C->getEndLoc());
11036}
11037
11038template <typename Derived>
11039OMPClause *
11040TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
11042 Vars.reserve(C->varlist_size());
11043 for (auto *VE : C->varlist()) {
11044 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11045 if (EVar.isInvalid())
11046 return nullptr;
11047 Vars.push_back(EVar.get());
11048 }
11049 CXXScopeSpec ReductionIdScopeSpec;
11050 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11051
11052 DeclarationNameInfo NameInfo = C->getNameInfo();
11053 if (NameInfo.getName()) {
11054 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11055 if (!NameInfo.getName())
11056 return nullptr;
11057 }
11058 // Build a list of all UDR decls with the same names ranged by the Scopes.
11059 // The Scope boundary is a duplication of the previous decl.
11060 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11061 for (auto *E : C->reduction_ops()) {
11062 // Transform all the decls.
11063 if (E) {
11064 auto *ULE = cast<UnresolvedLookupExpr>(E);
11065 UnresolvedSet<8> Decls;
11066 for (auto *D : ULE->decls()) {
11067 NamedDecl *InstD =
11068 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11069 Decls.addDecl(InstD, InstD->getAccess());
11070 }
11071 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11072 SemaRef.Context, /*NamingClass=*/nullptr,
11073 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11074 /*ADL=*/true, Decls.begin(), Decls.end(),
11075 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11076 } else
11077 UnresolvedReductions.push_back(nullptr);
11078 }
11079 return getDerived().RebuildOMPReductionClause(
11080 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11081 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11082 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11083}
11084
11085template <typename Derived>
11086OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
11087 OMPTaskReductionClause *C) {
11089 Vars.reserve(C->varlist_size());
11090 for (auto *VE : C->varlist()) {
11091 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11092 if (EVar.isInvalid())
11093 return nullptr;
11094 Vars.push_back(EVar.get());
11095 }
11096 CXXScopeSpec ReductionIdScopeSpec;
11097 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11098
11099 DeclarationNameInfo NameInfo = C->getNameInfo();
11100 if (NameInfo.getName()) {
11101 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11102 if (!NameInfo.getName())
11103 return nullptr;
11104 }
11105 // Build a list of all UDR decls with the same names ranged by the Scopes.
11106 // The Scope boundary is a duplication of the previous decl.
11107 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11108 for (auto *E : C->reduction_ops()) {
11109 // Transform all the decls.
11110 if (E) {
11111 auto *ULE = cast<UnresolvedLookupExpr>(E);
11112 UnresolvedSet<8> Decls;
11113 for (auto *D : ULE->decls()) {
11114 NamedDecl *InstD =
11115 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11116 Decls.addDecl(InstD, InstD->getAccess());
11117 }
11118 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11119 SemaRef.Context, /*NamingClass=*/nullptr,
11120 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11121 /*ADL=*/true, Decls.begin(), Decls.end(),
11122 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11123 } else
11124 UnresolvedReductions.push_back(nullptr);
11125 }
11126 return getDerived().RebuildOMPTaskReductionClause(
11127 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11128 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11129}
11130
11131template <typename Derived>
11132OMPClause *
11133TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
11135 Vars.reserve(C->varlist_size());
11136 for (auto *VE : C->varlist()) {
11137 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11138 if (EVar.isInvalid())
11139 return nullptr;
11140 Vars.push_back(EVar.get());
11141 }
11142 CXXScopeSpec ReductionIdScopeSpec;
11143 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11144
11145 DeclarationNameInfo NameInfo = C->getNameInfo();
11146 if (NameInfo.getName()) {
11147 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11148 if (!NameInfo.getName())
11149 return nullptr;
11150 }
11151 // Build a list of all UDR decls with the same names ranged by the Scopes.
11152 // The Scope boundary is a duplication of the previous decl.
11153 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11154 for (auto *E : C->reduction_ops()) {
11155 // Transform all the decls.
11156 if (E) {
11157 auto *ULE = cast<UnresolvedLookupExpr>(E);
11158 UnresolvedSet<8> Decls;
11159 for (auto *D : ULE->decls()) {
11160 NamedDecl *InstD =
11161 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11162 Decls.addDecl(InstD, InstD->getAccess());
11163 }
11164 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11165 SemaRef.Context, /*NamingClass=*/nullptr,
11166 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11167 /*ADL=*/true, Decls.begin(), Decls.end(),
11168 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11169 } else
11170 UnresolvedReductions.push_back(nullptr);
11171 }
11172 return getDerived().RebuildOMPInReductionClause(
11173 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11174 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11175}
11176
11177template <typename Derived>
11178OMPClause *
11179TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
11181 Vars.reserve(C->varlist_size());
11182 for (auto *VE : C->varlist()) {
11183 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11184 if (EVar.isInvalid())
11185 return nullptr;
11186 Vars.push_back(EVar.get());
11187 }
11188 ExprResult Step = getDerived().TransformExpr(C->getStep());
11189 if (Step.isInvalid())
11190 return nullptr;
11191 return getDerived().RebuildOMPLinearClause(
11192 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11193 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11194 C->getEndLoc());
11195}
11196
11197template <typename Derived>
11198OMPClause *
11199TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
11201 Vars.reserve(C->varlist_size());
11202 for (auto *VE : C->varlist()) {
11203 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11204 if (EVar.isInvalid())
11205 return nullptr;
11206 Vars.push_back(EVar.get());
11207 }
11208 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11209 if (Alignment.isInvalid())
11210 return nullptr;
11211 return getDerived().RebuildOMPAlignedClause(
11212 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11213 C->getColonLoc(), C->getEndLoc());
11214}
11215
11216template <typename Derived>
11217OMPClause *
11218TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
11220 Vars.reserve(C->varlist_size());
11221 for (auto *VE : C->varlist()) {
11222 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11223 if (EVar.isInvalid())
11224 return nullptr;
11225 Vars.push_back(EVar.get());
11226 }
11227 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11228 C->getLParenLoc(), C->getEndLoc());
11229}
11230
11231template <typename Derived>
11232OMPClause *
11233TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
11235 Vars.reserve(C->varlist_size());
11236 for (auto *VE : C->varlist()) {
11237 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11238 if (EVar.isInvalid())
11239 return nullptr;
11240 Vars.push_back(EVar.get());
11241 }
11242 return getDerived().RebuildOMPCopyprivateClause(
11243 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11244}
11245
11246template <typename Derived>
11247OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
11249 Vars.reserve(C->varlist_size());
11250 for (auto *VE : C->varlist()) {
11251 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11252 if (EVar.isInvalid())
11253 return nullptr;
11254 Vars.push_back(EVar.get());
11255 }
11256 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11257 C->getLParenLoc(), C->getEndLoc());
11258}
11259
11260template <typename Derived>
11261OMPClause *
11262TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
11263 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11264 if (E.isInvalid())
11265 return nullptr;
11266 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11267 C->getLParenLoc(), C->getEndLoc());
11268}
11269
11270template <typename Derived>
11271OMPClause *
11272TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
11274 Expr *DepModifier = C->getModifier();
11275 if (DepModifier) {
11276 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11277 if (DepModRes.isInvalid())
11278 return nullptr;
11279 DepModifier = DepModRes.get();
11280 }
11281 Vars.reserve(C->varlist_size());
11282 for (auto *VE : C->varlist()) {
11283 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11284 if (EVar.isInvalid())
11285 return nullptr;
11286 Vars.push_back(EVar.get());
11287 }
11288 return getDerived().RebuildOMPDependClause(
11289 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11290 C->getOmpAllMemoryLoc()},
11291 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11292}
11293
11294template <typename Derived>
11295OMPClause *
11296TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
11297 ExprResult E = getDerived().TransformExpr(C->getDevice());
11298 if (E.isInvalid())
11299 return nullptr;
11300 return getDerived().RebuildOMPDeviceClause(
11301 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11302 C->getModifierLoc(), C->getEndLoc());
11303}
11304
11305template <typename Derived, class T>
11308 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11309 DeclarationNameInfo &MapperIdInfo,
11310 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11311 // Transform expressions in the list.
11312 Vars.reserve(C->varlist_size());
11313 for (auto *VE : C->varlist()) {
11314 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11315 if (EVar.isInvalid())
11316 return true;
11317 Vars.push_back(EVar.get());
11318 }
11319 // Transform mapper scope specifier and identifier.
11320 NestedNameSpecifierLoc QualifierLoc;
11321 if (C->getMapperQualifierLoc()) {
11322 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11323 C->getMapperQualifierLoc());
11324 if (!QualifierLoc)
11325 return true;
11326 }
11327 MapperIdScopeSpec.Adopt(QualifierLoc);
11328 MapperIdInfo = C->getMapperIdInfo();
11329 if (MapperIdInfo.getName()) {
11330 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11331 if (!MapperIdInfo.getName())
11332 return true;
11333 }
11334 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11335 // the previous user-defined mapper lookup in dependent environment.
11336 for (auto *E : C->mapperlists()) {
11337 // Transform all the decls.
11338 if (E) {
11339 auto *ULE = cast<UnresolvedLookupExpr>(E);
11340 UnresolvedSet<8> Decls;
11341 for (auto *D : ULE->decls()) {
11342 NamedDecl *InstD =
11343 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11344 Decls.addDecl(InstD, InstD->getAccess());
11345 }
11346 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11347 TT.getSema().Context, /*NamingClass=*/nullptr,
11348 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11349 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11350 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11351 } else {
11352 UnresolvedMappers.push_back(nullptr);
11353 }
11354 }
11355 return false;
11356}
11357
11358template <typename Derived>
11359OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11360 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11362 Expr *IteratorModifier = C->getIteratorModifier();
11363 if (IteratorModifier) {
11364 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11365 if (MapModRes.isInvalid())
11366 return nullptr;
11367 IteratorModifier = MapModRes.get();
11368 }
11369 CXXScopeSpec MapperIdScopeSpec;
11370 DeclarationNameInfo MapperIdInfo;
11371 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11372 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
11373 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11374 return nullptr;
11375 return getDerived().RebuildOMPMapClause(
11376 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11377 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11378 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11379}
11380
11381template <typename Derived>
11382OMPClause *
11383TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
11384 Expr *Allocator = C->getAllocator();
11385 if (Allocator) {
11386 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11387 if (AllocatorRes.isInvalid())
11388 return nullptr;
11389 Allocator = AllocatorRes.get();
11390 }
11391 Expr *Alignment = C->getAlignment();
11392 if (Alignment) {
11393 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11394 if (AlignmentRes.isInvalid())
11395 return nullptr;
11396 Alignment = AlignmentRes.get();
11397 }
11399 Vars.reserve(C->varlist_size());
11400 for (auto *VE : C->varlist()) {
11401 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11402 if (EVar.isInvalid())
11403 return nullptr;
11404 Vars.push_back(EVar.get());
11405 }
11406 return getDerived().RebuildOMPAllocateClause(
11407 Allocator, Alignment, C->getFirstAllocateModifier(),
11408 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11409 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11410 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11411}
11412
11413template <typename Derived>
11414OMPClause *
11415TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
11417 Vars.reserve(C->varlist_size());
11418 for (auto *VE : C->varlist()) {
11419 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11420 if (EVar.isInvalid())
11421 return nullptr;
11422 Vars.push_back(EVar.get());
11423 }
11424 return getDerived().RebuildOMPNumTeamsClause(
11425 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11426}
11427
11428template <typename Derived>
11429OMPClause *
11430TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
11432 Vars.reserve(C->varlist_size());
11433 for (auto *VE : C->varlist()) {
11434 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11435 if (EVar.isInvalid())
11436 return nullptr;
11437 Vars.push_back(EVar.get());
11438 }
11439 return getDerived().RebuildOMPThreadLimitClause(
11440 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11441}
11442
11443template <typename Derived>
11444OMPClause *
11445TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
11446 ExprResult E = getDerived().TransformExpr(C->getPriority());
11447 if (E.isInvalid())
11448 return nullptr;
11449 return getDerived().RebuildOMPPriorityClause(
11450 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11451}
11452
11453template <typename Derived>
11454OMPClause *
11455TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
11456 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11457 if (E.isInvalid())
11458 return nullptr;
11459 return getDerived().RebuildOMPGrainsizeClause(
11460 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11461 C->getModifierLoc(), C->getEndLoc());
11462}
11463
11464template <typename Derived>
11465OMPClause *
11466TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
11467 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11468 if (E.isInvalid())
11469 return nullptr;
11470 return getDerived().RebuildOMPNumTasksClause(
11471 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11472 C->getModifierLoc(), C->getEndLoc());
11473}
11474
11475template <typename Derived>
11476OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
11477 ExprResult E = getDerived().TransformExpr(C->getHint());
11478 if (E.isInvalid())
11479 return nullptr;
11480 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11481 C->getLParenLoc(), C->getEndLoc());
11482}
11483
11484template <typename Derived>
11485OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
11486 OMPDistScheduleClause *C) {
11487 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11488 if (E.isInvalid())
11489 return nullptr;
11490 return getDerived().RebuildOMPDistScheduleClause(
11491 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11492 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11493}
11494
11495template <typename Derived>
11496OMPClause *
11497TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
11498 // Rebuild Defaultmap Clause since we need to invoke the checking of
11499 // defaultmap(none:variable-category) after template initialization.
11500 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11501 C->getDefaultmapKind(),
11502 C->getBeginLoc(),
11503 C->getLParenLoc(),
11504 C->getDefaultmapModifierLoc(),
11505 C->getDefaultmapKindLoc(),
11506 C->getEndLoc());
11507}
11508
11509template <typename Derived>
11510OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
11511 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11513 CXXScopeSpec MapperIdScopeSpec;
11514 DeclarationNameInfo MapperIdInfo;
11515 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11516 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
11517 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11518 return nullptr;
11519 return getDerived().RebuildOMPToClause(
11520 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11521 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11522}
11523
11524template <typename Derived>
11525OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
11526 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11528 CXXScopeSpec MapperIdScopeSpec;
11529 DeclarationNameInfo MapperIdInfo;
11530 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11531 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
11532 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11533 return nullptr;
11534 return getDerived().RebuildOMPFromClause(
11535 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11536 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11537}
11538
11539template <typename Derived>
11540OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
11541 OMPUseDevicePtrClause *C) {
11543 Vars.reserve(C->varlist_size());
11544 for (auto *VE : C->varlist()) {
11545 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11546 if (EVar.isInvalid())
11547 return nullptr;
11548 Vars.push_back(EVar.get());
11549 }
11550 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11551 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11552}
11553
11554template <typename Derived>
11555OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11556 OMPUseDeviceAddrClause *C) {
11558 Vars.reserve(C->varlist_size());
11559 for (auto *VE : C->varlist()) {
11560 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11561 if (EVar.isInvalid())
11562 return nullptr;
11563 Vars.push_back(EVar.get());
11564 }
11565 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11566 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11567}
11568
11569template <typename Derived>
11570OMPClause *
11571TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
11573 Vars.reserve(C->varlist_size());
11574 for (auto *VE : C->varlist()) {
11575 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11576 if (EVar.isInvalid())
11577 return nullptr;
11578 Vars.push_back(EVar.get());
11579 }
11580 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11581 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11582}
11583
11584template <typename Derived>
11585OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11586 OMPHasDeviceAddrClause *C) {
11588 Vars.reserve(C->varlist_size());
11589 for (auto *VE : C->varlist()) {
11590 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11591 if (EVar.isInvalid())
11592 return nullptr;
11593 Vars.push_back(EVar.get());
11594 }
11595 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11596 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11597}
11598
11599template <typename Derived>
11600OMPClause *
11601TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
11603 Vars.reserve(C->varlist_size());
11604 for (auto *VE : C->varlist()) {
11605 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11606 if (EVar.isInvalid())
11607 return nullptr;
11608 Vars.push_back(EVar.get());
11609 }
11610 return getDerived().RebuildOMPNontemporalClause(
11611 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11612}
11613
11614template <typename Derived>
11615OMPClause *
11616TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11618 Vars.reserve(C->varlist_size());
11619 for (auto *VE : C->varlist()) {
11620 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11621 if (EVar.isInvalid())
11622 return nullptr;
11623 Vars.push_back(EVar.get());
11624 }
11625 return getDerived().RebuildOMPInclusiveClause(
11626 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11627}
11628
11629template <typename Derived>
11630OMPClause *
11631TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11633 Vars.reserve(C->varlist_size());
11634 for (auto *VE : C->varlist()) {
11635 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11636 if (EVar.isInvalid())
11637 return nullptr;
11638 Vars.push_back(EVar.get());
11639 }
11640 return getDerived().RebuildOMPExclusiveClause(
11641 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11642}
11643
11644template <typename Derived>
11645OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11646 OMPUsesAllocatorsClause *C) {
11648 Data.reserve(C->getNumberOfAllocators());
11649 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11650 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11651 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11652 if (Allocator.isInvalid())
11653 continue;
11654 ExprResult AllocatorTraits;
11655 if (Expr *AT = D.AllocatorTraits) {
11656 AllocatorTraits = getDerived().TransformExpr(AT);
11657 if (AllocatorTraits.isInvalid())
11658 continue;
11659 }
11660 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11661 NewD.Allocator = Allocator.get();
11662 NewD.AllocatorTraits = AllocatorTraits.get();
11663 NewD.LParenLoc = D.LParenLoc;
11664 NewD.RParenLoc = D.RParenLoc;
11665 }
11666 return getDerived().RebuildOMPUsesAllocatorsClause(
11667 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11668}
11669
11670template <typename Derived>
11671OMPClause *
11672TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11673 SmallVector<Expr *, 4> Locators;
11674 Locators.reserve(C->varlist_size());
11675 ExprResult ModifierRes;
11676 if (Expr *Modifier = C->getModifier()) {
11677 ModifierRes = getDerived().TransformExpr(Modifier);
11678 if (ModifierRes.isInvalid())
11679 return nullptr;
11680 }
11681 for (Expr *E : C->varlist()) {
11682 ExprResult Locator = getDerived().TransformExpr(E);
11683 if (Locator.isInvalid())
11684 continue;
11685 Locators.push_back(Locator.get());
11686 }
11687 return getDerived().RebuildOMPAffinityClause(
11688 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11689 ModifierRes.get(), Locators);
11690}
11691
11692template <typename Derived>
11693OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11694 return getDerived().RebuildOMPOrderClause(
11695 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11696 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11697}
11698
11699template <typename Derived>
11700OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11701 return getDerived().RebuildOMPBindClause(
11702 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11703 C->getLParenLoc(), C->getEndLoc());
11704}
11705
11706template <typename Derived>
11707OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11708 OMPXDynCGroupMemClause *C) {
11709 ExprResult Size = getDerived().TransformExpr(C->getSize());
11710 if (Size.isInvalid())
11711 return nullptr;
11712 return getDerived().RebuildOMPXDynCGroupMemClause(
11713 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11714}
11715
11716template <typename Derived>
11717OMPClause *
11718TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11720 Vars.reserve(C->varlist_size());
11721 for (auto *VE : C->varlist()) {
11722 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11723 if (EVar.isInvalid())
11724 return nullptr;
11725 Vars.push_back(EVar.get());
11726 }
11727 return getDerived().RebuildOMPDoacrossClause(
11728 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11729 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11730}
11731
11732template <typename Derived>
11733OMPClause *
11734TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11736 for (auto *A : C->getAttrs())
11737 NewAttrs.push_back(getDerived().TransformAttr(A));
11738 return getDerived().RebuildOMPXAttributeClause(
11739 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11740}
11741
11742template <typename Derived>
11743OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11744 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11745}
11746
11747//===----------------------------------------------------------------------===//
11748// OpenACC transformation
11749//===----------------------------------------------------------------------===//
11750namespace {
11751template <typename Derived>
11752class OpenACCClauseTransform final
11753 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11754 TreeTransform<Derived> &Self;
11755 ArrayRef<const OpenACCClause *> ExistingClauses;
11756 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11757 OpenACCClause *NewClause = nullptr;
11758
11759 ExprResult VisitVar(Expr *VarRef) {
11760 ExprResult Res = Self.TransformExpr(VarRef);
11761
11762 if (!Res.isUsable())
11763 return Res;
11764
11765 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11766 ParsedClause.getClauseKind(),
11767 Res.get());
11768
11769 return Res;
11770 }
11771
11772 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11773 llvm::SmallVector<Expr *> InstantiatedVarList;
11774 for (Expr *CurVar : VarList) {
11775 ExprResult VarRef = VisitVar(CurVar);
11776
11777 if (VarRef.isUsable())
11778 InstantiatedVarList.push_back(VarRef.get());
11779 }
11780
11781 return InstantiatedVarList;
11782 }
11783
11784public:
11785 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11786 ArrayRef<const OpenACCClause *> ExistingClauses,
11787 SemaOpenACC::OpenACCParsedClause &PC)
11788 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11789
11790 OpenACCClause *CreatedClause() const { return NewClause; }
11791
11792#define VISIT_CLAUSE(CLAUSE_NAME) \
11793 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11794#include "clang/Basic/OpenACCClauses.def"
11795};
11796
11797template <typename Derived>
11798void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11799 const OpenACCDefaultClause &C) {
11800 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11801
11802 NewClause = OpenACCDefaultClause::Create(
11803 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11804 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11805 ParsedClause.getEndLoc());
11806}
11807
11808template <typename Derived>
11809void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11810 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11811 assert(Cond && "If constructed with invalid Condition");
11812 Sema::ConditionResult Res = Self.TransformCondition(
11813 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11814
11815 if (Res.isInvalid() || !Res.get().second)
11816 return;
11817
11818 ParsedClause.setConditionDetails(Res.get().second);
11819
11820 NewClause = OpenACCIfClause::Create(
11821 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11822 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11823 ParsedClause.getEndLoc());
11824}
11825
11826template <typename Derived>
11827void OpenACCClauseTransform<Derived>::VisitSelfClause(
11828 const OpenACCSelfClause &C) {
11829
11830 // If this is an 'update' 'self' clause, this is actually a var list instead.
11831 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11832 llvm::SmallVector<Expr *> InstantiatedVarList;
11833 for (Expr *CurVar : C.getVarList()) {
11834 ExprResult Res = Self.TransformExpr(CurVar);
11835
11836 if (!Res.isUsable())
11837 continue;
11838
11839 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
11840 ParsedClause.getClauseKind(),
11841 Res.get());
11842
11843 if (Res.isUsable())
11844 InstantiatedVarList.push_back(Res.get());
11845 }
11846
11847 ParsedClause.setVarListDetails(InstantiatedVarList,
11849
11850 NewClause = OpenACCSelfClause::Create(
11851 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11852 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11853 ParsedClause.getEndLoc());
11854 } else {
11855
11856 if (C.hasConditionExpr()) {
11857 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11858 Sema::ConditionResult Res =
11859 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11861
11862 if (Res.isInvalid() || !Res.get().second)
11863 return;
11864
11865 ParsedClause.setConditionDetails(Res.get().second);
11866 }
11867
11868 NewClause = OpenACCSelfClause::Create(
11869 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11870 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11871 ParsedClause.getEndLoc());
11872 }
11873}
11874
11875template <typename Derived>
11876void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11877 const OpenACCNumGangsClause &C) {
11878 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11879
11880 for (Expr *CurIntExpr : C.getIntExprs()) {
11881 ExprResult Res = Self.TransformExpr(CurIntExpr);
11882
11883 if (!Res.isUsable())
11884 return;
11885
11886 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11887 C.getClauseKind(),
11888 C.getBeginLoc(), Res.get());
11889 if (!Res.isUsable())
11890 return;
11891
11892 InstantiatedIntExprs.push_back(Res.get());
11893 }
11894
11895 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11897 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11898 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11899 ParsedClause.getEndLoc());
11900}
11901
11902template <typename Derived>
11903void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11904 const OpenACCPrivateClause &C) {
11905 llvm::SmallVector<Expr *> InstantiatedVarList;
11906 llvm::SmallVector<VarDecl *> InitRecipes;
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)
11918 InitRecipes.push_back(InitRecipe);
11919 else
11920 InitRecipes.push_back(
11921 Self.getSema()
11922 .OpenACC()
11923 .CreateInitRecipe(OpenACCClauseKind::Private, VarRef.get())
11924 .first);
11925 }
11926 }
11927 ParsedClause.setVarListDetails(InstantiatedVarList,
11929
11930 NewClause = OpenACCPrivateClause::Create(
11931 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11932 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11933 ParsedClause.getEndLoc());
11934}
11935
11936template <typename Derived>
11937void OpenACCClauseTransform<Derived>::VisitHostClause(
11938 const OpenACCHostClause &C) {
11939 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11941
11942 NewClause = OpenACCHostClause::Create(
11943 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11944 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11945 ParsedClause.getEndLoc());
11946}
11947
11948template <typename Derived>
11949void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11950 const OpenACCDeviceClause &C) {
11951 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11953
11954 NewClause = OpenACCDeviceClause::Create(
11955 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11956 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11957 ParsedClause.getEndLoc());
11958}
11959
11960template <typename Derived>
11961void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11962 const OpenACCFirstPrivateClause &C) {
11963 llvm::SmallVector<Expr *> InstantiatedVarList;
11965
11966 for (const auto [RefExpr, InitRecipe] :
11967 llvm::zip(C.getVarList(), C.getInitRecipes())) {
11968 ExprResult VarRef = VisitVar(RefExpr);
11969
11970 if (VarRef.isUsable()) {
11971 InstantiatedVarList.push_back(VarRef.get());
11972
11973 // We only have to create a new one if it is dependent, and Sema won't
11974 // make one of these unless the type is non-dependent.
11975 if (InitRecipe.RecipeDecl)
11976 InitRecipes.push_back(InitRecipe);
11977 else
11978 InitRecipes.push_back(Self.getSema().OpenACC().CreateInitRecipe(
11979 OpenACCClauseKind::FirstPrivate, VarRef.get()));
11980 }
11981 }
11982 ParsedClause.setVarListDetails(InstantiatedVarList,
11984
11986 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11987 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
11988 ParsedClause.getEndLoc());
11989}
11990
11991template <typename Derived>
11992void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11993 const OpenACCNoCreateClause &C) {
11994 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11996
11998 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11999 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12000 ParsedClause.getEndLoc());
12001}
12002
12003template <typename Derived>
12004void OpenACCClauseTransform<Derived>::VisitPresentClause(
12005 const OpenACCPresentClause &C) {
12006 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12008
12009 NewClause = OpenACCPresentClause::Create(
12010 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12011 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12012 ParsedClause.getEndLoc());
12013}
12014
12015template <typename Derived>
12016void OpenACCClauseTransform<Derived>::VisitCopyClause(
12017 const OpenACCCopyClause &C) {
12018 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12019 C.getModifierList());
12020
12021 NewClause = OpenACCCopyClause::Create(
12022 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12023 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12024 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12025 ParsedClause.getEndLoc());
12026}
12027
12028template <typename Derived>
12029void OpenACCClauseTransform<Derived>::VisitLinkClause(
12030 const OpenACCLinkClause &C) {
12031 llvm_unreachable("link clause not valid unless a decl transform");
12032}
12033
12034template <typename Derived>
12035void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12036 const OpenACCDeviceResidentClause &C) {
12037 llvm_unreachable("device_resident clause not valid unless a decl transform");
12038}
12039template <typename Derived>
12040void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12041 const OpenACCNoHostClause &C) {
12042 llvm_unreachable("nohost clause not valid unless a decl transform");
12043}
12044template <typename Derived>
12045void OpenACCClauseTransform<Derived>::VisitBindClause(
12046 const OpenACCBindClause &C) {
12047 llvm_unreachable("bind clause not valid unless a decl transform");
12048}
12049
12050template <typename Derived>
12051void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12052 const OpenACCCopyInClause &C) {
12053 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12054 C.getModifierList());
12055
12056 NewClause = OpenACCCopyInClause::Create(
12057 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12058 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12059 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12060 ParsedClause.getEndLoc());
12061}
12062
12063template <typename Derived>
12064void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12065 const OpenACCCopyOutClause &C) {
12066 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12067 C.getModifierList());
12068
12069 NewClause = OpenACCCopyOutClause::Create(
12070 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12071 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12072 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12073 ParsedClause.getEndLoc());
12074}
12075
12076template <typename Derived>
12077void OpenACCClauseTransform<Derived>::VisitCreateClause(
12078 const OpenACCCreateClause &C) {
12079 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12080 C.getModifierList());
12081
12082 NewClause = OpenACCCreateClause::Create(
12083 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12084 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12085 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12086 ParsedClause.getEndLoc());
12087}
12088template <typename Derived>
12089void OpenACCClauseTransform<Derived>::VisitAttachClause(
12090 const OpenACCAttachClause &C) {
12091 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12092
12093 // Ensure each var is a pointer type.
12094 llvm::erase_if(VarList, [&](Expr *E) {
12095 return Self.getSema().OpenACC().CheckVarIsPointerType(
12097 });
12098
12099 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12100 NewClause = OpenACCAttachClause::Create(
12101 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12102 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12103 ParsedClause.getEndLoc());
12104}
12105
12106template <typename Derived>
12107void OpenACCClauseTransform<Derived>::VisitDetachClause(
12108 const OpenACCDetachClause &C) {
12109 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12110
12111 // Ensure each var is a pointer type.
12112 llvm::erase_if(VarList, [&](Expr *E) {
12113 return Self.getSema().OpenACC().CheckVarIsPointerType(
12115 });
12116
12117 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12118 NewClause = OpenACCDetachClause::Create(
12119 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12120 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12121 ParsedClause.getEndLoc());
12122}
12123
12124template <typename Derived>
12125void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12126 const OpenACCDeleteClause &C) {
12127 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12129 NewClause = OpenACCDeleteClause::Create(
12130 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12131 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12132 ParsedClause.getEndLoc());
12133}
12134
12135template <typename Derived>
12136void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12137 const OpenACCUseDeviceClause &C) {
12138 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12141 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12142 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12143 ParsedClause.getEndLoc());
12144}
12145
12146template <typename Derived>
12147void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12148 const OpenACCDevicePtrClause &C) {
12149 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12150
12151 // Ensure each var is a pointer type.
12152 llvm::erase_if(VarList, [&](Expr *E) {
12153 return Self.getSema().OpenACC().CheckVarIsPointerType(
12155 });
12156
12157 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12159 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12160 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12161 ParsedClause.getEndLoc());
12162}
12163
12164template <typename Derived>
12165void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12166 const OpenACCNumWorkersClause &C) {
12167 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12168 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12169
12170 ExprResult Res = Self.TransformExpr(IntExpr);
12171 if (!Res.isUsable())
12172 return;
12173
12174 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12175 C.getClauseKind(),
12176 C.getBeginLoc(), Res.get());
12177 if (!Res.isUsable())
12178 return;
12179
12180 ParsedClause.setIntExprDetails(Res.get());
12182 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12183 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12184 ParsedClause.getEndLoc());
12185}
12186
12187template <typename Derived>
12188void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12189 const OpenACCDeviceNumClause &C) {
12190 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12191 assert(IntExpr && "device_num clause constructed with invalid int expr");
12192
12193 ExprResult Res = Self.TransformExpr(IntExpr);
12194 if (!Res.isUsable())
12195 return;
12196
12197 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12198 C.getClauseKind(),
12199 C.getBeginLoc(), Res.get());
12200 if (!Res.isUsable())
12201 return;
12202
12203 ParsedClause.setIntExprDetails(Res.get());
12205 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12206 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12207 ParsedClause.getEndLoc());
12208}
12209
12210template <typename Derived>
12211void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12212 const OpenACCDefaultAsyncClause &C) {
12213 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12214 assert(IntExpr && "default_async clause constructed with invalid int expr");
12215
12216 ExprResult Res = Self.TransformExpr(IntExpr);
12217 if (!Res.isUsable())
12218 return;
12219
12220 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12221 C.getClauseKind(),
12222 C.getBeginLoc(), Res.get());
12223 if (!Res.isUsable())
12224 return;
12225
12226 ParsedClause.setIntExprDetails(Res.get());
12228 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12229 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12230 ParsedClause.getEndLoc());
12231}
12232
12233template <typename Derived>
12234void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12235 const OpenACCVectorLengthClause &C) {
12236 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12237 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12238
12239 ExprResult Res = Self.TransformExpr(IntExpr);
12240 if (!Res.isUsable())
12241 return;
12242
12243 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12244 C.getClauseKind(),
12245 C.getBeginLoc(), Res.get());
12246 if (!Res.isUsable())
12247 return;
12248
12249 ParsedClause.setIntExprDetails(Res.get());
12251 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12252 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12253 ParsedClause.getEndLoc());
12254}
12255
12256template <typename Derived>
12257void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12258 const OpenACCAsyncClause &C) {
12259 if (C.hasIntExpr()) {
12260 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12261 if (!Res.isUsable())
12262 return;
12263
12264 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12265 C.getClauseKind(),
12266 C.getBeginLoc(), Res.get());
12267 if (!Res.isUsable())
12268 return;
12269 ParsedClause.setIntExprDetails(Res.get());
12270 }
12271
12272 NewClause = OpenACCAsyncClause::Create(
12273 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12274 ParsedClause.getLParenLoc(),
12275 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12276 : nullptr,
12277 ParsedClause.getEndLoc());
12278}
12279
12280template <typename Derived>
12281void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12282 const OpenACCWorkerClause &C) {
12283 if (C.hasIntExpr()) {
12284 // restrictions on this expression are all "does it exist in certain
12285 // situations" that are not possible to be dependent, so the only check we
12286 // have is that it transforms, and is an int expression.
12287 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12288 if (!Res.isUsable())
12289 return;
12290
12291 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12292 C.getClauseKind(),
12293 C.getBeginLoc(), Res.get());
12294 if (!Res.isUsable())
12295 return;
12296 ParsedClause.setIntExprDetails(Res.get());
12297 }
12298
12299 NewClause = OpenACCWorkerClause::Create(
12300 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12301 ParsedClause.getLParenLoc(),
12302 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12303 : nullptr,
12304 ParsedClause.getEndLoc());
12305}
12306
12307template <typename Derived>
12308void OpenACCClauseTransform<Derived>::VisitVectorClause(
12309 const OpenACCVectorClause &C) {
12310 if (C.hasIntExpr()) {
12311 // restrictions on this expression are all "does it exist in certain
12312 // situations" that are not possible to be dependent, so the only check we
12313 // have is that it transforms, and is an int expression.
12314 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12315 if (!Res.isUsable())
12316 return;
12317
12318 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12319 C.getClauseKind(),
12320 C.getBeginLoc(), Res.get());
12321 if (!Res.isUsable())
12322 return;
12323 ParsedClause.setIntExprDetails(Res.get());
12324 }
12325
12326 NewClause = OpenACCVectorClause::Create(
12327 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12328 ParsedClause.getLParenLoc(),
12329 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12330 : nullptr,
12331 ParsedClause.getEndLoc());
12332}
12333
12334template <typename Derived>
12335void OpenACCClauseTransform<Derived>::VisitWaitClause(
12336 const OpenACCWaitClause &C) {
12337 if (C.hasExprs()) {
12338 Expr *DevNumExpr = nullptr;
12339 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12340
12341 // Instantiate devnum expr if it exists.
12342 if (C.getDevNumExpr()) {
12343 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12344 if (!Res.isUsable())
12345 return;
12346 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12347 C.getClauseKind(),
12348 C.getBeginLoc(), Res.get());
12349 if (!Res.isUsable())
12350 return;
12351
12352 DevNumExpr = Res.get();
12353 }
12354
12355 // Instantiate queue ids.
12356 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12357 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12358 if (!Res.isUsable())
12359 return;
12360 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12361 C.getClauseKind(),
12362 C.getBeginLoc(), Res.get());
12363 if (!Res.isUsable())
12364 return;
12365
12366 InstantiatedQueueIdExprs.push_back(Res.get());
12367 }
12368
12369 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12370 std::move(InstantiatedQueueIdExprs));
12371 }
12372
12373 NewClause = OpenACCWaitClause::Create(
12374 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12375 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12376 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12377 ParsedClause.getEndLoc());
12378}
12379
12380template <typename Derived>
12381void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12382 const OpenACCDeviceTypeClause &C) {
12383 // Nothing to transform here, just create a new version of 'C'.
12385 Self.getSema().getASTContext(), C.getClauseKind(),
12386 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12387 C.getArchitectures(), ParsedClause.getEndLoc());
12388}
12389
12390template <typename Derived>
12391void OpenACCClauseTransform<Derived>::VisitAutoClause(
12392 const OpenACCAutoClause &C) {
12393 // Nothing to do, so just create a new node.
12394 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12395 ParsedClause.getBeginLoc(),
12396 ParsedClause.getEndLoc());
12397}
12398
12399template <typename Derived>
12400void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12401 const OpenACCIndependentClause &C) {
12402 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12403 ParsedClause.getBeginLoc(),
12404 ParsedClause.getEndLoc());
12405}
12406
12407template <typename Derived>
12408void OpenACCClauseTransform<Derived>::VisitSeqClause(
12409 const OpenACCSeqClause &C) {
12410 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12411 ParsedClause.getBeginLoc(),
12412 ParsedClause.getEndLoc());
12413}
12414template <typename Derived>
12415void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12416 const OpenACCFinalizeClause &C) {
12417 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12418 ParsedClause.getBeginLoc(),
12419 ParsedClause.getEndLoc());
12420}
12421
12422template <typename Derived>
12423void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12424 const OpenACCIfPresentClause &C) {
12425 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12426 ParsedClause.getBeginLoc(),
12427 ParsedClause.getEndLoc());
12428}
12429
12430template <typename Derived>
12431void OpenACCClauseTransform<Derived>::VisitReductionClause(
12432 const OpenACCReductionClause &C) {
12433 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12434 SmallVector<Expr *> ValidVars;
12436
12437 for (const auto [Var, OrigRecipes] :
12438 llvm::zip(TransformedVars, C.getRecipes())) {
12439 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12440 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12441 if (Res.isUsable()) {
12442 ValidVars.push_back(Res.get());
12443
12444 // TODO OpenACC: When the recipe changes, make sure we get these right
12445 // too. We probably need something similar for the operation.
12446 static_assert(sizeof(OpenACCReductionRecipe) == sizeof(int*));
12447 VarDecl *InitRecipe = nullptr;
12448 if (OrigRecipes.RecipeDecl)
12449 InitRecipe = OrigRecipes.RecipeDecl;
12450 else
12451 InitRecipe = Self.getSema()
12452 .OpenACC()
12453 .CreateInitRecipe(OpenACCClauseKind::Reduction,
12454 C.getReductionOp(), Res.get())
12455 .first;
12456
12457 Recipes.push_back({InitRecipe});
12458 }
12459 }
12460
12461 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12462 ExistingClauses, ParsedClause.getDirectiveKind(),
12463 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12464 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12465}
12466
12467template <typename Derived>
12468void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12469 const OpenACCCollapseClause &C) {
12470 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12471 assert(LoopCount && "collapse clause constructed with invalid loop count");
12472
12473 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12474
12475 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12477 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12478
12479 NewLoopCount =
12480 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12481
12482 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12484 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12485 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12486 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12487}
12488
12489template <typename Derived>
12490void OpenACCClauseTransform<Derived>::VisitTileClause(
12491 const OpenACCTileClause &C) {
12492
12493 llvm::SmallVector<Expr *> TransformedExprs;
12494
12495 for (Expr *E : C.getSizeExprs()) {
12496 ExprResult NewSizeExpr = Self.TransformExpr(E);
12497
12498 if (!NewSizeExpr.isUsable())
12499 return;
12500
12501 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12503 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12504
12505 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12506
12507 if (!NewSizeExpr.isUsable())
12508 return;
12509 TransformedExprs.push_back(NewSizeExpr.get());
12510 }
12511
12512 ParsedClause.setIntExprDetails(TransformedExprs);
12513 NewClause = OpenACCTileClause::Create(
12514 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12515 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12516 ParsedClause.getEndLoc());
12517}
12518template <typename Derived>
12519void OpenACCClauseTransform<Derived>::VisitGangClause(
12520 const OpenACCGangClause &C) {
12521 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12522 llvm::SmallVector<Expr *> TransformedIntExprs;
12523
12524 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12525 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12526 if (!ER.isUsable())
12527 continue;
12528
12529 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12530 ParsedClause.getDirectiveKind(),
12531 C.getExpr(I).first, ER.get());
12532 if (!ER.isUsable())
12533 continue;
12534 TransformedGangKinds.push_back(C.getExpr(I).first);
12535 TransformedIntExprs.push_back(ER.get());
12536 }
12537
12538 NewClause = Self.getSema().OpenACC().CheckGangClause(
12539 ParsedClause.getDirectiveKind(), ExistingClauses,
12540 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12541 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12542}
12543} // namespace
12544template <typename Derived>
12545OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12546 ArrayRef<const OpenACCClause *> ExistingClauses,
12547 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12548
12549 SemaOpenACC::OpenACCParsedClause ParsedClause(
12550 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12551 ParsedClause.setEndLoc(OldClause->getEndLoc());
12552
12553 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12554 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12555
12556 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12557 ParsedClause};
12558 Transform.Visit(OldClause);
12559
12560 return Transform.CreatedClause();
12561}
12562
12563template <typename Derived>
12565TreeTransform<Derived>::TransformOpenACCClauseList(
12567 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12568 for (const auto *Clause : OldClauses) {
12569 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12570 TransformedClauses, DirKind, Clause))
12571 TransformedClauses.push_back(TransformedClause);
12572 }
12573 return TransformedClauses;
12574}
12575
12576template <typename Derived>
12577StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
12578 OpenACCComputeConstruct *C) {
12579 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12580
12581 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12582 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12583 C->clauses());
12584
12585 if (getSema().OpenACC().ActOnStartStmtDirective(
12586 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12587 return StmtError();
12588
12589 // Transform Structured Block.
12590 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12591 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12592 C->clauses(), TransformedClauses);
12593 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12594 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12595 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12596
12597 return getDerived().RebuildOpenACCComputeConstruct(
12598 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12599 C->getEndLoc(), TransformedClauses, StrBlock);
12600}
12601
12602template <typename Derived>
12604TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
12605
12606 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12607
12608 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12609 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12610 C->clauses());
12611
12612 if (getSema().OpenACC().ActOnStartStmtDirective(
12613 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12614 return StmtError();
12615
12616 // Transform Loop.
12617 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12618 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12619 C->clauses(), TransformedClauses);
12620 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12621 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12622 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12623
12624 return getDerived().RebuildOpenACCLoopConstruct(
12625 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12626 TransformedClauses, Loop);
12627}
12628
12629template <typename Derived>
12630StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct(
12631 OpenACCCombinedConstruct *C) {
12632 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12633
12634 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12635 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12636 C->clauses());
12637
12638 if (getSema().OpenACC().ActOnStartStmtDirective(
12639 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12640 return StmtError();
12641
12642 // Transform Loop.
12643 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12644 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12645 C->clauses(), TransformedClauses);
12646 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12647 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12648 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12649
12650 return getDerived().RebuildOpenACCCombinedConstruct(
12651 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12652 C->getEndLoc(), TransformedClauses, Loop);
12653}
12654
12655template <typename Derived>
12657TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) {
12658 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12659
12660 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12661 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12662 C->clauses());
12663 if (getSema().OpenACC().ActOnStartStmtDirective(
12664 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12665 return StmtError();
12666
12667 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12668 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12669 C->clauses(), TransformedClauses);
12670 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12671 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12672 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12673
12674 return getDerived().RebuildOpenACCDataConstruct(
12675 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12676 TransformedClauses, StrBlock);
12677}
12678
12679template <typename Derived>
12680StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct(
12681 OpenACCEnterDataConstruct *C) {
12682 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12683
12684 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12685 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12686 C->clauses());
12687 if (getSema().OpenACC().ActOnStartStmtDirective(
12688 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12689 return StmtError();
12690
12691 return getDerived().RebuildOpenACCEnterDataConstruct(
12692 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12693 TransformedClauses);
12694}
12695
12696template <typename Derived>
12697StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct(
12698 OpenACCExitDataConstruct *C) {
12699 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12700
12701 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12702 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12703 C->clauses());
12704 if (getSema().OpenACC().ActOnStartStmtDirective(
12705 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12706 return StmtError();
12707
12708 return getDerived().RebuildOpenACCExitDataConstruct(
12709 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12710 TransformedClauses);
12711}
12712
12713template <typename Derived>
12714StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct(
12715 OpenACCHostDataConstruct *C) {
12716 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12717
12718 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12719 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12720 C->clauses());
12721 if (getSema().OpenACC().ActOnStartStmtDirective(
12722 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12723 return StmtError();
12724
12725 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12726 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12727 C->clauses(), TransformedClauses);
12728 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12729 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12730 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12731
12732 return getDerived().RebuildOpenACCHostDataConstruct(
12733 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12734 TransformedClauses, StrBlock);
12735}
12736
12737template <typename Derived>
12739TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) {
12740 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12741
12742 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12743 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12744 C->clauses());
12745 if (getSema().OpenACC().ActOnStartStmtDirective(
12746 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12747 return StmtError();
12748
12749 return getDerived().RebuildOpenACCInitConstruct(
12750 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12751 TransformedClauses);
12752}
12753
12754template <typename Derived>
12755StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct(
12756 OpenACCShutdownConstruct *C) {
12757 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12758
12759 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12760 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12761 C->clauses());
12762 if (getSema().OpenACC().ActOnStartStmtDirective(
12763 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12764 return StmtError();
12765
12766 return getDerived().RebuildOpenACCShutdownConstruct(
12767 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12768 TransformedClauses);
12769}
12770template <typename Derived>
12772TreeTransform<Derived>::TransformOpenACCSetConstruct(OpenACCSetConstruct *C) {
12773 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12774
12775 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12776 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12777 C->clauses());
12778 if (getSema().OpenACC().ActOnStartStmtDirective(
12779 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12780 return StmtError();
12781
12782 return getDerived().RebuildOpenACCSetConstruct(
12783 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12784 TransformedClauses);
12785}
12786
12787template <typename Derived>
12788StmtResult TreeTransform<Derived>::TransformOpenACCUpdateConstruct(
12789 OpenACCUpdateConstruct *C) {
12790 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12791
12792 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12793 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12794 C->clauses());
12795 if (getSema().OpenACC().ActOnStartStmtDirective(
12796 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12797 return StmtError();
12798
12799 return getDerived().RebuildOpenACCUpdateConstruct(
12800 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12801 TransformedClauses);
12802}
12803
12804template <typename Derived>
12806TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) {
12807 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12808
12809 ExprResult DevNumExpr;
12810 if (C->hasDevNumExpr()) {
12811 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12812
12813 if (DevNumExpr.isUsable())
12814 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12816 C->getBeginLoc(), DevNumExpr.get());
12817 }
12818
12819 llvm::SmallVector<Expr *> QueueIdExprs;
12820
12821 for (Expr *QE : C->getQueueIdExprs()) {
12822 assert(QE && "Null queue id expr?");
12823 ExprResult NewEQ = getDerived().TransformExpr(QE);
12824
12825 if (!NewEQ.isUsable())
12826 break;
12827 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12829 C->getBeginLoc(), NewEQ.get());
12830 if (NewEQ.isUsable())
12831 QueueIdExprs.push_back(NewEQ.get());
12832 }
12833
12834 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12835 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12836 C->clauses());
12837
12838 if (getSema().OpenACC().ActOnStartStmtDirective(
12839 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12840 return StmtError();
12841
12842 return getDerived().RebuildOpenACCWaitConstruct(
12843 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12844 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12845 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12846}
12847template <typename Derived>
12848StmtResult TreeTransform<Derived>::TransformOpenACCCacheConstruct(
12849 OpenACCCacheConstruct *C) {
12850 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12851
12852 llvm::SmallVector<Expr *> TransformedVarList;
12853 for (Expr *Var : C->getVarList()) {
12854 assert(Var && "Null var listexpr?");
12855
12856 ExprResult NewVar = getDerived().TransformExpr(Var);
12857
12858 if (!NewVar.isUsable())
12859 break;
12860
12861 NewVar = getSema().OpenACC().ActOnVar(
12862 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
12863 if (!NewVar.isUsable())
12864 break;
12865
12866 TransformedVarList.push_back(NewVar.get());
12867 }
12868
12869 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12870 C->getBeginLoc(), {}))
12871 return StmtError();
12872
12873 return getDerived().RebuildOpenACCCacheConstruct(
12874 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12875 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
12876 C->getEndLoc());
12877}
12878
12879template <typename Derived>
12880StmtResult TreeTransform<Derived>::TransformOpenACCAtomicConstruct(
12881 OpenACCAtomicConstruct *C) {
12882 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12883
12884 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12885 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12886 C->clauses());
12887
12888 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
12889 C->getBeginLoc(), {}))
12890 return StmtError();
12891
12892 // Transform Associated Stmt.
12893 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12894 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
12895
12896 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
12897 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
12898 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
12899 AssocStmt);
12900
12901 return getDerived().RebuildOpenACCAtomicConstruct(
12902 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
12903 C->getEndLoc(), TransformedClauses, AssocStmt);
12904}
12905
12906template <typename Derived>
12907ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr(
12908 OpenACCAsteriskSizeExpr *E) {
12909 if (getDerived().AlwaysRebuild())
12910 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12911 // Nothing can ever change, so there is never anything to transform.
12912 return E;
12913}
12914
12915//===----------------------------------------------------------------------===//
12916// Expression transformation
12917//===----------------------------------------------------------------------===//
12918template<typename Derived>
12920TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
12921 return TransformExpr(E->getSubExpr());
12922}
12923
12924template <typename Derived>
12925ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
12926 SYCLUniqueStableNameExpr *E) {
12927 if (!E->isTypeDependent())
12928 return E;
12929
12930 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12931
12932 if (!NewT)
12933 return ExprError();
12934
12935 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12936 return E;
12937
12938 return getDerived().RebuildSYCLUniqueStableNameExpr(
12939 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12940}
12941
12942template<typename Derived>
12944TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
12945 if (!E->isTypeDependent())
12946 return E;
12947
12948 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12949 E->getIdentKind());
12950}
12951
12952template<typename Derived>
12954TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
12955 NestedNameSpecifierLoc QualifierLoc;
12956 if (E->getQualifierLoc()) {
12957 QualifierLoc
12958 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12959 if (!QualifierLoc)
12960 return ExprError();
12961 }
12962
12963 ValueDecl *ND
12964 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12965 E->getDecl()));
12966 if (!ND || ND->isInvalidDecl())
12967 return ExprError();
12968
12969 NamedDecl *Found = ND;
12970 if (E->getFoundDecl() != E->getDecl()) {
12971 Found = cast_or_null<NamedDecl>(
12972 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12973 if (!Found)
12974 return ExprError();
12975 }
12976
12977 DeclarationNameInfo NameInfo = E->getNameInfo();
12978 if (NameInfo.getName()) {
12979 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12980 if (!NameInfo.getName())
12981 return ExprError();
12982 }
12983
12984 if (!getDerived().AlwaysRebuild() &&
12985 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12986 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12987 Found == E->getFoundDecl() &&
12988 NameInfo.getName() == E->getDecl()->getDeclName() &&
12989 !E->hasExplicitTemplateArgs()) {
12990
12991 // Mark it referenced in the new context regardless.
12992 // FIXME: this is a bit instantiation-specific.
12993 SemaRef.MarkDeclRefReferenced(E);
12994
12995 return E;
12996 }
12997
12998 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12999 if (E->hasExplicitTemplateArgs()) {
13000 TemplateArgs = &TransArgs;
13001 TransArgs.setLAngleLoc(E->getLAngleLoc());
13002 TransArgs.setRAngleLoc(E->getRAngleLoc());
13003 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13004 E->getNumTemplateArgs(),
13005 TransArgs))
13006 return ExprError();
13007 }
13008
13009 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13010 Found, TemplateArgs);
13011}
13012
13013template<typename Derived>
13015TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
13016 return E;
13017}
13018
13019template <typename Derived>
13020ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
13021 FixedPointLiteral *E) {
13022 return E;
13023}
13024
13025template<typename Derived>
13027TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
13028 return E;
13029}
13030
13031template<typename Derived>
13033TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
13034 return E;
13035}
13036
13037template<typename Derived>
13039TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
13040 return E;
13041}
13042
13043template<typename Derived>
13045TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
13046 return E;
13047}
13048
13049template<typename Derived>
13051TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
13052 return getDerived().TransformCallExpr(E);
13053}
13054
13055template<typename Derived>
13057TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
13058 ExprResult ControllingExpr;
13059 TypeSourceInfo *ControllingType = nullptr;
13060 if (E->isExprPredicate())
13061 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13062 else
13063 ControllingType = getDerived().TransformType(E->getControllingType());
13064
13065 if (ControllingExpr.isInvalid() && !ControllingType)
13066 return ExprError();
13067
13068 SmallVector<Expr *, 4> AssocExprs;
13070 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13071 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13072 if (TSI) {
13073 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13074 if (!AssocType)
13075 return ExprError();
13076 AssocTypes.push_back(AssocType);
13077 } else {
13078 AssocTypes.push_back(nullptr);
13079 }
13080
13081 ExprResult AssocExpr =
13082 getDerived().TransformExpr(Assoc.getAssociationExpr());
13083 if (AssocExpr.isInvalid())
13084 return ExprError();
13085 AssocExprs.push_back(AssocExpr.get());
13086 }
13087
13088 if (!ControllingType)
13089 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13090 E->getDefaultLoc(),
13091 E->getRParenLoc(),
13092 ControllingExpr.get(),
13093 AssocTypes,
13094 AssocExprs);
13095 return getDerived().RebuildGenericSelectionExpr(
13096 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13097 ControllingType, AssocTypes, AssocExprs);
13098}
13099
13100template<typename Derived>
13102TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
13103 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13104 if (SubExpr.isInvalid())
13105 return ExprError();
13106
13107 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13108 return E;
13109
13110 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13111 E->getRParen());
13112}
13113
13114/// The operand of a unary address-of operator has special rules: it's
13115/// allowed to refer to a non-static member of a class even if there's no 'this'
13116/// object available.
13117template<typename Derived>
13120 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13121 return getDerived().TransformDependentScopeDeclRefExpr(
13122 DRE, /*IsAddressOfOperand=*/true, nullptr);
13123 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13124 return getDerived().TransformUnresolvedLookupExpr(
13125 ULE, /*IsAddressOfOperand=*/true);
13126 else
13127 return getDerived().TransformExpr(E);
13128}
13129
13130template<typename Derived>
13133 ExprResult SubExpr;
13134 if (E->getOpcode() == UO_AddrOf)
13135 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13136 else
13137 SubExpr = TransformExpr(E->getSubExpr());
13138 if (SubExpr.isInvalid())
13139 return ExprError();
13140
13141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13142 return E;
13143
13144 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13145 E->getOpcode(),
13146 SubExpr.get());
13147}
13148
13149template<typename Derived>
13151TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13152 // Transform the type.
13153 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13154 if (!Type)
13155 return ExprError();
13156
13157 // Transform all of the components into components similar to what the
13158 // parser uses.
13159 // FIXME: It would be slightly more efficient in the non-dependent case to
13160 // just map FieldDecls, rather than requiring the rebuilder to look for
13161 // the fields again. However, __builtin_offsetof is rare enough in
13162 // template code that we don't care.
13163 bool ExprChanged = false;
13164 typedef Sema::OffsetOfComponent Component;
13165 SmallVector<Component, 4> Components;
13166 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13167 const OffsetOfNode &ON = E->getComponent(I);
13168 Component Comp;
13169 Comp.isBrackets = true;
13170 Comp.LocStart = ON.getSourceRange().getBegin();
13171 Comp.LocEnd = ON.getSourceRange().getEnd();
13172 switch (ON.getKind()) {
13173 case OffsetOfNode::Array: {
13174 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13175 ExprResult Index = getDerived().TransformExpr(FromIndex);
13176 if (Index.isInvalid())
13177 return ExprError();
13178
13179 ExprChanged = ExprChanged || Index.get() != FromIndex;
13180 Comp.isBrackets = true;
13181 Comp.U.E = Index.get();
13182 break;
13183 }
13184
13187 Comp.isBrackets = false;
13188 Comp.U.IdentInfo = ON.getFieldName();
13189 if (!Comp.U.IdentInfo)
13190 continue;
13191
13192 break;
13193
13194 case OffsetOfNode::Base:
13195 // Will be recomputed during the rebuild.
13196 continue;
13197 }
13198
13199 Components.push_back(Comp);
13200 }
13201
13202 // If nothing changed, retain the existing expression.
13203 if (!getDerived().AlwaysRebuild() &&
13204 Type == E->getTypeSourceInfo() &&
13205 !ExprChanged)
13206 return E;
13207
13208 // Build a new offsetof expression.
13209 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
13210 Components, E->getRParenLoc());
13211}
13212
13213template<typename Derived>
13215TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
13216 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13217 "opaque value expression requires transformation");
13218 return E;
13219}
13220
13221template <typename Derived>
13222ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
13224 bool Changed = false;
13225 for (Expr *C : E->subExpressions()) {
13226 ExprResult NewC = getDerived().TransformExpr(C);
13227 if (NewC.isInvalid())
13228 return ExprError();
13229 Children.push_back(NewC.get());
13230
13231 Changed |= NewC.get() != C;
13232 }
13233 if (!getDerived().AlwaysRebuild() && !Changed)
13234 return E;
13235 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13236 Children, E->getType());
13237}
13238
13239template<typename Derived>
13241TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
13242 // Rebuild the syntactic form. The original syntactic form has
13243 // opaque-value expressions in it, so strip those away and rebuild
13244 // the result. This is a really awful way of doing this, but the
13245 // better solution (rebuilding the semantic expressions and
13246 // rebinding OVEs as necessary) doesn't work; we'd need
13247 // TreeTransform to not strip away implicit conversions.
13248 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13249 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13250 if (result.isInvalid()) return ExprError();
13251
13252 // If that gives us a pseudo-object result back, the pseudo-object
13253 // expression must have been an lvalue-to-rvalue conversion which we
13254 // should reapply.
13255 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13256 result = SemaRef.PseudoObject().checkRValue(result.get());
13257
13258 return result;
13259}
13260
13261template<typename Derived>
13263TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
13264 UnaryExprOrTypeTraitExpr *E) {
13265 if (E->isArgumentType()) {
13266 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13267
13268 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13269 if (!NewT)
13270 return ExprError();
13271
13272 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13273 return E;
13274
13275 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13276 E->getKind(),
13277 E->getSourceRange());
13278 }
13279
13280 // C++0x [expr.sizeof]p1:
13281 // The operand is either an expression, which is an unevaluated operand
13282 // [...]
13283 EnterExpressionEvaluationContext Unevaluated(
13286
13287 // Try to recover if we have something like sizeof(T::X) where X is a type.
13288 // Notably, there must be *exactly* one set of parens if X is a type.
13289 TypeSourceInfo *RecoveryTSI = nullptr;
13290 ExprResult SubExpr;
13291 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13292 if (auto *DRE =
13293 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13294 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13295 PE, DRE, false, &RecoveryTSI);
13296 else
13297 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13298
13299 if (RecoveryTSI) {
13300 return getDerived().RebuildUnaryExprOrTypeTrait(
13301 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13302 } else if (SubExpr.isInvalid())
13303 return ExprError();
13304
13305 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13306 return E;
13307
13308 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13309 E->getOperatorLoc(),
13310 E->getKind(),
13311 E->getSourceRange());
13312}
13313
13314template<typename Derived>
13316TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
13317 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13318 if (LHS.isInvalid())
13319 return ExprError();
13320
13321 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13322 if (RHS.isInvalid())
13323 return ExprError();
13324
13325
13326 if (!getDerived().AlwaysRebuild() &&
13327 LHS.get() == E->getLHS() &&
13328 RHS.get() == E->getRHS())
13329 return E;
13330
13331 return getDerived().RebuildArraySubscriptExpr(
13332 LHS.get(),
13333 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13334}
13335
13336template <typename Derived>
13338TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
13339 ExprResult Base = getDerived().TransformExpr(E->getBase());
13340 if (Base.isInvalid())
13341 return ExprError();
13342
13343 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13344 if (RowIdx.isInvalid())
13345 return ExprError();
13346
13347 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13348 if (ColumnIdx.isInvalid())
13349 return ExprError();
13350
13351 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13352 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13353 return E;
13354
13355 return getDerived().RebuildMatrixSubscriptExpr(
13356 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13357}
13358
13359template <typename Derived>
13361TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
13362 ExprResult Base = getDerived().TransformExpr(E->getBase());
13363 if (Base.isInvalid())
13364 return ExprError();
13365
13366 ExprResult LowerBound;
13367 if (E->getLowerBound()) {
13368 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13369 if (LowerBound.isInvalid())
13370 return ExprError();
13371 }
13372
13373 ExprResult Length;
13374 if (E->getLength()) {
13375 Length = getDerived().TransformExpr(E->getLength());
13376 if (Length.isInvalid())
13377 return ExprError();
13378 }
13379
13380 ExprResult Stride;
13381 if (E->isOMPArraySection()) {
13382 if (Expr *Str = E->getStride()) {
13383 Stride = getDerived().TransformExpr(Str);
13384 if (Stride.isInvalid())
13385 return ExprError();
13386 }
13387 }
13388
13389 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13390 LowerBound.get() == E->getLowerBound() &&
13391 Length.get() == E->getLength() &&
13392 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13393 return E;
13394
13395 return getDerived().RebuildArraySectionExpr(
13396 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13397 LowerBound.get(), E->getColonLocFirst(),
13398 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13399 Length.get(), Stride.get(), E->getRBracketLoc());
13400}
13401
13402template <typename Derived>
13404TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
13405 ExprResult Base = getDerived().TransformExpr(E->getBase());
13406 if (Base.isInvalid())
13407 return ExprError();
13408
13410 bool ErrorFound = false;
13411 for (Expr *Dim : E->getDimensions()) {
13412 ExprResult DimRes = getDerived().TransformExpr(Dim);
13413 if (DimRes.isInvalid()) {
13414 ErrorFound = true;
13415 continue;
13416 }
13417 Dims.push_back(DimRes.get());
13418 }
13419
13420 if (ErrorFound)
13421 return ExprError();
13422 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13423 E->getRParenLoc(), Dims,
13424 E->getBracketsRanges());
13425}
13426
13427template <typename Derived>
13429TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
13430 unsigned NumIterators = E->numOfIterators();
13432
13433 bool ErrorFound = false;
13434 bool NeedToRebuild = getDerived().AlwaysRebuild();
13435 for (unsigned I = 0; I < NumIterators; ++I) {
13436 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13437 Data[I].DeclIdent = D->getIdentifier();
13438 Data[I].DeclIdentLoc = D->getLocation();
13439 if (D->getLocation() == D->getBeginLoc()) {
13440 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13441 "Implicit type must be int.");
13442 } else {
13443 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13444 QualType DeclTy = getDerived().TransformType(D->getType());
13445 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13446 }
13447 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13448 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13449 ExprResult End = getDerived().TransformExpr(Range.End);
13450 ExprResult Step = getDerived().TransformExpr(Range.Step);
13451 ErrorFound = ErrorFound ||
13452 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13453 !Data[I].Type.get().isNull())) ||
13454 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13455 if (ErrorFound)
13456 continue;
13457 Data[I].Range.Begin = Begin.get();
13458 Data[I].Range.End = End.get();
13459 Data[I].Range.Step = Step.get();
13460 Data[I].AssignLoc = E->getAssignLoc(I);
13461 Data[I].ColonLoc = E->getColonLoc(I);
13462 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13463 NeedToRebuild =
13464 NeedToRebuild ||
13465 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13466 D->getType().getTypePtrOrNull()) ||
13467 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13468 Range.Step != Data[I].Range.Step;
13469 }
13470 if (ErrorFound)
13471 return ExprError();
13472 if (!NeedToRebuild)
13473 return E;
13474
13475 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13476 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13477 if (!Res.isUsable())
13478 return Res;
13479 auto *IE = cast<OMPIteratorExpr>(Res.get());
13480 for (unsigned I = 0; I < NumIterators; ++I)
13481 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13482 IE->getIteratorDecl(I));
13483 return Res;
13484}
13485
13486template<typename Derived>
13488TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
13489 // Transform the callee.
13490 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13491 if (Callee.isInvalid())
13492 return ExprError();
13493
13494 // Transform arguments.
13495 bool ArgChanged = false;
13497 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13498 &ArgChanged))
13499 return ExprError();
13500
13501 if (!getDerived().AlwaysRebuild() &&
13502 Callee.get() == E->getCallee() &&
13503 !ArgChanged)
13504 return SemaRef.MaybeBindToTemporary(E);
13505
13506 // FIXME: Wrong source location information for the '('.
13507 SourceLocation FakeLParenLoc
13508 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13509
13510 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13511 if (E->hasStoredFPFeatures()) {
13512 FPOptionsOverride NewOverrides = E->getFPFeatures();
13513 getSema().CurFPFeatures =
13514 NewOverrides.applyOverrides(getSema().getLangOpts());
13515 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13516 }
13517
13518 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13519 Args,
13520 E->getRParenLoc());
13521}
13522
13523template<typename Derived>
13525TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
13526 ExprResult Base = getDerived().TransformExpr(E->getBase());
13527 if (Base.isInvalid())
13528 return ExprError();
13529
13530 NestedNameSpecifierLoc QualifierLoc;
13531 if (E->hasQualifier()) {
13532 QualifierLoc
13533 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13534
13535 if (!QualifierLoc)
13536 return ExprError();
13537 }
13538 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13539
13540 ValueDecl *Member
13541 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13542 E->getMemberDecl()));
13543 if (!Member)
13544 return ExprError();
13545
13546 NamedDecl *FoundDecl = E->getFoundDecl();
13547 if (FoundDecl == E->getMemberDecl()) {
13548 FoundDecl = Member;
13549 } else {
13550 FoundDecl = cast_or_null<NamedDecl>(
13551 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13552 if (!FoundDecl)
13553 return ExprError();
13554 }
13555
13556 if (!getDerived().AlwaysRebuild() &&
13557 Base.get() == E->getBase() &&
13558 QualifierLoc == E->getQualifierLoc() &&
13559 Member == E->getMemberDecl() &&
13560 FoundDecl == E->getFoundDecl() &&
13561 !E->hasExplicitTemplateArgs()) {
13562
13563 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13564 // for Openmp where the field need to be privatizized in the case.
13565 if (!(isa<CXXThisExpr>(E->getBase()) &&
13566 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13567 cast<ValueDecl>(Member)))) {
13568 // Mark it referenced in the new context regardless.
13569 // FIXME: this is a bit instantiation-specific.
13570 SemaRef.MarkMemberReferenced(E);
13571 return E;
13572 }
13573 }
13574
13575 TemplateArgumentListInfo TransArgs;
13576 if (E->hasExplicitTemplateArgs()) {
13577 TransArgs.setLAngleLoc(E->getLAngleLoc());
13578 TransArgs.setRAngleLoc(E->getRAngleLoc());
13579 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13580 E->getNumTemplateArgs(),
13581 TransArgs))
13582 return ExprError();
13583 }
13584
13585 // FIXME: Bogus source location for the operator
13586 SourceLocation FakeOperatorLoc =
13587 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13588
13589 // FIXME: to do this check properly, we will need to preserve the
13590 // first-qualifier-in-scope here, just in case we had a dependent
13591 // base (and therefore couldn't do the check) and a
13592 // nested-name-qualifier (and therefore could do the lookup).
13593 NamedDecl *FirstQualifierInScope = nullptr;
13594 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13595 if (MemberNameInfo.getName()) {
13596 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13597 if (!MemberNameInfo.getName())
13598 return ExprError();
13599 }
13600
13601 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13602 E->isArrow(),
13603 QualifierLoc,
13604 TemplateKWLoc,
13605 MemberNameInfo,
13606 Member,
13607 FoundDecl,
13608 (E->hasExplicitTemplateArgs()
13609 ? &TransArgs : nullptr),
13610 FirstQualifierInScope);
13611}
13612
13613template<typename Derived>
13615TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
13616 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13617 if (LHS.isInvalid())
13618 return ExprError();
13619
13620 ExprResult RHS =
13621 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13622 if (RHS.isInvalid())
13623 return ExprError();
13624
13625 if (!getDerived().AlwaysRebuild() &&
13626 LHS.get() == E->getLHS() &&
13627 RHS.get() == E->getRHS())
13628 return E;
13629
13630 if (E->isCompoundAssignmentOp())
13631 // FPFeatures has already been established from trailing storage
13632 return getDerived().RebuildBinaryOperator(
13633 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13634 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13635 FPOptionsOverride NewOverrides(E->getFPFeatures());
13636 getSema().CurFPFeatures =
13637 NewOverrides.applyOverrides(getSema().getLangOpts());
13638 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13639 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13640 LHS.get(), RHS.get());
13641}
13642
13643template <typename Derived>
13644ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
13645 CXXRewrittenBinaryOperator *E) {
13646 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13647
13648 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13649 if (LHS.isInvalid())
13650 return ExprError();
13651
13652 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13653 if (RHS.isInvalid())
13654 return ExprError();
13655
13656 // Extract the already-resolved callee declarations so that we can restrict
13657 // ourselves to using them as the unqualified lookup results when rebuilding.
13658 UnresolvedSet<2> UnqualLookups;
13659 bool ChangedAnyLookups = false;
13660 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13661 const_cast<Expr *>(Decomp.InnerBinOp)};
13662 for (Expr *PossibleBinOp : PossibleBinOps) {
13663 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13664 if (!Op)
13665 continue;
13666 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13667 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13668 continue;
13669
13670 // Transform the callee in case we built a call to a local extern
13671 // declaration.
13672 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13673 E->getOperatorLoc(), Callee->getFoundDecl()));
13674 if (!Found)
13675 return ExprError();
13676 if (Found != Callee->getFoundDecl())
13677 ChangedAnyLookups = true;
13678 UnqualLookups.addDecl(Found);
13679 }
13680
13681 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13682 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13683 // Mark all functions used in the rewrite as referenced. Note that when
13684 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13685 // function calls, and/or there might be a user-defined conversion sequence
13686 // applied to the operands of the <.
13687 // FIXME: this is a bit instantiation-specific.
13688 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13689 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13690 return E;
13691 }
13692
13693 return getDerived().RebuildCXXRewrittenBinaryOperator(
13694 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13695}
13696
13697template<typename Derived>
13699TreeTransform<Derived>::TransformCompoundAssignOperator(
13700 CompoundAssignOperator *E) {
13701 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13702 FPOptionsOverride NewOverrides(E->getFPFeatures());
13703 getSema().CurFPFeatures =
13704 NewOverrides.applyOverrides(getSema().getLangOpts());
13705 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13706 return getDerived().TransformBinaryOperator(E);
13707}
13708
13709template<typename Derived>
13710ExprResult TreeTransform<Derived>::
13711TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
13712 // Just rebuild the common and RHS expressions and see whether we
13713 // get any changes.
13714
13715 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13716 if (commonExpr.isInvalid())
13717 return ExprError();
13718
13719 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13720 if (rhs.isInvalid())
13721 return ExprError();
13722
13723 if (!getDerived().AlwaysRebuild() &&
13724 commonExpr.get() == e->getCommon() &&
13725 rhs.get() == e->getFalseExpr())
13726 return e;
13727
13728 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13729 e->getQuestionLoc(),
13730 nullptr,
13731 e->getColonLoc(),
13732 rhs.get());
13733}
13734
13735template<typename Derived>
13737TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
13738 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13739 if (Cond.isInvalid())
13740 return ExprError();
13741
13742 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13743 if (LHS.isInvalid())
13744 return ExprError();
13745
13746 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13747 if (RHS.isInvalid())
13748 return ExprError();
13749
13750 if (!getDerived().AlwaysRebuild() &&
13751 Cond.get() == E->getCond() &&
13752 LHS.get() == E->getLHS() &&
13753 RHS.get() == E->getRHS())
13754 return E;
13755
13756 return getDerived().RebuildConditionalOperator(Cond.get(),
13757 E->getQuestionLoc(),
13758 LHS.get(),
13759 E->getColonLoc(),
13760 RHS.get());
13761}
13762
13763template<typename Derived>
13765TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
13766 // Implicit casts are eliminated during transformation, since they
13767 // will be recomputed by semantic analysis after transformation.
13768 return getDerived().TransformExpr(E->getSubExprAsWritten());
13769}
13770
13771template<typename Derived>
13773TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
13774 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13775 if (!Type)
13776 return ExprError();
13777
13778 ExprResult SubExpr
13779 = getDerived().TransformExpr(E->getSubExprAsWritten());
13780 if (SubExpr.isInvalid())
13781 return ExprError();
13782
13783 if (!getDerived().AlwaysRebuild() &&
13784 Type == E->getTypeInfoAsWritten() &&
13785 SubExpr.get() == E->getSubExpr())
13786 return E;
13787
13788 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13789 Type,
13790 E->getRParenLoc(),
13791 SubExpr.get());
13792}
13793
13794template<typename Derived>
13796TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
13797 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13798 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13799 if (!NewT)
13800 return ExprError();
13801
13802 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13803 if (Init.isInvalid())
13804 return ExprError();
13805
13806 if (!getDerived().AlwaysRebuild() &&
13807 OldT == NewT &&
13808 Init.get() == E->getInitializer())
13809 return SemaRef.MaybeBindToTemporary(E);
13810
13811 // Note: the expression type doesn't necessarily match the
13812 // type-as-written, but that's okay, because it should always be
13813 // derivable from the initializer.
13814
13815 return getDerived().RebuildCompoundLiteralExpr(
13816 E->getLParenLoc(), NewT,
13817 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13818}
13819
13820template<typename Derived>
13822TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
13823 ExprResult Base = getDerived().TransformExpr(E->getBase());
13824 if (Base.isInvalid())
13825 return ExprError();
13826
13827 if (!getDerived().AlwaysRebuild() &&
13828 Base.get() == E->getBase())
13829 return E;
13830
13831 // FIXME: Bad source location
13832 SourceLocation FakeOperatorLoc =
13833 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13834 return getDerived().RebuildExtVectorElementExpr(
13835 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13836 E->getAccessor());
13837}
13838
13839template<typename Derived>
13841TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
13842 if (InitListExpr *Syntactic = E->getSyntacticForm())
13843 E = Syntactic;
13844
13845 bool InitChanged = false;
13846
13847 EnterExpressionEvaluationContext Context(
13849
13851 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13852 Inits, &InitChanged))
13853 return ExprError();
13854
13855 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13856 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13857 // in some cases. We can't reuse it in general, because the syntactic and
13858 // semantic forms are linked, and we can't know that semantic form will
13859 // match even if the syntactic form does.
13860 }
13861
13862 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13863 E->getRBraceLoc());
13864}
13865
13866template<typename Derived>
13868TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
13869 Designation Desig;
13870
13871 // transform the initializer value
13872 ExprResult Init = getDerived().TransformExpr(E->getInit());
13873 if (Init.isInvalid())
13874 return ExprError();
13875
13876 // transform the designators.
13877 SmallVector<Expr*, 4> ArrayExprs;
13878 bool ExprChanged = false;
13879 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13880 if (D.isFieldDesignator()) {
13881 if (D.getFieldDecl()) {
13882 FieldDecl *Field = cast_or_null<FieldDecl>(
13883 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13884 if (Field != D.getFieldDecl())
13885 // Rebuild the expression when the transformed FieldDecl is
13886 // different to the already assigned FieldDecl.
13887 ExprChanged = true;
13888 if (Field->isAnonymousStructOrUnion())
13889 continue;
13890 } else {
13891 // Ensure that the designator expression is rebuilt when there isn't
13892 // a resolved FieldDecl in the designator as we don't want to assign
13893 // a FieldDecl to a pattern designator that will be instantiated again.
13894 ExprChanged = true;
13895 }
13896 Desig.AddDesignator(Designator::CreateFieldDesignator(
13897 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13898 continue;
13899 }
13900
13901 if (D.isArrayDesignator()) {
13902 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13903 if (Index.isInvalid())
13904 return ExprError();
13905
13906 Desig.AddDesignator(
13907 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13908
13909 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
13910 ArrayExprs.push_back(Index.get());
13911 continue;
13912 }
13913
13914 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13915 ExprResult Start
13916 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13917 if (Start.isInvalid())
13918 return ExprError();
13919
13920 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13921 if (End.isInvalid())
13922 return ExprError();
13923
13924 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13925 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13926
13927 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13928 End.get() != E->getArrayRangeEnd(D);
13929
13930 ArrayExprs.push_back(Start.get());
13931 ArrayExprs.push_back(End.get());
13932 }
13933
13934 if (!getDerived().AlwaysRebuild() &&
13935 Init.get() == E->getInit() &&
13936 !ExprChanged)
13937 return E;
13938
13939 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13940 E->getEqualOrColonLoc(),
13941 E->usesGNUSyntax(), Init.get());
13942}
13943
13944// Seems that if TransformInitListExpr() only works on the syntactic form of an
13945// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13946template<typename Derived>
13948TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
13949 DesignatedInitUpdateExpr *E) {
13950 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13951 "initializer");
13952 return ExprError();
13953}
13954
13955template<typename Derived>
13957TreeTransform<Derived>::TransformNoInitExpr(
13958 NoInitExpr *E) {
13959 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13960 return ExprError();
13961}
13962
13963template<typename Derived>
13965TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
13966 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13967 return ExprError();
13968}
13969
13970template<typename Derived>
13972TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
13973 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13974 return ExprError();
13975}
13976
13977template<typename Derived>
13979TreeTransform<Derived>::TransformImplicitValueInitExpr(
13980 ImplicitValueInitExpr *E) {
13981 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13982
13983 // FIXME: Will we ever have proper type location here? Will we actually
13984 // need to transform the type?
13985 QualType T = getDerived().TransformType(E->getType());
13986 if (T.isNull())
13987 return ExprError();
13988
13989 if (!getDerived().AlwaysRebuild() &&
13990 T == E->getType())
13991 return E;
13992
13993 return getDerived().RebuildImplicitValueInitExpr(T);
13994}
13995
13996template<typename Derived>
13998TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
13999 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14000 if (!TInfo)
14001 return ExprError();
14002
14003 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14004 if (SubExpr.isInvalid())
14005 return ExprError();
14006
14007 if (!getDerived().AlwaysRebuild() &&
14008 TInfo == E->getWrittenTypeInfo() &&
14009 SubExpr.get() == E->getSubExpr())
14010 return E;
14011
14012 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14013 TInfo, E->getRParenLoc());
14014}
14015
14016template<typename Derived>
14018TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
14019 bool ArgumentChanged = false;
14021 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14022 &ArgumentChanged))
14023 return ExprError();
14024
14025 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14026 Inits,
14027 E->getRParenLoc());
14028}
14029
14030/// Transform an address-of-label expression.
14031///
14032/// By default, the transformation of an address-of-label expression always
14033/// rebuilds the expression, so that the label identifier can be resolved to
14034/// the corresponding label statement by semantic analysis.
14035template<typename Derived>
14037TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
14038 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14039 E->getLabel());
14040 if (!LD)
14041 return ExprError();
14042
14043 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14044 cast<LabelDecl>(LD));
14045}
14046
14047template<typename Derived>
14049TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
14050 SemaRef.ActOnStartStmtExpr();
14051 StmtResult SubStmt
14052 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14053 if (SubStmt.isInvalid()) {
14054 SemaRef.ActOnStmtExprError();
14055 return ExprError();
14056 }
14057
14058 unsigned OldDepth = E->getTemplateDepth();
14059 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14060
14061 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14062 SubStmt.get() == E->getSubStmt()) {
14063 // Calling this an 'error' is unintuitive, but it does the right thing.
14064 SemaRef.ActOnStmtExprError();
14065 return SemaRef.MaybeBindToTemporary(E);
14066 }
14067
14068 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14069 E->getRParenLoc(), NewDepth);
14070}
14071
14072template<typename Derived>
14074TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
14075 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14076 if (Cond.isInvalid())
14077 return ExprError();
14078
14079 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14080 if (LHS.isInvalid())
14081 return ExprError();
14082
14083 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14084 if (RHS.isInvalid())
14085 return ExprError();
14086
14087 if (!getDerived().AlwaysRebuild() &&
14088 Cond.get() == E->getCond() &&
14089 LHS.get() == E->getLHS() &&
14090 RHS.get() == E->getRHS())
14091 return E;
14092
14093 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14094 Cond.get(), LHS.get(), RHS.get(),
14095 E->getRParenLoc());
14096}
14097
14098template<typename Derived>
14100TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
14101 return E;
14102}
14103
14104template<typename Derived>
14106TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
14107 switch (E->getOperator()) {
14108 case OO_New:
14109 case OO_Delete:
14110 case OO_Array_New:
14111 case OO_Array_Delete:
14112 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14113
14114 case OO_Subscript:
14115 case OO_Call: {
14116 // This is a call to an object's operator().
14117 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14118
14119 // Transform the object itself.
14120 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14121 if (Object.isInvalid())
14122 return ExprError();
14123
14124 // FIXME: Poor location information. Also, if the location for the end of
14125 // the token is within a macro expansion, getLocForEndOfToken() will return
14126 // an invalid source location. If that happens and we have an otherwise
14127 // valid end location, use the valid one instead of the invalid one.
14128 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14129 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14130 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14131 FakeLParenLoc = EndLoc;
14132
14133 // Transform the call arguments.
14135 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14136 Args))
14137 return ExprError();
14138
14139 if (E->getOperator() == OO_Subscript)
14140 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14141 Args, E->getEndLoc());
14142
14143 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14144 E->getEndLoc());
14145 }
14146
14147#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14148 case OO_##Name: \
14149 break;
14150
14151#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14152#include "clang/Basic/OperatorKinds.def"
14153
14154 case OO_Conditional:
14155 llvm_unreachable("conditional operator is not actually overloadable");
14156
14157 case OO_None:
14159 llvm_unreachable("not an overloaded operator?");
14160 }
14161
14163 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14164 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14165 else
14166 First = getDerived().TransformExpr(E->getArg(0));
14167 if (First.isInvalid())
14168 return ExprError();
14169
14170 ExprResult Second;
14171 if (E->getNumArgs() == 2) {
14172 Second =
14173 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14174 if (Second.isInvalid())
14175 return ExprError();
14176 }
14177
14178 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14179 FPOptionsOverride NewOverrides(E->getFPFeatures());
14180 getSema().CurFPFeatures =
14181 NewOverrides.applyOverrides(getSema().getLangOpts());
14182 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14183
14184 Expr *Callee = E->getCallee();
14185 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14186 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14188 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14189 return ExprError();
14190
14191 return getDerived().RebuildCXXOperatorCallExpr(
14192 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14193 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14194 }
14195
14196 UnresolvedSet<1> Functions;
14197 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14198 Callee = ICE->getSubExprAsWritten();
14199 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14200 ValueDecl *VD = cast_or_null<ValueDecl>(
14201 getDerived().TransformDecl(DR->getLocation(), DR));
14202 if (!VD)
14203 return ExprError();
14204
14205 if (!isa<CXXMethodDecl>(VD))
14206 Functions.addDecl(VD);
14207
14208 return getDerived().RebuildCXXOperatorCallExpr(
14209 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14210 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14211}
14212
14213template<typename Derived>
14215TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
14216 return getDerived().TransformCallExpr(E);
14217}
14218
14219template <typename Derived>
14220ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
14221 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14222 getSema().CurContext != E->getParentContext();
14223
14224 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14225 return E;
14226
14227 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14228 E->getBeginLoc(), E->getEndLoc(),
14229 getSema().CurContext);
14230}
14231
14232template <typename Derived>
14233ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
14234 return E;
14235}
14236
14237template<typename Derived>
14239TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
14240 // Transform the callee.
14241 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14242 if (Callee.isInvalid())
14243 return ExprError();
14244
14245 // Transform exec config.
14246 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14247 if (EC.isInvalid())
14248 return ExprError();
14249
14250 // Transform arguments.
14251 bool ArgChanged = false;
14253 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14254 &ArgChanged))
14255 return ExprError();
14256
14257 if (!getDerived().AlwaysRebuild() &&
14258 Callee.get() == E->getCallee() &&
14259 !ArgChanged)
14260 return SemaRef.MaybeBindToTemporary(E);
14261
14262 // FIXME: Wrong source location information for the '('.
14263 SourceLocation FakeLParenLoc
14264 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14265 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14266 Args,
14267 E->getRParenLoc(), EC.get());
14268}
14269
14270template<typename Derived>
14273 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14274 if (!Type)
14275 return ExprError();
14276
14277 ExprResult SubExpr
14278 = getDerived().TransformExpr(E->getSubExprAsWritten());
14279 if (SubExpr.isInvalid())
14280 return ExprError();
14281
14282 if (!getDerived().AlwaysRebuild() &&
14283 Type == E->getTypeInfoAsWritten() &&
14284 SubExpr.get() == E->getSubExpr())
14285 return E;
14286 return getDerived().RebuildCXXNamedCastExpr(
14287 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
14288 Type, E->getAngleBrackets().getEnd(),
14289 // FIXME. this should be '(' location
14290 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14291}
14292
14293template<typename Derived>
14296 TypeSourceInfo *TSI =
14297 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14298 if (!TSI)
14299 return ExprError();
14300
14301 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14302 if (Sub.isInvalid())
14303 return ExprError();
14304
14305 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14306 Sub.get(), BCE->getEndLoc());
14307}
14308
14309template<typename Derived>
14311TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14312 return getDerived().TransformCXXNamedCastExpr(E);
14313}
14314
14315template<typename Derived>
14317TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
14318 return getDerived().TransformCXXNamedCastExpr(E);
14319}
14320
14321template<typename Derived>
14323TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
14324 CXXReinterpretCastExpr *E) {
14325 return getDerived().TransformCXXNamedCastExpr(E);
14326}
14327
14328template<typename Derived>
14330TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
14331 return getDerived().TransformCXXNamedCastExpr(E);
14332}
14333
14334template<typename Derived>
14336TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
14337 return getDerived().TransformCXXNamedCastExpr(E);
14338}
14339
14340template<typename Derived>
14342TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
14343 CXXFunctionalCastExpr *E) {
14344 TypeSourceInfo *Type =
14345 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14346 if (!Type)
14347 return ExprError();
14348
14349 ExprResult SubExpr
14350 = getDerived().TransformExpr(E->getSubExprAsWritten());
14351 if (SubExpr.isInvalid())
14352 return ExprError();
14353
14354 if (!getDerived().AlwaysRebuild() &&
14355 Type == E->getTypeInfoAsWritten() &&
14356 SubExpr.get() == E->getSubExpr())
14357 return E;
14358
14359 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14360 E->getLParenLoc(),
14361 SubExpr.get(),
14362 E->getRParenLoc(),
14363 E->isListInitialization());
14364}
14365
14366template<typename Derived>
14368TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
14369 if (E->isTypeOperand()) {
14370 TypeSourceInfo *TInfo
14371 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14372 if (!TInfo)
14373 return ExprError();
14374
14375 if (!getDerived().AlwaysRebuild() &&
14376 TInfo == E->getTypeOperandSourceInfo())
14377 return E;
14378
14379 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14380 TInfo, E->getEndLoc());
14381 }
14382
14383 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14384 // type. We must not unilaterally enter unevaluated context here, as then
14385 // semantic processing can re-transform an already transformed operand.
14386 Expr *Op = E->getExprOperand();
14388 if (E->isGLValue())
14389 if (auto *RD = Op->getType()->getAsCXXRecordDecl();
14390 RD && RD->isPolymorphic())
14391 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14392
14393 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
14395
14396 ExprResult SubExpr = getDerived().TransformExpr(Op);
14397 if (SubExpr.isInvalid())
14398 return ExprError();
14399
14400 if (!getDerived().AlwaysRebuild() &&
14401 SubExpr.get() == E->getExprOperand())
14402 return E;
14403
14404 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14405 SubExpr.get(), E->getEndLoc());
14406}
14407
14408template<typename Derived>
14410TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
14411 if (E->isTypeOperand()) {
14412 TypeSourceInfo *TInfo
14413 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14414 if (!TInfo)
14415 return ExprError();
14416
14417 if (!getDerived().AlwaysRebuild() &&
14418 TInfo == E->getTypeOperandSourceInfo())
14419 return E;
14420
14421 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14422 TInfo, E->getEndLoc());
14423 }
14424
14425 EnterExpressionEvaluationContext Unevaluated(
14427
14428 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14429 if (SubExpr.isInvalid())
14430 return ExprError();
14431
14432 if (!getDerived().AlwaysRebuild() &&
14433 SubExpr.get() == E->getExprOperand())
14434 return E;
14435
14436 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14437 SubExpr.get(), E->getEndLoc());
14438}
14439
14440template<typename Derived>
14442TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
14443 return E;
14444}
14445
14446template<typename Derived>
14448TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
14449 CXXNullPtrLiteralExpr *E) {
14450 return E;
14451}
14452
14453template<typename Derived>
14455TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
14456
14457 // In lambdas, the qualifiers of the type depends of where in
14458 // the call operator `this` appear, and we do not have a good way to
14459 // rebuild this information, so we transform the type.
14460 //
14461 // In other contexts, the type of `this` may be overrided
14462 // for type deduction, so we need to recompute it.
14463 //
14464 // Always recompute the type if we're in the body of a lambda, and
14465 // 'this' is dependent on a lambda's explicit object parameter; we
14466 // also need to always rebuild the expression in this case to clear
14467 // the flag.
14468 QualType T = [&]() {
14469 auto &S = getSema();
14470 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14471 return S.getCurrentThisType();
14472 if (S.getCurLambda())
14473 return getDerived().TransformType(E->getType());
14474 return S.getCurrentThisType();
14475 }();
14476
14477 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14478 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14479 // Mark it referenced in the new context regardless.
14480 // FIXME: this is a bit instantiation-specific.
14481 getSema().MarkThisReferenced(E);
14482 return E;
14483 }
14484
14485 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14486}
14487
14488template<typename Derived>
14490TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
14491 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14492 if (SubExpr.isInvalid())
14493 return ExprError();
14494
14495 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14496
14497 if (!getDerived().AlwaysRebuild() &&
14498 SubExpr.get() == E->getSubExpr())
14499 return E;
14500
14501 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14502 E->isThrownVariableInScope());
14503}
14504
14505template<typename Derived>
14507TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
14508 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14509 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14510 if (!Param)
14511 return ExprError();
14512
14513 ExprResult InitRes;
14514 if (E->hasRewrittenInit()) {
14515 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14516 if (InitRes.isInvalid())
14517 return ExprError();
14518 }
14519
14520 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14521 E->getUsedContext() == SemaRef.CurContext &&
14522 InitRes.get() == E->getRewrittenExpr())
14523 return E;
14524
14525 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14526 InitRes.get());
14527}
14528
14529template<typename Derived>
14531TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
14532 FieldDecl *Field = cast_or_null<FieldDecl>(
14533 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14534 if (!Field)
14535 return ExprError();
14536
14537 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14538 E->getUsedContext() == SemaRef.CurContext)
14539 return E;
14540
14541 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14542}
14543
14544template<typename Derived>
14546TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
14547 CXXScalarValueInitExpr *E) {
14548 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14549 if (!T)
14550 return ExprError();
14551
14552 if (!getDerived().AlwaysRebuild() &&
14553 T == E->getTypeSourceInfo())
14554 return E;
14555
14556 return getDerived().RebuildCXXScalarValueInitExpr(T,
14557 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14558 E->getRParenLoc());
14559}
14560
14561template<typename Derived>
14563TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
14564 // Transform the type that we're allocating
14565 TypeSourceInfo *AllocTypeInfo =
14566 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14567 if (!AllocTypeInfo)
14568 return ExprError();
14569
14570 // Transform the size of the array we're allocating (if any).
14571 std::optional<Expr *> ArraySize;
14572 if (E->isArray()) {
14573 ExprResult NewArraySize;
14574 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14575 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14576 if (NewArraySize.isInvalid())
14577 return ExprError();
14578 }
14579 ArraySize = NewArraySize.get();
14580 }
14581
14582 // Transform the placement arguments (if any).
14583 bool ArgumentChanged = false;
14584 SmallVector<Expr*, 8> PlacementArgs;
14585 if (getDerived().TransformExprs(E->getPlacementArgs(),
14586 E->getNumPlacementArgs(), true,
14587 PlacementArgs, &ArgumentChanged))
14588 return ExprError();
14589
14590 // Transform the initializer (if any).
14591 Expr *OldInit = E->getInitializer();
14592 ExprResult NewInit;
14593 if (OldInit)
14594 NewInit = getDerived().TransformInitializer(OldInit, true);
14595 if (NewInit.isInvalid())
14596 return ExprError();
14597
14598 // Transform new operator and delete operator.
14599 FunctionDecl *OperatorNew = nullptr;
14600 if (E->getOperatorNew()) {
14601 OperatorNew = cast_or_null<FunctionDecl>(
14602 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14603 if (!OperatorNew)
14604 return ExprError();
14605 }
14606
14607 FunctionDecl *OperatorDelete = nullptr;
14608 if (E->getOperatorDelete()) {
14609 OperatorDelete = cast_or_null<FunctionDecl>(
14610 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14611 if (!OperatorDelete)
14612 return ExprError();
14613 }
14614
14615 if (!getDerived().AlwaysRebuild() &&
14616 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14617 ArraySize == E->getArraySize() &&
14618 NewInit.get() == OldInit &&
14619 OperatorNew == E->getOperatorNew() &&
14620 OperatorDelete == E->getOperatorDelete() &&
14621 !ArgumentChanged) {
14622 // Mark any declarations we need as referenced.
14623 // FIXME: instantiation-specific.
14624 if (OperatorNew)
14625 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14626 if (OperatorDelete)
14627 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14628
14629 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14630 QualType ElementType
14631 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14632 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
14633 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record))
14635 }
14636 }
14637
14638 return E;
14639 }
14640
14641 QualType AllocType = AllocTypeInfo->getType();
14642 if (!ArraySize) {
14643 // If no array size was specified, but the new expression was
14644 // instantiated with an array type (e.g., "new T" where T is
14645 // instantiated with "int[4]"), extract the outer bound from the
14646 // array type as our array size. We do this with constant and
14647 // dependently-sized array types.
14648 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14649 if (!ArrayT) {
14650 // Do nothing
14651 } else if (const ConstantArrayType *ConsArrayT
14652 = dyn_cast<ConstantArrayType>(ArrayT)) {
14653 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14654 SemaRef.Context.getSizeType(),
14655 /*FIXME:*/ E->getBeginLoc());
14656 AllocType = ConsArrayT->getElementType();
14657 } else if (const DependentSizedArrayType *DepArrayT
14658 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14659 if (DepArrayT->getSizeExpr()) {
14660 ArraySize = DepArrayT->getSizeExpr();
14661 AllocType = DepArrayT->getElementType();
14662 }
14663 }
14664 }
14665
14666 return getDerived().RebuildCXXNewExpr(
14667 E->getBeginLoc(), E->isGlobalNew(),
14668 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14669 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14670 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14671}
14672
14673template<typename Derived>
14675TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
14676 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14677 if (Operand.isInvalid())
14678 return ExprError();
14679
14680 // Transform the delete operator, if known.
14681 FunctionDecl *OperatorDelete = nullptr;
14682 if (E->getOperatorDelete()) {
14683 OperatorDelete = cast_or_null<FunctionDecl>(
14684 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14685 if (!OperatorDelete)
14686 return ExprError();
14687 }
14688
14689 if (!getDerived().AlwaysRebuild() &&
14690 Operand.get() == E->getArgument() &&
14691 OperatorDelete == E->getOperatorDelete()) {
14692 // Mark any declarations we need as referenced.
14693 // FIXME: instantiation-specific.
14694 if (OperatorDelete)
14695 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14696
14697 if (!E->getArgument()->isTypeDependent()) {
14698 QualType Destroyed = SemaRef.Context.getBaseElementType(
14699 E->getDestroyedType());
14700 if (auto *Record = Destroyed->getAsCXXRecordDecl())
14702 SemaRef.LookupDestructor(Record));
14703 }
14704
14705 return E;
14706 }
14707
14708 return getDerived().RebuildCXXDeleteExpr(
14709 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14710}
14711
14712template<typename Derived>
14714TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
14715 CXXPseudoDestructorExpr *E) {
14716 ExprResult Base = getDerived().TransformExpr(E->getBase());
14717 if (Base.isInvalid())
14718 return ExprError();
14719
14720 ParsedType ObjectTypePtr;
14721 bool MayBePseudoDestructor = false;
14722 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14723 E->getOperatorLoc(),
14724 E->isArrow()? tok::arrow : tok::period,
14725 ObjectTypePtr,
14726 MayBePseudoDestructor);
14727 if (Base.isInvalid())
14728 return ExprError();
14729
14730 QualType ObjectType = ObjectTypePtr.get();
14731 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14732 if (QualifierLoc) {
14733 QualifierLoc
14734 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14735 if (!QualifierLoc)
14736 return ExprError();
14737 }
14738 CXXScopeSpec SS;
14739 SS.Adopt(QualifierLoc);
14740
14741 PseudoDestructorTypeStorage Destroyed;
14742 if (E->getDestroyedTypeInfo()) {
14743 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
14744 E->getDestroyedTypeInfo(), ObjectType,
14745 /*FirstQualifierInScope=*/nullptr);
14746 if (!DestroyedTypeInfo)
14747 return ExprError();
14748 Destroyed = DestroyedTypeInfo;
14749 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14750 // We aren't likely to be able to resolve the identifier down to a type
14751 // now anyway, so just retain the identifier.
14752 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14753 E->getDestroyedTypeLoc());
14754 } else {
14755 // Look for a destructor known with the given name.
14756 ParsedType T = SemaRef.getDestructorName(
14757 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14758 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14759 if (!T)
14760 return ExprError();
14761
14762 Destroyed
14764 E->getDestroyedTypeLoc());
14765 }
14766
14767 TypeSourceInfo *ScopeTypeInfo = nullptr;
14768 if (E->getScopeTypeInfo()) {
14769 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14770 E->getScopeTypeInfo(), ObjectType, nullptr);
14771 if (!ScopeTypeInfo)
14772 return ExprError();
14773 }
14774
14775 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14776 E->getOperatorLoc(),
14777 E->isArrow(),
14778 SS,
14779 ScopeTypeInfo,
14780 E->getColonColonLoc(),
14781 E->getTildeLoc(),
14782 Destroyed);
14783}
14784
14785template <typename Derived>
14787 bool RequiresADL,
14788 LookupResult &R) {
14789 // Transform all the decls.
14790 bool AllEmptyPacks = true;
14791 for (auto *OldD : Old->decls()) {
14792 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14793 if (!InstD) {
14794 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14795 // This can happen because of dependent hiding.
14796 if (isa<UsingShadowDecl>(OldD))
14797 continue;
14798 else {
14799 R.clear();
14800 return true;
14801 }
14802 }
14803
14804 // Expand using pack declarations.
14805 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14806 ArrayRef<NamedDecl*> Decls = SingleDecl;
14807 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14808 Decls = UPD->expansions();
14809
14810 // Expand using declarations.
14811 for (auto *D : Decls) {
14812 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14813 for (auto *SD : UD->shadows())
14814 R.addDecl(SD);
14815 } else {
14816 R.addDecl(D);
14817 }
14818 }
14819
14820 AllEmptyPacks &= Decls.empty();
14821 }
14822
14823 // C++ [temp.res]/8.4.2:
14824 // The program is ill-formed, no diagnostic required, if [...] lookup for
14825 // a name in the template definition found a using-declaration, but the
14826 // lookup in the corresponding scope in the instantiation odoes not find
14827 // any declarations because the using-declaration was a pack expansion and
14828 // the corresponding pack is empty
14829 if (AllEmptyPacks && !RequiresADL) {
14830 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14831 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14832 return true;
14833 }
14834
14835 // Resolve a kind, but don't do any further analysis. If it's
14836 // ambiguous, the callee needs to deal with it.
14837 R.resolveKind();
14838
14839 if (Old->hasTemplateKeyword() && !R.empty()) {
14841 getSema().FilterAcceptableTemplateNames(R,
14842 /*AllowFunctionTemplates=*/true,
14843 /*AllowDependent=*/true);
14844 if (R.empty()) {
14845 // If a 'template' keyword was used, a lookup that finds only non-template
14846 // names is an error.
14847 getSema().Diag(R.getNameLoc(),
14848 diag::err_template_kw_refers_to_non_template)
14850 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14851 getSema().Diag(FoundDecl->getLocation(),
14852 diag::note_template_kw_refers_to_non_template)
14853 << R.getLookupName();
14854 return true;
14855 }
14856 }
14857
14858 return false;
14859}
14860
14861template <typename Derived>
14863 UnresolvedLookupExpr *Old) {
14864 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
14865}
14866
14867template <typename Derived>
14870 bool IsAddressOfOperand) {
14871 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14873
14874 // Transform the declaration set.
14875 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14876 return ExprError();
14877
14878 // Rebuild the nested-name qualifier, if present.
14879 CXXScopeSpec SS;
14880 if (Old->getQualifierLoc()) {
14881 NestedNameSpecifierLoc QualifierLoc
14882 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14883 if (!QualifierLoc)
14884 return ExprError();
14885
14886 SS.Adopt(QualifierLoc);
14887 }
14888
14889 if (Old->getNamingClass()) {
14890 CXXRecordDecl *NamingClass
14891 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14892 Old->getNameLoc(),
14893 Old->getNamingClass()));
14894 if (!NamingClass) {
14895 R.clear();
14896 return ExprError();
14897 }
14898
14899 R.setNamingClass(NamingClass);
14900 }
14901
14902 // Rebuild the template arguments, if any.
14903 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14904 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14905 if (Old->hasExplicitTemplateArgs() &&
14906 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14907 Old->getNumTemplateArgs(),
14908 TransArgs)) {
14909 R.clear();
14910 return ExprError();
14911 }
14912
14913 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14914 // a non-static data member is named in an unevaluated operand, or when
14915 // a member is named in a dependent class scope function template explicit
14916 // specialization that is neither declared static nor with an explicit object
14917 // parameter.
14918 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14919 return SemaRef.BuildPossibleImplicitMemberExpr(
14920 SS, TemplateKWLoc, R,
14921 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14922 /*S=*/nullptr);
14923
14924 // If we have neither explicit template arguments, nor the template keyword,
14925 // it's a normal declaration name or member reference.
14926 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14927 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14928
14929 // If we have template arguments, then rebuild the template-id expression.
14930 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14931 Old->requiresADL(), &TransArgs);
14932}
14933
14934template<typename Derived>
14936TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
14937 bool ArgChanged = false;
14939 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14940 TypeSourceInfo *From = E->getArg(I);
14941 TypeLoc FromTL = From->getTypeLoc();
14942 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14943 TypeLocBuilder TLB;
14944 TLB.reserve(FromTL.getFullDataSize());
14945 QualType To = getDerived().TransformType(TLB, FromTL);
14946 if (To.isNull())
14947 return ExprError();
14948
14949 if (To == From->getType())
14950 Args.push_back(From);
14951 else {
14952 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14953 ArgChanged = true;
14954 }
14955 continue;
14956 }
14957
14958 ArgChanged = true;
14959
14960 // We have a pack expansion. Instantiate it.
14961 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14962 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14964 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14965
14966 // Determine whether the set of unexpanded parameter packs can and should
14967 // be expanded.
14968 bool Expand = true;
14969 bool RetainExpansion = false;
14970 UnsignedOrNone OrigNumExpansions =
14971 ExpansionTL.getTypePtr()->getNumExpansions();
14972 UnsignedOrNone NumExpansions = OrigNumExpansions;
14973 if (getDerived().TryExpandParameterPacks(
14974 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
14975 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
14976 RetainExpansion, NumExpansions))
14977 return ExprError();
14978
14979 if (!Expand) {
14980 // The transform has determined that we should perform a simple
14981 // transformation on the pack expansion, producing another pack
14982 // expansion.
14983 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
14984
14985 TypeLocBuilder TLB;
14986 TLB.reserve(From->getTypeLoc().getFullDataSize());
14987
14988 QualType To = getDerived().TransformType(TLB, PatternTL);
14989 if (To.isNull())
14990 return ExprError();
14991
14992 To = getDerived().RebuildPackExpansionType(To,
14993 PatternTL.getSourceRange(),
14994 ExpansionTL.getEllipsisLoc(),
14995 NumExpansions);
14996 if (To.isNull())
14997 return ExprError();
14998
14999 PackExpansionTypeLoc ToExpansionTL
15000 = TLB.push<PackExpansionTypeLoc>(To);
15001 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15002 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15003 continue;
15004 }
15005
15006 // Expand the pack expansion by substituting for each argument in the
15007 // pack(s).
15008 for (unsigned I = 0; I != *NumExpansions; ++I) {
15009 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15010 TypeLocBuilder TLB;
15011 TLB.reserve(PatternTL.getFullDataSize());
15012 QualType To = getDerived().TransformType(TLB, PatternTL);
15013 if (To.isNull())
15014 return ExprError();
15015
15016 if (To->containsUnexpandedParameterPack()) {
15017 To = getDerived().RebuildPackExpansionType(To,
15018 PatternTL.getSourceRange(),
15019 ExpansionTL.getEllipsisLoc(),
15020 NumExpansions);
15021 if (To.isNull())
15022 return ExprError();
15023
15024 PackExpansionTypeLoc ToExpansionTL
15025 = TLB.push<PackExpansionTypeLoc>(To);
15026 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15027 }
15028
15029 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15030 }
15031
15032 if (!RetainExpansion)
15033 continue;
15034
15035 // If we're supposed to retain a pack expansion, do so by temporarily
15036 // forgetting the partially-substituted parameter pack.
15037 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15038
15039 TypeLocBuilder TLB;
15040 TLB.reserve(From->getTypeLoc().getFullDataSize());
15041
15042 QualType To = getDerived().TransformType(TLB, PatternTL);
15043 if (To.isNull())
15044 return ExprError();
15045
15046 To = getDerived().RebuildPackExpansionType(To,
15047 PatternTL.getSourceRange(),
15048 ExpansionTL.getEllipsisLoc(),
15049 NumExpansions);
15050 if (To.isNull())
15051 return ExprError();
15052
15053 PackExpansionTypeLoc ToExpansionTL
15054 = TLB.push<PackExpansionTypeLoc>(To);
15055 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15056 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15057 }
15058
15059 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15060 return E;
15061
15062 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15063 E->getEndLoc());
15064}
15065
15066template<typename Derived>
15068TreeTransform<Derived>::TransformConceptSpecializationExpr(
15069 ConceptSpecializationExpr *E) {
15070 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15071 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15072 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15073 Old->NumTemplateArgs, TransArgs))
15074 return ExprError();
15075
15076 return getDerived().RebuildConceptSpecializationExpr(
15077 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15078 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15079 &TransArgs);
15080}
15081
15082template<typename Derived>
15084TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
15085 SmallVector<ParmVarDecl*, 4> TransParams;
15086 SmallVector<QualType, 4> TransParamTypes;
15087 Sema::ExtParameterInfoBuilder ExtParamInfos;
15088
15089 // C++2a [expr.prim.req]p2
15090 // Expressions appearing within a requirement-body are unevaluated operands.
15091 EnterExpressionEvaluationContext Ctx(
15094
15095 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
15096 getSema().Context, getSema().CurContext,
15097 E->getBody()->getBeginLoc());
15098
15099 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15100
15101 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15102 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15103 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15104
15105 for (ParmVarDecl *Param : TransParams)
15106 if (Param)
15107 Param->setDeclContext(Body);
15108
15109 // On failure to transform, TransformRequiresTypeParams returns an expression
15110 // in the event that the transformation of the type params failed in some way.
15111 // It is expected that this will result in a 'not satisfied' Requires clause
15112 // when instantiating.
15113 if (!TypeParamResult.isUnset())
15114 return TypeParamResult;
15115
15117 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15118 TransReqs))
15119 return ExprError();
15120
15121 for (concepts::Requirement *Req : TransReqs) {
15122 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15123 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15124 ER->getReturnTypeRequirement()
15125 .getTypeConstraintTemplateParameterList()->getParam(0)
15126 ->setDeclContext(Body);
15127 }
15128 }
15129 }
15130
15131 return getDerived().RebuildRequiresExpr(
15132 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15133 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15134}
15135
15136template<typename Derived>
15140 for (concepts::Requirement *Req : Reqs) {
15141 concepts::Requirement *TransReq = nullptr;
15142 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15143 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15144 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15145 TransReq = getDerived().TransformExprRequirement(ExprReq);
15146 else
15147 TransReq = getDerived().TransformNestedRequirement(
15148 cast<concepts::NestedRequirement>(Req));
15149 if (!TransReq)
15150 return true;
15151 Transformed.push_back(TransReq);
15152 }
15153 return false;
15154}
15155
15156template<typename Derived>
15160 if (Req->isSubstitutionFailure()) {
15161 if (getDerived().AlwaysRebuild())
15162 return getDerived().RebuildTypeRequirement(
15164 return Req;
15165 }
15166 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15167 if (!TransType)
15168 return nullptr;
15169 return getDerived().RebuildTypeRequirement(TransType);
15170}
15171
15172template<typename Derived>
15175 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15176 if (Req->isExprSubstitutionFailure())
15177 TransExpr = Req->getExprSubstitutionDiagnostic();
15178 else {
15179 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15180 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15181 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15182 if (TransExprRes.isInvalid())
15183 return nullptr;
15184 TransExpr = TransExprRes.get();
15185 }
15186
15187 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15188 const auto &RetReq = Req->getReturnTypeRequirement();
15189 if (RetReq.isEmpty())
15190 TransRetReq.emplace();
15191 else if (RetReq.isSubstitutionFailure())
15192 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15193 else if (RetReq.isTypeConstraint()) {
15194 TemplateParameterList *OrigTPL =
15195 RetReq.getTypeConstraintTemplateParameterList();
15197 getDerived().TransformTemplateParameterList(OrigTPL);
15198 if (!TPL)
15199 return nullptr;
15200 TransRetReq.emplace(TPL);
15201 }
15202 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15203 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15204 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15205 Req->getNoexceptLoc(),
15206 std::move(*TransRetReq));
15207 return getDerived().RebuildExprRequirement(
15208 cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
15209 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15210}
15211
15212template<typename Derived>
15216 if (Req->hasInvalidConstraint()) {
15217 if (getDerived().AlwaysRebuild())
15218 return getDerived().RebuildNestedRequirement(
15220 return Req;
15221 }
15222 ExprResult TransConstraint =
15223 getDerived().TransformExpr(Req->getConstraintExpr());
15224 if (TransConstraint.isInvalid())
15225 return nullptr;
15226 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15227}
15228
15229template<typename Derived>
15232 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15233 if (!T)
15234 return ExprError();
15235
15236 if (!getDerived().AlwaysRebuild() &&
15237 T == E->getQueriedTypeSourceInfo())
15238 return E;
15239
15240 ExprResult SubExpr;
15241 {
15244 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15245 if (SubExpr.isInvalid())
15246 return ExprError();
15247 }
15248
15249 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15250 SubExpr.get(), E->getEndLoc());
15251}
15252
15253template<typename Derived>
15255TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
15256 ExprResult SubExpr;
15257 {
15258 EnterExpressionEvaluationContext Unevaluated(
15260 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15261 if (SubExpr.isInvalid())
15262 return ExprError();
15263
15264 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15265 return E;
15266 }
15267
15268 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15269 SubExpr.get(), E->getEndLoc());
15270}
15271
15272template <typename Derived>
15274 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15275 TypeSourceInfo **RecoveryTSI) {
15276 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15277 DRE, AddrTaken, RecoveryTSI);
15278
15279 // Propagate both errors and recovered types, which return ExprEmpty.
15280 if (!NewDRE.isUsable())
15281 return NewDRE;
15282
15283 // We got an expr, wrap it up in parens.
15284 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15285 return PE;
15286 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15287 PE->getRParen());
15288}
15289
15290template <typename Derived>
15293 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
15294 nullptr);
15295}
15296
15297template <typename Derived>
15299 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15300 TypeSourceInfo **RecoveryTSI) {
15301 assert(E->getQualifierLoc());
15302 NestedNameSpecifierLoc QualifierLoc =
15303 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15304 if (!QualifierLoc)
15305 return ExprError();
15306 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15307
15308 // TODO: If this is a conversion-function-id, verify that the
15309 // destination type name (if present) resolves the same way after
15310 // instantiation as it did in the local scope.
15311
15312 DeclarationNameInfo NameInfo =
15313 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15314 if (!NameInfo.getName())
15315 return ExprError();
15316
15317 if (!E->hasExplicitTemplateArgs()) {
15318 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15319 // Note: it is sufficient to compare the Name component of NameInfo:
15320 // if name has not changed, DNLoc has not changed either.
15321 NameInfo.getName() == E->getDeclName())
15322 return E;
15323
15324 return getDerived().RebuildDependentScopeDeclRefExpr(
15325 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15326 IsAddressOfOperand, RecoveryTSI);
15327 }
15328
15329 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15330 if (getDerived().TransformTemplateArguments(
15331 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15332 return ExprError();
15333
15334 return getDerived().RebuildDependentScopeDeclRefExpr(
15335 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15336 RecoveryTSI);
15337}
15338
15339template<typename Derived>
15341TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
15342 // CXXConstructExprs other than for list-initialization and
15343 // CXXTemporaryObjectExpr are always implicit, so when we have
15344 // a 1-argument construction we just transform that argument.
15345 if (getDerived().AllowSkippingCXXConstructExpr() &&
15346 ((E->getNumArgs() == 1 ||
15347 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15348 (!getDerived().DropCallArgument(E->getArg(0))) &&
15349 !E->isListInitialization()))
15350 return getDerived().TransformInitializer(E->getArg(0),
15351 /*DirectInit*/ false);
15352
15353 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15354
15355 QualType T = getDerived().TransformType(E->getType());
15356 if (T.isNull())
15357 return ExprError();
15358
15359 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15360 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15361 if (!Constructor)
15362 return ExprError();
15363
15364 bool ArgumentChanged = false;
15366 {
15367 EnterExpressionEvaluationContext Context(
15369 E->isListInitialization());
15370 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15371 &ArgumentChanged))
15372 return ExprError();
15373 }
15374
15375 if (!getDerived().AlwaysRebuild() &&
15376 T == E->getType() &&
15377 Constructor == E->getConstructor() &&
15378 !ArgumentChanged) {
15379 // Mark the constructor as referenced.
15380 // FIXME: Instantiation-specific
15382 return E;
15383 }
15384
15385 return getDerived().RebuildCXXConstructExpr(
15386 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15387 E->hadMultipleCandidates(), E->isListInitialization(),
15388 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15389 E->getConstructionKind(), E->getParenOrBraceRange());
15390}
15391
15392template<typename Derived>
15393ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
15394 CXXInheritedCtorInitExpr *E) {
15395 QualType T = getDerived().TransformType(E->getType());
15396 if (T.isNull())
15397 return ExprError();
15398
15399 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15400 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15401 if (!Constructor)
15402 return ExprError();
15403
15404 if (!getDerived().AlwaysRebuild() &&
15405 T == E->getType() &&
15406 Constructor == E->getConstructor()) {
15407 // Mark the constructor as referenced.
15408 // FIXME: Instantiation-specific
15410 return E;
15411 }
15412
15413 return getDerived().RebuildCXXInheritedCtorInitExpr(
15414 T, E->getLocation(), Constructor,
15415 E->constructsVBase(), E->inheritedFromVBase());
15416}
15417
15418/// Transform a C++ temporary-binding expression.
15419///
15420/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15421/// transform the subexpression and return that.
15422template<typename Derived>
15424TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
15425 if (auto *Dtor = E->getTemporary()->getDestructor())
15427 const_cast<CXXDestructorDecl *>(Dtor));
15428 return getDerived().TransformExpr(E->getSubExpr());
15429}
15430
15431/// Transform a C++ expression that contains cleanups that should
15432/// be run after the expression is evaluated.
15433///
15434/// Since ExprWithCleanups nodes are implicitly generated, we
15435/// just transform the subexpression and return that.
15436template<typename Derived>
15438TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
15439 return getDerived().TransformExpr(E->getSubExpr());
15440}
15441
15442template<typename Derived>
15444TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
15445 CXXTemporaryObjectExpr *E) {
15446 TypeSourceInfo *T =
15447 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15448 if (!T)
15449 return ExprError();
15450
15451 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15452 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15453 if (!Constructor)
15454 return ExprError();
15455
15456 bool ArgumentChanged = false;
15458 Args.reserve(E->getNumArgs());
15459 {
15460 EnterExpressionEvaluationContext Context(
15462 E->isListInitialization());
15463 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15464 &ArgumentChanged))
15465 return ExprError();
15466
15467 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15468 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15469 if (Res.isInvalid())
15470 return ExprError();
15471 Args = {Res.get()};
15472 }
15473 }
15474
15475 if (!getDerived().AlwaysRebuild() &&
15476 T == E->getTypeSourceInfo() &&
15477 Constructor == E->getConstructor() &&
15478 !ArgumentChanged) {
15479 // FIXME: Instantiation-specific
15481 return SemaRef.MaybeBindToTemporary(E);
15482 }
15483
15484 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15485 return getDerived().RebuildCXXTemporaryObjectExpr(
15486 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15487}
15488
15489template<typename Derived>
15491TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
15492 // Transform any init-capture expressions before entering the scope of the
15493 // lambda body, because they are not semantically within that scope.
15494 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15495 struct TransformedInitCapture {
15496 // The location of the ... if the result is retaining a pack expansion.
15497 SourceLocation EllipsisLoc;
15498 // Zero or more expansions of the init-capture.
15500 };
15502 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15503 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15504 CEnd = E->capture_end();
15505 C != CEnd; ++C) {
15506 if (!E->isInitCapture(C))
15507 continue;
15508
15509 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15510 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15511
15512 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15513 UnsignedOrNone NumExpansions) {
15514 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15515 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15516
15517 if (NewExprInitResult.isInvalid()) {
15518 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15519 return;
15520 }
15521 Expr *NewExprInit = NewExprInitResult.get();
15522
15523 QualType NewInitCaptureType =
15524 getSema().buildLambdaInitCaptureInitialization(
15525 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15526 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15527 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15529 NewExprInit);
15530 Result.Expansions.push_back(
15531 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15532 };
15533
15534 // If this is an init-capture pack, consider expanding the pack now.
15535 if (OldVD->isParameterPack()) {
15536 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15537 ->getTypeLoc()
15538 .castAs<PackExpansionTypeLoc>();
15540 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15541
15542 // Determine whether the set of unexpanded parameter packs can and should
15543 // be expanded.
15544 bool Expand = true;
15545 bool RetainExpansion = false;
15546 UnsignedOrNone OrigNumExpansions =
15547 ExpansionTL.getTypePtr()->getNumExpansions();
15548 UnsignedOrNone NumExpansions = OrigNumExpansions;
15549 if (getDerived().TryExpandParameterPacks(
15550 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
15551 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15552 RetainExpansion, NumExpansions))
15553 return ExprError();
15554 assert(!RetainExpansion && "Should not need to retain expansion after a "
15555 "capture since it cannot be extended");
15556 if (Expand) {
15557 for (unsigned I = 0; I != *NumExpansions; ++I) {
15558 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15559 SubstInitCapture(SourceLocation(), std::nullopt);
15560 }
15561 } else {
15562 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15563 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15564 }
15565 } else {
15566 SubstInitCapture(SourceLocation(), std::nullopt);
15567 }
15568 }
15569
15570 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15571 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15572
15573 // Create the local class that will describe the lambda.
15574
15575 // FIXME: DependencyKind below is wrong when substituting inside a templated
15576 // context that isn't a DeclContext (such as a variable template), or when
15577 // substituting an unevaluated lambda inside of a function's parameter's type
15578 // - as parameter types are not instantiated from within a function's DC. We
15579 // use evaluation contexts to distinguish the function parameter case.
15582 DeclContext *DC = getSema().CurContext;
15583 // A RequiresExprBodyDecl is not interesting for dependencies.
15584 // For the following case,
15585 //
15586 // template <typename>
15587 // concept C = requires { [] {}; };
15588 //
15589 // template <class F>
15590 // struct Widget;
15591 //
15592 // template <C F>
15593 // struct Widget<F> {};
15594 //
15595 // While we are substituting Widget<F>, the parent of DC would be
15596 // the template specialization itself. Thus, the lambda expression
15597 // will be deemed as dependent even if there are no dependent template
15598 // arguments.
15599 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15600 while (DC->isRequiresExprBody())
15601 DC = DC->getParent();
15602 if ((getSema().isUnevaluatedContext() ||
15603 getSema().isConstantEvaluatedContext()) &&
15604 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15605 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15606
15607 CXXRecordDecl *OldClass = E->getLambdaClass();
15608 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15609 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15610 E->getCaptureDefault());
15611 getDerived().transformedLocalDecl(OldClass, {Class});
15612
15613 CXXMethodDecl *NewCallOperator =
15614 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15615
15616 // Enter the scope of the lambda.
15617 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15618 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15619 E->hasExplicitParameters(), E->isMutable());
15620
15621 // Introduce the context of the call operator.
15622 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15623 /*NewThisContext*/false);
15624
15625 bool Invalid = false;
15626
15627 // Transform captures.
15628 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15629 CEnd = E->capture_end();
15630 C != CEnd; ++C) {
15631 // When we hit the first implicit capture, tell Sema that we've finished
15632 // the list of explicit captures.
15633 if (C->isImplicit())
15634 break;
15635
15636 // Capturing 'this' is trivial.
15637 if (C->capturesThis()) {
15638 // If this is a lambda that is part of a default member initialiser
15639 // and which we're instantiating outside the class that 'this' is
15640 // supposed to refer to, adjust the type of 'this' accordingly.
15641 //
15642 // Otherwise, leave the type of 'this' as-is.
15643 Sema::CXXThisScopeRAII ThisScope(
15644 getSema(),
15645 dyn_cast_if_present<CXXRecordDecl>(
15646 getSema().getFunctionLevelDeclContext()),
15647 Qualifiers());
15648 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15649 /*BuildAndDiagnose*/ true, nullptr,
15650 C->getCaptureKind() == LCK_StarThis);
15651 continue;
15652 }
15653 // Captured expression will be recaptured during captured variables
15654 // rebuilding.
15655 if (C->capturesVLAType())
15656 continue;
15657
15658 // Rebuild init-captures, including the implied field declaration.
15659 if (E->isInitCapture(C)) {
15660 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15661
15662 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15664
15665 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15666 ExprResult Init = Info.first;
15667 QualType InitQualType = Info.second;
15668 if (Init.isInvalid() || InitQualType.isNull()) {
15669 Invalid = true;
15670 break;
15671 }
15672 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15673 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15674 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15675 getSema().CurContext);
15676 if (!NewVD) {
15677 Invalid = true;
15678 break;
15679 }
15680 NewVDs.push_back(NewVD);
15681 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15682 // Cases we want to tackle:
15683 // ([C(Pack)] {}, ...)
15684 // But rule out cases e.g.
15685 // [...C = Pack()] {}
15686 if (NewC.EllipsisLoc.isInvalid())
15687 LSI->ContainsUnexpandedParameterPack |=
15688 Init.get()->containsUnexpandedParameterPack();
15689 }
15690
15691 if (Invalid)
15692 break;
15693
15694 getDerived().transformedLocalDecl(OldVD, NewVDs);
15695 continue;
15696 }
15697
15698 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15699
15700 // Determine the capture kind for Sema.
15702 : C->getCaptureKind() == LCK_ByCopy
15705 SourceLocation EllipsisLoc;
15706 if (C->isPackExpansion()) {
15707 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15708 bool ShouldExpand = false;
15709 bool RetainExpansion = false;
15710 UnsignedOrNone NumExpansions = std::nullopt;
15711 if (getDerived().TryExpandParameterPacks(
15712 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
15713 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
15714 RetainExpansion, NumExpansions)) {
15715 Invalid = true;
15716 continue;
15717 }
15718
15719 if (ShouldExpand) {
15720 // The transform has determined that we should perform an expansion;
15721 // transform and capture each of the arguments.
15722 // expansion of the pattern. Do so.
15723 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
15724 for (unsigned I = 0; I != *NumExpansions; ++I) {
15725 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
15726 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
15727 getDerived().TransformDecl(C->getLocation(), Pack));
15728 if (!CapturedVar) {
15729 Invalid = true;
15730 continue;
15731 }
15732
15733 // Capture the transformed variable.
15734 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15735 }
15736
15737 // FIXME: Retain a pack expansion if RetainExpansion is true.
15738
15739 continue;
15740 }
15741
15742 EllipsisLoc = C->getEllipsisLoc();
15743 }
15744
15745 // Transform the captured variable.
15746 auto *CapturedVar = cast_or_null<ValueDecl>(
15747 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15748 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15749 Invalid = true;
15750 continue;
15751 }
15752
15753 // This is not an init-capture; however it contains an unexpanded pack e.g.
15754 // ([Pack] {}(), ...)
15755 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15756 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15757
15758 // Capture the transformed variable.
15759 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15760 EllipsisLoc);
15761 }
15762 getSema().finishLambdaExplicitCaptures(LSI);
15763
15764 // Transform the template parameters, and add them to the current
15765 // instantiation scope. The null case is handled correctly.
15766 auto TPL = getDerived().TransformTemplateParameterList(
15767 E->getTemplateParameterList());
15768 LSI->GLTemplateParameterList = TPL;
15769 if (TPL) {
15770 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15771 TPL);
15772 LSI->ContainsUnexpandedParameterPack |=
15773 TPL->containsUnexpandedParameterPack();
15774 }
15775
15776 TypeLocBuilder NewCallOpTLBuilder;
15777 TypeLoc OldCallOpTypeLoc =
15778 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15779 QualType NewCallOpType =
15780 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15781 if (NewCallOpType.isNull())
15782 return ExprError();
15783 LSI->ContainsUnexpandedParameterPack |=
15784 NewCallOpType->containsUnexpandedParameterPack();
15785 TypeSourceInfo *NewCallOpTSI =
15786 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15787
15788 // The type may be an AttributedType or some other kind of sugar;
15789 // get the actual underlying FunctionProtoType.
15790 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15791 assert(FPTL && "Not a FunctionProtoType?");
15792
15793 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
15794 if (!TRC.ArgPackSubstIndex)
15795 TRC.ArgPackSubstIndex = SemaRef.ArgPackSubstIndex;
15796
15797 getSema().CompleteLambdaCallOperator(
15798 NewCallOperator, E->getCallOperator()->getLocation(),
15799 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
15800 E->getCallOperator()->getConstexprKind(),
15801 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15802 E->hasExplicitResultType());
15803
15804 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15805 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15806
15807 {
15808 // Number the lambda for linkage purposes if necessary.
15809 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15810
15811 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15812 if (getDerived().ReplacingOriginal()) {
15813 Numbering = OldClass->getLambdaNumbering();
15814 }
15815
15816 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15817 }
15818
15819 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15820 // evaluation context even if we're not transforming the function body.
15821 getSema().PushExpressionEvaluationContextForFunction(
15823 E->getCallOperator());
15824
15825 Sema::CodeSynthesisContext C;
15827 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15828 getSema().pushCodeSynthesisContext(C);
15829
15830 // Instantiate the body of the lambda expression.
15831 StmtResult Body =
15832 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15833
15834 getSema().popCodeSynthesisContext();
15835
15836 // ActOnLambda* will pop the function scope for us.
15837 FuncScopeCleanup.disable();
15838
15839 if (Body.isInvalid()) {
15840 SavedContext.pop();
15841 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15842 /*IsInstantiation=*/true);
15843 return ExprError();
15844 }
15845
15846 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15847 /*IsInstantiation=*/true,
15848 /*RetainFunctionScopeInfo=*/true);
15849 SavedContext.pop();
15850
15851 // Recompute the dependency of the lambda so that we can defer the lambda call
15852 // construction until after we have all the necessary template arguments. For
15853 // example, given
15854 //
15855 // template <class> struct S {
15856 // template <class U>
15857 // using Type = decltype([](U){}(42.0));
15858 // };
15859 // void foo() {
15860 // using T = S<int>::Type<float>;
15861 // ^~~~~~
15862 // }
15863 //
15864 // We would end up here from instantiating S<int> when ensuring its
15865 // completeness. That would transform the lambda call expression regardless of
15866 // the absence of the corresponding argument for U.
15867 //
15868 // Going ahead with unsubstituted type U makes things worse: we would soon
15869 // compare the argument type (which is float) against the parameter U
15870 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15871 // error suggesting unmatched types 'U' and 'float'!
15872 //
15873 // That said, everything will be fine if we defer that semantic checking.
15874 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15875 // dependent. Since the CallExpr's dependency boils down to the lambda's
15876 // dependency in this case, we can harness that by recomputing the dependency
15877 // from the instantiation arguments.
15878 //
15879 // FIXME: Creating the type of a lambda requires us to have a dependency
15880 // value, which happens before its substitution. We update its dependency
15881 // *after* the substitution in case we can't decide the dependency
15882 // so early, e.g. because we want to see if any of the *substituted*
15883 // parameters are dependent.
15884 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
15885 Class->setLambdaDependencyKind(DependencyKind);
15886
15887 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15888 Body.get()->getEndLoc(), LSI);
15889}
15890
15891template<typename Derived>
15894 return TransformStmt(S);
15895}
15896
15897template<typename Derived>
15900 // Transform captures.
15901 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15902 CEnd = E->capture_end();
15903 C != CEnd; ++C) {
15904 // When we hit the first implicit capture, tell Sema that we've finished
15905 // the list of explicit captures.
15906 if (!C->isImplicit())
15907 continue;
15908
15909 // Capturing 'this' is trivial.
15910 if (C->capturesThis()) {
15911 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15912 /*BuildAndDiagnose*/ true, nullptr,
15913 C->getCaptureKind() == LCK_StarThis);
15914 continue;
15915 }
15916 // Captured expression will be recaptured during captured variables
15917 // rebuilding.
15918 if (C->capturesVLAType())
15919 continue;
15920
15921 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15922 assert(!E->isInitCapture(C) && "implicit init-capture?");
15923
15924 // Transform the captured variable.
15925 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15926 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15927 if (!CapturedVar || CapturedVar->isInvalidDecl())
15928 return StmtError();
15929
15930 // Capture the transformed variable.
15931 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15932 }
15933
15934 return S;
15935}
15936
15937template<typename Derived>
15941 TypeSourceInfo *T =
15942 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15943 if (!T)
15944 return ExprError();
15945
15946 bool ArgumentChanged = false;
15948 Args.reserve(E->getNumArgs());
15949 {
15952 E->isListInitialization());
15953 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15954 &ArgumentChanged))
15955 return ExprError();
15956 }
15957
15958 if (!getDerived().AlwaysRebuild() &&
15959 T == E->getTypeSourceInfo() &&
15960 !ArgumentChanged)
15961 return E;
15962
15963 // FIXME: we're faking the locations of the commas
15964 return getDerived().RebuildCXXUnresolvedConstructExpr(
15965 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15966}
15967
15968template<typename Derived>
15970TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
15971 CXXDependentScopeMemberExpr *E) {
15972 // Transform the base of the expression.
15973 ExprResult Base((Expr*) nullptr);
15974 Expr *OldBase;
15975 QualType BaseType;
15976 QualType ObjectType;
15977 if (!E->isImplicitAccess()) {
15978 OldBase = E->getBase();
15979 Base = getDerived().TransformExpr(OldBase);
15980 if (Base.isInvalid())
15981 return ExprError();
15982
15983 // Start the member reference and compute the object's type.
15984 ParsedType ObjectTy;
15985 bool MayBePseudoDestructor = false;
15986 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15987 E->getOperatorLoc(),
15988 E->isArrow()? tok::arrow : tok::period,
15989 ObjectTy,
15990 MayBePseudoDestructor);
15991 if (Base.isInvalid())
15992 return ExprError();
15993
15994 ObjectType = ObjectTy.get();
15995 BaseType = ((Expr*) Base.get())->getType();
15996 } else {
15997 OldBase = nullptr;
15998 BaseType = getDerived().TransformType(E->getBaseType());
15999 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16000 }
16001
16002 // Transform the first part of the nested-name-specifier that qualifies
16003 // the member name.
16004 NamedDecl *FirstQualifierInScope
16005 = getDerived().TransformFirstQualifierInScope(
16006 E->getFirstQualifierFoundInScope(),
16007 E->getQualifierLoc().getBeginLoc());
16008
16009 NestedNameSpecifierLoc QualifierLoc;
16010 if (E->getQualifier()) {
16011 QualifierLoc
16012 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16013 ObjectType,
16014 FirstQualifierInScope);
16015 if (!QualifierLoc)
16016 return ExprError();
16017 }
16018
16019 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16020
16021 // TODO: If this is a conversion-function-id, verify that the
16022 // destination type name (if present) resolves the same way after
16023 // instantiation as it did in the local scope.
16024
16025 DeclarationNameInfo NameInfo
16026 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16027 if (!NameInfo.getName())
16028 return ExprError();
16029
16030 if (!E->hasExplicitTemplateArgs()) {
16031 // This is a reference to a member without an explicitly-specified
16032 // template argument list. Optimize for this common case.
16033 if (!getDerived().AlwaysRebuild() &&
16034 Base.get() == OldBase &&
16035 BaseType == E->getBaseType() &&
16036 QualifierLoc == E->getQualifierLoc() &&
16037 NameInfo.getName() == E->getMember() &&
16038 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16039 return E;
16040
16041 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16042 BaseType,
16043 E->isArrow(),
16044 E->getOperatorLoc(),
16045 QualifierLoc,
16046 TemplateKWLoc,
16047 FirstQualifierInScope,
16048 NameInfo,
16049 /*TemplateArgs*/nullptr);
16050 }
16051
16052 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16053 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16054 E->getNumTemplateArgs(),
16055 TransArgs))
16056 return ExprError();
16057
16058 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16059 BaseType,
16060 E->isArrow(),
16061 E->getOperatorLoc(),
16062 QualifierLoc,
16063 TemplateKWLoc,
16064 FirstQualifierInScope,
16065 NameInfo,
16066 &TransArgs);
16067}
16068
16069template <typename Derived>
16070ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
16071 UnresolvedMemberExpr *Old) {
16072 // Transform the base of the expression.
16073 ExprResult Base((Expr *)nullptr);
16074 QualType BaseType;
16075 if (!Old->isImplicitAccess()) {
16076 Base = getDerived().TransformExpr(Old->getBase());
16077 if (Base.isInvalid())
16078 return ExprError();
16079 Base =
16080 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16081 if (Base.isInvalid())
16082 return ExprError();
16083 BaseType = Base.get()->getType();
16084 } else {
16085 BaseType = getDerived().TransformType(Old->getBaseType());
16086 }
16087
16088 NestedNameSpecifierLoc QualifierLoc;
16089 if (Old->getQualifierLoc()) {
16090 QualifierLoc =
16091 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16092 if (!QualifierLoc)
16093 return ExprError();
16094 }
16095
16096 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16097
16098 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16099
16100 // Transform the declaration set.
16101 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16102 return ExprError();
16103
16104 // Determine the naming class.
16105 if (Old->getNamingClass()) {
16106 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16107 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16108 if (!NamingClass)
16109 return ExprError();
16110
16111 R.setNamingClass(NamingClass);
16112 }
16113
16114 TemplateArgumentListInfo TransArgs;
16115 if (Old->hasExplicitTemplateArgs()) {
16116 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16117 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16118 if (getDerived().TransformTemplateArguments(
16119 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16120 return ExprError();
16121 }
16122
16123 // FIXME: to do this check properly, we will need to preserve the
16124 // first-qualifier-in-scope here, just in case we had a dependent
16125 // base (and therefore couldn't do the check) and a
16126 // nested-name-qualifier (and therefore could do the lookup).
16127 NamedDecl *FirstQualifierInScope = nullptr;
16128
16129 return getDerived().RebuildUnresolvedMemberExpr(
16130 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16131 TemplateKWLoc, FirstQualifierInScope, R,
16132 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16133}
16134
16135template<typename Derived>
16137TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
16138 EnterExpressionEvaluationContext Unevaluated(
16140 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16141 if (SubExpr.isInvalid())
16142 return ExprError();
16143
16144 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16145 return E;
16146
16147 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16148}
16149
16150template<typename Derived>
16152TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
16153 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16154 if (Pattern.isInvalid())
16155 return ExprError();
16156
16157 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16158 return E;
16159
16160 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16161 E->getNumExpansions());
16162}
16163
16164template <typename Derived>
16166 ArrayRef<TemplateArgument> PackArgs) {
16168 for (const TemplateArgument &Arg : PackArgs) {
16169 if (!Arg.isPackExpansion()) {
16170 Result = *Result + 1;
16171 continue;
16172 }
16173
16174 TemplateArgumentLoc ArgLoc;
16175 InventTemplateArgumentLoc(Arg, ArgLoc);
16176
16177 // Find the pattern of the pack expansion.
16178 SourceLocation Ellipsis;
16179 UnsignedOrNone OrigNumExpansions = std::nullopt;
16180 TemplateArgumentLoc Pattern =
16181 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16182 OrigNumExpansions);
16183
16184 // Substitute under the pack expansion. Do not expand the pack (yet).
16185 TemplateArgumentLoc OutPattern;
16186 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16187 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16188 /*Uneval*/ true))
16189 return 1u;
16190
16191 // See if we can determine the number of arguments from the result.
16192 UnsignedOrNone NumExpansions =
16193 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16194 if (!NumExpansions) {
16195 // No: we must be in an alias template expansion, and we're going to
16196 // need to actually expand the packs.
16197 Result = std::nullopt;
16198 break;
16199 }
16200
16201 Result = *Result + *NumExpansions;
16202 }
16203 return Result;
16204}
16205
16206template<typename Derived>
16209 // If E is not value-dependent, then nothing will change when we transform it.
16210 // Note: This is an instantiation-centric view.
16211 if (!E->isValueDependent())
16212 return E;
16213
16216
16218 TemplateArgument ArgStorage;
16219
16220 // Find the argument list to transform.
16221 if (E->isPartiallySubstituted()) {
16222 PackArgs = E->getPartialArguments();
16223 } else if (E->isValueDependent()) {
16224 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16225 bool ShouldExpand = false;
16226 bool RetainExpansion = false;
16227 UnsignedOrNone NumExpansions = std::nullopt;
16228 if (getDerived().TryExpandParameterPacks(
16229 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16230 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16231 RetainExpansion, NumExpansions))
16232 return ExprError();
16233
16234 // If we need to expand the pack, build a template argument from it and
16235 // expand that.
16236 if (ShouldExpand) {
16237 auto *Pack = E->getPack();
16238 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16239 ArgStorage = getSema().Context.getPackExpansionType(
16240 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16241 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16242 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16243 } else {
16244 auto *VD = cast<ValueDecl>(Pack);
16245 ExprResult DRE = getSema().BuildDeclRefExpr(
16246 VD, VD->getType().getNonLValueExprType(getSema().Context),
16247 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16248 E->getPackLoc());
16249 if (DRE.isInvalid())
16250 return ExprError();
16251 ArgStorage = TemplateArgument(
16252 new (getSema().Context)
16253 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16254 /*IsCanonical=*/false);
16255 }
16256 PackArgs = ArgStorage;
16257 }
16258 }
16259
16260 // If we're not expanding the pack, just transform the decl.
16261 if (!PackArgs.size()) {
16262 auto *Pack = cast_or_null<NamedDecl>(
16263 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16264 if (!Pack)
16265 return ExprError();
16266 return getDerived().RebuildSizeOfPackExpr(
16267 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16268 std::nullopt, {});
16269 }
16270
16271 // Try to compute the result without performing a partial substitution.
16272 UnsignedOrNone Result =
16273 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16274
16275 // Common case: we could determine the number of expansions without
16276 // substituting.
16277 if (Result)
16278 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16279 E->getPackLoc(),
16280 E->getRParenLoc(), *Result, {});
16281
16282 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16283 E->getPackLoc());
16284 {
16285 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16286 typedef TemplateArgumentLocInventIterator<
16287 Derived, const TemplateArgument*> PackLocIterator;
16288 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16289 PackLocIterator(*this, PackArgs.end()),
16290 TransformedPackArgs, /*Uneval*/true))
16291 return ExprError();
16292 }
16293
16294 // Check whether we managed to fully-expand the pack.
16295 // FIXME: Is it possible for us to do so and not hit the early exit path?
16297 bool PartialSubstitution = false;
16298 for (auto &Loc : TransformedPackArgs.arguments()) {
16299 Args.push_back(Loc.getArgument());
16300 if (Loc.getArgument().isPackExpansion())
16301 PartialSubstitution = true;
16302 }
16303
16304 if (PartialSubstitution)
16305 return getDerived().RebuildSizeOfPackExpr(
16306 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16307 std::nullopt, Args);
16308
16309 return getDerived().RebuildSizeOfPackExpr(
16310 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16311 /*Length=*/static_cast<unsigned>(Args.size()),
16312 /*PartialArgs=*/{});
16313}
16314
16315template <typename Derived>
16317TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
16318 if (!E->isValueDependent())
16319 return E;
16320
16321 // Transform the index
16322 ExprResult IndexExpr;
16323 {
16324 EnterExpressionEvaluationContext ConstantContext(
16326 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16327 if (IndexExpr.isInvalid())
16328 return ExprError();
16329 }
16330
16331 SmallVector<Expr *, 5> ExpandedExprs;
16332 bool FullySubstituted = true;
16333 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16334 Expr *Pattern = E->getPackIdExpression();
16336 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16337 Unexpanded);
16338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16339
16340 // Determine whether the set of unexpanded parameter packs can and should
16341 // be expanded.
16342 bool ShouldExpand = true;
16343 bool RetainExpansion = false;
16344 UnsignedOrNone OrigNumExpansions = std::nullopt,
16345 NumExpansions = std::nullopt;
16346 if (getDerived().TryExpandParameterPacks(
16347 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16348 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16349 RetainExpansion, NumExpansions))
16350 return true;
16351 if (!ShouldExpand) {
16352 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16353 ExprResult Pack = getDerived().TransformExpr(Pattern);
16354 if (Pack.isInvalid())
16355 return ExprError();
16356 return getDerived().RebuildPackIndexingExpr(
16357 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16358 {}, /*FullySubstituted=*/false);
16359 }
16360 for (unsigned I = 0; I != *NumExpansions; ++I) {
16361 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16362 ExprResult Out = getDerived().TransformExpr(Pattern);
16363 if (Out.isInvalid())
16364 return true;
16365 if (Out.get()->containsUnexpandedParameterPack()) {
16366 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16367 OrigNumExpansions);
16368 if (Out.isInvalid())
16369 return true;
16370 FullySubstituted = false;
16371 }
16372 ExpandedExprs.push_back(Out.get());
16373 }
16374 // If we're supposed to retain a pack expansion, do so by temporarily
16375 // forgetting the partially-substituted parameter pack.
16376 if (RetainExpansion) {
16377 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16378
16379 ExprResult Out = getDerived().TransformExpr(Pattern);
16380 if (Out.isInvalid())
16381 return true;
16382
16383 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16384 OrigNumExpansions);
16385 if (Out.isInvalid())
16386 return true;
16387 FullySubstituted = false;
16388 ExpandedExprs.push_back(Out.get());
16389 }
16390 } else if (!E->expandsToEmptyPack()) {
16391 if (getDerived().TransformExprs(E->getExpressions().data(),
16392 E->getExpressions().size(), false,
16393 ExpandedExprs))
16394 return ExprError();
16395 }
16396
16397 return getDerived().RebuildPackIndexingExpr(
16398 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16399 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16400}
16401
16402template<typename Derived>
16404TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
16405 SubstNonTypeTemplateParmPackExpr *E) {
16406 // Default behavior is to do nothing with this transformation.
16407 return E;
16408}
16409
16410template<typename Derived>
16412TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
16413 SubstNonTypeTemplateParmExpr *E) {
16414 // Default behavior is to do nothing with this transformation.
16415 return E;
16416}
16417
16418template<typename Derived>
16420TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
16421 // Default behavior is to do nothing with this transformation.
16422 return E;
16423}
16424
16425template<typename Derived>
16427TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
16428 MaterializeTemporaryExpr *E) {
16429 return getDerived().TransformExpr(E->getSubExpr());
16430}
16431
16432template<typename Derived>
16434TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
16435 UnresolvedLookupExpr *Callee = nullptr;
16436 if (Expr *OldCallee = E->getCallee()) {
16437 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16438 if (CalleeResult.isInvalid())
16439 return ExprError();
16440 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16441 }
16442
16443 Expr *Pattern = E->getPattern();
16444
16446 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16447 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16448
16449 // Determine whether the set of unexpanded parameter packs can and should
16450 // be expanded.
16451 bool Expand = true;
16452 bool RetainExpansion = false;
16453 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
16454 NumExpansions = OrigNumExpansions;
16455 if (getDerived().TryExpandParameterPacks(
16456 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16457 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16458 NumExpansions))
16459 return true;
16460
16461 if (!Expand) {
16462 // Do not expand any packs here, just transform and rebuild a fold
16463 // expression.
16464 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16465
16466 ExprResult LHS =
16467 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16468 if (LHS.isInvalid())
16469 return true;
16470
16471 ExprResult RHS =
16472 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16473 if (RHS.isInvalid())
16474 return true;
16475
16476 if (!getDerived().AlwaysRebuild() &&
16477 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16478 return E;
16479
16480 return getDerived().RebuildCXXFoldExpr(
16481 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16482 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16483 }
16484
16485 // Formally a fold expression expands to nested parenthesized expressions.
16486 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16487 // them.
16488 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
16489 SemaRef.Diag(E->getEllipsisLoc(),
16490 clang::diag::err_fold_expression_limit_exceeded)
16491 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16492 << E->getSourceRange();
16493 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16494 return ExprError();
16495 }
16496
16497 // The transform has determined that we should perform an elementwise
16498 // expansion of the pattern. Do so.
16499 ExprResult Result = getDerived().TransformExpr(E->getInit());
16500 if (Result.isInvalid())
16501 return true;
16502 bool LeftFold = E->isLeftFold();
16503
16504 // If we're retaining an expansion for a right fold, it is the innermost
16505 // component and takes the init (if any).
16506 if (!LeftFold && RetainExpansion) {
16507 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16508
16509 ExprResult Out = getDerived().TransformExpr(Pattern);
16510 if (Out.isInvalid())
16511 return true;
16512
16513 Result = getDerived().RebuildCXXFoldExpr(
16514 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16515 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16516 if (Result.isInvalid())
16517 return true;
16518 }
16519
16520 bool WarnedOnComparison = false;
16521 for (unsigned I = 0; I != *NumExpansions; ++I) {
16522 Sema::ArgPackSubstIndexRAII SubstIndex(
16523 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16524 ExprResult Out = getDerived().TransformExpr(Pattern);
16525 if (Out.isInvalid())
16526 return true;
16527
16528 if (Out.get()->containsUnexpandedParameterPack()) {
16529 // We still have a pack; retain a pack expansion for this slice.
16530 Result = getDerived().RebuildCXXFoldExpr(
16531 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16532 E->getOperator(), E->getEllipsisLoc(),
16533 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16534 OrigNumExpansions);
16535 } else if (Result.isUsable()) {
16536 // We've got down to a single element; build a binary operator.
16537 Expr *LHS = LeftFold ? Result.get() : Out.get();
16538 Expr *RHS = LeftFold ? Out.get() : Result.get();
16539 if (Callee) {
16540 UnresolvedSet<16> Functions;
16541 Functions.append(Callee->decls_begin(), Callee->decls_end());
16542 Result = getDerived().RebuildCXXOperatorCallExpr(
16544 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16545 Functions, LHS, RHS);
16546 } else {
16547 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16548 E->getOperator(), LHS, RHS,
16549 /*ForFoldExpresion=*/true);
16550 if (!WarnedOnComparison && Result.isUsable()) {
16551 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
16552 BO && BO->isComparisonOp()) {
16553 WarnedOnComparison = true;
16554 SemaRef.Diag(BO->getBeginLoc(),
16555 diag::warn_comparison_in_fold_expression)
16556 << BO->getOpcodeStr();
16557 }
16558 }
16559 }
16560 } else
16561 Result = Out;
16562
16563 if (Result.isInvalid())
16564 return true;
16565 }
16566
16567 // If we're retaining an expansion for a left fold, it is the outermost
16568 // component and takes the complete expansion so far as its init (if any).
16569 if (LeftFold && RetainExpansion) {
16570 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16571
16572 ExprResult Out = getDerived().TransformExpr(Pattern);
16573 if (Out.isInvalid())
16574 return true;
16575
16576 Result = getDerived().RebuildCXXFoldExpr(
16577 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16578 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16579 if (Result.isInvalid())
16580 return true;
16581 }
16582
16583 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16584 PE->setIsProducedByFoldExpansion();
16585
16586 // If we had no init and an empty pack, and we're not retaining an expansion,
16587 // then produce a fallback value or error.
16588 if (Result.isUnset())
16589 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16590 E->getOperator());
16591 return Result;
16592}
16593
16594template <typename Derived>
16596TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
16597 SmallVector<Expr *, 4> TransformedInits;
16598 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16599
16600 QualType T = getDerived().TransformType(E->getType());
16601
16602 bool ArgChanged = false;
16603
16604 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
16605 TransformedInits, &ArgChanged))
16606 return ExprError();
16607
16608 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
16609 return E;
16610
16611 return getDerived().RebuildCXXParenListInitExpr(
16612 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
16613 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
16614}
16615
16616template<typename Derived>
16618TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
16619 CXXStdInitializerListExpr *E) {
16620 return getDerived().TransformExpr(E->getSubExpr());
16621}
16622
16623template<typename Derived>
16625TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
16626 return SemaRef.MaybeBindToTemporary(E);
16627}
16628
16629template<typename Derived>
16631TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
16632 return E;
16633}
16634
16635template<typename Derived>
16637TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
16638 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16639 if (SubExpr.isInvalid())
16640 return ExprError();
16641
16642 if (!getDerived().AlwaysRebuild() &&
16643 SubExpr.get() == E->getSubExpr())
16644 return E;
16645
16646 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16647}
16648
16649template<typename Derived>
16651TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
16652 // Transform each of the elements.
16653 SmallVector<Expr *, 8> Elements;
16654 bool ArgChanged = false;
16655 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16656 /*IsCall=*/false, Elements, &ArgChanged))
16657 return ExprError();
16658
16659 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16660 return SemaRef.MaybeBindToTemporary(E);
16661
16662 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16663 Elements.data(),
16664 Elements.size());
16665}
16666
16667template<typename Derived>
16669TreeTransform<Derived>::TransformObjCDictionaryLiteral(
16670 ObjCDictionaryLiteral *E) {
16671 // Transform each of the elements.
16673 bool ArgChanged = false;
16674 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16675 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16676
16677 if (OrigElement.isPackExpansion()) {
16678 // This key/value element is a pack expansion.
16680 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16681 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16682 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16683
16684 // Determine whether the set of unexpanded parameter packs can
16685 // and should be expanded.
16686 bool Expand = true;
16687 bool RetainExpansion = false;
16688 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
16689 UnsignedOrNone NumExpansions = OrigNumExpansions;
16690 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16691 OrigElement.Value->getEndLoc());
16692 if (getDerived().TryExpandParameterPacks(
16693 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
16694 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
16695 NumExpansions))
16696 return ExprError();
16697
16698 if (!Expand) {
16699 // The transform has determined that we should perform a simple
16700 // transformation on the pack expansion, producing another pack
16701 // expansion.
16702 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16703 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16704 if (Key.isInvalid())
16705 return ExprError();
16706
16707 if (Key.get() != OrigElement.Key)
16708 ArgChanged = true;
16709
16710 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16711 if (Value.isInvalid())
16712 return ExprError();
16713
16714 if (Value.get() != OrigElement.Value)
16715 ArgChanged = true;
16716
16717 ObjCDictionaryElement Expansion = {
16718 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16719 };
16720 Elements.push_back(Expansion);
16721 continue;
16722 }
16723
16724 // Record right away that the argument was changed. This needs
16725 // to happen even if the array expands to nothing.
16726 ArgChanged = true;
16727
16728 // The transform has determined that we should perform an elementwise
16729 // expansion of the pattern. Do so.
16730 for (unsigned I = 0; I != *NumExpansions; ++I) {
16731 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16732 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16733 if (Key.isInvalid())
16734 return ExprError();
16735
16736 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16737 if (Value.isInvalid())
16738 return ExprError();
16739
16740 ObjCDictionaryElement Element = {
16741 Key.get(), Value.get(), SourceLocation(), NumExpansions
16742 };
16743
16744 // If any unexpanded parameter packs remain, we still have a
16745 // pack expansion.
16746 // FIXME: Can this really happen?
16747 if (Key.get()->containsUnexpandedParameterPack() ||
16748 Value.get()->containsUnexpandedParameterPack())
16749 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16750
16751 Elements.push_back(Element);
16752 }
16753
16754 // FIXME: Retain a pack expansion if RetainExpansion is true.
16755
16756 // We've finished with this pack expansion.
16757 continue;
16758 }
16759
16760 // Transform and check key.
16761 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16762 if (Key.isInvalid())
16763 return ExprError();
16764
16765 if (Key.get() != OrigElement.Key)
16766 ArgChanged = true;
16767
16768 // Transform and check value.
16770 = getDerived().TransformExpr(OrigElement.Value);
16771 if (Value.isInvalid())
16772 return ExprError();
16773
16774 if (Value.get() != OrigElement.Value)
16775 ArgChanged = true;
16776
16777 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16778 std::nullopt};
16779 Elements.push_back(Element);
16780 }
16781
16782 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16783 return SemaRef.MaybeBindToTemporary(E);
16784
16785 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16786 Elements);
16787}
16788
16789template<typename Derived>
16791TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
16792 TypeSourceInfo *EncodedTypeInfo
16793 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16794 if (!EncodedTypeInfo)
16795 return ExprError();
16796
16797 if (!getDerived().AlwaysRebuild() &&
16798 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16799 return E;
16800
16801 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16802 EncodedTypeInfo,
16803 E->getRParenLoc());
16804}
16805
16806template<typename Derived>
16807ExprResult TreeTransform<Derived>::
16808TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
16809 // This is a kind of implicit conversion, and it needs to get dropped
16810 // and recomputed for the same general reasons that ImplicitCastExprs
16811 // do, as well a more specific one: this expression is only valid when
16812 // it appears *immediately* as an argument expression.
16813 return getDerived().TransformExpr(E->getSubExpr());
16814}
16815
16816template<typename Derived>
16817ExprResult TreeTransform<Derived>::
16818TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
16819 TypeSourceInfo *TSInfo
16820 = getDerived().TransformType(E->getTypeInfoAsWritten());
16821 if (!TSInfo)
16822 return ExprError();
16823
16824 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16825 if (Result.isInvalid())
16826 return ExprError();
16827
16828 if (!getDerived().AlwaysRebuild() &&
16829 TSInfo == E->getTypeInfoAsWritten() &&
16830 Result.get() == E->getSubExpr())
16831 return E;
16832
16833 return SemaRef.ObjC().BuildObjCBridgedCast(
16834 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16835 Result.get());
16836}
16837
16838template <typename Derived>
16839ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
16840 ObjCAvailabilityCheckExpr *E) {
16841 return E;
16842}
16843
16844template<typename Derived>
16846TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
16847 // Transform arguments.
16848 bool ArgChanged = false;
16850 Args.reserve(E->getNumArgs());
16851 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16852 &ArgChanged))
16853 return ExprError();
16854
16855 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16856 // Class message: transform the receiver type.
16857 TypeSourceInfo *ReceiverTypeInfo
16858 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16859 if (!ReceiverTypeInfo)
16860 return ExprError();
16861
16862 // If nothing changed, just retain the existing message send.
16863 if (!getDerived().AlwaysRebuild() &&
16864 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16865 return SemaRef.MaybeBindToTemporary(E);
16866
16867 // Build a new class message send.
16869 E->getSelectorLocs(SelLocs);
16870 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16871 E->getSelector(),
16872 SelLocs,
16873 E->getMethodDecl(),
16874 E->getLeftLoc(),
16875 Args,
16876 E->getRightLoc());
16877 }
16878 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16879 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16880 if (!E->getMethodDecl())
16881 return ExprError();
16882
16883 // Build a new class message send to 'super'.
16885 E->getSelectorLocs(SelLocs);
16886 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16887 E->getSelector(),
16888 SelLocs,
16889 E->getReceiverType(),
16890 E->getMethodDecl(),
16891 E->getLeftLoc(),
16892 Args,
16893 E->getRightLoc());
16894 }
16895
16896 // Instance message: transform the receiver
16897 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16898 "Only class and instance messages may be instantiated");
16899 ExprResult Receiver
16900 = getDerived().TransformExpr(E->getInstanceReceiver());
16901 if (Receiver.isInvalid())
16902 return ExprError();
16903
16904 // If nothing changed, just retain the existing message send.
16905 if (!getDerived().AlwaysRebuild() &&
16906 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16907 return SemaRef.MaybeBindToTemporary(E);
16908
16909 // Build a new instance message send.
16911 E->getSelectorLocs(SelLocs);
16912 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16913 E->getSelector(),
16914 SelLocs,
16915 E->getMethodDecl(),
16916 E->getLeftLoc(),
16917 Args,
16918 E->getRightLoc());
16919}
16920
16921template<typename Derived>
16923TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
16924 return E;
16925}
16926
16927template<typename Derived>
16929TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
16930 return E;
16931}
16932
16933template<typename Derived>
16935TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
16936 // Transform the base expression.
16937 ExprResult Base = getDerived().TransformExpr(E->getBase());
16938 if (Base.isInvalid())
16939 return ExprError();
16940
16941 // We don't need to transform the ivar; it will never change.
16942
16943 // If nothing changed, just retain the existing expression.
16944 if (!getDerived().AlwaysRebuild() &&
16945 Base.get() == E->getBase())
16946 return E;
16947
16948 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16949 E->getLocation(),
16950 E->isArrow(), E->isFreeIvar());
16951}
16952
16953template<typename Derived>
16955TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
16956 // 'super' and types never change. Property never changes. Just
16957 // retain the existing expression.
16958 if (!E->isObjectReceiver())
16959 return E;
16960
16961 // Transform the base expression.
16962 ExprResult Base = getDerived().TransformExpr(E->getBase());
16963 if (Base.isInvalid())
16964 return ExprError();
16965
16966 // We don't need to transform the property; it will never change.
16967
16968 // If nothing changed, just retain the existing expression.
16969 if (!getDerived().AlwaysRebuild() &&
16970 Base.get() == E->getBase())
16971 return E;
16972
16973 if (E->isExplicitProperty())
16974 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16975 E->getExplicitProperty(),
16976 E->getLocation());
16977
16978 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16979 SemaRef.Context.PseudoObjectTy,
16980 E->getImplicitPropertyGetter(),
16981 E->getImplicitPropertySetter(),
16982 E->getLocation());
16983}
16984
16985template<typename Derived>
16987TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
16988 // Transform the base expression.
16989 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16990 if (Base.isInvalid())
16991 return ExprError();
16992
16993 // Transform the key expression.
16994 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16995 if (Key.isInvalid())
16996 return ExprError();
16997
16998 // If nothing changed, just retain the existing expression.
16999 if (!getDerived().AlwaysRebuild() &&
17000 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17001 return E;
17002
17003 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17004 Base.get(), Key.get(),
17005 E->getAtIndexMethodDecl(),
17006 E->setAtIndexMethodDecl());
17007}
17008
17009template<typename Derived>
17011TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
17012 // Transform the base expression.
17013 ExprResult Base = getDerived().TransformExpr(E->getBase());
17014 if (Base.isInvalid())
17015 return ExprError();
17016
17017 // If nothing changed, just retain the existing expression.
17018 if (!getDerived().AlwaysRebuild() &&
17019 Base.get() == E->getBase())
17020 return E;
17021
17022 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17023 E->getOpLoc(),
17024 E->isArrow());
17025}
17026
17027template<typename Derived>
17029TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
17030 bool ArgumentChanged = false;
17031 SmallVector<Expr*, 8> SubExprs;
17032 SubExprs.reserve(E->getNumSubExprs());
17033 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17034 SubExprs, &ArgumentChanged))
17035 return ExprError();
17036
17037 if (!getDerived().AlwaysRebuild() &&
17038 !ArgumentChanged)
17039 return E;
17040
17041 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17042 SubExprs,
17043 E->getRParenLoc());
17044}
17045
17046template<typename Derived>
17048TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
17049 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17050 if (SrcExpr.isInvalid())
17051 return ExprError();
17052
17053 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17054 if (!Type)
17055 return ExprError();
17056
17057 if (!getDerived().AlwaysRebuild() &&
17058 Type == E->getTypeSourceInfo() &&
17059 SrcExpr.get() == E->getSrcExpr())
17060 return E;
17061
17062 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17063 SrcExpr.get(), Type,
17064 E->getRParenLoc());
17065}
17066
17067template<typename Derived>
17069TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
17070 BlockDecl *oldBlock = E->getBlockDecl();
17071
17072 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17073 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17074
17075 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17076 blockScope->TheDecl->setBlockMissingReturnType(
17077 oldBlock->blockMissingReturnType());
17078
17080 SmallVector<QualType, 4> paramTypes;
17081
17082 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17083
17084 // Parameter substitution.
17085 Sema::ExtParameterInfoBuilder extParamInfos;
17086 if (getDerived().TransformFunctionTypeParams(
17087 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17088 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17089 extParamInfos)) {
17090 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17091 return ExprError();
17092 }
17093
17094 QualType exprResultType =
17095 getDerived().TransformType(exprFunctionType->getReturnType());
17096
17097 auto epi = exprFunctionType->getExtProtoInfo();
17098 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17099
17100 QualType functionType =
17101 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17102 blockScope->FunctionType = functionType;
17103
17104 // Set the parameters on the block decl.
17105 if (!params.empty())
17106 blockScope->TheDecl->setParams(params);
17107
17108 if (!oldBlock->blockMissingReturnType()) {
17109 blockScope->HasImplicitReturnType = false;
17110 blockScope->ReturnType = exprResultType;
17111 }
17112
17113 // Transform the body
17114 StmtResult body = getDerived().TransformStmt(E->getBody());
17115 if (body.isInvalid()) {
17116 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17117 return ExprError();
17118 }
17119
17120#ifndef NDEBUG
17121 // In builds with assertions, make sure that we captured everything we
17122 // captured before.
17123 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17124 for (const auto &I : oldBlock->captures()) {
17125 VarDecl *oldCapture = I.getVariable();
17126
17127 // Ignore parameter packs.
17128 if (oldCapture->isParameterPack())
17129 continue;
17130
17131 VarDecl *newCapture =
17132 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17133 oldCapture));
17134 assert(blockScope->CaptureMap.count(newCapture));
17135 }
17136
17137 // The this pointer may not be captured by the instantiated block, even when
17138 // it's captured by the original block, if the expression causing the
17139 // capture is in the discarded branch of a constexpr if statement.
17140 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17141 "this pointer isn't captured in the old block");
17142 }
17143#endif
17144
17145 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17146 /*Scope=*/nullptr);
17147}
17148
17149template<typename Derived>
17151TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
17152 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17153 if (SrcExpr.isInvalid())
17154 return ExprError();
17155
17156 QualType Type = getDerived().TransformType(E->getType());
17157
17158 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17159 E->getRParenLoc());
17160}
17161
17162template<typename Derived>
17164TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
17165 bool ArgumentChanged = false;
17166 SmallVector<Expr*, 8> SubExprs;
17167 SubExprs.reserve(E->getNumSubExprs());
17168 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17169 SubExprs, &ArgumentChanged))
17170 return ExprError();
17171
17172 if (!getDerived().AlwaysRebuild() &&
17173 !ArgumentChanged)
17174 return E;
17175
17176 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17177 E->getOp(), E->getRParenLoc());
17178}
17179
17180//===----------------------------------------------------------------------===//
17181// Type reconstruction
17182//===----------------------------------------------------------------------===//
17183
17184template<typename Derived>
17187 return SemaRef.BuildPointerType(PointeeType, Star,
17188 getDerived().getBaseEntity());
17189}
17190
17191template<typename Derived>
17194 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17195 getDerived().getBaseEntity());
17196}
17197
17198template<typename Derived>
17201 bool WrittenAsLValue,
17202 SourceLocation Sigil) {
17203 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17204 Sigil, getDerived().getBaseEntity());
17205}
17206
17207template <typename Derived>
17209 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17210 SourceLocation Sigil) {
17211 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17212 getDerived().getBaseEntity());
17213}
17214
17215template<typename Derived>
17217 const ObjCTypeParamDecl *Decl,
17218 SourceLocation ProtocolLAngleLoc,
17220 ArrayRef<SourceLocation> ProtocolLocs,
17221 SourceLocation ProtocolRAngleLoc) {
17222 return SemaRef.ObjC().BuildObjCTypeParamType(
17223 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17224 /*FailOnError=*/true);
17225}
17226
17227template<typename Derived>
17229 QualType BaseType,
17231 SourceLocation TypeArgsLAngleLoc,
17233 SourceLocation TypeArgsRAngleLoc,
17234 SourceLocation ProtocolLAngleLoc,
17236 ArrayRef<SourceLocation> ProtocolLocs,
17237 SourceLocation ProtocolRAngleLoc) {
17238 return SemaRef.ObjC().BuildObjCObjectType(
17239 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17240 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17241 /*FailOnError=*/true,
17242 /*Rebuilding=*/true);
17243}
17244
17245template<typename Derived>
17247 QualType PointeeType,
17249 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17250}
17251
17252template <typename Derived>
17254 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17255 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17256 if (SizeExpr || !Size)
17257 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17258 IndexTypeQuals, BracketsRange,
17259 getDerived().getBaseEntity());
17260
17261 QualType Types[] = {
17265 };
17266 QualType SizeType;
17267 for (const auto &T : Types)
17268 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17269 SizeType = T;
17270 break;
17271 }
17272
17273 // Note that we can return a VariableArrayType here in the case where
17274 // the element type was a dependent VariableArrayType.
17275 IntegerLiteral *ArraySize
17276 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17277 /*FIXME*/BracketsRange.getBegin());
17278 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17279 IndexTypeQuals, BracketsRange,
17280 getDerived().getBaseEntity());
17281}
17282
17283template <typename Derived>
17285 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17286 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17287 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17288 IndexTypeQuals, BracketsRange);
17289}
17290
17291template <typename Derived>
17293 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17294 SourceRange BracketsRange) {
17295 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17296 IndexTypeQuals, BracketsRange);
17297}
17298
17299template <typename Derived>
17301 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17302 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17303 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17304 SizeExpr,
17305 IndexTypeQuals, BracketsRange);
17306}
17307
17308template <typename Derived>
17310 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17311 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17312 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17313 SizeExpr,
17314 IndexTypeQuals, BracketsRange);
17315}
17316
17317template <typename Derived>
17319 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17320 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17321 AttributeLoc);
17322}
17323
17324template <typename Derived>
17326 unsigned NumElements,
17327 VectorKind VecKind) {
17328 // FIXME: semantic checking!
17329 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17330}
17331
17332template <typename Derived>
17334 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17335 VectorKind VecKind) {
17336 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17337}
17338
17339template<typename Derived>
17341 unsigned NumElements,
17342 SourceLocation AttributeLoc) {
17343 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17344 NumElements, true);
17345 IntegerLiteral *VectorSize
17346 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17347 AttributeLoc);
17348 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17349}
17350
17351template<typename Derived>
17354 Expr *SizeExpr,
17355 SourceLocation AttributeLoc) {
17356 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17357}
17358
17359template <typename Derived>
17361 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17362 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17363 NumColumns);
17364}
17365
17366template <typename Derived>
17368 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17369 SourceLocation AttributeLoc) {
17370 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17371 AttributeLoc);
17372}
17373
17374template <typename Derived>
17378 return SemaRef.BuildFunctionType(T, ParamTypes,
17379 getDerived().getBaseLocation(),
17380 getDerived().getBaseEntity(),
17381 EPI);
17382}
17383
17384template<typename Derived>
17386 return SemaRef.Context.getFunctionNoProtoType(T);
17387}
17388
17389template <typename Derived>
17392 SourceLocation NameLoc, Decl *D) {
17393 assert(D && "no decl found");
17394 if (D->isInvalidDecl()) return QualType();
17395
17396 // FIXME: Doesn't account for ObjCInterfaceDecl!
17397 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17398 // A valid resolved using typename pack expansion decl can have multiple
17399 // UsingDecls, but they must each have exactly one type, and it must be
17400 // the same type in every case. But we must have at least one expansion!
17401 if (UPD->expansions().empty()) {
17402 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17403 << UPD->isCXXClassMember() << UPD;
17404 return QualType();
17405 }
17406
17407 // We might still have some unresolved types. Try to pick a resolved type
17408 // if we can. The final instantiation will check that the remaining
17409 // unresolved types instantiate to the type we pick.
17410 QualType FallbackT;
17411 QualType T;
17412 for (auto *E : UPD->expansions()) {
17413 QualType ThisT =
17414 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17415 if (ThisT.isNull())
17416 continue;
17417 if (ThisT->getAs<UnresolvedUsingType>())
17418 FallbackT = ThisT;
17419 else if (T.isNull())
17420 T = ThisT;
17421 else
17422 assert(getSema().Context.hasSameType(ThisT, T) &&
17423 "mismatched resolved types in using pack expansion");
17424 }
17425 return T.isNull() ? FallbackT : T;
17426 }
17427 if (auto *Using = dyn_cast<UsingDecl>(D)) {
17428 assert(Using->hasTypename() &&
17429 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17430
17431 // A valid resolved using typename decl points to exactly one type decl.
17432 assert(++Using->shadow_begin() == Using->shadow_end());
17433
17434 UsingShadowDecl *Shadow = *Using->shadow_begin();
17435 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
17436 return QualType();
17437 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
17438 }
17439 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
17440 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17441 return SemaRef.Context.getUnresolvedUsingType(
17442 Keyword, Qualifier, cast<UnresolvedUsingTypenameDecl>(D));
17443}
17444
17445template <typename Derived>
17447 TypeOfKind Kind) {
17448 return SemaRef.BuildTypeofExprType(E, Kind);
17449}
17450
17451template<typename Derived>
17453 TypeOfKind Kind) {
17454 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17455}
17456
17457template <typename Derived>
17459 return SemaRef.BuildDecltypeType(E);
17460}
17461
17462template <typename Derived>
17464 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17465 SourceLocation EllipsisLoc, bool FullySubstituted,
17466 ArrayRef<QualType> Expansions) {
17467 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17468 FullySubstituted, Expansions);
17469}
17470
17471template<typename Derived>
17475 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17476}
17477
17478template <typename Derived>
17481 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
17482 return SemaRef.CheckTemplateIdType(Keyword, Template, TemplateNameLoc,
17483 TemplateArgs);
17484}
17485
17486template<typename Derived>
17488 SourceLocation KWLoc) {
17489 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17490}
17491
17492template<typename Derived>
17494 SourceLocation KWLoc,
17495 bool isReadPipe) {
17496 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17497 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17498}
17499
17500template <typename Derived>
17502 unsigned NumBits,
17504 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17505 NumBits, true);
17506 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17507 SemaRef.Context.IntTy, Loc);
17508 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17509}
17510
17511template <typename Derived>
17513 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17514 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17515}
17516
17517template <typename Derived>
17519 bool TemplateKW,
17520 TemplateName Name) {
17521 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17522 Name);
17523}
17524
17525template <typename Derived>
17527 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
17528 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
17530 TemplateName.setIdentifier(&Name, NameLoc);
17532 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17533 TemplateName, ParsedType::make(ObjectType),
17534 /*EnteringContext=*/false, Template,
17535 AllowInjectedClassName);
17536 return Template.get();
17537}
17538
17539template<typename Derived>
17542 SourceLocation TemplateKWLoc,
17543 OverloadedOperatorKind Operator,
17544 SourceLocation NameLoc,
17545 QualType ObjectType,
17546 bool AllowInjectedClassName) {
17547 UnqualifiedId Name;
17548 // FIXME: Bogus location information.
17549 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17550 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17552 getSema().ActOnTemplateName(
17553 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17554 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17555 return Template.get();
17556}
17557
17558template <typename Derived>
17561 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17562 Expr *Second) {
17563 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17564
17565 if (First->getObjectKind() == OK_ObjCProperty) {
17568 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17569 Opc, First, Second);
17571 if (Result.isInvalid())
17572 return ExprError();
17573 First = Result.get();
17574 }
17575
17576 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17577 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17578 if (Result.isInvalid())
17579 return ExprError();
17580 Second = Result.get();
17581 }
17582
17583 // Determine whether this should be a builtin operation.
17584 if (Op == OO_Subscript) {
17585 if (!First->getType()->isOverloadableType() &&
17586 !Second->getType()->isOverloadableType())
17587 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17588 OpLoc);
17589 } else if (Op == OO_Arrow) {
17590 // It is possible that the type refers to a RecoveryExpr created earlier
17591 // in the tree transformation.
17592 if (First->getType()->isDependentType())
17593 return ExprError();
17594 // -> is never a builtin operation.
17595 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17596 } else if (Second == nullptr || isPostIncDec) {
17597 if (!First->getType()->isOverloadableType() ||
17598 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17599 // The argument is not of overloadable type, or this is an expression
17600 // of the form &Class::member, so try to create a built-in unary
17601 // operation.
17603 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17604
17605 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17606 }
17607 } else {
17608 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17609 !First->getType()->isOverloadableType() &&
17610 !Second->getType()->isOverloadableType()) {
17611 // Neither of the arguments is type-dependent or has an overloadable
17612 // type, so try to create a built-in binary operation.
17615 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17616 if (Result.isInvalid())
17617 return ExprError();
17618
17619 return Result;
17620 }
17621 }
17622
17623 // Create the overloaded operator invocation for unary operators.
17624 if (!Second || isPostIncDec) {
17626 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17627 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17628 RequiresADL);
17629 }
17630
17631 // Create the overloaded operator invocation for binary operators.
17633 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17634 First, Second, RequiresADL);
17635 if (Result.isInvalid())
17636 return ExprError();
17637
17638 return Result;
17639}
17640
17641template<typename Derived>
17644 SourceLocation OperatorLoc,
17645 bool isArrow,
17646 CXXScopeSpec &SS,
17647 TypeSourceInfo *ScopeType,
17648 SourceLocation CCLoc,
17649 SourceLocation TildeLoc,
17650 PseudoDestructorTypeStorage Destroyed) {
17651 QualType CanonicalBaseType = Base->getType().getCanonicalType();
17652 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17653 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
17654 (isArrow && isa<PointerType>(CanonicalBaseType) &&
17655 !cast<PointerType>(CanonicalBaseType)
17656 ->getPointeeType()
17657 ->getAsCanonical<RecordType>())) {
17658 // This pseudo-destructor expression is still a pseudo-destructor.
17659 return SemaRef.BuildPseudoDestructorExpr(
17660 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17661 CCLoc, TildeLoc, Destroyed);
17662 }
17663
17664 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17666 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17667 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17668 NameInfo.setNamedTypeInfo(DestroyedType);
17669
17670 // The scope type is now known to be a valid nested name specifier
17671 // component. Tack it on to the nested name specifier.
17672 if (ScopeType) {
17673 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
17674 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17675 diag::err_expected_class_or_namespace)
17676 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17677 return ExprError();
17678 }
17679 SS.clear();
17680 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
17681 }
17682
17683 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17684 return getSema().BuildMemberReferenceExpr(
17685 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
17686 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
17687 /*TemplateArgs*/ nullptr,
17688 /*S*/ nullptr);
17689}
17690
17691template<typename Derived>
17694 SourceLocation Loc = S->getBeginLoc();
17695 CapturedDecl *CD = S->getCapturedDecl();
17696 unsigned NumParams = CD->getNumParams();
17697 unsigned ContextParamPos = CD->getContextParamPosition();
17699 for (unsigned I = 0; I < NumParams; ++I) {
17700 if (I != ContextParamPos) {
17701 Params.push_back(
17702 std::make_pair(
17703 CD->getParam(I)->getName(),
17704 getDerived().TransformType(CD->getParam(I)->getType())));
17705 } else {
17706 Params.push_back(std::make_pair(StringRef(), QualType()));
17707 }
17708 }
17709 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17710 S->getCapturedRegionKind(), Params);
17711 StmtResult Body;
17712 {
17713 Sema::CompoundScopeRAII CompoundScope(getSema());
17714 Body = getDerived().TransformStmt(S->getCapturedStmt());
17715 }
17716
17717 if (Body.isInvalid()) {
17718 getSema().ActOnCapturedRegionError();
17719 return StmtError();
17720 }
17721
17722 return getSema().ActOnCapturedRegionEnd(Body.get());
17723}
17724
17725template <typename Derived>
17727TreeTransform<Derived>::TransformSYCLKernelCallStmt(SYCLKernelCallStmt *S) {
17728 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
17729 // function definition or instantiation of a function template specialization
17730 // and will therefore never appear in a dependent context.
17731 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
17732 "context");
17733}
17734
17735template <typename Derived>
17736ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) {
17737 // We can transform the base expression and allow argument resolution to fill
17738 // in the rest.
17739 return getDerived().TransformExpr(E->getArgLValue());
17740}
17741
17742} // end namespace clang
17743
17744#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
MatchType Type
StringRef P
const Decl * D
Expr * E
unsigned OldSize
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1192
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.
int Priority
Definition: Format.cpp:3181
unsigned Iter
Definition: HTMLLogger.cpp:153
#define X(type, name)
Definition: Value.h:145
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
uint32_t Id
Definition: SemaARM.cpp:1179
SourceRange Range
Definition: SemaObjC.cpp:753
SourceLocation Loc
Definition: SemaObjC.cpp:754
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)
SourceLocation Begin
std::string Label
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1201
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:744
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2851
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2867
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UsingShadowDecl *D, QualType UnderlyingType=QualType()) const
IdentifierTable & Idents
Definition: ASTContext.h:740
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier NNS, const IdentifierInfo *Name) const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CanQualType UnsignedLongTy
Definition: ASTContext.h:1232
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType IntTy
Definition: ASTContext.h:1231
CanQualType PseudoObjectTy
Definition: ASTContext.h:1253
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2442
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1233
CanQualType BuiltinFnTy
Definition: ASTContext.h:1252
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, TemplateDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getPackExpansionType(QualType Pattern, UnsignedOrNone NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
CanQualType UnsignedCharTy
Definition: ASTContext.h:1232
CanQualType UnsignedIntTy
Definition: ASTContext.h:1232
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
TemplateName getQualifiedTemplateName(NestedNameSpecifier Qualifier, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1233
CanQualType UnsignedShortTy
Definition: ASTContext.h:1232
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UnresolvedUsingTypenameDecl *D) const
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
PtrTy get() const
Definition: Ownership.h:171
bool isInvalid() const
Definition: Ownership.h:167
bool isUsable() const
Definition: Ownership.h:169
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2990
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
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: TypeBase.h:7180
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: TypeBase.h:7190
AutoTypeKeyword getKeyword() const
Definition: TypeBase.h:7211
TemplateDecl * getTypeConstraintConcept() const
Definition: TypeBase.h:7195
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2175
bool isAssignmentOp() const
Definition: Expr.h:4113
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2137
void setIsVariadic(bool value)
Definition: Decl.h:4710
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
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1494
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
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
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1039
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1753
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:375
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition: DeclCXX.h:1854
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
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3738
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1513
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4906
unsigned getNumParams() const
Definition: Decl.h:4944
unsigned getContextParamPosition() const
Definition: Decl.h:4973
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4946
This captures a statement into a function.
Definition: Stmt.h:3886
Expr * getSubExpr()
Definition: Expr.h:3662
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1720
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)
Definition: ASTConcept.cpp:87
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:438
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1382
reference front() const
Definition: DeclBase.h:1405
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1879
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1793
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1272
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1611
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:435
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
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:431
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, CanQualType Ty)
Returns a declaration name for special kind of C++ name, e.g., for a constructor, destructor,...
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
The name of a declaration.
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
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: TypeBase.h:7167
bool isDeduced() const
Definition: TypeBase.h:7168
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3504
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2655
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2647
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2614
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2622
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: TypeBase.h:7465
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:590
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition: Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition: Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Designator.h:115
bool hasErrorOccurred() const
Definition: Diagnostic.h:871
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition: TypeBase.h:5002
Expr * getCondition() const
Definition: TypeBase.h:5009
auto * getDecl() const
Definition: TypeLoc.h:747
RAII object that enters a new expression evaluation context.
Wrapper for source info for enum types.
Definition: TypeLoc.h:870
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3886
This represents one expression.
Definition: Expr.h:112
bool isGLValue() const
Definition: Expr.h:287
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
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:273
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
Represents difference between two FPOptions values.
Definition: LangOptions.h:919
Represents a member of a struct/union/class.
Definition: Decl.h:3157
Represents a function declaration or definition.
Definition: Decl.h:1999
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2771
Represents an abstract function effect, using just an enumeration describing its kind.
Definition: TypeBase.h:4895
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5574
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition: Type.cpp:5560
ArrayRef< EffectConditionExpr > conditions() const
Definition: TypeBase.h:5116
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: TypeBase.h:4860
Represents a prototype with parameter type info, e.g.
Definition: TypeBase.h:5282
QualType desugar() const
Definition: TypeBase.h:5863
param_type_iterator param_type_begin() const
Definition: TypeBase.h:5726
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: TypeBase.h:5764
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: TypeBase.h:5702
ExtProtoInfo getExtProtoInfo() const
Definition: TypeBase.h:5571
ArrayRef< QualType > getParamTypes() const
Definition: TypeBase.h:5567
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:4504
QualType getReturnType() const
Definition: TypeBase.h:4818
AssociationTy< false > Association
Definition: Expr.h:6345
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3789
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5993
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:531
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
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1970
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.
Definition: SemaLookup.cpp:488
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
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4914
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 ...
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.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:55
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:266
This represents clauses with a list of expressions that are mappable.
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:6146
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1952
@ 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
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
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
@ Array
An index into an array.
Definition: Expr.h:2428
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2432
@ Field
A field.
Definition: Expr.h:2430
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2435
Wrapper for void* pointer.
Definition: Ownership.h:51
static OpaquePtr make(QualType P)
Definition: Ownership.h:61
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1180
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1230
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)
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)
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)
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)
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< VarDecl * > InitRecipes, SourceLocation EndLoc)
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:2741
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2737
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2753
Represents a pack expansion of types.
Definition: TypeBase.h:7524
UnsignedOrNone getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: TypeBase.h:7549
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2184
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2209
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2213
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
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
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
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:8343
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: TypeBase.h:8383
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: TypeBase.h:8437
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: TypeBase.h:8375
Represents a template name as written in source code.
Definition: TemplateName.h:504
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
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: TypeBase.h:6502
Base for LValueReferenceType and RValueReferenceType.
Definition: TypeBase.h:3589
QualType getPointeeTypeAsWritten() const
Definition: TypeBase.h:3605
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...
Definition: ExprConcepts.h:505
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:1319
Represents a __leave statement.
Definition: Stmt.h:3847
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)
ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C instance message expression.
QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError=false)
Build an Objective-C type parameter type.
Definition: SemaObjC.cpp:480
ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C class message expression.
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition: SemaObjC.cpp:320
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
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
QualType BuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError, bool Rebuilding)
Build an Objective-C object pointer type.
Definition: SemaObjC.cpp:707
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.
void setVarListDetails(ArrayRef< Expr * > VarList, OpenACCModifierKind ModKind)
Definition: SemaOpenACC.h:628
ArrayRef< Expr * > getQueueIdExprs() const
Definition: SemaOpenACC.h:436
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:358
void setLParenLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:559
void setConditionDetails(Expr *ConditionExpr)
Definition: SemaOpenACC.h:568
void setCollapseDetails(bool IsForce, Expr *LoopCount)
Definition: SemaOpenACC.h:743
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:360
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:364
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:362
void setDefaultDetails(OpenACCDefaultClauseKind DefKind)
Definition: SemaOpenACC.h:562
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:416
OpenACCModifierKind getModifierList() const
Definition: SemaOpenACC.h:529
void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)
Definition: SemaOpenACC.h:729
void setEndLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:560
void setIntExprDetails(ArrayRef< Expr * > IntExprs)
Definition: SemaOpenACC.h:582
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:368
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 * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' clause.
OMPClause * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' clause.
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'schedule' clause.
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' clause.
OMPClause * ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'proc_bind' clause.
OMPClause * ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_bare' clause.
StmtResult ActOnOpenMPInformationalDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Process an OpenMP informational directive.
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
OMPClause * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
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 * 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.
ExprResult checkAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
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:13496
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:8393
A RAII object to enter scope of a compound statement.
Definition: Sema.h:1283
A helper class for building up ExtParameterInfos.
Definition: Sema.h:12907
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:12926
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:12914
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:13881
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:1676
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6383
ExprResult ActOnCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition: SemaExpr.cpp:8036
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range)
CheckSpecifiedExceptionType - Check if the given type is valid in an exception specification.
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)
Definition: SemaStmt.cpp:4554
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:9281
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:9289
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:9284
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, SourceLocation AttrLoc)
BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression is uninstantiated.
Definition: SemaType.cpp:6486
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19987
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)
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
Definition: SemaDecl.cpp:17346
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4808
ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
CreateBuiltinBinOp - Creates a new built-in binary operation with operator Opc at location TokLoc.
Definition: SemaExpr.cpp:15069
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2329
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:631
SemaOpenMP & OpenMP()
Definition: Sema.h:1498
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:16101
void ActOnStmtExprError()
Definition: SemaExpr.cpp:16107
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt={})
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
Definition: SemaExpr.cpp:20514
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
Definition: SemaType.cpp:7625
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...
Definition: SemaExpr.cpp:20730
ConditionKind
Definition: Sema.h:7788
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition: SemaCast.cpp:438
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
Definition: SemaStmt.cpp:3223
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
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
Definition: SemaType.cpp:2395
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3549
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:16120
ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, bool *NoArrowOperatorFound=nullptr)
BuildOverloadedArrowExpr - Build a call to an overloaded operator-> (if one exists),...
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition: Sema.h:1523
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16763
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
QualType CheckTemplateIdType(ElaboratedTypeKeyword Keyword, TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
ASTContext & Context
Definition: Sema.h:1276
ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a C++ typeid expression with a type operand.
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
Definition: SemaType.cpp:2642
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:915
concepts::TypeRequirement * BuildTypeRequirement(TypeSourceInfo *Type)
SemaObjC & ObjC()
Definition: Sema.h:1483
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:918
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)
Definition: SemaExpr.cpp:16038
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)
Definition: SemaStmt.cpp:4478
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:756
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3523
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:7126
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:16088
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:8030
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
Definition: SemaType.cpp:9723
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)
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
Definition: SemaDecl.cpp:17371
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:2298
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
Definition: SemaType.cpp:1942
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16375
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 *.
Definition: SemaExpr.cpp:1759
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
Definition: SemaType.cpp:1579
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1296
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:83
const LangOptions & getLangOpts() const
Definition: Sema.h:911
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1790
SemaOpenACC & OpenACC()
Definition: Sema.h:1488
@ ReuseLambdaContextDecl
Definition: Sema.h:6970
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)
Definition: SemaExpr.cpp:17044
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)
Definition: SemaExpr.cpp:16190
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2557
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
Definition: SemaInit.cpp:7699
ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
ConvertVectorExpr - Handle __builtin_convertvector.
QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo &II, SourceLocation IILoc, TypeSourceInfo **TSI, bool DeducedTSTContext)
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
DeclContext * getCurLexicalContext() const
Definition: Sema.h:1117
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)
Definition: SemaCast.cpp:3441
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:1307
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:15237
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
Definition: SemaType.cpp:1859
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input, bool RequiresADL=true)
Create a unary operation that may resolve to an overloaded operator.
QualType BuildMemberPointerType(QualType T, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
Definition: SemaType.cpp:2695
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:3230
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:1411
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,...
bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, NamedDecl *ScopeLookupResult, bool ErrorRecoveryLookup, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
Build a new nested-name-specifier for "identifier::", as described by ActOnCXXNestedNameSpecifier.
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:20356
ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, SourceLocation RParen)
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
Definition: SemaExpr.cpp:2918
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:2253
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3238
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4154
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:21316
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.
Definition: SemaExpr.cpp:6816
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
bool CheckRebuiltStmtAttributes(ArrayRef< const Attr * > Attrs)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
Definition: SemaExpr.cpp:8916
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9845
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.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
concepts::ExprRequirement * BuildExprRequirement(Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement)
QualType BuildAtomicType(QualType T, SourceLocation Loc)
Definition: SemaType.cpp:10131
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
Definition: SemaDecl.cpp:14172
bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, const FunctionEffectWithCondition &EC, SourceLocation NewAttrLoc)
Warn and return true if adding a function effect to a set would create a conflict.
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
Definition: SemaExpr.cpp:218
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:13490
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
Definition: SemaStmt.cpp:3946
ExprResult BuildPseudoDestructorExpr(Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
QualType BuildPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a pointer type.
Definition: SemaType.cpp:1806
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.
Definition: SemaStmt.cpp:2689
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1820
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1172
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
ExprResult BuiltinShuffleVector(CallExpr *TheCall)
BuiltinShuffleVector - Handle __builtin_shufflevector.
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Definition: SemaType.cpp:9813
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:10075
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4516
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4687
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:75
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Definition: SemaExpr.cpp:3003
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:8262
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity)
Build an array type.
Definition: SemaType.cpp:2050
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
Definition: SemaExpr.cpp:15609
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:5658
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:1934
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc)
Complete a lambda-expression having processed and attached the lambda body.
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1938
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:11001
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...
Definition: SemaExpr.cpp:16561
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9700
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.
Definition: SemaExpr.cpp:20380
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,...
Definition: SemaExpr.cpp:18401
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2449
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp:21528
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
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7344
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:16413
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4905
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.
Definition: SemaExpr.cpp:6520
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2773
static ConditionResult ConditionError()
Definition: Sema.h:7775
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:436
SemaPseudoObject & PseudoObject()
Definition: Sema.h:1508
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Definition: SemaStmt.cpp:588
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...
Definition: SemaStmt.cpp:4353
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:568
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:18236
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.
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2756
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3205
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:8599
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5083
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)
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4435
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1709
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:5013
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
bool isInvalid() const
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:358
StmtClass
Definition: Stmt.h:87
@ 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
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:346
Represents the result of substituting a builtin template as a pack.
Definition: TypeBase.h:7062
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:151
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:418
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:1001
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.
Definition: TemplateBase.h:634
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:669
ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:661
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)
std::input_iterator_tag iterator_category
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:528
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:618
SourceLocation getTemplateKWLoc() const
Definition: TemplateBase.h:609
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
Expr * getSourceExpression() const
Definition: TemplateBase.h:584
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Definition: TemplateBase.h:61
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:411
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.
Definition: TemplateBase.h:322
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:366
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:346
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.
Definition: TemplateBase.h:329
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:296
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:399
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:396
Represents a C++ template name within the type system.
Definition: TemplateName.h:222
bool isNull() const
Determine whether this template name is NULL.
NestedNameSpecifier getQualifier() const
Definition: TemplateName.h:346
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:74
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 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, bool AllowInjectedClassName)
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.
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)
QualType RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, SourceLocation TemplateKWLoc, TemplateName Name, SourceLocation NameLoc, TemplateArgumentListInfo &Args, bool AllowInjectedClassName)
Build a new typename type that refers to a template-id.
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
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.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
bool PreparePackForExpansion(TemplateArgumentLoc In, bool Uneval, TemplateArgumentLoc &Out, UnexpandedInfo &Info)
Checks if the argument pack from In will need to be expanded and does the necessary prework.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
QualType RebuildUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, UsingShadowDecl *D, QualType UnderlyingType)
Build a new type found via an alias.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=StmtDiscardKind::Discarded)
Transform the given statement.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
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:2843
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:193
A container of type source information.
Definition: TypeBase.h:8314
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:8325
The base class of the type hierarchy.
Definition: TypeBase.h:1833
bool isSignableType(const ASTContext &Ctx) const
Definition: TypeBase.h:8592
bool isPointerType() const
Definition: TypeBase.h:8580
bool isReferenceType() const
Definition: TypeBase.h:8604
bool isEnumeralType() const
Definition: TypeBase.h:8711
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:752
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: TypeBase.h:2917
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: TypeBase.h:2800
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: TypeBase.h:2423
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: TypeBase.h:9079
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:5355
bool isFunctionType() const
Definition: TypeBase.h:8576
bool isObjCObjectPointerType() const
Definition: TypeBase.h:8749
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: TypeBase.h:2429
const T * getAs() const
Member-template getAs<specific type>'.
Definition: TypeBase.h:9159
bool isRecordType() const
Definition: TypeBase.h:8707
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3559
Wrapper for source info for typedefs.
Definition: TypeLoc.h:782
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2246
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1411
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:998
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
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: TypeBase.h:5998
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3393
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3457
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
QualType getType() const
Definition: Decl.h:722
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition: Decl.cpp:5461
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
A requires-expression requirement which queries the validity and properties of an expression ('simple...
Definition: ExprConcepts.h:282
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:411
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition: ExprConcepts.h:401
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:393
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:432
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
Definition: ExprConcepts.h:487
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:170
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:227
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:262
TypeSourceInfo * getType() const
Definition: ExprConcepts.h:269
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 ...
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:985
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:29
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
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
The JSON file list parser is used to communicate input to InstallAPI.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
Definition: OpenMPKinds.h:194
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
@ NUM_OVERLOADED_OPERATORS
Definition: OperatorKinds.h:26
OpenACCDirectiveKind
Definition: OpenACCKinds.h:28
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
@ CPlusPlus23
Definition: LangStandard.h:60
OpenACCAtomicKind
Definition: OpenACCKinds.h:172
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: TypeBase.h:1792
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:25
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
Definition: OpenMPKinds.h:119
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
Definition: OpenMPKinds.h:172
TryCaptureKind
Definition: Sema.h:651
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
@ Found
Name lookup found a single declaration that met the criteria.
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
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.
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.
Definition: OpenMPKinds.h:136
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition: Sema.h:602
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
Definition: OpenMPKinds.h:187
BinaryOperatorKind
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'.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ FirstPrivate
'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...
@ 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
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:104
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
Definition: OpenMPKinds.h:233
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
ExprResult ExprEmpty()
Definition: Ownership.h:272
StmtResult StmtError()
Definition: Ownership.h:266
@ Property
The type of a property.
@ Result
The result type of a method or function.
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
Definition: OpenMPKinds.h:208
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: TypeBase.h:3735
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
Definition: OpenMPKinds.h:158
@ Template
We are parsing a template declaration.
OpenMPGrainsizeClauseModifier
Definition: OpenMPKinds.h:214
OpenMPNumTasksClauseModifier
Definition: OpenMPKinds.h:220
UnaryOperatorKind
ActionResult< Expr * > ExprResult
Definition: Ownership.h:249
TagTypeKind
The kind of a tag type.
Definition: TypeBase.h:5906
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.
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
Definition: Diagnostic.h:1524
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
Definition: OpenMPKinds.h:143
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:250
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
Definition: OpenMPKinds.h:111
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
Definition: OpenMPKinds.h:240
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:63
@ 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
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:230
const FunctionProtoType * T
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
@ Exists
The symbol exists.
@ Error
An error occurred.
@ DoesNotExist
The symbol does not exist.
OpenMPNumThreadsClauseModifier
Definition: OpenMPKinds.h:226
VectorKind
Definition: TypeBase.h:4150
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition: OpenMPKinds.h:48
SourceLocIdentKind
Definition: Expr.h:4940
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: TypeBase.h:5881
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
Definition: OpenMPKinds.h:165
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition: Expr.h:1991
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:259
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
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
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:5019
Holds information about the various types of exception specification.
Definition: TypeBase.h:5339
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: TypeBase.h:5355
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: TypeBase.h:5341
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: TypeBase.h:5344
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: TypeBase.h:5347
Extra information about a function prototype.
Definition: TypeBase.h:5367
const ExtParameterInfo * ExtParameterInfos
Definition: TypeBase.h:5372
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:559
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:566
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3281
const NamespaceBaseDecl * Namespace
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:259
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition: Sema.h:12984
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:3268
Location information for a TemplateArgument.
Definition: TemplateBase.h:480
UnsignedOrNone OrigNumExpansions
Definition: TreeTransform.h:62
SourceLocation Ellipsis
Definition: TreeTransform.h:61
UnsignedOrNone NumExpansions
Definition: TreeTransform.h:66