clang 24.0.0git
Expr.h
Go to the documentation of this file.
1//===--- Expr.h - Classes for representing expressions ----------*- 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//
9// This file defines the Expr interface and subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_EXPR_H
14#define LLVM_CLANG_AST_EXPR_H
15
17#include "clang/AST/APValue.h"
18#include "clang/AST/ASTVector.h"
20#include "clang/AST/Decl.h"
24#include "clang/AST/Stmt.h"
26#include "clang/AST/TypeBase.h"
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APSInt.h"
33#include "llvm/ADT/SmallVector.h"
34#include "llvm/ADT/StringRef.h"
35#include "llvm/ADT/iterator.h"
36#include "llvm/ADT/iterator_range.h"
37#include "llvm/Support/AtomicOrdering.h"
38#include "llvm/Support/Compiler.h"
39#include "llvm/Support/TrailingObjects.h"
40#include <optional>
41
42namespace clang {
43class AllocSizeAttr;
44class APValue;
45class ASTContext;
46class BlockDecl;
50class CastExpr;
51class Decl;
52class IdentifierInfo;
54class NamedDecl;
56class OpaqueValueExpr;
57class ParmVarDecl;
58class StringLiteral;
59class TargetInfo;
60class ValueDecl;
61class WarnUnusedResultAttr;
62
63/// A simple array of base specifiers.
65
66/// An adjustment to be made to the temporary created when emitting a
67/// reference binding, which accesses a particular subobject of that
68/// temporary.
70 enum {
74 } Kind;
75
76 struct DTB {
79 };
80
81 struct P {
84 };
85
86 union {
89 struct P Ptr;
90 };
91
93 const CXXRecordDecl *DerivedClass)
95 DerivedToBase.BasePath = BasePath;
96 DerivedToBase.DerivedClass = DerivedClass;
97 }
98
100 this->Field = Field;
101 }
102
105 this->Ptr.MPT = MPT;
106 this->Ptr.RHS = RHS;
107 }
108};
109
110/// This represents one expression. Note that Expr's are subclasses of Stmt.
111/// This allows an expression to be transparently used any place a Stmt is
112/// required.
113class Expr : public ValueStmt {
114 QualType TR;
115
116public:
117 Expr() = delete;
118 Expr(const Expr&) = delete;
119 Expr(Expr &&) = delete;
120 Expr &operator=(const Expr&) = delete;
121 Expr &operator=(Expr&&) = delete;
122
123protected:
125 : ValueStmt(SC) {
126 ExprBits.Dependent = 0;
127 ExprBits.ValueKind = VK;
128 ExprBits.ObjectKind = OK;
129 assert(ExprBits.ObjectKind == OK && "truncated kind");
130 setType(T);
131 }
132
133 /// Construct an empty expression.
134 explicit Expr(StmtClass SC, EmptyShell) : ValueStmt(SC) { }
135
136 /// Each concrete expr subclass is expected to compute its dependence and call
137 /// this in the constructor.
139 ExprBits.Dependent = static_cast<unsigned>(Deps);
140 }
141 friend class ASTImporter; // Sets dependence directly.
142 friend class ASTStmtReader; // Sets dependence directly.
143
144public:
145 QualType getType() const { return TR; }
147 // In C++, the type of an expression is always adjusted so that it
148 // will not have reference type (C++ [expr]p6). Use
149 // QualType::getNonReferenceType() to retrieve the non-reference
150 // type. Additionally, inspect Expr::isLvalue to determine whether
151 // an expression that is adjusted in this manner should be
152 // considered an lvalue.
153 assert((t.isNull() || !t->isReferenceType()) &&
154 "Expressions can't have reference type");
155
156 TR = t;
157 }
158
159 /// If this expression is an enumeration constant, return the
160 /// enumeration type under which said constant was declared.
161 /// Otherwise return the expression's type.
162 /// Note this effectively circumvents the weak typing of C's enum constants
163 QualType getEnumCoercedType(const ASTContext &Ctx) const;
164
166 return static_cast<ExprDependence>(ExprBits.Dependent);
167 }
168
169 /// Determines whether the value of this expression depends on
170 /// - a template parameter (C++ [temp.dep.constexpr])
171 /// - or an error, whose resolution is unknown
172 ///
173 /// For example, the array bound of "Chars" in the following example is
174 /// value-dependent.
175 /// @code
176 /// template<int Size, char (&Chars)[Size]> struct meta_string;
177 /// @endcode
178 bool isValueDependent() const {
179 return static_cast<bool>(getDependence() & ExprDependence::Value);
180 }
181
182 /// Determines whether the type of this expression depends on
183 /// - a template parameter (C++ [temp.dep.expr], which means that its type
184 /// could change from one template instantiation to the next)
185 /// - or an error
186 ///
187 /// For example, the expressions "x" and "x + y" are type-dependent in
188 /// the following code, but "y" is not type-dependent:
189 /// @code
190 /// template<typename T>
191 /// void add(T x, int y) {
192 /// x + y;
193 /// }
194 /// @endcode
195 bool isTypeDependent() const {
196 return static_cast<bool>(getDependence() & ExprDependence::Type);
197 }
198
199 /// Whether this expression is instantiation-dependent, meaning that
200 /// it depends in some way on
201 /// - a template parameter (even if neither its type nor (constant) value
202 /// can change due to the template instantiation)
203 /// - or an error
204 ///
205 /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
206 /// instantiation-dependent (since it involves a template parameter \c T), but
207 /// is neither type- nor value-dependent, since the type of the inner
208 /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
209 /// \c sizeof is known.
210 ///
211 /// \code
212 /// template<typename T>
213 /// void f(T x, T y) {
214 /// sizeof(sizeof(T() + T());
215 /// }
216 /// \endcode
217 ///
218 /// \code
219 /// void func(int) {
220 /// func(); // the expression is instantiation-dependent, because it depends
221 /// // on an error.
222 /// }
223 /// \endcode
225 return static_cast<bool>(getDependence() & ExprDependence::Instantiation);
226 }
227
228 /// Whether this expression contains an unexpanded parameter
229 /// pack (for C++11 variadic templates).
230 ///
231 /// Given the following function template:
232 ///
233 /// \code
234 /// template<typename F, typename ...Types>
235 /// void forward(const F &f, Types &&...args) {
236 /// f(static_cast<Types&&>(args)...);
237 /// }
238 /// \endcode
239 ///
240 /// The expressions \c args and \c static_cast<Types&&>(args) both
241 /// contain parameter packs.
243 return static_cast<bool>(getDependence() & ExprDependence::UnexpandedPack);
244 }
245
246 /// Whether this expression contains subexpressions which had errors.
247 bool containsErrors() const {
248 return static_cast<bool>(getDependence() & ExprDependence::Error);
249 }
250
251 /// getExprLoc - Return the preferred location for the arrow when diagnosing
252 /// a problem with a generic expression.
253 SourceLocation getExprLoc() const LLVM_READONLY;
254
255 /// Determine whether an lvalue-to-rvalue conversion should implicitly be
256 /// applied to this expression if it appears as a discarded-value expression
257 /// in C++11 onwards. This applies to certain forms of volatile glvalues.
259
260 /// isUnusedResultAWarning - Return true if this immediate expression should
261 /// be warned about if the result is unused. If so, fill in expr, location,
262 /// and ranges with expr to warn on and source locations/ranges appropriate
263 /// for a warning.
264 bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
265 SourceRange &R1, SourceRange &R2,
266 ASTContext &Ctx) const;
267
268 /// Returns the WarnUnusedResultAttr that is declared on the callee
269 /// or its return type declaration, together with a NamedDecl that
270 /// refers to the declaration the attribute is attached to.
271 static std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
272 getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType);
273
274 /// isLValue - True if this expression is an "l-value" according to
275 /// the rules of the current language. C and C++ give somewhat
276 /// different rules for this concept, but in general, the result of
277 /// an l-value expression identifies a specific object whereas the
278 /// result of an r-value expression is a value detached from any
279 /// specific storage.
280 ///
281 /// C++11 divides the concept of "r-value" into pure r-values
282 /// ("pr-values") and so-called expiring values ("x-values"), which
283 /// identify specific objects that can be safely cannibalized for
284 /// their resources.
285 bool isLValue() const { return getValueKind() == VK_LValue; }
286 bool isPRValue() const { return getValueKind() == VK_PRValue; }
287 bool isXValue() const { return getValueKind() == VK_XValue; }
288 bool isGLValue() const { return getValueKind() != VK_PRValue; }
289
303 /// Reasons why an expression might not be an l-value.
305
326 /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
327 /// does not have an incomplete type, does not have a const-qualified type,
328 /// and if it is a structure or union, does not have any member (including,
329 /// recursively, any member or element of all contained aggregates or unions)
330 /// with a const-qualified type.
331 ///
332 /// \param Loc [in,out] - A source location which *may* be filled
333 /// in with the location of the expression making this a
334 /// non-modifiable lvalue, if specified.
336 isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
337
338 /// The return type of classify(). Represents the C++11 expression
339 /// taxonomy.
340 class Classification {
341 public:
342 /// The various classification results. Most of these mean prvalue.
343 enum Kinds {
346 CL_Function, // Functions cannot be lvalues in C.
347 CL_Void, // Void cannot be an lvalue in C.
348 CL_AddressableVoid, // Void expression whose address can be taken in C.
349 CL_DuplicateVectorComponents, // A vector shuffle with dupes.
350 CL_DuplicateMatrixComponents, // A matrix shuffle with dupes.
351 CL_MemberFunction, // An expression referring to a member function
353 CL_ClassTemporary, // A temporary of class type, or subobject thereof.
354 CL_ArrayTemporary, // A temporary of array type.
355 CL_ObjCMessageRValue, // ObjC message is an rvalue
356 CL_PRValue // A prvalue for any other reason, of any other type
357 };
358 /// The results of modification testing.
360 CM_Untested, // testModifiable was false.
362 CM_RValue, // Not modifiable because it's an rvalue
363 CM_Function, // Not modifiable because it's a function; C++ only
364 CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
365 CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
371 };
372
373 private:
374 friend class Expr;
375
376 unsigned short Kind;
377 unsigned short Modifiable;
378
379 explicit Classification(Kinds k, ModifiableType m)
380 : Kind(k), Modifiable(m)
381 {}
382
383 public:
385
386 Kinds getKind() const { return static_cast<Kinds>(Kind); }
388 assert(Modifiable != CM_Untested && "Did not test for modifiability.");
389 return static_cast<ModifiableType>(Modifiable);
390 }
391 bool isLValue() const { return Kind == CL_LValue; }
392 bool isXValue() const { return Kind == CL_XValue; }
393 bool isGLValue() const { return Kind <= CL_XValue; }
394 bool isPRValue() const { return Kind >= CL_Function; }
395 bool isRValue() const { return Kind >= CL_XValue; }
396 bool isModifiable() const { return getModifiable() == CM_Modifiable; }
397
398 /// Create a simple, modifiable lvalue
399 static Classification makeSimpleLValue() {
401 }
402
403 };
404 /// Classify - Classify this expression according to the C++11
405 /// expression taxonomy.
406 ///
407 /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
408 /// old lvalue vs rvalue. This function determines the type of expression this
409 /// is. There are three expression types:
410 /// - lvalues are classical lvalues as in C++03.
411 /// - prvalues are equivalent to rvalues in C++03.
412 /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
413 /// function returning an rvalue reference.
414 /// lvalues and xvalues are collectively referred to as glvalues, while
415 /// prvalues and xvalues together form rvalues.
417 return ClassifyImpl(Ctx, nullptr);
418 }
419
420 /// ClassifyModifiable - Classify this expression according to the
421 /// C++11 expression taxonomy, and see if it is valid on the left side
422 /// of an assignment.
423 ///
424 /// This function extends classify in that it also tests whether the
425 /// expression is modifiable (C99 6.3.2.1p1).
426 /// \param Loc A source location that might be filled with a relevant location
427 /// if the expression is not modifiable.
429 return ClassifyImpl(Ctx, &Loc);
430 }
431
432 /// Returns the set of floating point options that apply to this expression.
433 /// Only meaningful for operations on floating point values.
435
436 /// getValueKindForType - Given a formal return or parameter type,
437 /// give its value kind.
439 if (const ReferenceType *RT = T->getAs<ReferenceType>())
440 return (isa<LValueReferenceType>(RT)
441 ? VK_LValue
442 : (RT->getPointeeType()->isFunctionType()
443 ? VK_LValue : VK_XValue));
444 return VK_PRValue;
445 }
446
447 /// getValueKind - The value kind that this expression produces.
449 return static_cast<ExprValueKind>(ExprBits.ValueKind);
450 }
451
452 /// getObjectKind - The object kind that this expression produces.
453 /// Object kinds are meaningful only for expressions that yield an
454 /// l-value or x-value.
456 return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
457 }
458
461 return (OK == OK_Ordinary || OK == OK_BitField);
462 }
463
464 /// setValueKind - Set the value kind produced by this expression.
465 void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
466
467 /// setObjectKind - Set the object kind produced by this expression.
468 void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
469
470private:
471 Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
472
473public:
474
475 /// Returns true if this expression is a gl-value that
476 /// potentially refers to a bit-field.
477 ///
478 /// In C++, whether a gl-value refers to a bitfield is essentially
479 /// an aspect of the value-kind type system.
480 bool refersToBitField() const { return getObjectKind() == OK_BitField; }
481
482 /// If this expression refers to a bit-field, retrieve the
483 /// declaration of that bit-field.
484 ///
485 /// Note that this returns a non-null pointer in subtly different
486 /// places than refersToBitField returns true. In particular, this can
487 /// return a non-null pointer even for r-values loaded from
488 /// bit-fields, but it will return null for a conditional bit-field.
490
491 /// If this expression refers to an enum constant, retrieve its declaration
493
495 return const_cast<Expr *>(this)->getEnumConstantDecl();
496 }
497
499 return const_cast<Expr*>(this)->getSourceBitField();
500 }
501
504 return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
505 }
506
507 /// If this expression is an l-value for an Objective C
508 /// property, find the underlying property reference expression.
510
511 /// Check if this expression is the ObjC 'self' implicit parameter.
512 bool isObjCSelfExpr() const;
513
514 /// Returns whether this expression refers to a vector element.
515 bool refersToVectorElement() const;
516
517 /// Returns whether this expression refers to a matrix element.
520 }
521
522 /// Returns whether this expression refers to a global register
523 /// variable.
524 bool refersToGlobalRegisterVar() const;
525
526 /// Returns whether this expression has a placeholder type.
527 bool hasPlaceholderType() const {
528 return getType()->isPlaceholderType();
529 }
530
531 /// Returns whether this expression has a specific placeholder type.
534 if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
535 return BT->getKind() == K;
536 return false;
537 }
538
539 /// isKnownToHaveBooleanValue - Return true if this is an integer expression
540 /// that is known to return 0 or 1. This happens for _Bool/bool expressions
541 /// but also int expressions which are produced by things like comparisons in
542 /// C.
543 ///
544 /// \param Semantic If true, only return true for expressions that are known
545 /// to be semantically boolean, which might not be true even for expressions
546 /// that are known to evaluate to 0/1. For instance, reading an unsigned
547 /// bit-field with width '1' will evaluate to 0/1, but doesn't necessarily
548 /// semantically correspond to a bool.
549 bool isKnownToHaveBooleanValue(bool Semantic = true) const;
550
551 /// Check whether this array fits the idiom of a flexible array member,
552 /// depending on the value of -fstrict-flex-array.
553 /// When IgnoreTemplateOrMacroSubstitution is set, it doesn't consider sizes
554 /// resulting from the substitution of a macro or a template as special sizes.
556 const ASTContext &Context,
557 LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
558 bool IgnoreTemplateOrMacroSubstitution = false) const;
559
560 /// isIntegerConstantExpr - Return the value if this expression is a valid
561 /// integer constant expression. If not a valid i-c-e, return std::nullopt.
562 ///
563 /// Note: This does not perform the implicit conversions required by C++11
564 /// [expr.const]p5.
565 ///
566 /// If \p AllowRelaxedEval is \c true, this will allow certain constructs that
567 /// are not valid per the specification.
568 // FIXME: Add proper documentation about the constructs we allow.
569 std::optional<llvm::APSInt>
571 bool AllowRelaxedEval = false) const;
572 bool isIntegerConstantExpr(const ASTContext &Ctx) const;
573
574 /// isCXX98IntegralConstantExpr - Return true if this expression is an
575 /// integral constant expression in C++98. Can only be used in C++.
576 bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
577
578 /// isCXX11ConstantExpr - Return true if this expression is a constant
579 /// expression in C++11. Can only be used in C++.
580 ///
581 /// Note: This does not perform the implicit conversions required by C++11
582 /// [expr.const]p5.
583 ///
584 /// If \p AllowRelaxedEval is \c true, this will allow certain constructs that
585 /// are not valid per the specification.
586 // FIXME: Add proper documentation about the constructs we allow.
587 bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
588 bool AllowRelaxedEval = false) const;
589
590 /// isPotentialConstantExpr - Return true if this function's definition
591 /// might be usable in a constant expression in C++11, if it were marked
592 /// constexpr. Return false if the function can never produce a constant
593 /// expression, along with diagnostics describing why not.
594 static bool isPotentialConstantExpr(const FunctionDecl *FD,
596 PartialDiagnosticAt> &Diags);
597
598 /// isPotentialConstantExprUnevaluated - Return true if this expression might
599 /// be usable in a constant expression in C++11 in an unevaluated context, if
600 /// it were in function FD marked constexpr. Return false if the function can
601 /// never produce a constant expression, along with diagnostics describing
602 /// why not.
604 const FunctionDecl *FD,
606 PartialDiagnosticAt> &Diags);
607
608 /// Returns true if this expression can be emitted to
609 /// IR as a constant, and thus can be used as a constant initializer in C.
610 /// If this expression is not constant and Culprit is non-null,
611 /// it is used to store the address of first non constant expr.
612 bool isConstantInitializer(ASTContext &Ctx, bool ForRef = false,
613 const Expr **Culprit = nullptr) const;
614
615 /// If this expression is an unambiguous reference to a single declaration,
616 /// in the style of __builtin_function_start, return that declaration. Note
617 /// that this may return a non-static member function or field in C++ if this
618 /// expression is a member pointer constant.
619 const ValueDecl *getAsBuiltinConstantDeclRef(const ASTContext &Context) const;
620
621 /// EvalStatus is a struct with detailed info about an evaluation in progress.
622 struct EvalStatus {
623 /// Whether the evaluated expression has side effects.
624 /// For example, (f() && 0) can be folded, but it still has side effects.
625 bool HasSideEffects = false;
626
627 /// Whether the evaluation hit undefined behavior.
628 /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
629 /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
631
632 /// Whether any diagnostic has been emitted. This is set regardless of
633 /// whether @ref #Diag is set or not.
634 bool DiagEmitted = false;
635
636 /// Diag - If this is non-null, it will be filled in with a stack of notes
637 /// indicating why evaluation failed (or why it failed to produce a constant
638 /// expression).
639 /// If the expression is unfoldable, the notes will indicate why it's not
640 /// foldable. If the expression is foldable, but not a constant expression,
641 /// the notes will describes why it isn't a constant expression. If the
642 /// expression *is* a constant expression, no notes will be produced.
643 ///
644 /// FIXME: this causes significant performance concerns and should be
645 /// refactored at some point. Not all evaluations of the constant
646 /// expression interpreter will display the given diagnostics, this means
647 /// those kinds of uses are paying the expense of generating a diagnostic
648 /// (which may include expensive operations like converting APValue objects
649 /// to a string representation).
651
652 /// Location where we spot ptr to int cast or null subobject while
653 /// evaluating constant expression in MS compatibility mode.
655
656 EvalStatus() = default;
657
658 /// Return true if the evaluated expression has
659 /// side effects.
660 bool hasSideEffects() const {
661 return HasSideEffects;
662 }
663 };
664
665 /// EvalResult is a struct with detailed info about an evaluated expression.
667 /// Val - This is the value the expression can be folded to.
669
670 /// Return true if the evaluated lvalue expression
671 /// is global.
672 bool isGlobalLValue() const;
673 };
674
675 /// EvaluateAsRValue - Return true if this is a constant which we can fold to
676 /// an rvalue using any crazy technique (that has nothing to do with language
677 /// standards) that we want to, even if the expression has side-effects. If
678 /// this function returns true, it returns the folded constant in Result. If
679 /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
680 /// applied.
682 bool InConstantContext = false) const;
683
684 /// EvaluateAsBooleanCondition - Return true if this is a constant
685 /// which we can fold and convert to a boolean condition using
686 /// any crazy technique that we want to, even if the expression has
687 /// side-effects.
688 bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx,
689 bool InConstantContext = false) const;
690
692 SE_NoSideEffects, ///< Strictly evaluate the expression.
693 SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
694 ///< arbitrary unmodeled side effects.
695 SE_AllowSideEffects ///< Allow any unmodeled side effect.
696 };
697
698 /// EvaluateAsInt - Return true if this is a constant which we can fold and
699 /// convert to an integer, using any crazy technique that we want to.
700 bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
701 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
702 bool InConstantContext = false) const;
703
704 /// EvaluateAsFloat - Return true if this is a constant which we can fold and
705 /// convert to a floating point value, using any crazy technique that we
706 /// want to.
707 bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
708 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
709 bool InConstantContext = false) const;
710
711 /// EvaluateAsFixedPoint - Return true if this is a constant which we can fold
712 /// and convert to a fixed point value.
713 bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
714 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
715 bool InConstantContext = false) const;
716
717 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
718 /// constant folded without side-effects, but discard the result.
719 bool isEvaluatable(const ASTContext &Ctx,
720 SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
721
722 /// HasSideEffects - This routine returns true for all those expressions
723 /// which have any effect other than producing a value. Example is a function
724 /// call, volatile variable read, or throwing an exception. If
725 /// IncludePossibleEffects is false, this call treats certain expressions with
726 /// potential side effects (such as function call-like expressions,
727 /// instantiation-dependent expressions, or invocations from a macro) as not
728 /// having side effects.
729 bool HasSideEffects(const ASTContext &Ctx,
730 bool IncludePossibleEffects = true) const;
731
732 /// Determine whether this expression involves a call to any function
733 /// that is not trivial.
734 bool hasNonTrivialCall(const ASTContext &Ctx) const;
735
736 /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
737 /// integer. This must be called on an expression that constant folds to an
738 /// integer.
739 llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
740
742 const ASTContext &Ctx,
744
745 void EvaluateForOverflow(const ASTContext &Ctx) const;
746
747 /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
748 /// lvalue with link time known address, with no side-effects.
749 bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
750 bool InConstantContext = false) const;
751
752 /// EvaluateAsInitializer - Evaluate an expression as if it were the
753 /// initializer of the given declaration. Returns true if the initializer
754 /// can be folded to a constant, and produces any relevant notes. In C++11,
755 /// notes will be produced if the expression is not a constant expression.
756 bool EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD,
757 EvalResult &Result,
758 bool IsConstantInitializer) const;
759
760 /// EvaluateWithSubstitution - Evaluate an expression as if from the context
761 /// of a call to the given function with the given arguments, inside an
762 /// unevaluated context. Returns true if the expression could be folded to a
763 /// constant.
765 const FunctionDecl *Callee,
767 const Expr *This = nullptr) const;
768
769 enum class ConstantExprKind {
770 /// An integer constant expression (an array bound, enumerator, case value,
771 /// bit-field width, or similar) or similar.
773 /// A non-class template argument. Such a value is only used for mangling,
774 /// not for code generation, so can refer to dllimported functions.
776 /// A class template argument. Such a value is used for code generation.
778 /// An immediate invocation. The destruction of the end result of this
779 /// evaluation is not part of the evaluation, but all other temporaries
780 /// are destroyed.
782 };
783
784 /// Evaluate an expression that is required to be a constant expression. Does
785 /// not check the syntactic constraints for C and C++98 constant expressions.
787 EvalResult &Result, const ASTContext &Ctx,
788 ConstantExprKind Kind = ConstantExprKind::Normal) const;
789
790 /// If the current Expr is a pointer, this will try to statically
791 /// determine the number of bytes available where the pointer is pointing.
792 /// Returns true if all of the above holds and we were able to figure out the
793 /// size, false otherwise.
794 ///
795 /// \param Type - How to evaluate the size of the Expr, as defined by the
796 /// "type" parameter of __builtin_object_size
797 std::optional<uint64_t> tryEvaluateObjectSize(const ASTContext &Ctx,
798 unsigned Type) const;
799
800 /// If the current Expr is a pointer, this will try to statically
801 /// determine the strlen of the string pointed to.
802 /// Returns true if all of the above holds and we were able to figure out the
803 /// strlen, false otherwise.
804 std::optional<uint64_t> tryEvaluateStrLen(const ASTContext &Ctx) const;
805
806 bool EvaluateCharRangeAsString(std::string &Result,
807 const Expr *SizeExpression,
808 const Expr *PtrExpression, ASTContext &Ctx,
809 EvalResult &Status) const;
810
811 bool EvaluateCharRangeAsString(APValue &Result, const Expr *SizeExpression,
812 const Expr *PtrExpression, ASTContext &Ctx,
813 EvalResult &Status) const;
814
815 /// If the current Expr can be evaluated to a pointer to a null-terminated
816 /// constant string, return the constant string (without the terminating
817 /// null).
818 std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const;
819
820 /// Enumeration used to describe the kind of Null pointer constant
821 /// returned from \c isNullPointerConstant().
823 /// Expression is not a Null pointer constant.
825
826 /// Expression is a Null pointer constant built from a zero integer
827 /// expression that is not a simple, possibly parenthesized, zero literal.
828 /// C++ Core Issue 903 will classify these expressions as "not pointers"
829 /// once it is adopted.
830 /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
832
833 /// Expression is a Null pointer constant built from a literal zero.
835
836 /// Expression is a C++11 nullptr.
838
839 /// Expression is a GNU-style __null constant.
841 };
842
843 /// Enumeration used to describe how \c isNullPointerConstant()
844 /// should cope with value-dependent expressions.
846 /// Specifies that the expression should never be value-dependent.
848
849 /// Specifies that a value-dependent expression of integral or
850 /// dependent type should be considered a null pointer constant.
852
853 /// Specifies that a value-dependent expression should be considered
854 /// to never be a null pointer constant.
856 };
857
858 /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
859 /// a Null pointer constant. The return value can further distinguish the
860 /// kind of NULL pointer constant that was detected.
862 ASTContext &Ctx,
864
865 /// isOBJCGCCandidate - Return true if this expression may be used in a read/
866 /// write barrier.
867 bool isOBJCGCCandidate(ASTContext &Ctx) const;
868
869 /// Returns true if this expression is a bound member function.
870 bool isBoundMemberFunction(ASTContext &Ctx) const;
871
872 /// Given an expression of bound-member type, find the type
873 /// of the member. Returns null if this is an *overloaded* bound
874 /// member expression.
875 static QualType findBoundMemberType(const Expr *expr);
876
877 /// Skip past any invisible AST nodes which might surround this
878 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes,
879 /// but also injected CXXMemberExpr and CXXConstructExpr which represent
880 /// implicit conversions.
883 return const_cast<Expr *>(this)->IgnoreUnlessSpelledInSource();
884 }
885
886 /// Skip past any implicit casts which might surround this expression until
887 /// reaching a fixed point. Skips:
888 /// * ImplicitCastExpr
889 /// * FullExpr
890 Expr *IgnoreImpCasts() LLVM_READONLY;
891 const Expr *IgnoreImpCasts() const {
892 return const_cast<Expr *>(this)->IgnoreImpCasts();
893 }
894
895 /// Skip past any casts which might surround this expression until reaching
896 /// a fixed point. Skips:
897 /// * CastExpr
898 /// * FullExpr
899 /// * MaterializeTemporaryExpr
900 /// * SubstNonTypeTemplateParmExpr
901 Expr *IgnoreCasts() LLVM_READONLY;
902 const Expr *IgnoreCasts() const {
903 return const_cast<Expr *>(this)->IgnoreCasts();
904 }
905
906 /// Skip past any implicit AST nodes which might surround this expression
907 /// until reaching a fixed point. Skips:
908 /// * What IgnoreImpCasts() skips
909 /// * MaterializeTemporaryExpr
910 /// * CXXBindTemporaryExpr
911 Expr *IgnoreImplicit() LLVM_READONLY;
912 const Expr *IgnoreImplicit() const {
913 return const_cast<Expr *>(this)->IgnoreImplicit();
914 }
915
916 /// Skip past any implicit AST nodes which might surround this expression
917 /// until reaching a fixed point. Same as IgnoreImplicit, except that it
918 /// also skips over implicit calls to constructors and conversion functions.
919 ///
920 /// FIXME: Should IgnoreImplicit do this?
921 Expr *IgnoreImplicitAsWritten() LLVM_READONLY;
923 return const_cast<Expr *>(this)->IgnoreImplicitAsWritten();
924 }
925
926 /// Skip past any parentheses which might surround this expression until
927 /// reaching a fixed point. Skips:
928 /// * ParenExpr
929 /// * UnaryOperator if `UO_Extension`
930 /// * GenericSelectionExpr if `!isResultDependent()`
931 /// * ChooseExpr if `!isConditionDependent()`
932 /// * ConstantExpr
933 Expr *IgnoreParens() LLVM_READONLY;
934 const Expr *IgnoreParens() const {
935 return const_cast<Expr *>(this)->IgnoreParens();
936 }
937
938 /// Skip past any parentheses and implicit casts which might surround this
939 /// expression until reaching a fixed point.
940 /// FIXME: IgnoreParenImpCasts really ought to be equivalent to
941 /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
942 /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
943 /// * What IgnoreParens() skips
944 /// * What IgnoreImpCasts() skips
945 /// * MaterializeTemporaryExpr
946 /// * SubstNonTypeTemplateParmExpr
947 Expr *IgnoreParenImpCasts() LLVM_READONLY;
948 const Expr *IgnoreParenImpCasts() const {
949 return const_cast<Expr *>(this)->IgnoreParenImpCasts();
950 }
951
952 /// Skip past any parentheses and casts which might surround this expression
953 /// until reaching a fixed point. Skips:
954 /// * What IgnoreParens() skips
955 /// * What IgnoreCasts() skips
956 Expr *IgnoreParenCasts() LLVM_READONLY;
957 const Expr *IgnoreParenCasts() const {
958 return const_cast<Expr *>(this)->IgnoreParenCasts();
959 }
960
961 /// Skip conversion operators. If this Expr is a call to a conversion
962 /// operator, return the argument.
965 return const_cast<Expr *>(this)->IgnoreConversionOperatorSingleStep();
966 }
967
968 /// Skip past any parentheses and lvalue casts which might surround this
969 /// expression until reaching a fixed point. Skips:
970 /// * What IgnoreParens() skips
971 /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue
972 /// casts are skipped
973 /// FIXME: This is intended purely as a temporary workaround for code
974 /// that hasn't yet been rewritten to do the right thing about those
975 /// casts, and may disappear along with the last internal use.
976 Expr *IgnoreParenLValueCasts() LLVM_READONLY;
978 return const_cast<Expr *>(this)->IgnoreParenLValueCasts();
979 }
980
981 /// Skip past any parentheses and casts which do not change the value
982 /// (including ptr->int casts of the same size) until reaching a fixed point.
983 /// Skips:
984 /// * What IgnoreParens() skips
985 /// * CastExpr which do not change the value
986 /// * SubstNonTypeTemplateParmExpr
987 Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY;
988 const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const {
989 return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx);
990 }
991
992 /// Skip past any parentheses and derived-to-base casts until reaching a
993 /// fixed point. Skips:
994 /// * What IgnoreParens() skips
995 /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase,
996 /// CK_UncheckedDerivedToBase and CK_NoOp)
997 Expr *IgnoreParenBaseCasts() LLVM_READONLY;
998 const Expr *IgnoreParenBaseCasts() const {
999 return const_cast<Expr *>(this)->IgnoreParenBaseCasts();
1000 }
1001
1002 /// Determine whether this expression is a default function argument.
1003 ///
1004 /// Default arguments are implicitly generated in the abstract syntax tree
1005 /// by semantic analysis for function calls, object constructions, etc. in
1006 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
1007 /// this routine also looks through any implicit casts to determine whether
1008 /// the expression is a default argument.
1009 bool isDefaultArgument() const;
1010
1011 /// Determine whether the result of this expression is a
1012 /// temporary object of the given class type.
1013 bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
1014
1015 /// Whether this expression is an implicit reference to 'this' in C++.
1016 bool isImplicitCXXThis() const;
1017
1019
1020 /// For an expression of class type or pointer to class type,
1021 /// return the most derived class decl the expression is known to refer to.
1022 ///
1023 /// If this expression is a cast, this method looks through it to find the
1024 /// most derived decl that can be inferred from the expression.
1025 /// This is valid because derived-to-base conversions have undefined
1026 /// behavior if the object isn't dynamically of the derived type.
1028
1029 /// Get the inner expression that determines the best dynamic class.
1030 /// If this is a prvalue, we guarantee that it is of the most-derived type
1031 /// for the object itself.
1032 const Expr *getBestDynamicClassTypeExpr() const;
1033
1034 /// Walk outwards from an expression we want to bind a reference to and
1035 /// find the expression whose lifetime needs to be extended. Record
1036 /// the LHSs of comma expressions and adjustments needed along the path.
1039 SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
1043 return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
1044 }
1045
1046 /// Checks that the two Expr's will refer to the same value as a comparison
1047 /// operand. The caller must ensure that the values referenced by the Expr's
1048 /// are not modified between E1 and E2 or the result my be invalid.
1049 static bool isSameComparisonOperand(const Expr* E1, const Expr* E2);
1050
1051 static bool classof(const Stmt *T) {
1052 return T->getStmtClass() >= firstExprConstant &&
1053 T->getStmtClass() <= lastExprConstant;
1054 }
1055};
1056// PointerLikeTypeTraits is specialized so it can be used with a forward-decl of
1057// Expr. Verify that we got it right.
1059 llvm::ConstantLog2<alignof(Expr)>(),
1060 "PointerLikeTypeTraits<Expr*> assumes too much alignment.");
1061
1063
1064//===----------------------------------------------------------------------===//
1065// Wrapper Expressions.
1066//===----------------------------------------------------------------------===//
1067
1068/// FullExpr - Represents a "full-expression" node.
1069class FullExpr : public Expr {
1070protected:
1072
1074 : Expr(SC, subexpr->getType(), subexpr->getValueKind(),
1075 subexpr->getObjectKind()),
1076 SubExpr(subexpr) {
1078 }
1081public:
1082 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1084
1085 /// As with any mutator of the AST, be very careful when modifying an
1086 /// existing AST to preserve its invariants.
1087 void setSubExpr(Expr *E) { SubExpr = E; }
1088
1089 static bool classof(const Stmt *T) {
1090 return T->getStmtClass() >= firstFullExprConstant &&
1091 T->getStmtClass() <= lastFullExprConstant;
1092 }
1093};
1094
1095/// Describes the kind of result that can be tail-allocated.
1097
1098/// ConstantExpr - An expression that occurs in a constant context and
1099/// optionally the result of evaluating the expression.
1100class ConstantExpr final
1101 : public FullExpr,
1102 private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> {
1103 static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value,
1104 "ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
1105 "for tail-allocated storage");
1106 friend TrailingObjects;
1107 friend class ASTStmtReader;
1108 friend class ASTStmtWriter;
1109
1110 size_t numTrailingObjects(OverloadToken<APValue>) const {
1112 }
1113 size_t numTrailingObjects(OverloadToken<uint64_t>) const {
1115 }
1116
1117 uint64_t &Int64Result() {
1119 "invalid accessor");
1120 return *getTrailingObjects<uint64_t>();
1121 }
1122 const uint64_t &Int64Result() const {
1123 return const_cast<ConstantExpr *>(this)->Int64Result();
1124 }
1125 APValue &APValueResult() {
1127 "invalid accessor");
1128 return *getTrailingObjects<APValue>();
1129 }
1130 APValue &APValueResult() const {
1131 return const_cast<ConstantExpr *>(this)->APValueResult();
1132 }
1133
1134 ConstantExpr(Expr *SubExpr, ConstantResultStorageKind StorageKind,
1135 bool IsImmediateInvocation);
1136 ConstantExpr(EmptyShell Empty, ConstantResultStorageKind StorageKind);
1137
1138public:
1139 static ConstantExpr *Create(const ASTContext &Context, Expr *E,
1140 const APValue &Result);
1141 static ConstantExpr *
1142 Create(const ASTContext &Context, Expr *E,
1144 bool IsImmediateInvocation = false);
1145 static ConstantExpr *CreateEmpty(const ASTContext &Context,
1146 ConstantResultStorageKind StorageKind);
1147
1150 const ASTContext &Context);
1151
1152 SourceLocation getBeginLoc() const LLVM_READONLY {
1153 return SubExpr->getBeginLoc();
1154 }
1155 SourceLocation getEndLoc() const LLVM_READONLY {
1156 return SubExpr->getEndLoc();
1157 }
1158
1159 static bool classof(const Stmt *T) {
1160 return T->getStmtClass() == ConstantExprClass;
1161 }
1162
1163 void SetResult(APValue Value, const ASTContext &Context) {
1164 MoveIntoResult(Value, Context);
1165 }
1166 void MoveIntoResult(APValue &Value, const ASTContext &Context);
1167
1169 return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind);
1170 }
1175 return ConstantExprBits.IsImmediateInvocation;
1176 }
1177 bool hasAPValueResult() const {
1178 return ConstantExprBits.APValueKind != APValue::None;
1179 }
1180 APValue getAPValueResult() const;
1181 llvm::APSInt getResultAsAPSInt() const;
1182 // Iterators
1185 return const_child_range(&SubExpr, &SubExpr + 1);
1186 }
1187};
1188
1189//===----------------------------------------------------------------------===//
1190// Primary Expressions.
1191//===----------------------------------------------------------------------===//
1192
1193/// OpaqueValueExpr - An expression referring to an opaque object of a
1194/// fixed type and value class. These don't correspond to concrete
1195/// syntax; instead they're used to express operations (usually copy
1196/// operations) on values whose source is generally obvious from
1197/// context.
1198class OpaqueValueExpr : public Expr {
1199 friend class ASTStmtReader;
1200 Expr *SourceExpr;
1201
1202public:
1204 ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr)
1205 : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) {
1206 setIsUnique(false);
1207 OpaqueValueExprBits.Loc = Loc;
1209 }
1210
1211 /// Given an expression which invokes a copy constructor --- i.e. a
1212 /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
1213 /// find the OpaqueValueExpr that's the source of the construction.
1214 static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
1215
1217 : Expr(OpaqueValueExprClass, Empty) {}
1218
1219 /// Retrieve the location of this expression.
1221
1222 SourceLocation getBeginLoc() const LLVM_READONLY {
1223 return SourceExpr ? SourceExpr->getBeginLoc() : getLocation();
1224 }
1225 SourceLocation getEndLoc() const LLVM_READONLY {
1226 return SourceExpr ? SourceExpr->getEndLoc() : getLocation();
1227 }
1228 SourceLocation getExprLoc() const LLVM_READONLY {
1229 return SourceExpr ? SourceExpr->getExprLoc() : getLocation();
1230 }
1231
1235
1239
1240 /// The source expression of an opaque value expression is the
1241 /// expression which originally generated the value. This is
1242 /// provided as a convenience for analyses that don't wish to
1243 /// precisely model the execution behavior of the program.
1244 ///
1245 /// The source expression is typically set when building the
1246 /// expression which binds the opaque value expression in the first
1247 /// place.
1248 Expr *getSourceExpr() const { return SourceExpr; }
1249
1250 void setIsUnique(bool V) {
1251 assert((!V || SourceExpr) &&
1252 "unique OVEs are expected to have source expressions");
1253 OpaqueValueExprBits.IsUnique = V;
1254 }
1255
1256 bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1257
1258 static bool classof(const Stmt *T) {
1259 return T->getStmtClass() == OpaqueValueExprClass;
1260 }
1261};
1262
1263/// A reference to a declared variable, function, enum, etc.
1264/// [C99 6.5.1p2]
1265///
1266/// This encodes all the information about how a declaration is referenced
1267/// within an expression.
1268///
1269/// There are several optional constructs attached to DeclRefExprs only when
1270/// they apply in order to conserve memory. These are laid out past the end of
1271/// the object, and flags in the DeclRefExprBitfield track whether they exist:
1272///
1273/// DeclRefExprBits.HasQualifier:
1274/// Specifies when this declaration reference expression has a C++
1275/// nested-name-specifier.
1276/// DeclRefExprBits.HasFoundDecl:
1277/// Specifies when this declaration reference expression has a record of
1278/// a NamedDecl (different from the referenced ValueDecl) which was found
1279/// during name lookup and/or overload resolution.
1280/// DeclRefExprBits.HasTemplateKWAndArgsInfo:
1281/// Specifies when this declaration reference expression has an explicit
1282/// C++ template keyword and/or template argument list.
1283/// DeclRefExprBits.RefersToEnclosingVariableOrCapture
1284/// Specifies when this declaration reference expression (validly)
1285/// refers to an enclosed local or a captured variable.
1286class DeclRefExpr final
1287 : public Expr,
1288 private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1289 NamedDecl *, ASTTemplateKWAndArgsInfo,
1290 TemplateArgumentLoc> {
1291 friend class ASTStmtReader;
1292 friend class ASTStmtWriter;
1293 friend TrailingObjects;
1294
1295 /// The declaration that we are referencing.
1296 ValueDecl *D;
1297
1298 /// Provides source/type location info for the declaration name
1299 /// embedded in D.
1300 DeclarationNameLoc DNLoc;
1301
1302 size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1303 return hasQualifier();
1304 }
1305
1306 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1307 return hasFoundDecl();
1308 }
1309
1310 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1311 return hasTemplateKWAndArgsInfo();
1312 }
1313
1314 /// Test whether there is a distinct FoundDecl attached to the end of
1315 /// this DRE.
1316 bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1317
1318 DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1319 SourceLocation TemplateKWLoc, ValueDecl *D,
1320 bool RefersToEnclosingVariableOrCapture,
1321 const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1322 const TemplateArgumentListInfo *TemplateArgs, QualType T,
1324
1325 /// Construct an empty declaration reference expression.
1326 explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1327
1328public:
1329 DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
1330 bool RefersToEnclosingVariableOrCapture, QualType T,
1331 ExprValueKind VK, SourceLocation L,
1332 const DeclarationNameLoc &LocInfo = DeclarationNameLoc(),
1333 NonOdrUseReason NOUR = NOUR_None);
1334
1335 static DeclRefExpr *
1336 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1337 SourceLocation TemplateKWLoc, ValueDecl *D,
1338 bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1339 QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1340 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1341 NonOdrUseReason NOUR = NOUR_None);
1342
1343 static DeclRefExpr *
1344 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1345 SourceLocation TemplateKWLoc, ValueDecl *D,
1346 bool RefersToEnclosingVariableOrCapture,
1347 const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1348 NamedDecl *FoundD = nullptr,
1349 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1350 NonOdrUseReason NOUR = NOUR_None);
1351
1352 /// Construct an empty declaration reference expression.
1353 static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1354 bool HasFoundDecl,
1355 bool HasTemplateKWAndArgsInfo,
1356 unsigned NumTemplateArgs);
1357
1358 ValueDecl *getDecl() { return D; }
1359 const ValueDecl *getDecl() const { return D; }
1360 void setDecl(ValueDecl *NewD);
1361
1363 return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1364 }
1365
1368
1370 if (hasQualifier())
1371 return getQualifierLoc().getBeginLoc();
1372 return DeclRefExprBits.Loc;
1373 }
1374
1375 SourceLocation getEndLoc() const LLVM_READONLY;
1376
1377 /// Determine whether this declaration reference was preceded by a
1378 /// C++ nested-name-specifier, e.g., \c N::foo.
1379 bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1380
1381 /// If the name was qualified, retrieves the nested-name-specifier
1382 /// that precedes the name, with source-location information.
1384 if (!hasQualifier())
1385 return NestedNameSpecifierLoc();
1386 return *getTrailingObjects<NestedNameSpecifierLoc>();
1387 }
1388
1389 /// If the name was qualified, retrieves the nested-name-specifier
1390 /// that precedes the name. Otherwise, returns NULL.
1394
1395 /// Get the NamedDecl through which this reference occurred.
1396 ///
1397 /// This Decl may be different from the ValueDecl actually referred to in the
1398 /// presence of using declarations, etc. It always returns non-NULL, and may
1399 /// simple return the ValueDecl when appropriate.
1400
1402 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1403 }
1404
1405 /// Get the NamedDecl through which this reference occurred.
1406 /// See non-const variant.
1407 const NamedDecl *getFoundDecl() const {
1408 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1409 }
1410
1412 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1413 }
1414
1415 /// Retrieve the location of the template keyword preceding
1416 /// this name, if any.
1419 return SourceLocation();
1420 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1421 }
1422
1423 /// Retrieve the location of the left angle bracket starting the
1424 /// explicit template argument list following the name, if any.
1427 return SourceLocation();
1428 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1429 }
1430
1431 /// Retrieve the location of the right angle bracket ending the
1432 /// explicit template argument list following the name, if any.
1435 return SourceLocation();
1436 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1437 }
1438
1439 /// Determines whether the name in this declaration reference
1440 /// was preceded by the template keyword.
1442
1443 /// Determines whether this declaration reference was followed by an
1444 /// explicit template argument list.
1445 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1446
1447 /// Copies the template arguments (if present) into the given
1448 /// structure.
1451 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1452 getTrailingObjects<TemplateArgumentLoc>(), List);
1453 }
1454
1455 /// Retrieve the template arguments provided as part of this
1456 /// template-id.
1459 return nullptr;
1460 return getTrailingObjects<TemplateArgumentLoc>();
1461 }
1462
1463 /// Retrieve the number of template arguments provided as part of this
1464 /// template-id.
1465 unsigned getNumTemplateArgs() const {
1467 return 0;
1468 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1469 }
1470
1474
1475 /// Returns true if this expression refers to a function that
1476 /// was resolved from an overloaded set having size greater than 1.
1478 return DeclRefExprBits.HadMultipleCandidates;
1479 }
1480 /// Sets the flag telling whether this expression refers to
1481 /// a function that was resolved from an overloaded set having size
1482 /// greater than 1.
1483 void setHadMultipleCandidates(bool V = true) {
1484 DeclRefExprBits.HadMultipleCandidates = V;
1485 }
1486
1487 /// Is this expression a non-odr-use reference, and if so, why?
1489 return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason);
1490 }
1491
1492 /// Does this DeclRefExpr refer to an enclosing local or a captured
1493 /// variable?
1495 return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1496 }
1497
1499 return DeclRefExprBits.IsImmediateEscalating;
1500 }
1501
1503 DeclRefExprBits.IsImmediateEscalating = Set;
1504 }
1505
1507 return DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter;
1508 }
1509
1511 bool Set, const ASTContext &Context) {
1512 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = Set;
1513 setDependence(computeDependence(this, Context));
1514 }
1515
1516 static bool classof(const Stmt *T) {
1517 return T->getStmtClass() == DeclRefExprClass;
1518 }
1519
1520 // Iterators
1524
1528};
1529
1530class IntegerLiteral : public Expr, public APIntStorage {
1531 SourceLocation Loc;
1532
1533 /// Construct an empty integer literal.
1534 explicit IntegerLiteral(EmptyShell Empty)
1535 : Expr(IntegerLiteralClass, Empty) { }
1536
1537public:
1538 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1539 // or UnsignedLongLongTy
1540 IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1541 SourceLocation l);
1542
1543 /// Returns a new integer literal with value 'V' and type 'type'.
1544 /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1545 /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1546 /// \param V - the value that the returned integer literal contains.
1547 static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1549 /// Returns a new empty integer literal.
1550 static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1551
1552 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1553 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1554
1555 /// Retrieve the location of the literal.
1556 SourceLocation getLocation() const { return Loc; }
1557
1558 void setLocation(SourceLocation Location) { Loc = Location; }
1559
1560 static bool classof(const Stmt *T) {
1561 return T->getStmtClass() == IntegerLiteralClass;
1562 }
1563
1564 // Iterators
1571};
1572
1573class FixedPointLiteral : public Expr, public APIntStorage {
1574 SourceLocation Loc;
1575 unsigned Scale;
1576
1577 /// \brief Construct an empty fixed-point literal.
1578 explicit FixedPointLiteral(EmptyShell Empty)
1579 : Expr(FixedPointLiteralClass, Empty) {}
1580
1581 public:
1582 FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1583 SourceLocation l, unsigned Scale);
1584
1585 // Store the int as is without any bit shifting.
1586 static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1587 const llvm::APInt &V,
1589 unsigned Scale);
1590
1591 /// Returns an empty fixed-point literal.
1592 static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty);
1593
1594 /// Returns an internal integer representation of the literal.
1595 llvm::APInt getValue() const { return APIntStorage::getValue(); }
1596
1597 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1598 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1599
1600 /// \brief Retrieve the location of the literal.
1601 SourceLocation getLocation() const { return Loc; }
1602
1603 void setLocation(SourceLocation Location) { Loc = Location; }
1604
1605 unsigned getScale() const { return Scale; }
1606 void setScale(unsigned S) { Scale = S; }
1607
1608 static bool classof(const Stmt *T) {
1609 return T->getStmtClass() == FixedPointLiteralClass;
1610 }
1611
1612 std::string getValueAsString(unsigned Radix) const;
1613
1614 // Iterators
1621};
1622
1624
1625class CharacterLiteral : public Expr {
1626 unsigned Value;
1627 SourceLocation Loc;
1628public:
1629 // type should be IntTy
1632 : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary),
1633 Value(value), Loc(l) {
1634 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1635 setDependence(ExprDependence::None);
1636 }
1637
1638 /// Construct an empty character literal.
1639 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1640
1641 SourceLocation getLocation() const { return Loc; }
1643 return static_cast<CharacterLiteralKind>(CharacterLiteralBits.Kind);
1644 }
1645
1646 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1647 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1648
1649 unsigned getValue() const { return Value; }
1650
1651 void setLocation(SourceLocation Location) { Loc = Location; }
1653 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1654 }
1655 void setValue(unsigned Val) { Value = Val; }
1656
1657 static bool classof(const Stmt *T) {
1658 return T->getStmtClass() == CharacterLiteralClass;
1659 }
1660
1661 static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS);
1662
1663 // Iterators
1670};
1671
1672class FloatingLiteral : public Expr, private APFloatStorage {
1673 SourceLocation Loc;
1674
1675 FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1677
1678 /// Construct an empty floating-point literal.
1679 explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1680
1681public:
1682 static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1683 bool isexact, QualType Type, SourceLocation L);
1684 static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1685
1686 llvm::APFloat getValue() const {
1688 }
1689 void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1690 assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1692 }
1693
1694 /// Get a raw enumeration value representing the floating-point semantics of
1695 /// this literal (32-bit IEEE, x87, ...), suitable for serialization.
1696 llvm::APFloatBase::Semantics getRawSemantics() const {
1697 return static_cast<llvm::APFloatBase::Semantics>(
1698 FloatingLiteralBits.Semantics);
1699 }
1700
1701 /// Set the raw enumeration value representing the floating-point semantics of
1702 /// this literal (32-bit IEEE, x87, ...), suitable for serialization.
1703 void setRawSemantics(llvm::APFloatBase::Semantics Sem) {
1704 FloatingLiteralBits.Semantics = Sem;
1705 }
1706
1707 /// Return the APFloat semantics this literal uses.
1708 const llvm::fltSemantics &getSemantics() const {
1709 return llvm::APFloatBase::EnumToSemantics(
1710 static_cast<llvm::APFloatBase::Semantics>(
1711 FloatingLiteralBits.Semantics));
1712 }
1713
1714 /// Set the APFloat semantics this literal uses.
1715 void setSemantics(const llvm::fltSemantics &Sem) {
1716 FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem);
1717 }
1718
1719 bool isExact() const { return FloatingLiteralBits.IsExact; }
1720 void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1721
1722 /// getValueAsApproximateDouble - This returns the value as an inaccurate
1723 /// double. Note that this may cause loss of precision, but is useful for
1724 /// debugging dumps, etc.
1725 double getValueAsApproximateDouble() const;
1726
1727 SourceLocation getLocation() const { return Loc; }
1728 void setLocation(SourceLocation L) { Loc = L; }
1729
1730 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1731 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1732
1733 static bool classof(const Stmt *T) {
1734 return T->getStmtClass() == FloatingLiteralClass;
1735 }
1736
1737 // Iterators
1744};
1745
1746/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1747/// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1748/// IntegerLiteral classes. Instances of this class always have a Complex type
1749/// whose element type matches the subexpression.
1750///
1751class ImaginaryLiteral : public Expr {
1752 Stmt *Val;
1753public:
1755 : Expr(ImaginaryLiteralClass, Ty, VK_PRValue, OK_Ordinary), Val(val) {
1756 setDependence(ExprDependence::None);
1757 }
1758
1759 /// Build an empty imaginary literal.
1761 : Expr(ImaginaryLiteralClass, Empty) { }
1762
1763 const Expr *getSubExpr() const { return cast<Expr>(Val); }
1764 Expr *getSubExpr() { return cast<Expr>(Val); }
1765 void setSubExpr(Expr *E) { Val = E; }
1766
1767 SourceLocation getBeginLoc() const LLVM_READONLY {
1768 return Val->getBeginLoc();
1769 }
1770 SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1771
1772 static bool classof(const Stmt *T) {
1773 return T->getStmtClass() == ImaginaryLiteralClass;
1774 }
1775
1776 // Iterators
1777 child_range children() { return child_range(&Val, &Val+1); }
1779 return const_child_range(&Val, &Val + 1);
1780 }
1781};
1782
1790 // Binary kind of string literal is used for the data coming via #embed
1791 // directive. File's binary contents is transformed to a special kind of
1792 // string literal that in some cases may be used directly as an initializer
1793 // and some features of classic string literals are not applicable to this
1794 // kind of a string literal, for example finding a particular byte's source
1795 // location for better diagnosing.
1797};
1798
1799/// StringLiteral - This represents a string literal expression, e.g. "foo"
1800/// or L"bar" (wide strings). The actual string data can be obtained with
1801/// getBytes() and is NOT null-terminated. The length of the string data is
1802/// determined by calling getByteLength().
1803///
1804/// The C type for a string is always a ConstantArrayType. In C++, the char
1805/// type is const qualified, in C it is not.
1806///
1807/// Note that strings in C can be formed by concatenation of multiple string
1808/// literal pptokens in translation phase #6. This keeps track of the locations
1809/// of each of these pieces.
1810///
1811/// Strings in C can also be truncated and extended by assigning into arrays,
1812/// e.g. with constructs like:
1813/// char X[2] = "foobar";
1814/// In this case, getByteLength() will return 6, but the string literal will
1815/// have type "char[2]".
1816class StringLiteral final
1817 : public Expr,
1818 private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1819 char> {
1820 friend class ASTStmtReader;
1821 friend TrailingObjects;
1822
1823 /// StringLiteral is followed by several trailing objects. They are in order:
1824 ///
1825 /// * A single unsigned storing the length in characters of this string. The
1826 /// length in bytes is this length times the width of a single character.
1827 /// Always present and stored as a trailing objects because storing it in
1828 /// StringLiteral would increase the size of StringLiteral by sizeof(void *)
1829 /// due to alignment requirements. If you add some data to StringLiteral,
1830 /// consider moving it inside StringLiteral.
1831 ///
1832 /// * An array of getNumConcatenated() SourceLocation, one for each of the
1833 /// token this string is made of.
1834 ///
1835 /// * An array of getByteLength() char used to store the string data.
1836
1837 unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1838 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1839 return getNumConcatenated();
1840 }
1841
1842 unsigned numTrailingObjects(OverloadToken<char>) const {
1843 return getByteLength();
1844 }
1845
1846 char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1847 const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1848
1849 const uint16_t *getStrDataAsUInt16() const {
1850 return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1851 }
1852
1853 const uint32_t *getStrDataAsUInt32() const {
1854 return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1855 }
1856
1857 /// Build a string literal.
1858 StringLiteral(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind,
1859 bool Pascal, QualType Ty, ArrayRef<SourceLocation> Locs);
1860
1861 /// Build an empty string literal.
1862 StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1863 unsigned CharByteWidth);
1864
1865 /// Map a target and string kind to the appropriate character width.
1866 static unsigned mapCharByteWidth(TargetInfo const &Target,
1868
1869 /// Set one of the string literal token.
1870 void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1871 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1872 getTrailingObjects<SourceLocation>()[TokNum] = L;
1873 }
1874
1875public:
1876 /// This is the "fully general" constructor that allows representation of
1877 /// strings formed from one or more concatenated tokens.
1878 static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1879 StringLiteralKind Kind, bool Pascal, QualType Ty,
1880 ArrayRef<SourceLocation> Locs);
1881
1882 /// Construct an empty string literal.
1883 static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1884 unsigned NumConcatenated, unsigned Length,
1885 unsigned CharByteWidth);
1886
1887 StringRef getString() const {
1888 assert((isUnevaluated() || getCharByteWidth() == 1) &&
1889 "This function is used in places that assume strings use char");
1890 return StringRef(getStrDataAsChar(), getByteLength());
1891 }
1892
1893 /// Allow access to clients that need the byte representation, such as
1894 /// ASTWriterStmt::VisitStringLiteral().
1895 StringRef getBytes() const {
1896 // FIXME: StringRef may not be the right type to use as a result for this.
1897 return StringRef(getStrDataAsChar(), getByteLength());
1898 }
1899
1900 /// Prints the contents of the string to \p OS.
1901 void outputString(raw_ostream &OS) const;
1902
1903 /// Return the code unit at the given position.
1904 ///
1905 /// \pre \p I < getLength()
1906 uint32_t getCodeUnit(size_t I) const {
1907 assert(I < getLength() && "out of bounds access");
1908 switch (getCharByteWidth()) {
1909 case 1:
1910 return static_cast<unsigned char>(getStrDataAsChar()[I]);
1911 case 2:
1912 return getStrDataAsUInt16()[I];
1913 case 4:
1914 return getStrDataAsUInt32()[I];
1915 }
1916 llvm_unreachable("Unsupported character width!");
1917 }
1918
1919 // Get code unit but preserve sign info.
1920 int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const {
1921 int64_t V = getCodeUnit(I);
1922 if (isOrdinary() || isWide()) {
1923 // Ordinary and wide string literals have types that can be signed.
1924 // It is important for checking C23 constexpr initializers.
1925 unsigned Width = getCharByteWidth() * BitWidth;
1926 llvm::APInt AInt(Width, (uint64_t)V);
1927 V = AInt.getSExtValue();
1928 }
1929 return V;
1930 }
1931
1932 /// Scan the string literal contents for a code unit with value 0.
1933 /// If \p StartIndex is outside of the length of the string, this returns \c
1934 /// std::nullopt.
1935 ///
1936 /// Otherwise, returns the offset (in code units, not bytes) of the zero code
1937 /// unit, starting at index \p StartIndex. If no such code unit could be
1938 /// found, this returns `getLength() - StartIndex`.
1939 UnsignedOrNone findZeroCodeUnit(unsigned StartIndex = 0) const;
1940
1941 /// \returns The length of the full string in bytes.
1942 unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1943 /// \returns The length of the full string in characters.
1944 unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1945 /// \returns The size of one character in the string, in bytes.
1946 unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1947
1949 return static_cast<StringLiteralKind>(StringLiteralBits.Kind);
1950 }
1951
1952 bool isOrdinary() const { return getKind() == StringLiteralKind::Ordinary; }
1953 bool isWide() const { return getKind() == StringLiteralKind::Wide; }
1954 bool isUTF8() const { return getKind() == StringLiteralKind::UTF8; }
1955 bool isUTF16() const { return getKind() == StringLiteralKind::UTF16; }
1956 bool isUTF32() const { return getKind() == StringLiteralKind::UTF32; }
1958 bool isPascal() const { return StringLiteralBits.IsPascal; }
1959
1960 /// Scans the string contents for any non-ascii characters.
1961 ///
1962 /// \pre isUnevaluated() || getCharByteWidth() == 1
1963 /// \returns \c true if a non-ascii character was found, \c false otherwise.
1964 bool containsNonAscii() const {
1965 for (auto c : getString())
1966 if (!isASCII(c))
1967 return true;
1968 return false;
1969 }
1970
1971 /// Scans the string contents for any non-ascii or null characters.
1972 ///
1973 /// \pre isUnevaluated() || getCharByteWidth() == 1
1974 /// \returns \c true if a non-ascii or null character was found, \c false
1975 /// otherwise.
1977 for (auto c : getString())
1978 if (!isASCII(c) || !c)
1979 return true;
1980 return false;
1981 }
1982
1983 /// Get the number of string literal tokens that were
1984 /// concatenated in translation phase #6 to form this string literal.
1985 unsigned getNumConcatenated() const {
1986 return StringLiteralBits.NumConcatenated;
1987 }
1988
1989 /// Get one of the string literal token.
1990 SourceLocation getStrTokenLoc(unsigned TokNum) const {
1991 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1992 return getTrailingObjects<SourceLocation>()[TokNum];
1993 }
1994
1995 /// Return a source location that points to the specified
1996 /// byte of this string literal.
1997 ///
1998 /// Strings are amazingly complex. They can be formed from multiple tokens
1999 /// and can have escape sequences in them in addition to the usual trigraph
2000 /// and escaped newline business. This routine handles this complexity.
2002 getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
2003 const LangOptions &Features, const TargetInfo &Target,
2004 unsigned *StartToken = nullptr,
2005 unsigned *StartTokenByteOffset = nullptr) const;
2006
2008
2010 return getTrailingObjects<SourceLocation>();
2011 }
2012
2014 return getTrailingObjects<SourceLocation>() + getNumConcatenated();
2015 }
2016
2017 SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
2018 SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
2019
2020 static bool classof(const Stmt *T) {
2021 return T->getStmtClass() == StringLiteralClass;
2022 }
2023
2024 // Iterators
2031};
2032
2036 LFunction, // Same as Function, but as wide string.
2039 LFuncSig, // Same as FuncSig, but as wide string
2041 /// The same as PrettyFunction, except that the
2042 /// 'virtual' keyword is omitted for virtual member functions.
2044};
2045
2046/// [C99 6.4.2.2] - A predefined identifier such as __func__.
2047class PredefinedExpr final
2048 : public Expr,
2049 private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
2050 friend class ASTStmtReader;
2051 friend TrailingObjects;
2052
2053 // PredefinedExpr is optionally followed by a single trailing
2054 // "Stmt *" for the predefined identifier. It is present if and only if
2055 // hasFunctionName() is true and is always a "StringLiteral *".
2056
2057 PredefinedExpr(SourceLocation L, QualType FNTy, PredefinedIdentKind IK,
2058 bool IsTransparent, StringLiteral *SL);
2059
2060 explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
2061
2062 /// True if this PredefinedExpr has storage for a function name.
2063 bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
2064
2065 void setFunctionName(StringLiteral *SL) {
2066 assert(hasFunctionName() &&
2067 "This PredefinedExpr has no storage for a function name!");
2068 *getTrailingObjects() = SL;
2069 }
2070
2071public:
2072 /// Create a PredefinedExpr.
2073 ///
2074 /// If IsTransparent, the PredefinedExpr is transparently handled as a
2075 /// StringLiteral.
2076 static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2077 QualType FNTy, PredefinedIdentKind IK,
2078 bool IsTransparent, StringLiteral *SL);
2079
2080 /// Create an empty PredefinedExpr.
2081 static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
2082 bool HasFunctionName);
2083
2085 return static_cast<PredefinedIdentKind>(PredefinedExprBits.Kind);
2086 }
2087
2088 bool isTransparent() const { return PredefinedExprBits.IsTransparent; }
2089
2092
2094 return hasFunctionName()
2095 ? static_cast<StringLiteral *>(*getTrailingObjects())
2096 : nullptr;
2097 }
2098
2100 return hasFunctionName()
2101 ? static_cast<StringLiteral *>(*getTrailingObjects())
2102 : nullptr;
2103 }
2104
2105 static StringRef getIdentKindName(PredefinedIdentKind IK);
2106 StringRef getIdentKindName() const {
2108 }
2109
2110 static std::string ComputeName(PredefinedIdentKind IK,
2111 const Decl *CurrentDecl,
2112 bool ForceElaboratedPrinting = false);
2113
2116
2117 static bool classof(const Stmt *T) {
2118 return T->getStmtClass() == PredefinedExprClass;
2119 }
2120
2121 // Iterators
2123 return child_range(getTrailingObjects(hasFunctionName()));
2124 }
2125
2127 return const_child_range(getTrailingObjects(hasFunctionName()));
2128 }
2129};
2130
2131/// This expression type represents an asterisk in an OpenACC Size-Expr, used in
2132/// the 'tile' and 'gang' clauses. It is of 'int' type, but should not be
2133/// evaluated.
2134class OpenACCAsteriskSizeExpr final : public Expr {
2135 friend class ASTStmtReader;
2136 SourceLocation AsteriskLoc;
2137
2138 OpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc, QualType IntTy)
2139 : Expr(OpenACCAsteriskSizeExprClass, IntTy, VK_PRValue, OK_Ordinary),
2140 AsteriskLoc(AsteriskLoc) {}
2141
2142 void setAsteriskLocation(SourceLocation Loc) { AsteriskLoc = Loc; }
2143
2144public:
2145 static OpenACCAsteriskSizeExpr *Create(const ASTContext &C,
2146 SourceLocation Loc);
2147 static OpenACCAsteriskSizeExpr *CreateEmpty(const ASTContext &C);
2148
2149 SourceLocation getBeginLoc() const { return AsteriskLoc; }
2150 SourceLocation getEndLoc() const { return AsteriskLoc; }
2151 SourceLocation getLocation() const { return AsteriskLoc; }
2152
2153 static bool classof(const Stmt *T) {
2154 return T->getStmtClass() == OpenACCAsteriskSizeExprClass;
2155 }
2156 // Iterators
2160
2164};
2165
2166// This represents a use of the __builtin_sycl_unique_stable_name, which takes a
2167// type-id, and at CodeGen time emits a unique string representation of the
2168// type in a way that permits us to properly encode information about the SYCL
2169// kernels.
2170class SYCLUniqueStableNameExpr final : public Expr {
2171 friend class ASTStmtReader;
2172 SourceLocation OpLoc, LParen, RParen;
2173 TypeSourceInfo *TypeInfo;
2174
2175 SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy);
2176 SYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen,
2177 SourceLocation RParen, QualType ResultTy,
2178 TypeSourceInfo *TSI);
2179
2180 void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; }
2181
2182 void setLocation(SourceLocation L) { OpLoc = L; }
2183 void setLParenLocation(SourceLocation L) { LParen = L; }
2184 void setRParenLocation(SourceLocation L) { RParen = L; }
2185
2186public:
2187 TypeSourceInfo *getTypeSourceInfo() { return TypeInfo; }
2188
2189 const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; }
2190
2192 Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen,
2193 SourceLocation RParen, TypeSourceInfo *TSI);
2194
2196
2198 SourceLocation getEndLoc() const { return RParen; }
2199 SourceLocation getLocation() const { return OpLoc; }
2200 SourceLocation getLParenLocation() const { return LParen; }
2201 SourceLocation getRParenLocation() const { return RParen; }
2202
2203 static bool classof(const Stmt *T) {
2204 return T->getStmtClass() == SYCLUniqueStableNameExprClass;
2205 }
2206
2207 // Iterators
2211
2215
2216 // Convenience function to generate the name of the currently stored type.
2217 std::string ComputeName(ASTContext &Context) const;
2218
2219 // Get the generated name of the type. Note that this only works after all
2220 // kernels have been instantiated.
2221 static std::string ComputeName(ASTContext &Context, QualType Ty);
2222};
2223
2224/// ParenExpr - This represents a parenthesized expression, e.g. "(1)". This
2225/// AST node is only formed if full location information is requested.
2226class ParenExpr : public Expr {
2227 SourceLocation L, R;
2228 Stmt *Val;
2229
2230public:
2232 : Expr(ParenExprClass, val->getType(), val->getValueKind(),
2233 val->getObjectKind()),
2234 L(l), R(r), Val(val) {
2235 ParenExprBits.ProducedByFoldExpansion = false;
2237 }
2238
2239 /// Construct an empty parenthesized expression.
2241 : Expr(ParenExprClass, Empty) { }
2242
2243 const Expr *getSubExpr() const { return cast<Expr>(Val); }
2244 Expr *getSubExpr() { return cast<Expr>(Val); }
2245 void setSubExpr(Expr *E) { Val = E; }
2246
2247 SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
2248 SourceLocation getEndLoc() const LLVM_READONLY { return R; }
2249
2250 /// Get the location of the left parentheses '('.
2251 SourceLocation getLParen() const { return L; }
2252 void setLParen(SourceLocation Loc) { L = Loc; }
2253
2254 /// Get the location of the right parentheses ')'.
2255 SourceLocation getRParen() const { return R; }
2256 void setRParen(SourceLocation Loc) { R = Loc; }
2257
2258 static bool classof(const Stmt *T) {
2259 return T->getStmtClass() == ParenExprClass;
2260 }
2261
2262 // Iterators
2263 child_range children() { return child_range(&Val, &Val+1); }
2265 return const_child_range(&Val, &Val + 1);
2266 }
2267
2269 return ParenExprBits.ProducedByFoldExpansion != 0;
2270 }
2271 void setIsProducedByFoldExpansion(bool ProducedByFoldExpansion = true) {
2272 ParenExprBits.ProducedByFoldExpansion = ProducedByFoldExpansion;
2273 }
2274};
2275
2276/// UnaryOperator - This represents the unary-expression's (except sizeof and
2277/// alignof), the postinc/postdec operators from postfix-expression, and various
2278/// extensions.
2279///
2280/// Notes on various nodes:
2281///
2282/// Real/Imag - These return the real/imag part of a complex operand. If
2283/// applied to a non-complex value, the former returns its operand and the
2284/// later returns zero in the type of the operand.
2285///
2286class UnaryOperator final
2287 : public Expr,
2288 private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> {
2289 Stmt *Val;
2290
2291 FPOptionsOverride &getTrailingFPFeatures() {
2292 assert(UnaryOperatorBits.HasFPFeatures);
2293 return *getTrailingObjects();
2294 }
2295
2296 const FPOptionsOverride &getTrailingFPFeatures() const {
2297 assert(UnaryOperatorBits.HasFPFeatures);
2298 return *getTrailingObjects();
2299 }
2300
2301public:
2303
2304protected:
2305 UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
2307 bool CanOverflow, FPOptionsOverride FPFeatures);
2308
2309 /// Build an empty unary operator.
2310 explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
2311 : Expr(UnaryOperatorClass, Empty) {
2312 UnaryOperatorBits.Opc = UO_AddrOf;
2313 UnaryOperatorBits.HasFPFeatures = HasFPFeatures;
2314 }
2315
2316public:
2317 static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
2318
2319 static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
2322 bool CanOverflow, FPOptionsOverride FPFeatures);
2323
2325 return static_cast<Opcode>(UnaryOperatorBits.Opc);
2326 }
2327 void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
2328
2329 Expr *getSubExpr() const { return cast<Expr>(Val); }
2330 void setSubExpr(Expr *E) { Val = E; }
2331
2332 /// getOperatorLoc - Return the location of the operator.
2335
2336 /// Returns true if the unary operator can cause an overflow. For instance,
2337 /// signed int i = INT_MAX; i++;
2338 /// signed char c = CHAR_MAX; c++;
2339 /// Due to integer promotions, c++ is promoted to an int before the postfix
2340 /// increment, and the result is an int that cannot overflow. However, i++
2341 /// can overflow.
2342 bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
2343 void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
2344
2345 /// Get the FP contractibility status of this operator. Only meaningful for
2346 /// operations on floating point types.
2350
2351 /// Get the FENV_ACCESS status of this operator. Only meaningful for
2352 /// operations on floating point types.
2353 bool isFEnvAccessOn(const LangOptions &LO) const {
2354 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
2355 }
2356
2357 /// isPostfix - Return true if this is a postfix operation, like x++.
2358 static bool isPostfix(Opcode Op) {
2359 return Op == UO_PostInc || Op == UO_PostDec;
2360 }
2361
2362 /// isPrefix - Return true if this is a prefix operation, like --x.
2363 static bool isPrefix(Opcode Op) {
2364 return Op == UO_PreInc || Op == UO_PreDec;
2365 }
2366
2367 bool isPrefix() const { return isPrefix(getOpcode()); }
2368 bool isPostfix() const { return isPostfix(getOpcode()); }
2369
2370 static bool isIncrementOp(Opcode Op) {
2371 return Op == UO_PreInc || Op == UO_PostInc;
2372 }
2373 bool isIncrementOp() const {
2374 return isIncrementOp(getOpcode());
2375 }
2376
2377 static bool isDecrementOp(Opcode Op) {
2378 return Op == UO_PreDec || Op == UO_PostDec;
2379 }
2380 bool isDecrementOp() const {
2381 return isDecrementOp(getOpcode());
2382 }
2383
2384 static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
2387 }
2388
2389 static bool isArithmeticOp(Opcode Op) {
2390 return Op >= UO_Plus && Op <= UO_LNot;
2391 }
2392 bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
2393
2394 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2395 /// corresponds to, e.g. "sizeof" or "[pre]++"
2396 static StringRef getOpcodeStr(Opcode Op);
2397
2398 /// Retrieve the unary opcode that corresponds to the given
2399 /// overloaded operator.
2400 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
2401
2402 /// Retrieve the overloaded operator kind that corresponds to
2403 /// the given unary opcode.
2405
2406 SourceLocation getBeginLoc() const LLVM_READONLY {
2407 return isPostfix() ? Val->getBeginLoc() : getOperatorLoc();
2408 }
2409 SourceLocation getEndLoc() const LLVM_READONLY {
2410 return isPostfix() ? getOperatorLoc() : Val->getEndLoc();
2411 }
2413
2414 static bool classof(const Stmt *T) {
2415 return T->getStmtClass() == UnaryOperatorClass;
2416 }
2417
2418 // Iterators
2419 child_range children() { return child_range(&Val, &Val+1); }
2421 return const_child_range(&Val, &Val + 1);
2422 }
2423
2424 /// Is FPFeatures in Trailing Storage?
2425 bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; }
2426
2427 /// Get FPFeatures from trailing storage.
2429 return getTrailingFPFeatures();
2430 }
2431
2432 /// Get the store FPOptionsOverride or default if not stored.
2436
2437protected:
2438 /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
2439 void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
2440
2441public:
2442 /// Get the FP features status of this operator. Only meaningful for
2443 /// operations on floating point types.
2445 if (UnaryOperatorBits.HasFPFeatures)
2448 }
2450 if (UnaryOperatorBits.HasFPFeatures)
2451 return getStoredFPFeatures();
2452 return FPOptionsOverride();
2453 }
2454
2456 friend class ASTNodeImporter;
2457 friend class ASTReader;
2458 friend class ASTStmtReader;
2459 friend class ASTStmtWriter;
2460};
2461
2462/// Helper class for OffsetOfExpr.
2463
2464// __builtin_offsetof(type, identifier(.identifier|[expr])*)
2466public:
2467 /// The kind of offsetof node we have.
2468 enum Kind {
2469 /// An index into an array.
2470 Array = 0x00,
2471 /// A field.
2472 Field = 0x01,
2473 /// A field in a dependent type, known only by its name.
2475 /// An implicit indirection through a C++ base class, when the
2476 /// field found is in a base class.
2477 Base = 0x03
2478 };
2479
2480private:
2481 enum { MaskBits = 2, Mask = 0x03 };
2482
2483 /// The source range that covers this part of the designator.
2484 SourceRange Range;
2485
2486 /// The data describing the designator, which comes in three
2487 /// different forms, depending on the lower two bits.
2488 /// - An unsigned index into the array of Expr*'s stored after this node
2489 /// in memory, for [constant-expression] designators.
2490 /// - A FieldDecl*, for references to a known field.
2491 /// - An IdentifierInfo*, for references to a field with a given name
2492 /// when the class type is dependent.
2493 /// - A CXXBaseSpecifier*, for references that look at a field in a
2494 /// base class.
2496
2497public:
2498 /// Create an offsetof node that refers to an array element.
2499 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2500 SourceLocation RBracketLoc)
2501 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2502
2503 /// Create an offsetof node that refers to a field.
2505 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2506 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2507
2508 /// Create an offsetof node that refers to an identifier.
2510 SourceLocation NameLoc)
2511 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2512 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2513
2514 /// Create an offsetof node that refers into a C++ base class.
2516 : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2517
2518 /// Determine what kind of offsetof node this is.
2519 Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2520
2521 /// For an array element node, returns the index into the array
2522 /// of expressions.
2523 unsigned getArrayExprIndex() const {
2524 assert(getKind() == Array);
2525 return Data >> 2;
2526 }
2527
2528 /// For a field offsetof node, returns the field.
2530 assert(getKind() == Field);
2531 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2532 }
2533
2534 /// For a field or identifier offsetof node, returns the name of
2535 /// the field.
2536 const IdentifierInfo *getFieldName() const;
2537
2538 /// For a base class node, returns the base specifier.
2540 assert(getKind() == Base);
2541 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2542 }
2543
2544 /// Retrieve the source range that covers this offsetof node.
2545 ///
2546 /// For an array element node, the source range contains the locations of
2547 /// the square brackets. For a field or identifier node, the source range
2548 /// contains the location of the period (if there is one) and the
2549 /// identifier.
2550 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2551 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2552 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2553};
2554
2555/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2556/// offsetof(record-type, member-designator). For example, given:
2557/// @code
2558/// struct S {
2559/// float f;
2560/// double d;
2561/// };
2562/// struct T {
2563/// int i;
2564/// struct S s[10];
2565/// };
2566/// @endcode
2567/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2568
2569class OffsetOfExpr final
2570 : public Expr,
2571 private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2572 SourceLocation OperatorLoc, RParenLoc;
2573 // Base type;
2574 TypeSourceInfo *TSInfo;
2575 // Number of sub-components (i.e. instances of OffsetOfNode).
2576 unsigned NumComps;
2577 // Number of sub-expressions (i.e. array subscript expressions).
2578 unsigned NumExprs;
2579
2580 size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2581 return NumComps;
2582 }
2583
2584 OffsetOfExpr(const ASTContext &C, QualType type,
2585 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2587 SourceLocation RParenLoc);
2588
2589 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2590 : Expr(OffsetOfExprClass, EmptyShell()),
2591 TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2592
2593public:
2594
2595 static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2596 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2598 ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2599
2600 static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2601 unsigned NumComps, unsigned NumExprs);
2602
2603 /// getOperatorLoc - Return the location of the operator.
2604 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2605 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2606
2607 /// Return the location of the right parentheses.
2608 SourceLocation getRParenLoc() const { return RParenLoc; }
2609 void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2610
2612 return TSInfo;
2613 }
2615 TSInfo = tsi;
2616 }
2617
2618 const OffsetOfNode &getComponent(unsigned Idx) const {
2619 return getTrailingObjects<OffsetOfNode>(NumComps)[Idx];
2620 }
2621
2622 void setComponent(unsigned Idx, OffsetOfNode ON) {
2623 getTrailingObjects<OffsetOfNode>(NumComps)[Idx] = ON;
2624 }
2625
2626 unsigned getNumComponents() const {
2627 return NumComps;
2628 }
2629
2630 Expr* getIndexExpr(unsigned Idx) {
2631 return getTrailingObjects<Expr *>(NumExprs)[Idx];
2632 }
2633
2634 const Expr *getIndexExpr(unsigned Idx) const {
2635 return getTrailingObjects<Expr *>(NumExprs)[Idx];
2636 }
2637
2638 void setIndexExpr(unsigned Idx, Expr* E) {
2639 getTrailingObjects<Expr *>(NumComps)[Idx] = E;
2640 }
2641
2642 unsigned getNumExpressions() const {
2643 return NumExprs;
2644 }
2645
2646 SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2647 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2648
2649 static bool classof(const Stmt *T) {
2650 return T->getStmtClass() == OffsetOfExprClass;
2651 }
2652
2653 // Iterators
2655 Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2656 return child_range(begin, begin + NumExprs);
2657 }
2659 Stmt *const *begin =
2660 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2661 return const_child_range(begin, begin + NumExprs);
2662 }
2664};
2665
2666/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2667/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
2668/// vec_step (OpenCL 1.1 6.11.12).
2670 union {
2673 } Argument;
2674 SourceLocation OpLoc, RParenLoc;
2675
2676public:
2677 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
2678 QualType resultType, SourceLocation op,
2679 SourceLocation rp)
2680 : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue,
2681 OK_Ordinary),
2682 OpLoc(op), RParenLoc(rp) {
2683 assert(ExprKind <= UETT_Last && "invalid enum value!");
2684 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2685 assert(static_cast<unsigned>(ExprKind) ==
2687 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2688 UnaryExprOrTypeTraitExprBits.IsType = true;
2689 Argument.Ty = TInfo;
2691 }
2692
2693 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
2694 QualType resultType, SourceLocation op,
2695 SourceLocation rp);
2696
2697 /// Construct an empty sizeof/alignof expression.
2699 : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2700
2701 UnaryExprOrTypeTrait getKind() const {
2702 return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2703 }
2704 void setKind(UnaryExprOrTypeTrait K) {
2705 assert(K <= UETT_Last && "invalid enum value!");
2707 assert(static_cast<unsigned>(K) == UnaryExprOrTypeTraitExprBits.Kind &&
2708 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2709 }
2710
2711 bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2713 return getArgumentTypeInfo()->getType();
2714 }
2716 assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2717 return Argument.Ty;
2718 }
2720 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2721 return static_cast<Expr*>(Argument.Ex);
2722 }
2723 const Expr *getArgumentExpr() const {
2724 return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2725 }
2726
2728 Argument.Ex = E;
2729 UnaryExprOrTypeTraitExprBits.IsType = false;
2730 }
2732 Argument.Ty = TInfo;
2733 UnaryExprOrTypeTraitExprBits.IsType = true;
2734 }
2735
2736 /// Gets the argument type, or the type of the argument expression, whichever
2737 /// is appropriate.
2741
2742 SourceLocation getOperatorLoc() const { return OpLoc; }
2743 void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2744
2745 SourceLocation getRParenLoc() const { return RParenLoc; }
2746 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2747
2748 SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2749 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2750
2751 static bool classof(const Stmt *T) {
2752 return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2753 }
2754
2755 // Iterators
2758};
2759
2760//===----------------------------------------------------------------------===//
2761// Postfix Operators.
2762//===----------------------------------------------------------------------===//
2763
2764/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2765class ArraySubscriptExpr : public Expr {
2766 enum { LHS, RHS, END_EXPR };
2767 Stmt *SubExprs[END_EXPR];
2768
2769 bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
2770
2771public:
2773 ExprObjectKind OK, SourceLocation rbracketloc)
2774 : Expr(ArraySubscriptExprClass, t, VK, OK) {
2775 SubExprs[LHS] = lhs;
2776 SubExprs[RHS] = rhs;
2777 ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc;
2779 }
2780
2781 /// Create an empty array subscript expression.
2783 : Expr(ArraySubscriptExprClass, Shell) { }
2784
2785 /// An array access can be written A[4] or 4[A] (both are equivalent).
2786 /// - getBase() and getIdx() always present the normalized view: A[4].
2787 /// In this case getBase() returns "A" and getIdx() returns "4".
2788 /// - getLHS() and getRHS() present the syntactic view. e.g. for
2789 /// 4[A] getLHS() returns "4".
2790 /// Note: Because vector element access is also written A[4] we must
2791 /// predicate the format conversion in getBase and getIdx only on the
2792 /// the type of the RHS, as it is possible for the LHS to be a vector of
2793 /// integer type
2794 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2795 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2796 void setLHS(Expr *E) { SubExprs[LHS] = E; }
2797
2798 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2799 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2800 void setRHS(Expr *E) { SubExprs[RHS] = E; }
2801
2802 Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
2803 const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
2804
2805 Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
2806 const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
2807
2808 SourceLocation getBeginLoc() const LLVM_READONLY {
2809 return getLHS()->getBeginLoc();
2810 }
2812
2814 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2815 }
2817 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2818 }
2819
2820 SourceLocation getExprLoc() const LLVM_READONLY {
2821 return getBase()->getExprLoc();
2822 }
2823
2824 static bool classof(const Stmt *T) {
2825 return T->getStmtClass() == ArraySubscriptExprClass;
2826 }
2827
2828 // Iterators
2830 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2831 }
2833 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2834 }
2835};
2836
2837/// MatrixSingleSubscriptExpr - Matrix single subscript expression for the
2838/// MatrixType extension when you want to get\set a vector from a Matrix.
2840 enum { BASE, ROW_IDX, END_EXPR };
2841 Stmt *SubExprs[END_EXPR];
2842
2843public:
2844 /// matrix[row]
2845 ///
2846 /// \param Base The matrix expression.
2847 /// \param RowIdx The row index expression.
2848 /// \param T The type of the row (usually a vector type).
2849 /// \param RBracketLoc Location of the closing ']'.
2851 SourceLocation RBracketLoc)
2852 : Expr(MatrixSingleSubscriptExprClass, T,
2853 Base->getValueKind(), // lvalue/rvalue follows the matrix base
2855 SubExprs[BASE] = Base;
2856 SubExprs[ROW_IDX] = RowIdx;
2857 ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2859 }
2860
2861 /// Create an empty matrix single-subscript expression.
2863 : Expr(MatrixSingleSubscriptExprClass, Shell) {}
2864
2865 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2866 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2867 void setBase(Expr *E) { SubExprs[BASE] = E; }
2868
2869 Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2870 const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2871 void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2872
2873 SourceLocation getBeginLoc() const LLVM_READONLY {
2874 return getBase()->getBeginLoc();
2875 }
2876
2878
2879 SourceLocation getExprLoc() const LLVM_READONLY {
2880 return getBase()->getExprLoc();
2881 }
2882
2884 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2885 }
2887 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2888 }
2889
2890 static bool classof(const Stmt *T) {
2891 return T->getStmtClass() == MatrixSingleSubscriptExprClass;
2892 }
2893
2894 // Iterators
2896 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2897 }
2899 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2900 }
2901};
2902
2903/// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType
2904/// extension.
2905/// MatrixSubscriptExpr can be either incomplete (only Base and RowIdx are set
2906/// so far, the type is IncompleteMatrixIdx) or complete (Base, RowIdx and
2907/// ColumnIdx refer to valid expressions). Incomplete matrix expressions only
2908/// exist during the initial construction of the AST.
2910 enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR };
2911 Stmt *SubExprs[END_EXPR];
2912
2913public:
2915 SourceLocation RBracketLoc)
2916 : Expr(MatrixSubscriptExprClass, T, Base->getValueKind(),
2918 SubExprs[BASE] = Base;
2919 SubExprs[ROW_IDX] = RowIdx;
2920 SubExprs[COLUMN_IDX] = ColumnIdx;
2921 ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2923 }
2924
2925 /// Create an empty matrix subscript expression.
2927 : Expr(MatrixSubscriptExprClass, Shell) {}
2928
2929 bool isIncomplete() const {
2930 bool IsIncomplete = hasPlaceholderType(BuiltinType::IncompleteMatrixIdx);
2931 assert((SubExprs[COLUMN_IDX] || IsIncomplete) &&
2932 "expressions without column index must be marked as incomplete");
2933 return IsIncomplete;
2934 }
2935 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2936 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2937 void setBase(Expr *E) { SubExprs[BASE] = E; }
2938
2939 Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2940 const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2941 void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2942
2943 Expr *getColumnIdx() { return cast_or_null<Expr>(SubExprs[COLUMN_IDX]); }
2944 const Expr *getColumnIdx() const {
2945 assert(!isIncomplete() &&
2946 "cannot get the column index of an incomplete expression");
2947 return cast<Expr>(SubExprs[COLUMN_IDX]);
2948 }
2949 void setColumnIdx(Expr *E) { SubExprs[COLUMN_IDX] = E; }
2950
2951 SourceLocation getBeginLoc() const LLVM_READONLY {
2952 return getBase()->getBeginLoc();
2953 }
2954
2956
2957 SourceLocation getExprLoc() const LLVM_READONLY {
2958 return getBase()->getExprLoc();
2959 }
2960
2962 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2963 }
2965 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2966 }
2967
2968 static bool classof(const Stmt *T) {
2969 return T->getStmtClass() == MatrixSubscriptExprClass;
2970 }
2971
2972 // Iterators
2974 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2975 }
2977 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2978 }
2979};
2980
2981/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2982/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2983/// while its subclasses may represent alternative syntax that (semantically)
2984/// results in a function call. For example, CXXOperatorCallExpr is
2985/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2986/// "str1 + str2" to resolve to a function call.
2987class CallExpr : public Expr {
2988 enum { FN = 0, PREARGS_START = 1 };
2989
2990 /// The number of arguments in the call expression.
2991 unsigned NumArgs;
2992
2993 /// The location of the right parentheses. This has a different meaning for
2994 /// the derived classes of CallExpr.
2995 SourceLocation RParenLoc;
2996
2997 // CallExpr store some data in trailing objects. However since CallExpr
2998 // is used a base of other expression classes we cannot use
2999 // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic
3000 // and casts.
3001 //
3002 // The trailing objects are in order:
3003 //
3004 // * A single "Stmt *" for the callee expression.
3005 //
3006 // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions.
3007 //
3008 // * An array of getNumArgs() "Stmt *" for the argument expressions.
3009 //
3010 // * An optional of type FPOptionsOverride.
3011 //
3012 // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
3013 // itself is 24 bytes. To avoid having to recompute or store the offset of the
3014 // trailing objects, we put it at 32 bytes (such that it is suitable for all
3015 // subclasses) We use the 8 bytes gap left for instances of CallExpr to store
3016 // the begin source location, which has a significant impact on perf as
3017 // getBeginLoc is assumed to be cheap.
3018 // The layourt is as follow:
3019 // CallExpr | Begin | 4 bytes left | Trailing Objects
3020 // CXXMemberCallExpr | Trailing Objects
3021 // A bit in CallExprBitfields indicates if source locations are present.
3022
3023protected:
3024 static constexpr unsigned OffsetToTrailingObjects = 32;
3025 template <typename T>
3026 static constexpr unsigned
3027 sizeToAllocateForCallExprSubclass(unsigned SizeOfTrailingObjects) {
3028 static_assert(sizeof(T) <= CallExpr::OffsetToTrailingObjects);
3029 return SizeOfTrailingObjects + CallExpr::OffsetToTrailingObjects;
3030 }
3031
3032private:
3033 /// Return a pointer to the start of the trailing array of "Stmt *".
3034 Stmt **getTrailingStmts() {
3035 return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) +
3037 }
3038 Stmt *const *getTrailingStmts() const {
3039 return const_cast<CallExpr *>(this)->getTrailingStmts();
3040 }
3041
3042 unsigned getSizeOfTrailingStmts() const {
3043 return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *);
3044 }
3045
3046 size_t getOffsetOfTrailingFPFeatures() const {
3047 assert(hasStoredFPFeatures());
3048 return OffsetToTrailingObjects + getSizeOfTrailingStmts();
3049 }
3050
3051public:
3052 enum class ADLCallKind : bool { NotADL, UsesADL };
3055
3056protected:
3057 /// Build a call expression, assuming that appropriate storage has been
3058 /// allocated for the trailing objects.
3059 CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
3061 SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
3062 unsigned MinNumArgs, ADLCallKind UsesADL);
3063
3064 /// Build an empty call expression, for deserialization.
3065 CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
3066 bool hasFPFeatures, EmptyShell Empty);
3067
3068 /// Return the size in bytes needed for the trailing objects.
3069 /// Used by the derived classes to allocate the right amount of storage.
3070 static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs,
3071 bool HasFPFeatures) {
3072 return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *) +
3073 HasFPFeatures * sizeof(FPOptionsOverride);
3074 }
3075
3076 Stmt *getPreArg(unsigned I) {
3077 assert(I < getNumPreArgs() && "Prearg access out of range!");
3078 return getTrailingStmts()[PREARGS_START + I];
3079 }
3080 const Stmt *getPreArg(unsigned I) const {
3081 assert(I < getNumPreArgs() && "Prearg access out of range!");
3082 return getTrailingStmts()[PREARGS_START + I];
3083 }
3084 void setPreArg(unsigned I, Stmt *PreArg) {
3085 assert(I < getNumPreArgs() && "Prearg access out of range!");
3086 getTrailingStmts()[PREARGS_START + I] = PreArg;
3087 }
3088
3089 unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
3090
3091 /// Return a pointer to the trailing FPOptions
3093 assert(hasStoredFPFeatures());
3094 return reinterpret_cast<FPOptionsOverride *>(
3095 reinterpret_cast<char *>(this) + OffsetToTrailingObjects +
3096 getSizeOfTrailingStmts());
3097 }
3099 assert(hasStoredFPFeatures());
3100 return reinterpret_cast<const FPOptionsOverride *>(
3101 reinterpret_cast<const char *>(this) + OffsetToTrailingObjects +
3102 getSizeOfTrailingStmts());
3103 }
3104
3105public:
3106 /// Create a call expression.
3107 /// \param Fn The callee expression,
3108 /// \param Args The argument array,
3109 /// \param Ty The type of the call expression (which is *not* the return
3110 /// type in general),
3111 /// \param VK The value kind of the call expression (lvalue, rvalue, ...),
3112 /// \param RParenLoc The location of the right parenthesis in the call
3113 /// expression.
3114 /// \param FPFeatures Floating-point features associated with the call,
3115 /// \param MinNumArgs Specifies the minimum number of arguments. The actual
3116 /// number of arguments will be the greater of Args.size()
3117 /// and MinNumArgs. This is used in a few places to allocate
3118 /// enough storage for the default arguments.
3119 /// \param UsesADL Specifies whether the callee was found through
3120 /// argument-dependent lookup.
3121 ///
3122 /// Note that you can use CreateTemporary if you need a temporary call
3123 /// expression on the stack.
3124 static CallExpr *Create(const ASTContext &Ctx, Expr *Fn,
3126 SourceLocation RParenLoc,
3127 FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
3128 ADLCallKind UsesADL = NotADL);
3129
3130 /// Create an empty call expression, for deserialization.
3131 static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
3132 bool HasFPFeatures, EmptyShell Empty);
3133
3134 Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
3135 const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
3136 void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
3137
3139 return static_cast<ADLCallKind>(CallExprBits.UsesADL);
3140 }
3142 CallExprBits.UsesADL = static_cast<bool>(V);
3143 }
3144 bool usesADL() const { return getADLCallKind() == UsesADL; }
3145
3146 bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
3147
3148 bool usesMemberSyntax() const {
3149 return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax;
3150 }
3151 void setUsesMemberSyntax(bool V = true) {
3152 CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
3153 // Because the source location may be different for explicit
3154 // member, we reset the cached values.
3155 if (CallExprBits.HasTrailingSourceLoc) {
3156 CallExprBits.HasTrailingSourceLoc = false;
3157 updateTrailingSourceLoc();
3158 }
3159 }
3160
3161 bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
3162 void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
3163
3165 const Decl *getCalleeDecl() const {
3167 }
3168
3169 /// If the callee is a FunctionDecl, return it. Otherwise return null.
3171 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
3172 }
3174 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
3175 }
3176
3177 /// getNumArgs - Return the number of actual arguments to this call.
3178 unsigned getNumArgs() const { return NumArgs; }
3179
3180 /// Retrieve the call arguments.
3182 return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
3183 getNumPreArgs());
3184 }
3185 const Expr *const *getArgs() const {
3186 return reinterpret_cast<const Expr *const *>(
3187 getTrailingStmts() + PREARGS_START + getNumPreArgs());
3188 }
3189
3190 /// getArg - Return the specified argument.
3191 Expr *getArg(unsigned Arg) {
3192 assert(Arg < getNumArgs() && "Arg access out of range!");
3193 return getArgs()[Arg];
3194 }
3195 const Expr *getArg(unsigned Arg) const {
3196 assert(Arg < getNumArgs() && "Arg access out of range!");
3197 return getArgs()[Arg];
3198 }
3199
3200 /// setArg - Set the specified argument.
3201 /// ! the dependence bits might be stale after calling this setter, it is
3202 /// *caller*'s responsibility to recompute them by calling
3203 /// computeDependence().
3204 void setArg(unsigned Arg, Expr *ArgExpr) {
3205 assert(Arg < getNumArgs() && "Arg access out of range!");
3206 getArgs()[Arg] = ArgExpr;
3207 }
3208
3209 /// Compute and set dependence bits.
3212 this,
3213 ArrayRef(reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START),
3214 getNumPreArgs())));
3215 }
3216
3217 /// Reduce the number of arguments in this call expression. This is used for
3218 /// example during error recovery to drop extra arguments. There is no way
3219 /// to perform the opposite because: 1.) We don't track how much storage
3220 /// we have for the argument array 2.) This would potentially require growing
3221 /// the argument array, something we cannot support since the arguments are
3222 /// stored in a trailing array.
3223 void shrinkNumArgs(unsigned NewNumArgs) {
3224 assert((NewNumArgs <= getNumArgs()) &&
3225 "shrinkNumArgs cannot increase the number of arguments!");
3226 NumArgs = NewNumArgs;
3227 }
3228
3229 /// Bluntly set a new number of arguments without doing any checks whatsoever.
3230 /// Only used during construction of a CallExpr in a few places in Sema.
3231 /// FIXME: Find a way to remove it.
3232 void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; }
3233
3236 typedef llvm::iterator_range<arg_iterator> arg_range;
3237 typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
3238
3241 return const_arg_range(arg_begin(), arg_end());
3242 }
3243
3245 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3246 }
3248
3250 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3251 }
3253
3254 /// This method provides fast access to all the subexpressions of
3255 /// a CallExpr without going through the slower virtual child_iterator
3256 /// interface. This provides efficient reverse iteration of the
3257 /// subexpressions. This is currently used for CFG construction.
3259 return {getTrailingStmts(), PREARGS_START + getNumPreArgs() + getNumArgs()};
3260 }
3261
3262 /// Get FPOptionsOverride from trailing storage.
3264 assert(hasStoredFPFeatures());
3265 return *getTrailingFPFeatures();
3266 }
3267 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
3272
3273 /// Get the store FPOptionsOverride or default if not stored.
3277
3278 /// Get the FP features status of this operator. Only meaningful for
3279 /// operations on floating point types.
3285
3287 if (hasStoredFPFeatures())
3288 return getStoredFPFeatures();
3289 return FPOptionsOverride();
3290 }
3291
3292 /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
3293 /// of the callee. If not, return 0.
3294 unsigned getBuiltinCallee() const;
3295
3296 /// Returns \c true if this is a call to a builtin which does not
3297 /// evaluate side-effects within its arguments.
3298 bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
3299
3300 /// getCallReturnType - Get the return type of the call expr. This is not
3301 /// always the type of the expr itself, if the return type is a reference
3302 /// type.
3303 QualType getCallReturnType(const ASTContext &Ctx) const;
3304
3305 /// Returns the WarnUnusedResultAttr that is declared on the callee
3306 /// or its return type declaration, together with a NamedDecl that
3307 /// refers to the declaration the attribute is attached to.
3308 std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
3312
3313 /// Returns true if this call expression should warn on unused results.
3314 bool hasUnusedResultAttr(const ASTContext &Ctx) const {
3315 return getUnusedResultAttr(Ctx).second != nullptr;
3316 }
3317
3318 SourceLocation getRParenLoc() const { return RParenLoc; }
3319 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3320
3322 if (CallExprBits.HasTrailingSourceLoc) {
3323 static_assert(sizeof(CallExpr) <=
3325 return *reinterpret_cast<const SourceLocation *>(
3326 reinterpret_cast<const char *>(this + 1));
3327 }
3328
3329 if (usesMemberSyntax())
3330 if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid())
3331 return FirstArgLoc;
3332
3333 // FIXME: Some builtins have no callee begin location
3335 if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
3336 begin = getArg(0)->getBeginLoc();
3337 return begin;
3338 }
3339
3341
3342private:
3343 friend class ASTStmtReader;
3344 bool hasTrailingSourceLoc() const {
3345 return CallExprBits.HasTrailingSourceLoc;
3346 }
3347
3348 void updateTrailingSourceLoc() {
3349 assert(!CallExprBits.HasTrailingSourceLoc &&
3350 "Trailing source loc already set?");
3351 assert(getStmtClass() == CallExprClass &&
3352 "Calling setTrailingSourceLocs on a subclass of CallExpr");
3353 static_assert(sizeof(CallExpr) <=
3355
3356 SourceLocation *Locs =
3357 reinterpret_cast<SourceLocation *>(reinterpret_cast<char *>(this + 1));
3358 new (Locs) SourceLocation(getBeginLoc());
3359 CallExprBits.HasTrailingSourceLoc = true;
3360 }
3361
3362public:
3363 /// Return true if this is a call to __assume() or __builtin_assume() with
3364 /// a non-value-dependent constant parameter evaluating as false.
3365 bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
3366
3367 /// Used by Sema to implement MSVC-compatible delayed name lookup.
3368 /// (Usually Exprs themselves should set dependence).
3370 setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
3371 }
3372
3373 /// Try to get the alloc_size attribute of the callee. May return null.
3374 const AllocSizeAttr *getCalleeAllocSizeAttr() const;
3375
3376 /// Evaluates the total size in bytes allocated by calling a function
3377 /// decorated with alloc_size. Returns std::nullopt if the the result cannot
3378 /// be evaluated.
3379 std::optional<llvm::APInt>
3381
3382 bool isCallToStdMove() const;
3383
3384 static bool classof(const Stmt *T) {
3385 return T->getStmtClass() >= firstCallExprConstant &&
3386 T->getStmtClass() <= lastCallExprConstant;
3387 }
3388
3389 // Iterators
3391 return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START +
3393 }
3394
3396 return const_child_range(getTrailingStmts(),
3397 getTrailingStmts() + PREARGS_START +
3399 }
3400};
3401
3402/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
3403///
3404class MemberExpr final
3405 : public Expr,
3406 private llvm::TrailingObjects<MemberExpr, NestedNameSpecifierLoc,
3407 DeclAccessPair, ASTTemplateKWAndArgsInfo,
3408 TemplateArgumentLoc> {
3409 friend class ASTReader;
3410 friend class ASTStmtReader;
3411 friend class ASTStmtWriter;
3412 friend TrailingObjects;
3413
3414 /// Base - the expression for the base pointer or structure references. In
3415 /// X.F, this is "X".
3416 Stmt *Base;
3417
3418 /// MemberDecl - This is the decl being referenced by the field/member name.
3419 /// In X.F, this is the decl referenced by F.
3420 ValueDecl *MemberDecl;
3421
3422 /// MemberDNLoc - Provides source/type location info for the
3423 /// declaration name embedded in MemberDecl.
3424 DeclarationNameLoc MemberDNLoc;
3425
3426 /// MemberLoc - This is the location of the member name.
3427 SourceLocation MemberLoc;
3428
3429 size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
3430 return hasQualifier();
3431 }
3432
3433 size_t numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3434 return hasFoundDecl();
3435 }
3436
3437 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3438 return hasTemplateKWAndArgsInfo();
3439 }
3440
3441 bool hasFoundDecl() const { return MemberExprBits.HasFoundDecl; }
3442
3443 bool hasTemplateKWAndArgsInfo() const {
3444 return MemberExprBits.HasTemplateKWAndArgsInfo;
3445 }
3446
3447 MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
3448 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3449 ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
3450 const DeclarationNameInfo &NameInfo,
3451 const TemplateArgumentListInfo *TemplateArgs, QualType T,
3453 MemberExpr(EmptyShell Empty)
3454 : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
3455
3456public:
3457 static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow,
3458 SourceLocation OperatorLoc,
3459 NestedNameSpecifierLoc QualifierLoc,
3460 SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
3461 DeclAccessPair FoundDecl,
3462 DeclarationNameInfo MemberNameInfo,
3463 const TemplateArgumentListInfo *TemplateArgs,
3464 QualType T, ExprValueKind VK, ExprObjectKind OK,
3465 NonOdrUseReason NOUR);
3466
3467 /// Create an implicit MemberExpr, with no location, qualifier, template
3468 /// arguments, and so on. Suitable only for non-static member access.
3469 static MemberExpr *CreateImplicit(const ASTContext &C, Expr *Base,
3470 bool IsArrow, ValueDecl *MemberDecl,
3472 ExprObjectKind OK) {
3473 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
3474 SourceLocation(), MemberDecl,
3475 DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
3476 DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None);
3477 }
3478
3479 static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
3480 bool HasFoundDecl,
3481 bool HasTemplateKWAndArgsInfo,
3482 unsigned NumTemplateArgs);
3483
3484 void setBase(Expr *E) { Base = E; }
3485 Expr *getBase() const { return cast<Expr>(Base); }
3486
3487 /// Retrieve the member declaration to which this expression refers.
3488 ///
3489 /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
3490 /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
3491 ValueDecl *getMemberDecl() const { return MemberDecl; }
3492 void setMemberDecl(ValueDecl *D);
3493
3494 /// Retrieves the declaration found by lookup.
3496 if (!hasFoundDecl())
3498 getMemberDecl()->getAccess());
3499 return *getTrailingObjects<DeclAccessPair>();
3500 }
3501
3502 /// Determines whether this member expression actually had
3503 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
3504 /// x->Base::foo.
3505 bool hasQualifier() const { return MemberExprBits.HasQualifier; }
3506
3507 /// If the member name was qualified, retrieves the
3508 /// nested-name-specifier that precedes the member name, with source-location
3509 /// information.
3511 if (!hasQualifier())
3512 return NestedNameSpecifierLoc();
3513 return *getTrailingObjects<NestedNameSpecifierLoc>();
3514 }
3515
3516 /// If the member name was qualified, retrieves the
3517 /// nested-name-specifier that precedes the member name. Otherwise, returns
3518 /// NULL.
3522
3523 /// Retrieve the location of the template keyword preceding
3524 /// the member name, if any.
3526 if (!hasTemplateKWAndArgsInfo())
3527 return SourceLocation();
3528 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3529 }
3530
3531 /// Retrieve the location of the left angle bracket starting the
3532 /// explicit template argument list following the member name, if any.
3534 if (!hasTemplateKWAndArgsInfo())
3535 return SourceLocation();
3536 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3537 }
3538
3539 /// Retrieve the location of the right angle bracket ending the
3540 /// explicit template argument list following the member name, if any.
3542 if (!hasTemplateKWAndArgsInfo())
3543 return SourceLocation();
3544 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3545 }
3546
3547 /// Determines whether the member name was preceded by the template keyword.
3549
3550 /// Determines whether the member name was followed by an
3551 /// explicit template argument list.
3552 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3553
3554 /// Copies the template arguments (if present) into the given
3555 /// structure.
3558 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3559 getTrailingObjects<TemplateArgumentLoc>(), List);
3560 }
3561
3562 /// Retrieve the template arguments provided as part of this
3563 /// template-id.
3566 return nullptr;
3567
3568 return getTrailingObjects<TemplateArgumentLoc>();
3569 }
3570
3571 /// Retrieve the number of template arguments provided as part of this
3572 /// template-id.
3573 unsigned getNumTemplateArgs() const {
3575 return 0;
3576
3577 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3578 }
3579
3583
3584 /// Retrieve the member declaration name info.
3586 return DeclarationNameInfo(MemberDecl->getDeclName(),
3587 MemberLoc, MemberDNLoc);
3588 }
3589
3590 SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
3591
3592 bool isArrow() const { return MemberExprBits.IsArrow; }
3593 void setArrow(bool A) { MemberExprBits.IsArrow = A; }
3594
3595 /// getMemberLoc - Return the location of the "member", in X->F, it is the
3596 /// location of 'F'.
3597 SourceLocation getMemberLoc() const { return MemberLoc; }
3598 void setMemberLoc(SourceLocation L) { MemberLoc = L; }
3599
3600 SourceLocation getBeginLoc() const LLVM_READONLY;
3601 SourceLocation getEndLoc() const LLVM_READONLY;
3602
3603 SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
3604
3605 /// Determine whether the base of this explicit is implicit.
3606 bool isImplicitAccess() const {
3607 return getBase() && getBase()->isImplicitCXXThis();
3608 }
3609
3610 /// Returns true if this member expression refers to a method that
3611 /// was resolved from an overloaded set having size greater than 1.
3613 return MemberExprBits.HadMultipleCandidates;
3614 }
3615 /// Sets the flag telling whether this expression refers to
3616 /// a method that was resolved from an overloaded set having size
3617 /// greater than 1.
3618 void setHadMultipleCandidates(bool V = true) {
3619 MemberExprBits.HadMultipleCandidates = V;
3620 }
3621
3622 /// Returns true if virtual dispatch is performed.
3623 /// If the member access is fully qualified, (i.e. X::f()), virtual
3624 /// dispatching is not performed. In -fapple-kext mode qualified
3625 /// calls to virtual method will still go through the vtable.
3626 bool performsVirtualDispatch(const LangOptions &LO) const {
3627 return LO.AppleKext || !hasQualifier();
3628 }
3629
3630 /// Is this expression a non-odr-use reference, and if so, why?
3631 /// This is only meaningful if the named member is a static member.
3633 return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason);
3634 }
3635
3636 static bool classof(const Stmt *T) {
3637 return T->getStmtClass() == MemberExprClass;
3638 }
3639
3640 // Iterators
3641 child_range children() { return child_range(&Base, &Base+1); }
3643 return const_child_range(&Base, &Base + 1);
3644 }
3645};
3646
3647/// CompoundLiteralExpr - [C99 6.5.2.5]
3648///
3650 /// LParenLoc - If non-null, this is the location of the left paren in a
3651 /// compound literal like "(int){4}". This can be null if this is a
3652 /// synthesized compound expression.
3653 SourceLocation LParenLoc;
3654
3655 /// The type as written. This can be an incomplete array type, in
3656 /// which case the actual expression type will be different.
3657 /// The int part of the pair stores whether this expr is file scope.
3658 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
3659 Stmt *Init;
3660
3661 /// Value of constant literals with static storage duration.
3662 mutable APValue *StaticValue = nullptr;
3663
3664public:
3666 QualType T, ExprValueKind VK, Expr *init, bool fileScope)
3667 : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
3668 LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
3669 assert(Init && "Init is a nullptr");
3671 }
3672
3673 /// Construct an empty compound literal.
3675 : Expr(CompoundLiteralExprClass, Empty) { }
3676
3677 const Expr *getInitializer() const { return cast<Expr>(Init); }
3678 Expr *getInitializer() { return cast<Expr>(Init); }
3679 void setInitializer(Expr *E) { Init = E; }
3680
3681 bool isFileScope() const { return TInfoAndScope.getInt(); }
3682 void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
3683
3684 SourceLocation getLParenLoc() const { return LParenLoc; }
3685 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3686
3688 return TInfoAndScope.getPointer();
3689 }
3691 TInfoAndScope.setPointer(tinfo);
3692 }
3693
3694 bool hasStaticStorage() const { return isFileScope() && isGLValue(); }
3696 APValue &getStaticValue() const;
3697
3698 SourceLocation getBeginLoc() const LLVM_READONLY {
3699 if (LParenLoc.isInvalid())
3700 return Init->getBeginLoc();
3701 return LParenLoc;
3702 }
3703 SourceLocation getEndLoc() const LLVM_READONLY { return Init->getEndLoc(); }
3704
3705 static bool classof(const Stmt *T) {
3706 return T->getStmtClass() == CompoundLiteralExprClass;
3707 }
3708
3709 // Iterators
3710 child_range children() { return child_range(&Init, &Init+1); }
3712 return const_child_range(&Init, &Init + 1);
3713 }
3714};
3715
3716/// CastExpr - Base class for type casts, including both implicit
3717/// casts (ImplicitCastExpr) and explicit casts that have some
3718/// representation in the source code (ExplicitCastExpr's derived
3719/// classes).
3720class CastExpr : public Expr {
3721 Stmt *Op;
3722
3723 bool CastConsistency() const;
3724
3725 const CXXBaseSpecifier * const *path_buffer() const {
3726 return const_cast<CastExpr*>(this)->path_buffer();
3727 }
3728 CXXBaseSpecifier **path_buffer();
3729
3730 friend class ASTStmtReader;
3731
3732protected:
3734 Expr *op, unsigned BasePathSize, bool HasFPFeatures)
3735 : Expr(SC, ty, VK, OK_Ordinary), Op(op) {
3736 CastExprBits.Kind = kind;
3737 CastExprBits.PartOfExplicitCast = false;
3738 CastExprBits.BasePathSize = BasePathSize;
3739 assert((CastExprBits.BasePathSize == BasePathSize) &&
3740 "BasePathSize overflow!");
3741 assert(CastConsistency());
3742 CastExprBits.HasFPFeatures = HasFPFeatures;
3743 }
3744
3745 /// Construct an empty cast.
3746 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize,
3747 bool HasFPFeatures)
3748 : Expr(SC, Empty) {
3749 CastExprBits.PartOfExplicitCast = false;
3750 CastExprBits.BasePathSize = BasePathSize;
3751 CastExprBits.HasFPFeatures = HasFPFeatures;
3752 assert((CastExprBits.BasePathSize == BasePathSize) &&
3753 "BasePathSize overflow!");
3754 }
3755
3756 /// Return a pointer to the trailing FPOptions.
3757 /// \pre hasStoredFPFeatures() == true
3760 return const_cast<CastExpr *>(this)->getTrailingFPFeatures();
3761 }
3762
3763public:
3764 CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
3765 void setCastKind(CastKind K) { CastExprBits.Kind = K; }
3766
3767 static const char *getCastKindName(CastKind CK);
3768 const char *getCastKindName() const { return getCastKindName(getCastKind()); }
3769
3770 Expr *getSubExpr() { return cast<Expr>(Op); }
3771 const Expr *getSubExpr() const { return cast<Expr>(Op); }
3772 void setSubExpr(Expr *E) { Op = E; }
3773
3774 /// Retrieve the cast subexpression as it was written in the source
3775 /// code, looking through any implicit casts or other intermediate nodes
3776 /// introduced by semantic analysis.
3778 const Expr *getSubExprAsWritten() const {
3779 return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3780 }
3781
3782 /// If this cast applies a user-defined conversion, retrieve the conversion
3783 /// function that it invokes.
3785
3788 bool path_empty() const { return path_size() == 0; }
3789 unsigned path_size() const { return CastExprBits.BasePathSize; }
3790 path_iterator path_begin() { return path_buffer(); }
3791 path_iterator path_end() { return path_buffer() + path_size(); }
3792 path_const_iterator path_begin() const { return path_buffer(); }
3793 path_const_iterator path_end() const { return path_buffer() + path_size(); }
3794
3795 /// Path through the class hierarchy taken by casts between base and derived
3796 /// classes (see implementation of `CastConsistency()` for a full list of
3797 /// cast kinds that have a path).
3798 ///
3799 /// For each derived-to-base edge in the path, the path contains a
3800 /// `CXXBaseSpecifier` for the base class of that edge; the entries are
3801 /// ordered from derived class to base class.
3802 ///
3803 /// For example, given classes `Base`, `Intermediate : public Base` and
3804 /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
3805 /// `Base *` contains two entries: One for `Intermediate`, and one for `Base`,
3806 /// in that order.
3807 llvm::iterator_range<path_iterator> path() {
3808 return llvm::make_range(path_begin(), path_end());
3809 }
3810 llvm::iterator_range<path_const_iterator> path() const {
3811 return llvm::make_range(path_begin(), path_end());
3812 }
3813
3815 assert(getCastKind() == CK_ToUnion);
3817 }
3818
3819 bool hasStoredFPFeatures() const { return CastExprBits.HasFPFeatures; }
3820
3821 /// Get FPOptionsOverride from trailing storage.
3823 assert(hasStoredFPFeatures());
3824 return *getTrailingFPFeatures();
3825 }
3826
3827 /// Get the store FPOptionsOverride or default if not stored.
3831
3832 /// Get the FP features status of this operation. Only meaningful for
3833 /// operations on floating point types.
3839
3841 if (hasStoredFPFeatures())
3842 return getStoredFPFeatures();
3843 return FPOptionsOverride();
3844 }
3845
3846 /// Return
3847 // True : if this conversion changes the volatile-ness of a gl-value.
3848 // Qualification conversions on gl-values currently use CK_NoOp, but
3849 // it's important to recognize volatile-changing conversions in
3850 // clients code generation that normally eagerly peephole loads. Note
3851 // that the query is answering for this specific node; Sema may
3852 // produce multiple cast nodes for any particular conversion sequence.
3853 // False : Otherwise.
3855 return (isGLValue() && (getType().isVolatileQualified() !=
3856 getSubExpr()->getType().isVolatileQualified()));
3857 }
3858
3859 static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3860 QualType opType);
3861 static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3862 QualType opType);
3863
3864 static bool classof(const Stmt *T) {
3865 return T->getStmtClass() >= firstCastExprConstant &&
3866 T->getStmtClass() <= lastCastExprConstant;
3867 }
3868
3869 // Iterators
3870 child_range children() { return child_range(&Op, &Op+1); }
3871 const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3872};
3873
3874/// ImplicitCastExpr - Allows us to explicitly represent implicit type
3875/// conversions, which have no direct representation in the original
3876/// source code. For example: converting T[]->T*, void f()->void
3877/// (*f)(), float->double, short->int, etc.
3878///
3879/// In C, implicit casts always produce rvalues. However, in C++, an
3880/// implicit cast whose result is being bound to a reference will be
3881/// an lvalue or xvalue. For example:
3882///
3883/// @code
3884/// class Base { };
3885/// class Derived : public Base { };
3886/// Derived &&ref();
3887/// void f(Derived d) {
3888/// Base& b = d; // initializer is an ImplicitCastExpr
3889/// // to an lvalue of type Base
3890/// Base&& r = ref(); // initializer is an ImplicitCastExpr
3891/// // to an xvalue of type Base
3892/// }
3893/// @endcode
3894class ImplicitCastExpr final
3895 : public CastExpr,
3896 private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *,
3897 FPOptionsOverride> {
3898
3899 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
3900 unsigned BasePathLength, FPOptionsOverride FPO,
3902 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength,
3905 if (hasStoredFPFeatures())
3906 *getTrailingFPFeatures() = FPO;
3907 }
3908
3909 /// Construct an empty implicit cast.
3910 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize,
3911 bool HasFPFeatures)
3912 : CastExpr(ImplicitCastExprClass, Shell, PathSize, HasFPFeatures) {}
3913
3914 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3915 return path_size();
3916 }
3917
3918public:
3922 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0,
3923 FPO.requiresTrailingStorage()) {
3924 if (hasStoredFPFeatures())
3925 *getTrailingFPFeatures() = FPO;
3926 }
3927
3928 bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3929 void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3930 CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3931 }
3932
3933 static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3934 CastKind Kind, Expr *Operand,
3935 const CXXCastPath *BasePath,
3937
3938 static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3939 unsigned PathSize, bool HasFPFeatures);
3940
3941 SourceLocation getBeginLoc() const LLVM_READONLY {
3942 return getSubExpr()->getBeginLoc();
3943 }
3944 SourceLocation getEndLoc() const LLVM_READONLY {
3945 return getSubExpr()->getEndLoc();
3946 }
3947
3948 static bool classof(const Stmt *T) {
3949 return T->getStmtClass() == ImplicitCastExprClass;
3950 }
3951
3953 friend class CastExpr;
3954};
3955
3956/// ExplicitCastExpr - An explicit cast written in the source
3957/// code.
3958///
3959/// This class is effectively an abstract class, because it provides
3960/// the basic representation of an explicitly-written cast without
3961/// specifying which kind of cast (C cast, functional cast, static
3962/// cast, etc.) was written; specific derived classes represent the
3963/// particular style of cast and its location information.
3964///
3965/// Unlike implicit casts, explicit cast nodes have two different
3966/// types: the type that was written into the source code, and the
3967/// actual type of the expression as determined by semantic
3968/// analysis. These types may differ slightly. For example, in C++ one
3969/// can cast to a reference type, which indicates that the resulting
3970/// expression will be an lvalue or xvalue. The reference type, however,
3971/// will not be used as the type of the expression.
3973 /// TInfo - Source type info for the (written) type
3974 /// this expression is casting to.
3975 TypeSourceInfo *TInfo;
3976
3977protected:
3979 CastKind kind, Expr *op, unsigned PathSize,
3980 bool HasFPFeatures, TypeSourceInfo *writtenTy)
3981 : CastExpr(SC, exprTy, VK, kind, op, PathSize, HasFPFeatures),
3982 TInfo(writtenTy) {
3984 }
3985
3986 /// Construct an empty explicit cast.
3987 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize,
3988 bool HasFPFeatures)
3989 : CastExpr(SC, Shell, PathSize, HasFPFeatures) {}
3990
3991public:
3992 /// getTypeInfoAsWritten - Returns the type source info for the type
3993 /// that this expression is casting to.
3994 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3995 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3996
3997 /// getTypeAsWritten - Returns the type that this expression is
3998 /// casting to, as written in the source code.
3999 QualType getTypeAsWritten() const { return TInfo->getType(); }
4000
4001 static bool classof(const Stmt *T) {
4002 return T->getStmtClass() >= firstExplicitCastExprConstant &&
4003 T->getStmtClass() <= lastExplicitCastExprConstant;
4004 }
4005};
4006
4007/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
4008/// cast in C++ (C++ [expr.cast]), which uses the syntax
4009/// (Type)expr. For example: @c (int)f.
4010class CStyleCastExpr final
4011 : public ExplicitCastExpr,
4012 private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *,
4013 FPOptionsOverride> {
4014 SourceLocation LPLoc; // the location of the left paren
4015 SourceLocation RPLoc; // the location of the right paren
4016
4017 CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
4018 unsigned PathSize, FPOptionsOverride FPO,
4020 : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
4021 FPO.requiresTrailingStorage(), writtenTy),
4022 LPLoc(l), RPLoc(r) {
4023 if (hasStoredFPFeatures())
4024 *getTrailingFPFeatures() = FPO;
4025 }
4026
4027 /// Construct an empty C-style explicit cast.
4028 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize,
4029 bool HasFPFeatures)
4030 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize, HasFPFeatures) {}
4031
4032 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
4033 return path_size();
4034 }
4035
4036public:
4037 static CStyleCastExpr *
4038 Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K,
4039 Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
4041
4042 static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
4043 unsigned PathSize, bool HasFPFeatures);
4044
4045 SourceLocation getLParenLoc() const { return LPLoc; }
4046 void setLParenLoc(SourceLocation L) { LPLoc = L; }
4047
4048 SourceLocation getRParenLoc() const { return RPLoc; }
4049 void setRParenLoc(SourceLocation L) { RPLoc = L; }
4050
4051 SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
4052 SourceLocation getEndLoc() const LLVM_READONLY {
4053 return getSubExpr()->getEndLoc();
4054 }
4055
4056 static bool classof(const Stmt *T) {
4057 return T->getStmtClass() == CStyleCastExprClass;
4058 }
4059
4061 friend class CastExpr;
4062};
4063
4064/// A builtin binary operation expression such as "x + y" or "x <= y".
4065///
4066/// This expression node kind describes a builtin binary operation,
4067/// such as "x + y" for integer values "x" and "y". The operands will
4068/// already have been converted to appropriate types (e.g., by
4069/// performing promotions or conversions).
4070///
4071/// In C++, where operators may be overloaded, a different kind of
4072/// expression node (CXXOperatorCallExpr) is used to express the
4073/// invocation of an overloaded operator with operator syntax. Within
4074/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
4075/// used to store an expression "x + y" depends on the subexpressions
4076/// for x and y. If neither x or y is type-dependent, and the "+"
4077/// operator resolves to a built-in operation, BinaryOperator will be
4078/// used to express the computation (x and y may still be
4079/// value-dependent). If either x or y is type-dependent, or if the
4080/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
4081/// be used to express the computation.
4082class BinaryOperator : public Expr {
4083 enum { LHS, RHS, END_EXPR };
4084 Stmt *SubExprs[END_EXPR];
4085
4086public:
4088
4089protected:
4090 size_t offsetOfTrailingStorage() const;
4091
4092 /// Return a pointer to the trailing FPOptions
4094 assert(BinaryOperatorBits.HasFPFeatures);
4095 return reinterpret_cast<FPOptionsOverride *>(
4096 reinterpret_cast<char *>(this) + offsetOfTrailingStorage());
4097 }
4099 assert(BinaryOperatorBits.HasFPFeatures);
4100 return reinterpret_cast<const FPOptionsOverride *>(
4101 reinterpret_cast<const char *>(this) + offsetOfTrailingStorage());
4102 }
4103
4104 /// Build a binary operator, assuming that appropriate storage has been
4105 /// allocated for the trailing objects when needed.
4106 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4108 SourceLocation opLoc, FPOptionsOverride FPFeatures);
4109
4110 /// Construct an empty binary operator.
4111 explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
4112 BinaryOperatorBits.Opc = BO_Comma;
4113 BinaryOperatorBits.ExcludedOverflowPattern = false;
4114 }
4115
4116public:
4117 static BinaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
4118
4119 static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs,
4120 Opcode opc, QualType ResTy, ExprValueKind VK,
4122 FPOptionsOverride FPFeatures);
4126
4128 return static_cast<Opcode>(BinaryOperatorBits.Opc);
4129 }
4130 void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
4131
4132 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4133 void setLHS(Expr *E) { SubExprs[LHS] = E; }
4134 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4135 void setRHS(Expr *E) { SubExprs[RHS] = E; }
4136
4137 SourceLocation getBeginLoc() const LLVM_READONLY {
4138 return getLHS()->getBeginLoc();
4139 }
4140 SourceLocation getEndLoc() const LLVM_READONLY {
4141 return getRHS()->getEndLoc();
4142 }
4143
4144 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
4145 /// corresponds to, e.g. "<<=".
4146 static StringRef getOpcodeStr(Opcode Op);
4147
4148 StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
4149
4150 /// Retrieve the binary opcode that corresponds to the given
4151 /// overloaded operator.
4153
4154 /// Retrieve the overloaded operator kind that corresponds to
4155 /// the given binary opcode.
4157
4158 /// predicates to categorize the respective opcodes.
4159 static bool isPtrMemOp(Opcode Opc) {
4160 return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
4161 }
4162 bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
4163
4164 static bool isMultiplicativeOp(Opcode Opc) {
4165 return Opc >= BO_Mul && Opc <= BO_Rem;
4166 }
4168 static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
4169 bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
4170 static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
4171 bool isShiftOp() const { return isShiftOp(getOpcode()); }
4172
4173 static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
4174 bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
4175
4176 static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
4177 bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
4178
4179 static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
4180 bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
4181
4182 static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
4183 bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
4184
4185 static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; }
4186 bool isCommaOp() const { return isCommaOp(getOpcode()); }
4187
4189 switch (Opc) {
4190 default:
4191 llvm_unreachable("Not a comparison operator.");
4192 case BO_LT: return BO_GE;
4193 case BO_GT: return BO_LE;
4194 case BO_LE: return BO_GT;
4195 case BO_GE: return BO_LT;
4196 case BO_EQ: return BO_NE;
4197 case BO_NE: return BO_EQ;
4198 }
4199 }
4200
4202 switch (Opc) {
4203 default:
4204 llvm_unreachable("Not a comparison operator.");
4205 case BO_LT: return BO_GT;
4206 case BO_GT: return BO_LT;
4207 case BO_LE: return BO_GE;
4208 case BO_GE: return BO_LE;
4209 case BO_EQ:
4210 case BO_NE:
4211 return Opc;
4212 }
4213 }
4214
4215 static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
4216 bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
4217
4218 static bool isAssignmentOp(Opcode Opc) {
4219 return Opc >= BO_Assign && Opc <= BO_OrAssign;
4220 }
4221 bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
4222
4224 return Opc > BO_Assign && Opc <= BO_OrAssign;
4225 }
4228 }
4230 assert(isCompoundAssignmentOp(Opc));
4231 if (Opc >= BO_AndAssign)
4232 return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
4233 else
4234 return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
4235 }
4236
4237 static bool isShiftAssignOp(Opcode Opc) {
4238 return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
4239 }
4240 bool isShiftAssignOp() const {
4241 return isShiftAssignOp(getOpcode());
4242 }
4243
4244 /// Return true if a binary operator using the specified opcode and operands
4245 /// would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
4246 /// integer to a pointer.
4247 static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
4248 const Expr *LHS,
4249 const Expr *RHS);
4250
4251 static bool classof(const Stmt *S) {
4252 return S->getStmtClass() >= firstBinaryOperatorConstant &&
4253 S->getStmtClass() <= lastBinaryOperatorConstant;
4254 }
4255
4256 // Iterators
4258 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4259 }
4261 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4262 }
4263
4264 /// Set and fetch the bit that shows whether FPFeatures needs to be
4265 /// allocated in Trailing Storage
4266 void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; }
4267 bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }
4268
4269 /// Set and get the bit that informs arithmetic overflow sanitizers whether
4270 /// or not they should exclude certain BinaryOperators from instrumentation
4272 BinaryOperatorBits.ExcludedOverflowPattern = B;
4273 }
4275 return BinaryOperatorBits.ExcludedOverflowPattern;
4276 }
4277
4278 /// Get FPFeatures from trailing storage
4280 assert(hasStoredFPFeatures());
4281 return *getTrailingFPFeatures();
4282 }
4283 /// Set FPFeatures in trailing storage, used only by Serialization
4285 assert(BinaryOperatorBits.HasFPFeatures);
4286 *getTrailingFPFeatures() = F;
4287 }
4288 /// Get the store FPOptionsOverride or default if not stored.
4292
4293 /// Get the FP features status of this operator. Only meaningful for
4294 /// operations on floating point types.
4296 if (BinaryOperatorBits.HasFPFeatures)
4299 }
4300
4301 // This is used in ASTImporter
4303 if (BinaryOperatorBits.HasFPFeatures)
4304 return getStoredFPFeatures();
4305 return FPOptionsOverride();
4306 }
4307
4308 /// Get the FP contractibility status of this operator. Only meaningful for
4309 /// operations on floating point types.
4313
4314 /// Get the FENV_ACCESS status of this operator. Only meaningful for
4315 /// operations on floating point types.
4316 bool isFEnvAccessOn(const LangOptions &LO) const {
4317 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
4318 }
4319
4320protected:
4321 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4323 SourceLocation opLoc, FPOptionsOverride FPFeatures,
4324 bool dead2);
4325
4326 /// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
4328 BinaryOperatorBits.Opc = BO_MulAssign;
4329 }
4330
4331 /// Return the size in bytes needed for the trailing objects.
4332 /// Used to allocate the right amount of storage.
4333 static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
4334 return HasFPFeatures * sizeof(FPOptionsOverride);
4335 }
4336};
4337
4338/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
4339/// track of the type the operation is performed in. Due to the semantics of
4340/// these operators, the operands are promoted, the arithmetic performed, an
4341/// implicit conversion back to the result type done, then the assignment takes
4342/// place. This captures the intermediate type which the computation is done
4343/// in.
4344class CompoundAssignOperator : public BinaryOperator {
4345 QualType ComputationLHSType;
4346 QualType ComputationResultType;
4347
4348 /// Construct an empty CompoundAssignOperator.
4349 explicit CompoundAssignOperator(const ASTContext &C, EmptyShell Empty,
4350 bool hasFPFeatures)
4351 : BinaryOperator(CompoundAssignOperatorClass, Empty) {}
4352
4353protected:
4356 SourceLocation OpLoc, FPOptionsOverride FPFeatures,
4357 QualType CompLHSType, QualType CompResultType)
4358 : BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
4359 true),
4360 ComputationLHSType(CompLHSType), ComputationResultType(CompResultType) {
4361 assert(isCompoundAssignmentOp() &&
4362 "Only should be used for compound assignments");
4363 }
4364
4365public:
4367 bool hasFPFeatures);
4368
4369 static CompoundAssignOperator *
4370 Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
4372 FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(),
4373 QualType CompResultType = QualType());
4374
4375 // The two computation types are the type the LHS is converted
4376 // to for the computation and the type of the result; the two are
4377 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
4378 QualType getComputationLHSType() const { return ComputationLHSType; }
4379 void setComputationLHSType(QualType T) { ComputationLHSType = T; }
4380
4381 QualType getComputationResultType() const { return ComputationResultType; }
4382 void setComputationResultType(QualType T) { ComputationResultType = T; }
4383
4384 static bool classof(const Stmt *S) {
4385 return S->getStmtClass() == CompoundAssignOperatorClass;
4386 }
4387};
4388
4390 assert(BinaryOperatorBits.HasFPFeatures);
4392 : sizeof(BinaryOperator);
4393}
4394
4395/// AbstractConditionalOperator - An abstract base class for
4396/// ConditionalOperator and BinaryConditionalOperator.
4398 SourceLocation QuestionLoc, ColonLoc;
4399 friend class ASTStmtReader;
4400
4401protected:
4404 SourceLocation cloc)
4405 : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {}
4406
4409
4410public:
4411 /// getCond - Return the expression representing the condition for
4412 /// the ?: operator.
4413 Expr *getCond() const;
4414
4415 /// getTrueExpr - Return the subexpression representing the value of
4416 /// the expression if the condition evaluates to true.
4417 Expr *getTrueExpr() const;
4418
4419 /// getFalseExpr - Return the subexpression representing the value of
4420 /// the expression if the condition evaluates to false. This is
4421 /// the same as getRHS.
4422 Expr *getFalseExpr() const;
4423
4424 SourceLocation getQuestionLoc() const { return QuestionLoc; }
4425 SourceLocation getColonLoc() const { return ColonLoc; }
4426
4427 static bool classof(const Stmt *T) {
4428 return T->getStmtClass() == ConditionalOperatorClass ||
4429 T->getStmtClass() == BinaryConditionalOperatorClass;
4430 }
4431};
4432
4433/// ConditionalOperator - The ?: ternary operator. The GNU "missing
4434/// middle" extension is a BinaryConditionalOperator.
4436 enum { COND, LHS, RHS, END_EXPR };
4437 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4438
4439 friend class ASTStmtReader;
4440public:
4442 SourceLocation CLoc, Expr *rhs, QualType t,
4444 : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, QLoc,
4445 CLoc) {
4446 SubExprs[COND] = cond;
4447 SubExprs[LHS] = lhs;
4448 SubExprs[RHS] = rhs;
4450 }
4451
4452 /// Build an empty conditional operator.
4454 : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
4455
4456 /// getCond - Return the expression representing the condition for
4457 /// the ?: operator.
4458 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4459
4460 /// getTrueExpr - Return the subexpression representing the value of
4461 /// the expression if the condition evaluates to true.
4462 Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
4463
4464 /// getFalseExpr - Return the subexpression representing the value of
4465 /// the expression if the condition evaluates to false. This is
4466 /// the same as getRHS.
4467 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
4468
4469 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4470 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4471
4472 SourceLocation getBeginLoc() const LLVM_READONLY {
4473 return getCond()->getBeginLoc();
4474 }
4475 SourceLocation getEndLoc() const LLVM_READONLY {
4476 return getRHS()->getEndLoc();
4477 }
4478
4479 static bool classof(const Stmt *T) {
4480 return T->getStmtClass() == ConditionalOperatorClass;
4481 }
4482
4483 // Iterators
4485 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4486 }
4488 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4489 }
4490};
4491
4492/// BinaryConditionalOperator - The GNU extension to the conditional
4493/// operator which allows the middle operand to be omitted.
4494///
4495/// This is a different expression kind on the assumption that almost
4496/// every client ends up needing to know that these are different.
4498 enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
4499
4500 /// - the common condition/left-hand-side expression, which will be
4501 /// evaluated as the opaque value
4502 /// - the condition, expressed in terms of the opaque value
4503 /// - the left-hand-side, expressed in terms of the opaque value
4504 /// - the right-hand-side
4505 Stmt *SubExprs[NUM_SUBEXPRS];
4506 OpaqueValueExpr *OpaqueValue;
4507
4508 friend class ASTStmtReader;
4509public:
4511 Expr *cond, Expr *lhs, Expr *rhs,
4512 SourceLocation qloc, SourceLocation cloc,
4514 : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
4515 qloc, cloc),
4516 OpaqueValue(opaqueValue) {
4517 SubExprs[COMMON] = common;
4518 SubExprs[COND] = cond;
4519 SubExprs[LHS] = lhs;
4520 SubExprs[RHS] = rhs;
4521 assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
4523 }
4524
4525 /// Build an empty conditional operator.
4527 : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
4528
4529 /// getCommon - Return the common expression, written to the
4530 /// left of the condition. The opaque value will be bound to the
4531 /// result of this expression.
4532 Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
4533
4534 /// getOpaqueValue - Return the opaque value placeholder.
4535 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4536
4537 /// getCond - Return the condition expression; this is defined
4538 /// in terms of the opaque value.
4539 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4540
4541 /// getTrueExpr - Return the subexpression which will be
4542 /// evaluated if the condition evaluates to true; this is defined
4543 /// in terms of the opaque value.
4545 return cast<Expr>(SubExprs[LHS]);
4546 }
4547
4548 /// getFalseExpr - Return the subexpression which will be
4549 /// evaluated if the condition evaluates to false; this is
4550 /// defined in terms of the opaque value.
4552 return cast<Expr>(SubExprs[RHS]);
4553 }
4554
4555 SourceLocation getBeginLoc() const LLVM_READONLY {
4556 return getCommon()->getBeginLoc();
4557 }
4558 SourceLocation getEndLoc() const LLVM_READONLY {
4559 return getFalseExpr()->getEndLoc();
4560 }
4561
4562 static bool classof(const Stmt *T) {
4563 return T->getStmtClass() == BinaryConditionalOperatorClass;
4564 }
4565
4566 // Iterators
4568 return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4569 }
4571 return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4572 }
4573};
4574
4576 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4577 return co->getCond();
4578 return cast<BinaryConditionalOperator>(this)->getCond();
4579}
4580
4582 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4583 return co->getTrueExpr();
4584 return cast<BinaryConditionalOperator>(this)->getTrueExpr();
4585}
4586
4588 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4589 return co->getFalseExpr();
4590 return cast<BinaryConditionalOperator>(this)->getFalseExpr();
4591}
4592
4593/// AddrLabelExpr - The GNU address of label extension, representing &&label.
4594class AddrLabelExpr : public Expr {
4595 SourceLocation AmpAmpLoc, LabelLoc;
4596 LabelDecl *Label;
4597public:
4599 QualType t)
4600 : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc),
4601 LabelLoc(LLoc), Label(L) {
4602 setDependence(ExprDependence::None);
4603 }
4604
4605 /// Build an empty address of a label expression.
4607 : Expr(AddrLabelExprClass, Empty) { }
4608
4609 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
4610 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
4611 SourceLocation getLabelLoc() const { return LabelLoc; }
4612 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
4613
4614 SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
4615 SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
4616
4617 LabelDecl *getLabel() const { return Label; }
4618 void setLabel(LabelDecl *L) { Label = L; }
4619
4620 static bool classof(const Stmt *T) {
4621 return T->getStmtClass() == AddrLabelExprClass;
4622 }
4623
4624 // Iterators
4631};
4632
4633/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
4634/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
4635/// takes the value of the last subexpression.
4636///
4637/// A StmtExpr is always an r-value; values "returned" out of a
4638/// StmtExpr will be copied.
4639class StmtExpr : public Expr {
4640 Stmt *SubStmt;
4641 SourceLocation LParenLoc, RParenLoc;
4642public:
4644 SourceLocation RParenLoc, unsigned TemplateDepth)
4645 : Expr(StmtExprClass, T, VK_PRValue, OK_Ordinary), SubStmt(SubStmt),
4646 LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4647 setDependence(computeDependence(this, TemplateDepth));
4648 // FIXME: A templated statement expression should have an associated
4649 // DeclContext so that nested declarations always have a dependent context.
4650 StmtExprBits.TemplateDepth = TemplateDepth;
4651 }
4652
4653 /// Build an empty statement expression.
4654 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
4655
4657 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
4658 void setSubStmt(CompoundStmt *S) { SubStmt = S; }
4659
4660 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4661 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4662
4663 SourceLocation getLParenLoc() const { return LParenLoc; }
4664 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
4665 SourceLocation getRParenLoc() const { return RParenLoc; }
4666 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4667
4668 unsigned getTemplateDepth() const { return StmtExprBits.TemplateDepth; }
4669
4670 static bool classof(const Stmt *T) {
4671 return T->getStmtClass() == StmtExprClass;
4672 }
4673
4674 // Iterators
4675 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
4677 return const_child_range(&SubStmt, &SubStmt + 1);
4678 }
4679};
4680
4681/// ShuffleVectorExpr - clang-specific builtin-in function
4682/// __builtin_shufflevector.
4683/// This AST node represents a operator that does a constant
4684/// shuffle, similar to LLVM's shufflevector instruction. It takes
4685/// two vectors and a variable number of constant indices,
4686/// and returns the appropriately shuffled vector.
4687class ShuffleVectorExpr : public Expr {
4688 SourceLocation BuiltinLoc, RParenLoc;
4689
4690 // SubExprs - the list of values passed to the __builtin_shufflevector
4691 // function. The first two are vectors, and the rest are constant
4692 // indices. The number of values in this list is always
4693 // 2+the number of indices in the vector type.
4694 Stmt **SubExprs;
4695
4696public:
4699
4700 /// Build an empty vector-shuffle expression.
4702 : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
4703
4704 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4705 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4706
4707 SourceLocation getRParenLoc() const { return RParenLoc; }
4708 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4709
4710 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4711 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4712
4713 static bool classof(const Stmt *T) {
4714 return T->getStmtClass() == ShuffleVectorExprClass;
4715 }
4716
4717 /// getNumSubExprs - Return the size of the SubExprs array. This includes the
4718 /// constant expression, the actual arguments passed in, and the function
4719 /// pointers.
4720 unsigned getNumSubExprs() const { return ShuffleVectorExprBits.NumExprs; }
4721
4722 /// Retrieve the array of expressions.
4723 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4724
4725 /// getExpr - Return the Expr at the specified index.
4726 Expr *getExpr(unsigned Index) {
4727 assert((Index < ShuffleVectorExprBits.NumExprs) &&
4728 "Arg access out of range!");
4729 return cast<Expr>(SubExprs[Index]);
4730 }
4731 const Expr *getExpr(unsigned Index) const {
4732 assert((Index < ShuffleVectorExprBits.NumExprs) &&
4733 "Arg access out of range!");
4734 return cast<Expr>(SubExprs[Index]);
4735 }
4736
4737 void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
4738
4739 llvm::APSInt getShuffleMaskIdx(unsigned N) const {
4740 assert((N < ShuffleVectorExprBits.NumExprs - 2) &&
4741 "Shuffle idx out of range!");
4742 assert(isa<ConstantExpr>(getExpr(N + 2)) &&
4743 "Index expression must be a ConstantExpr");
4744 return cast<ConstantExpr>(getExpr(N + 2))->getAPValueResult().getInt();
4745 }
4746
4747 // Iterators
4749 return child_range(&SubExprs[0],
4750 &SubExprs[0] + ShuffleVectorExprBits.NumExprs);
4751 }
4753 return const_child_range(&SubExprs[0],
4754 &SubExprs[0] + ShuffleVectorExprBits.NumExprs);
4755 }
4756};
4757
4758/// ConvertVectorExpr - Clang builtin function __builtin_convertvector
4759/// This AST node provides support for converting a vector type to another
4760/// vector type of the same arity.
4761class ConvertVectorExpr final
4762 : public Expr,
4763 private llvm::TrailingObjects<ConvertVectorExpr, FPOptionsOverride> {
4764private:
4765 Stmt *SrcExpr;
4766 TypeSourceInfo *TInfo;
4767 SourceLocation BuiltinLoc, RParenLoc;
4768
4769 friend TrailingObjects;
4770 friend class ASTReader;
4771 friend class ASTStmtReader;
4772 explicit ConvertVectorExpr(bool HasFPFeatures, EmptyShell Empty)
4773 : Expr(ConvertVectorExprClass, Empty) {
4774 ConvertVectorExprBits.HasFPFeatures = HasFPFeatures;
4775 }
4776
4777 ConvertVectorExpr(Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType,
4779 SourceLocation BuiltinLoc, SourceLocation RParenLoc,
4780 FPOptionsOverride FPFeatures)
4781 : Expr(ConvertVectorExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
4782 TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
4783 ConvertVectorExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4784 if (hasStoredFPFeatures())
4785 setStoredFPFeatures(FPFeatures);
4787 }
4788
4789 size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const {
4790 return ConvertVectorExprBits.HasFPFeatures ? 1 : 0;
4791 }
4792
4793 FPOptionsOverride &getTrailingFPFeatures() {
4794 assert(ConvertVectorExprBits.HasFPFeatures);
4795 return *getTrailingObjects();
4796 }
4797
4798 const FPOptionsOverride &getTrailingFPFeatures() const {
4799 assert(ConvertVectorExprBits.HasFPFeatures);
4800 return *getTrailingObjects();
4801 }
4802
4803public:
4804 static ConvertVectorExpr *CreateEmpty(const ASTContext &C,
4805 bool hasFPFeatures);
4806
4807 static ConvertVectorExpr *Create(const ASTContext &C, Expr *SrcExpr,
4808 TypeSourceInfo *TI, QualType DstType,
4810 SourceLocation BuiltinLoc,
4811 SourceLocation RParenLoc,
4812 FPOptionsOverride FPFeatures);
4813
4814 /// Get the FP contractibility status of this operator. Only meaningful for
4815 /// operations on floating point types.
4819
4820 /// Is FPFeatures in Trailing Storage?
4821 bool hasStoredFPFeatures() const {
4822 return ConvertVectorExprBits.HasFPFeatures;
4823 }
4824
4825 /// Get FPFeatures from trailing storage.
4827 return getTrailingFPFeatures();
4828 }
4829
4830 /// Get the store FPOptionsOverride or default if not stored.
4834
4835 /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
4836 void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
4837
4838 /// Get the FP features status of this operator. Only meaningful for
4839 /// operations on floating point types.
4841 if (ConvertVectorExprBits.HasFPFeatures)
4844 }
4845
4847 if (ConvertVectorExprBits.HasFPFeatures)
4848 return getStoredFPFeatures();
4849 return FPOptionsOverride();
4850 }
4851
4852 /// getSrcExpr - Return the Expr to be converted.
4853 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4854
4855 /// getTypeSourceInfo - Return the destination type.
4857 return TInfo;
4858 }
4860 TInfo = ti;
4861 }
4862
4863 /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
4864 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4865
4866 /// getRParenLoc - Return the location of final right parenthesis.
4867 SourceLocation getRParenLoc() const { return RParenLoc; }
4868
4869 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4870 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4871
4872 static bool classof(const Stmt *T) {
4873 return T->getStmtClass() == ConvertVectorExprClass;
4874 }
4875
4876 // Iterators
4877 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4879 return const_child_range(&SrcExpr, &SrcExpr + 1);
4880 }
4881};
4882
4883/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
4884/// This AST node is similar to the conditional operator (?:) in C, with
4885/// the following exceptions:
4886/// - the test expression must be a integer constant expression.
4887/// - the expression returned acts like the chosen subexpression in every
4888/// visible way: the type is the same as that of the chosen subexpression,
4889/// and all predicates (whether it's an l-value, whether it's an integer
4890/// constant expression, etc.) return the same result as for the chosen
4891/// sub-expression.
4892class ChooseExpr : public Expr {
4893 enum { COND, LHS, RHS, END_EXPR };
4894 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4895 SourceLocation BuiltinLoc, RParenLoc;
4896
4897public:
4898 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
4900 bool condIsTrue)
4901 : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP) {
4902 ChooseExprBits.CondIsTrue = condIsTrue;
4903 SubExprs[COND] = cond;
4904 SubExprs[LHS] = lhs;
4905 SubExprs[RHS] = rhs;
4906
4908 }
4909
4910 /// Build an empty __builtin_choose_expr.
4911 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4912
4913 /// isConditionTrue - Return whether the condition is true (i.e. not
4914 /// equal to zero).
4915 bool isConditionTrue() const {
4916 assert(!isConditionDependent() &&
4917 "Dependent condition isn't true or false");
4918 return ChooseExprBits.CondIsTrue;
4919 }
4920 void setIsConditionTrue(bool isTrue) { ChooseExprBits.CondIsTrue = isTrue; }
4921
4923 return getCond()->isTypeDependent() || getCond()->isValueDependent();
4924 }
4925
4926 /// getChosenSubExpr - Return the subexpression chosen according to the
4927 /// condition.
4929 return isConditionTrue() ? getLHS() : getRHS();
4930 }
4931
4932 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4933 void setCond(Expr *E) { SubExprs[COND] = E; }
4934 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4935 void setLHS(Expr *E) { SubExprs[LHS] = E; }
4936 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4937 void setRHS(Expr *E) { SubExprs[RHS] = E; }
4938
4939 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4940 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4941
4942 SourceLocation getRParenLoc() const { return RParenLoc; }
4943 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4944
4945 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4946 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4947
4948 static bool classof(const Stmt *T) {
4949 return T->getStmtClass() == ChooseExprClass;
4950 }
4951
4952 // Iterators
4954 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4955 }
4957 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4958 }
4959};
4960
4961/// GNUNullExpr - Implements the GNU __null extension, which is a name
4962/// for a null pointer constant that has integral type (e.g., int or
4963/// long) and is the same size and alignment as a pointer. The __null
4964/// extension is typically only used by system headers, which define
4965/// NULL as __null in C++ rather than using 0 (which is an integer
4966/// that may not match the size of a pointer).
4967class GNUNullExpr : public Expr {
4968 /// TokenLoc - The location of the __null keyword.
4969 SourceLocation TokenLoc;
4970
4971public:
4973 : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary), TokenLoc(Loc) {
4974 setDependence(ExprDependence::None);
4975 }
4976
4977 /// Build an empty GNU __null expression.
4978 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4979
4980 /// getTokenLocation - The location of the __null token.
4981 SourceLocation getTokenLocation() const { return TokenLoc; }
4982 void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4983
4984 SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4985 SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4986
4987 static bool classof(const Stmt *T) {
4988 return T->getStmtClass() == GNUNullExprClass;
4989 }
4990
4991 // Iterators
4998};
4999
5000/// Represents a call to the builtin function \c __builtin_va_arg.
5001class VAArgExpr : public Expr {
5002public:
5004
5005private:
5006 Stmt *Val;
5007 llvm::PointerIntPair<TypeSourceInfo *, 2, VarArgKind> TInfo;
5008 SourceLocation BuiltinLoc, RParenLoc;
5009public:
5011 SourceLocation RPLoc, QualType t, VarArgKind VaKind)
5012 : Expr(VAArgExprClass, t, VK_PRValue, OK_Ordinary), Val(e),
5013 TInfo(TInfo, VaKind), BuiltinLoc(BLoc), RParenLoc(RPLoc) {
5015 }
5016
5017 /// Create an empty __builtin_va_arg expression.
5019 : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, VA_Std) {}
5020
5021 const Expr *getSubExpr() const { return cast<Expr>(Val); }
5022 Expr *getSubExpr() { return cast<Expr>(Val); }
5023 void setSubExpr(Expr *E) { Val = E; }
5024
5025 VarArgKind getVarargABI() const { return TInfo.getInt(); }
5026 void setVarargABI(VarArgKind Kind) { TInfo.setInt(Kind); }
5027
5028 /// Returns whether this is really a Win64 ABI va_arg expression.
5029 bool isMicrosoftABI() const { return TInfo.getInt() == VA_MS; }
5030
5031 /// Returns whether this is really a z/OS ABI va_arg expression.
5032 bool isZOSABI() const { return TInfo.getInt() == VA_ZOS; }
5033
5034 TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
5035 void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
5036
5037 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5038 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
5039
5040 SourceLocation getRParenLoc() const { return RParenLoc; }
5041 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
5042
5043 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5044 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5045
5046 static bool classof(const Stmt *T) {
5047 return T->getStmtClass() == VAArgExprClass;
5048 }
5049
5050 // Iterators
5051 child_range children() { return child_range(&Val, &Val+1); }
5053 return const_child_range(&Val, &Val + 1);
5054 }
5055};
5056
5066
5067/// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(),
5068/// __builtin_FUNCTION(), __builtin_FUNCSIG(), __builtin_FILE(),
5069/// __builtin_FILE_NAME() or __builtin_source_location().
5070class SourceLocExpr final : public Expr {
5071 SourceLocation BuiltinLoc, RParenLoc;
5072 DeclContext *ParentContext;
5073
5074public:
5076 QualType ResultTy, SourceLocation BLoc,
5077 SourceLocation RParenLoc, DeclContext *Context);
5078
5079 /// Build an empty call expression.
5080 explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {}
5081
5082 /// Return the result of evaluating this SourceLocExpr in the specified
5083 /// (and possibly null) default argument or initialization context.
5085 const Expr *DefaultExpr) const;
5086
5087 /// Return a string representing the name of the specific builtin function.
5088 StringRef getBuiltinStr() const;
5089
5091 return static_cast<SourceLocIdentKind>(SourceLocExprBits.Kind);
5092 }
5093
5094 bool isIntType() const {
5095 switch (getIdentKind()) {
5101 return false;
5104 return true;
5105 }
5106 llvm_unreachable("unknown source location expression kind");
5107 }
5108
5109 /// If the SourceLocExpr has been resolved return the subexpression
5110 /// representing the resolved value. Otherwise return null.
5111 const DeclContext *getParentContext() const { return ParentContext; }
5112 DeclContext *getParentContext() { return ParentContext; }
5113
5114 SourceLocation getLocation() const { return BuiltinLoc; }
5115 SourceLocation getBeginLoc() const { return BuiltinLoc; }
5116 SourceLocation getEndLoc() const { return RParenLoc; }
5117
5121
5125
5126 static bool classof(const Stmt *T) {
5127 return T->getStmtClass() == SourceLocExprClass;
5128 }
5129
5131 switch (Kind) {
5135 return true;
5136 default:
5137 return false;
5138 }
5139 }
5140
5141private:
5142 friend class ASTStmtReader;
5143};
5144
5145/// Stores data related to a single #embed directive.
5148 // FileName string already includes braces, i.e. it is <files/my_file> for a
5149 // directive #embed <files/my_file>.
5150 StringRef FileName;
5151 size_t getDataElementCount() const { return BinaryData->getByteLength(); }
5152};
5153
5154/// Represents a reference to #emded data. By default, this references the whole
5155/// range. Otherwise it represents a subrange of data imported by #embed
5156/// directive. Needed to handle nested initializer lists with #embed directives.
5157/// Example:
5158/// struct S {
5159/// int x, y;
5160/// };
5161///
5162/// struct T {
5163/// int x[2];
5164/// struct S s
5165/// };
5166///
5167/// struct T t[] = {
5168/// #embed "data" // data contains 10 elements;
5169/// };
5170///
5171/// The resulting semantic form of initializer list will contain (EE stands
5172/// for EmbedExpr):
5173/// { {EE(first two data elements), {EE(3rd element), EE(4th element) }},
5174/// { {EE(5th and 6th element), {EE(7th element), EE(8th element) }},
5175/// { {EE(9th and 10th element), { zeroinitializer }}}
5176///
5177/// EmbedExpr inside of a semantic initializer list and referencing more than
5178/// one element can only appear for arrays of scalars.
5179class EmbedExpr final : public Expr {
5180 SourceLocation EmbedKeywordLoc;
5181 IntegerLiteral *FakeChildNode = nullptr;
5182 const ASTContext *Ctx = nullptr;
5183 EmbedDataStorage *Data;
5184 unsigned Begin = 0;
5185 unsigned NumOfElements;
5186
5187public:
5188 EmbedExpr(const ASTContext &Ctx, SourceLocation Loc, EmbedDataStorage *Data,
5189 unsigned Begin, unsigned NumOfElements);
5190 explicit EmbedExpr(EmptyShell Empty) : Expr(EmbedExprClass, Empty) {}
5191
5192 SourceLocation getLocation() const { return EmbedKeywordLoc; }
5193 SourceLocation getBeginLoc() const { return EmbedKeywordLoc; }
5194 SourceLocation getEndLoc() const { return EmbedKeywordLoc; }
5195
5196 StringLiteral *getDataStringLiteral() const { return Data->BinaryData; }
5197 StringRef getFileName() const { return Data->FileName; }
5198 EmbedDataStorage *getData() const { return Data; }
5199
5200 unsigned getStartingElementPos() const { return Begin; }
5201 size_t getDataElementCount() const { return NumOfElements; }
5202
5203 // Allows accessing every byte of EmbedExpr data and iterating over it.
5204 // An Iterator knows the EmbedExpr that it refers to, and an offset value
5205 // within the data.
5206 // Dereferencing an Iterator results in construction of IntegerLiteral AST
5207 // node filled with byte of data of the corresponding EmbedExpr within offset
5208 // that the Iterator currently has.
5209 template <bool Const>
5210 class ChildElementIter
5211 : public llvm::iterator_facade_base<
5212 ChildElementIter<Const>, std::random_access_iterator_tag,
5213 std::conditional_t<Const, const IntegerLiteral *,
5214 IntegerLiteral *>> {
5215 friend class EmbedExpr;
5216
5217 EmbedExpr *EExpr = nullptr;
5218 unsigned long long CurOffset = ULLONG_MAX;
5219 using BaseTy = typename ChildElementIter::iterator_facade_base;
5220
5221 ChildElementIter(EmbedExpr *E) : EExpr(E) {
5222 if (E)
5223 CurOffset = E->getStartingElementPos();
5224 }
5225
5226 public:
5227 ChildElementIter() : CurOffset(ULLONG_MAX) {}
5228 typename BaseTy::reference operator*() const {
5229 assert(EExpr && CurOffset != ULLONG_MAX &&
5230 "trying to dereference an invalid iterator");
5231 IntegerLiteral *N = EExpr->FakeChildNode;
5232 N->setValue(*EExpr->Ctx,
5233 llvm::APInt(N->getBitWidth(),
5234 EExpr->Data->BinaryData->getCodeUnit(CurOffset),
5235 /*Signed=*/true));
5236 // We want to return a reference to the fake child node in the
5237 // EmbedExpr, not the local variable N.
5238 return const_cast<typename BaseTy::reference>(EExpr->FakeChildNode);
5239 }
5240 typename BaseTy::pointer operator->() const { return **this; }
5241 using BaseTy::operator++;
5242 ChildElementIter &operator++() {
5243 assert(EExpr && "trying to increment an invalid iterator");
5244 assert(CurOffset != ULLONG_MAX &&
5245 "Already at the end of what we can iterate over");
5246 if (++CurOffset >=
5247 EExpr->getDataElementCount() + EExpr->getStartingElementPos()) {
5248 CurOffset = ULLONG_MAX;
5249 EExpr = nullptr;
5250 }
5251 return *this;
5252 }
5253 bool operator==(ChildElementIter Other) const {
5254 return (EExpr == Other.EExpr && CurOffset == Other.CurOffset);
5255 }
5256 }; // class ChildElementIter
5257
5258public:
5259 using fake_child_range = llvm::iterator_range<ChildElementIter<false>>;
5260 using const_fake_child_range = llvm::iterator_range<ChildElementIter<true>>;
5261
5266
5272
5276
5280
5281 static bool classof(const Stmt *T) {
5282 return T->getStmtClass() == EmbedExprClass;
5283 }
5284
5286
5288 return ChildElementIter<true>(const_cast<EmbedExpr *>(this));
5289 }
5290
5291 template <typename Call, typename... Targs>
5292 bool doForEachDataElement(Call &&C, unsigned &StartingIndexInArray,
5293 Targs &&...Fargs) const {
5294 for (auto It : underlying_data_elements()) {
5295 if (!std::invoke(std::forward<Call>(C), const_cast<IntegerLiteral *>(It),
5296 StartingIndexInArray, std::forward<Targs>(Fargs)...))
5297 return false;
5298 StartingIndexInArray++;
5299 }
5300 return true;
5301 }
5302
5303private:
5304 friend class ASTStmtReader;
5305};
5306
5307/// Describes an C or C++ initializer list.
5308///
5309/// InitListExpr describes an initializer list, which can be used to
5310/// initialize objects of different types, including
5311/// struct/class/union types, arrays, and vectors. For example:
5312///
5313/// @code
5314/// struct foo x = { 1, { 2, 3 } };
5315/// @endcode
5316///
5317/// Prior to semantic analysis, an initializer list will represent the
5318/// initializer list as written by the user, but will have the
5319/// placeholder type "void". This initializer list is called the
5320/// syntactic form of the initializer, and may contain C99 designated
5321/// initializers (represented as DesignatedInitExprs), initializations
5322/// of subobject members without explicit braces, and so on. Clients
5323/// interested in the original syntax of the initializer list should
5324/// use the syntactic form of the initializer list.
5325///
5326/// After semantic analysis, the initializer list will represent the
5327/// semantic form of the initializer, where the initializations of all
5328/// subobjects are made explicit with nested InitListExpr nodes and
5329/// C99 designators have been eliminated by placing the designated
5330/// initializations into the subobject they initialize. Additionally,
5331/// any "holes" in the initialization, where no initializer has been
5332/// specified for a particular subobject, will be replaced with
5333/// implicitly-generated ImplicitValueInitExpr expressions that
5334/// value-initialize the subobjects. Note, however, that the
5335/// initializer lists may still have fewer initializers than there are
5336/// elements to initialize within the object.
5337///
5338/// After semantic analysis has completed, given an initializer list,
5339/// method isSemanticForm() returns true if and only if this is the
5340/// semantic form of the initializer list (note: the same AST node
5341/// may at the same time be the syntactic form).
5342/// Given the semantic form of the initializer list, one can retrieve
5343/// the syntactic form of that initializer list (when different)
5344/// using method getSyntacticForm(); the method returns null if applied
5345/// to a initializer list which is already in syntactic form.
5346/// Similarly, given the syntactic form (i.e., an initializer list such
5347/// that isSemanticForm() returns false), one can retrieve the semantic
5348/// form using method getSemanticForm().
5349/// Since many initializer lists have the same syntactic and semantic forms,
5350/// getSyntacticForm() may return NULL, indicating that the current
5351/// semantic initializer list also serves as its syntactic form.
5352class InitListExpr : public Expr {
5353 // FIXME: Eliminate this vector in favor of ASTContext allocation
5354 typedef ASTVector<Stmt *> InitExprsTy;
5355 InitExprsTy InitExprs;
5356 SourceLocation LBraceLoc, RBraceLoc;
5357
5358 /// The alternative form of the initializer list (if it exists).
5359 /// The int part of the pair stores whether this initializer list is
5360 /// in semantic form. If not null, the pointer points to:
5361 /// - the syntactic form, if this is in semantic form;
5362 /// - the semantic form, if this is in syntactic form.
5363 llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
5364
5365 /// Either:
5366 /// If this initializer list initializes an array with more elements than
5367 /// there are initializers in the list, specifies an expression to be used
5368 /// for value initialization of the rest of the elements.
5369 /// Or
5370 /// If this initializer list initializes a union, specifies which
5371 /// field within the union will be initialized.
5372 llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
5373
5374public:
5375 InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
5376 ArrayRef<Expr *> initExprs, SourceLocation rbraceloc,
5377 bool isExplicit);
5378
5379 /// Build an empty initializer list.
5381 : Expr(InitListExprClass, Empty), AltForm(nullptr, true) {
5382 InitListExprBits.IsExplicit = false;
5383 }
5384
5385 unsigned getNumInits() const { return InitExprs.size(); }
5386
5387 /// getNumInits but if the list has an EmbedExpr inside includes full length
5388 /// of embedded data.
5390 unsigned Sum = InitExprs.size();
5391 for (auto *IE : InitExprs)
5392 if (auto *EE = dyn_cast<EmbedExpr>(IE))
5393 Sum += EE->getDataElementCount() - 1;
5394 return Sum;
5395 }
5396
5397 /// Retrieve the set of initializers.
5398 Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
5399
5400 /// Retrieve the set of initializers.
5401 Expr * const *getInits() const {
5402 return reinterpret_cast<Expr * const *>(InitExprs.data());
5403 }
5404
5405 ArrayRef<Expr *> inits() const { return {getInits(), getNumInits()}; }
5406
5407 const Expr *getInit(unsigned Init) const {
5408 assert(Init < getNumInits() && "Initializer access out of range!");
5409 return cast_or_null<Expr>(InitExprs[Init]);
5410 }
5411
5412 Expr *getInit(unsigned Init) {
5413 assert(Init < getNumInits() && "Initializer access out of range!");
5414 return cast_or_null<Expr>(InitExprs[Init]);
5415 }
5416
5417 void setInit(unsigned Init, Expr *expr) {
5418 assert(Init < getNumInits() && "Initializer access out of range!");
5419 InitExprs[Init] = expr;
5420
5421 if (expr)
5422 setDependence(getDependence() | expr->getDependence());
5423 }
5424
5425 /// Mark the semantic form of the InitListExpr as error when the semantic
5426 /// analysis fails.
5427 void markError() {
5428 assert(isSemanticForm());
5429 setDependence(getDependence() | ExprDependence::ErrorDependent);
5430 }
5431
5432 /// Reserve space for some number of initializers.
5433 void reserveInits(const ASTContext &C, unsigned NumInits);
5434
5435 /// Specify the number of initializers
5436 ///
5437 /// If there are more than @p NumInits initializers, the remaining
5438 /// initializers will be destroyed. If there are fewer than @p
5439 /// NumInits initializers, NULL expressions will be added for the
5440 /// unknown initializers.
5441 void resizeInits(const ASTContext &Context, unsigned NumInits);
5442
5443 /// Updates the initializer at index @p Init with the new
5444 /// expression @p expr, and returns the old expression at that
5445 /// location.
5446 ///
5447 /// When @p Init is out of range for this initializer list, the
5448 /// initializer list will be extended with NULL expressions to
5449 /// accommodate the new entry.
5450 Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
5451
5452 /// If this initializer list initializes an array with more elements
5453 /// than there are initializers in the list, specifies an expression to be
5454 /// used for value initialization of the rest of the elements.
5456 return dyn_cast_if_present<Expr *>(ArrayFillerOrUnionFieldInit);
5457 }
5458 const Expr *getArrayFiller() const {
5459 return const_cast<InitListExpr *>(this)->getArrayFiller();
5460 }
5461 void setArrayFiller(Expr *filler);
5462
5463 /// Return true if this is an array initializer and its array "filler"
5464 /// has been set.
5465 bool hasArrayFiller() const { return getArrayFiller(); }
5466
5467 /// Determine whether this initializer list contains a designated initializer.
5468 bool hasDesignatedInit() const {
5469 return llvm::any_of(
5470 *this, [](const Stmt *S) { return isa<DesignatedInitExpr>(S); });
5471 }
5472
5473 /// If this initializes a union, specifies which field in the
5474 /// union to initialize.
5475 ///
5476 /// Typically, this field is the first named field within the
5477 /// union. However, a designated initializer can specify the
5478 /// initialization of a different field within the union.
5480 return dyn_cast_if_present<FieldDecl *>(ArrayFillerOrUnionFieldInit);
5481 }
5483 return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
5484 }
5486 assert((FD == nullptr
5487 || getInitializedFieldInUnion() == nullptr
5488 || getInitializedFieldInUnion() == FD)
5489 && "Only one field of a union may be initialized at a time!");
5490 ArrayFillerOrUnionFieldInit = FD;
5491 }
5492
5493 // Explicit InitListExpr's originate from source code (and have valid source
5494 // locations). Implicit InitListExpr's are created by the semantic analyzer.
5495 bool isExplicit() const { return InitListExprBits.IsExplicit; }
5496
5497 /// Is this an initializer for an array of characters, initialized by a string
5498 /// literal or an @encode?
5499 bool isStringLiteralInit() const;
5500
5501 /// Is this a transparent initializer list (that is, an InitListExpr that is
5502 /// purely syntactic, and whose semantics are that of the sole contained
5503 /// initializer)?
5504 bool isTransparent() const;
5505
5506 /// Is this the zero initializer {0} in a language which considers it
5507 /// idiomatic?
5508 bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
5509
5510 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5511 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
5512 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5513 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
5514
5515 bool isSemanticForm() const { return AltForm.getInt(); }
5517 return isSemanticForm() ? nullptr : AltForm.getPointer();
5518 }
5519 bool isSyntacticForm() const {
5520 return !AltForm.getInt() || !AltForm.getPointer();
5521 }
5523 return isSemanticForm() ? AltForm.getPointer() : nullptr;
5524 }
5525
5527 AltForm.setPointer(Init);
5528 AltForm.setInt(true);
5529 Init->AltForm.setPointer(this);
5530 Init->AltForm.setInt(false);
5531 }
5532
5534 return InitListExprBits.HadArrayRangeDesignator != 0;
5535 }
5536 void sawArrayRangeDesignator(bool ARD = true) {
5537 InitListExprBits.HadArrayRangeDesignator = ARD;
5538 }
5539
5540 SourceLocation getBeginLoc() const LLVM_READONLY;
5541 SourceLocation getEndLoc() const LLVM_READONLY;
5542
5543 static bool classof(const Stmt *T) {
5544 return T->getStmtClass() == InitListExprClass;
5545 }
5546
5547 // Iterators
5549 const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
5550 return child_range(cast_away_const(CCR.begin()),
5551 cast_away_const(CCR.end()));
5552 }
5553
5555 // FIXME: This does not include the array filler expression.
5556 if (InitExprs.empty())
5558 return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
5559 }
5560
5565
5566 iterator begin() { return InitExprs.begin(); }
5567 const_iterator begin() const { return InitExprs.begin(); }
5568 iterator end() { return InitExprs.end(); }
5569 const_iterator end() const { return InitExprs.end(); }
5570 reverse_iterator rbegin() { return InitExprs.rbegin(); }
5571 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
5572 reverse_iterator rend() { return InitExprs.rend(); }
5573 const_reverse_iterator rend() const { return InitExprs.rend(); }
5574
5575 friend class ASTStmtReader;
5576 friend class ASTStmtWriter;
5577};
5578
5579/// Represents a C99 designated initializer expression.
5580///
5581/// A designated initializer expression (C99 6.7.8) contains one or
5582/// more designators (which can be field designators, array
5583/// designators, or GNU array-range designators) followed by an
5584/// expression that initializes the field or element(s) that the
5585/// designators refer to. For example, given:
5586///
5587/// @code
5588/// struct point {
5589/// double x;
5590/// double y;
5591/// };
5592/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
5593/// @endcode
5594///
5595/// The InitListExpr contains three DesignatedInitExprs, the first of
5596/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
5597/// designators, one array designator for @c [2] followed by one field
5598/// designator for @c .y. The initialization expression will be 1.0.
5599class DesignatedInitExpr final
5600 : public Expr,
5601 private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
5602public:
5603 /// Forward declaration of the Designator class.
5604 class Designator;
5605
5606private:
5607 /// The location of the '=' or ':' prior to the actual initializer
5608 /// expression.
5609 SourceLocation EqualOrColonLoc;
5610
5611 /// Whether this designated initializer used the GNU deprecated
5612 /// syntax rather than the C99 '=' syntax.
5613 LLVM_PREFERRED_TYPE(bool)
5614 unsigned GNUSyntax : 1;
5615
5616 /// The number of designators in this initializer expression.
5617 unsigned NumDesignators : 15;
5618
5619 /// The number of subexpressions of this initializer expression,
5620 /// which contains both the initializer and any additional
5621 /// expressions used by array and array-range designators.
5622 unsigned NumSubExprs : 16;
5623
5624 /// The designators in this designated initialization
5625 /// expression.
5626 Designator *Designators;
5627
5628 DesignatedInitExpr(const ASTContext &C, QualType Ty,
5629 ArrayRef<Designator> Designators,
5630 SourceLocation EqualOrColonLoc, bool GNUSyntax,
5631 ArrayRef<Expr *> IndexExprs, Expr *Init);
5632
5633 explicit DesignatedInitExpr(unsigned NumSubExprs)
5634 : Expr(DesignatedInitExprClass, EmptyShell()),
5635 NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
5636
5637public:
5638 /// Represents a single C99 designator.
5639 ///
5640 /// @todo This class is infuriatingly similar to clang::Designator,
5641 /// but minor differences (storing indices vs. storing pointers)
5642 /// keep us from reusing it. Try harder, later, to rectify these
5643 /// differences.
5644 class Designator {
5645 /// A field designator, e.g., ".x".
5646 struct FieldDesignatorInfo {
5647 /// Refers to the field that is being initialized. The low bit
5648 /// of this field determines whether this is actually a pointer
5649 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
5650 /// initially constructed, a field designator will store an
5651 /// IdentifierInfo*. After semantic analysis has resolved that
5652 /// name, the field designator will instead store a FieldDecl*.
5653 uintptr_t NameOrField;
5654
5655 /// The location of the '.' in the designated initializer.
5656 SourceLocation DotLoc;
5657
5658 /// The location of the field name in the designated initializer.
5659 SourceLocation FieldLoc;
5660
5661 FieldDesignatorInfo(const IdentifierInfo *II, SourceLocation DotLoc,
5662 SourceLocation FieldLoc)
5663 : NameOrField(reinterpret_cast<uintptr_t>(II) | 0x1), DotLoc(DotLoc),
5664 FieldLoc(FieldLoc) {}
5665 };
5666
5667 /// An array or GNU array-range designator, e.g., "[9]" or "[10...15]".
5668 struct ArrayOrRangeDesignatorInfo {
5669 /// Location of the first index expression within the designated
5670 /// initializer expression's list of subexpressions.
5671 unsigned Index;
5672
5673 /// The location of the '[' starting the array range designator.
5674 SourceLocation LBracketLoc;
5675
5676 /// The location of the ellipsis separating the start and end
5677 /// indices. Only valid for GNU array-range designators.
5678 SourceLocation EllipsisLoc;
5679
5680 /// The location of the ']' terminating the array range designator.
5681 SourceLocation RBracketLoc;
5682
5683 ArrayOrRangeDesignatorInfo(unsigned Index, SourceLocation LBracketLoc,
5684 SourceLocation RBracketLoc)
5685 : Index(Index), LBracketLoc(LBracketLoc), RBracketLoc(RBracketLoc) {}
5686
5687 ArrayOrRangeDesignatorInfo(unsigned Index,
5688 SourceLocation LBracketLoc,
5689 SourceLocation EllipsisLoc,
5690 SourceLocation RBracketLoc)
5691 : Index(Index), LBracketLoc(LBracketLoc), EllipsisLoc(EllipsisLoc),
5692 RBracketLoc(RBracketLoc) {}
5693 };
5694
5695 /// The kind of designator this describes.
5696 enum DesignatorKind {
5697 FieldDesignator,
5698 ArrayDesignator,
5699 ArrayRangeDesignator
5700 };
5701
5702 DesignatorKind Kind;
5703
5704 union {
5705 /// A field designator, e.g., ".x".
5706 struct FieldDesignatorInfo FieldInfo;
5707
5708 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
5709 struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo;
5710 };
5711
5712 Designator(DesignatorKind Kind) : Kind(Kind) {}
5713
5714 public:
5716
5717 bool isFieldDesignator() const { return Kind == FieldDesignator; }
5718 bool isArrayDesignator() const { return Kind == ArrayDesignator; }
5719 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
5720
5721 //===------------------------------------------------------------------===//
5722 // FieldDesignatorInfo
5723
5724 /// Creates a field designator.
5725 static Designator CreateFieldDesignator(const IdentifierInfo *FieldName,
5726 SourceLocation DotLoc,
5727 SourceLocation FieldLoc) {
5728 Designator D(FieldDesignator);
5729 new (&D.FieldInfo) FieldDesignatorInfo(FieldName, DotLoc, FieldLoc);
5730 return D;
5731 }
5732
5733 const IdentifierInfo *getFieldName() const;
5734
5736 assert(isFieldDesignator() && "Only valid on a field designator");
5737 if (FieldInfo.NameOrField & 0x01)
5738 return nullptr;
5739 return reinterpret_cast<FieldDecl *>(FieldInfo.NameOrField);
5740 }
5741
5743 assert(isFieldDesignator() && "Only valid on a field designator");
5744 FieldInfo.NameOrField = reinterpret_cast<uintptr_t>(FD);
5745 }
5746
5748 assert(isFieldDesignator() && "Only valid on a field designator");
5749 return FieldInfo.DotLoc;
5750 }
5751
5753 assert(isFieldDesignator() && "Only valid on a field designator");
5754 return FieldInfo.FieldLoc;
5755 }
5756
5757 //===------------------------------------------------------------------===//
5758 // ArrayOrRangeDesignator
5759
5760 /// Creates an array designator.
5761 static Designator CreateArrayDesignator(unsigned Index,
5762 SourceLocation LBracketLoc,
5763 SourceLocation RBracketLoc) {
5764 Designator D(ArrayDesignator);
5765 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5766 RBracketLoc);
5767 return D;
5768 }
5769
5770 /// Creates a GNU array-range designator.
5771 static Designator CreateArrayRangeDesignator(unsigned Index,
5772 SourceLocation LBracketLoc,
5773 SourceLocation EllipsisLoc,
5774 SourceLocation RBracketLoc) {
5775 Designator D(ArrayRangeDesignator);
5776 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5777 EllipsisLoc,
5778 RBracketLoc);
5779 return D;
5780 }
5781
5782 unsigned getArrayIndex() const {
5783 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5784 "Only valid on an array or array-range designator");
5785 return ArrayOrRangeInfo.Index;
5786 }
5787
5789 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5790 "Only valid on an array or array-range designator");
5791 return ArrayOrRangeInfo.LBracketLoc;
5792 }
5793
5795 assert(isArrayRangeDesignator() &&
5796 "Only valid on an array-range designator");
5797 return ArrayOrRangeInfo.EllipsisLoc;
5798 }
5799
5801 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5802 "Only valid on an array or array-range designator");
5803 return ArrayOrRangeInfo.RBracketLoc;
5804 }
5805
5806 SourceLocation getBeginLoc() const LLVM_READONLY {
5807 if (isFieldDesignator())
5808 return getDotLoc().isInvalid() ? getFieldLoc() : getDotLoc();
5809 return getLBracketLoc();
5810 }
5811
5812 SourceLocation getEndLoc() const LLVM_READONLY {
5814 }
5815
5816 SourceRange getSourceRange() const LLVM_READONLY {
5817 return SourceRange(getBeginLoc(), getEndLoc());
5818 }
5819 };
5820
5821 static DesignatedInitExpr *Create(const ASTContext &C,
5822 ArrayRef<Designator> Designators,
5823 ArrayRef<Expr *> IndexExprs,
5824 SourceLocation EqualOrColonLoc,
5825 bool GNUSyntax, Expr *Init);
5826
5828 unsigned NumIndexExprs);
5829
5830 /// Returns the number of designators in this initializer.
5831 unsigned size() const { return NumDesignators; }
5832
5833 // Iterator access to the designators.
5835 return {Designators, NumDesignators};
5836 }
5837
5839 return {Designators, NumDesignators};
5840 }
5841
5842 Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
5843 const Designator *getDesignator(unsigned Idx) const {
5844 return &designators()[Idx];
5845 }
5846
5847 void setDesignators(const ASTContext &C, const Designator *Desigs,
5848 unsigned NumDesigs);
5849
5850 Expr *getArrayIndex(const Designator &D) const;
5851 Expr *getArrayRangeStart(const Designator &D) const;
5852 Expr *getArrayRangeEnd(const Designator &D) const;
5853
5854 /// Retrieve the location of the '=' that precedes the
5855 /// initializer value itself, if present.
5856 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
5857 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
5858
5859 /// Whether this designated initializer should result in direct-initialization
5860 /// of the designated subobject (eg, '{.foo{1, 2, 3}}').
5861 bool isDirectInit() const { return EqualOrColonLoc.isInvalid(); }
5862
5863 /// Determines whether this designated initializer used the
5864 /// deprecated GNU syntax for designated initializers.
5865 bool usesGNUSyntax() const { return GNUSyntax; }
5866 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
5867
5868 /// Retrieve the initializer value.
5869 Expr *getInit() const {
5870 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
5871 }
5872
5873 void setInit(Expr *init) {
5874 *child_begin() = init;
5875 }
5876
5877 /// Retrieve the total number of subexpressions in this
5878 /// designated initializer expression, including the actual
5879 /// initialized value and any expressions that occur within array
5880 /// and array-range designators.
5881 unsigned getNumSubExprs() const { return NumSubExprs; }
5882
5883 Expr *getSubExpr(unsigned Idx) const {
5884 return cast<Expr>(getTrailingObjects(NumSubExprs)[Idx]);
5885 }
5886
5887 void setSubExpr(unsigned Idx, Expr *E) {
5888 getTrailingObjects(NumSubExprs)[Idx] = E;
5889 }
5890
5891 /// Replaces the designator at index @p Idx with the series
5892 /// of designators in [First, Last).
5893 void ExpandDesignator(const ASTContext &C, unsigned Idx,
5894 const Designator *First, const Designator *Last);
5895
5897
5898 SourceLocation getBeginLoc() const LLVM_READONLY;
5899 SourceLocation getEndLoc() const LLVM_READONLY;
5900
5901 static bool classof(const Stmt *T) {
5902 return T->getStmtClass() == DesignatedInitExprClass;
5903 }
5904
5905 // Iterators
5907 Stmt **begin = getTrailingObjects();
5908 return child_range(begin, begin + NumSubExprs);
5909 }
5911 Stmt *const *begin = getTrailingObjects();
5912 return const_child_range(begin, begin + NumSubExprs);
5913 }
5914
5916};
5917
5918/// Represents a place-holder for an object not to be initialized by
5919/// anything.
5920///
5921/// This only makes sense when it appears as part of an updater of a
5922/// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
5923/// initializes a big object, and the NoInitExpr's mark the spots within the
5924/// big object not to be overwritten by the updater.
5925///
5926/// \see DesignatedInitUpdateExpr
5927class NoInitExpr : public Expr {
5928public:
5930 : Expr(NoInitExprClass, ty, VK_PRValue, OK_Ordinary) {
5932 }
5933
5935 : Expr(NoInitExprClass, Empty) { }
5936
5937 static bool classof(const Stmt *T) {
5938 return T->getStmtClass() == NoInitExprClass;
5939 }
5940
5941 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5942 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5943
5944 // Iterators
5951};
5952
5953// In cases like:
5954// struct Q { int a, b, c; };
5955// Q *getQ();
5956// void foo() {
5957// struct A { Q q; } a = { *getQ(), .q.b = 3 };
5958// }
5959//
5960// We will have an InitListExpr for a, with type A, and then a
5961// DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
5962// is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
5963//
5965 // BaseAndUpdaterExprs[0] is the base expression;
5966 // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
5967 Stmt *BaseAndUpdaterExprs[2];
5968
5969public:
5971 Expr *baseExprs, SourceLocation rBraceLoc);
5972
5974 : Expr(DesignatedInitUpdateExprClass, Empty) { }
5975
5976 SourceLocation getBeginLoc() const LLVM_READONLY;
5977 SourceLocation getEndLoc() const LLVM_READONLY;
5978
5979 static bool classof(const Stmt *T) {
5980 return T->getStmtClass() == DesignatedInitUpdateExprClass;
5981 }
5982
5983 Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
5984 void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
5985
5987 return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
5988 }
5989 void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
5990
5991 // Iterators
5992 // children = the base and the updater
5994 return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
5995 }
5997 return const_child_range(&BaseAndUpdaterExprs[0],
5998 &BaseAndUpdaterExprs[0] + 2);
5999 }
6000};
6001
6002/// Represents a loop initializing the elements of an array.
6003///
6004/// The need to initialize the elements of an array occurs in a number of
6005/// contexts:
6006///
6007/// * in the implicit copy/move constructor for a class with an array member
6008/// * when a lambda-expression captures an array by value
6009/// * when a decomposition declaration decomposes an array
6010///
6011/// There are two subexpressions: a common expression (the source array)
6012/// that is evaluated once up-front, and a per-element initializer that
6013/// runs once for each array element.
6014///
6015/// Within the per-element initializer, the common expression may be referenced
6016/// via an OpaqueValueExpr, and the current index may be obtained via an
6017/// ArrayInitIndexExpr.
6018class ArrayInitLoopExpr : public Expr {
6019 Stmt *SubExprs[2];
6020
6021 explicit ArrayInitLoopExpr(EmptyShell Empty)
6022 : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
6023
6024public:
6025 explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
6026 : Expr(ArrayInitLoopExprClass, T, VK_PRValue, OK_Ordinary),
6027 SubExprs{CommonInit, ElementInit} {
6029 }
6030
6031 /// Get the common subexpression shared by all initializations (the source
6032 /// array).
6034 return cast<OpaqueValueExpr>(SubExprs[0]);
6035 }
6036
6037 /// Get the initializer to use for each array element.
6038 Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
6039
6040 llvm::APInt getArraySize() const {
6041 return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
6042 ->getSize();
6043 }
6044
6045 static bool classof(const Stmt *S) {
6046 return S->getStmtClass() == ArrayInitLoopExprClass;
6047 }
6048
6049 SourceLocation getBeginLoc() const LLVM_READONLY {
6050 return getCommonExpr()->getBeginLoc();
6051 }
6052 SourceLocation getEndLoc() const LLVM_READONLY {
6053 return getCommonExpr()->getEndLoc();
6054 }
6055
6057 return child_range(SubExprs, SubExprs + 2);
6058 }
6060 return const_child_range(SubExprs, SubExprs + 2);
6061 }
6062
6063 friend class ASTReader;
6064 friend class ASTStmtReader;
6065 friend class ASTStmtWriter;
6066};
6067
6068/// Represents the index of the current element of an array being
6069/// initialized by an ArrayInitLoopExpr. This can only appear within the
6070/// subexpression of an ArrayInitLoopExpr.
6071class ArrayInitIndexExpr : public Expr {
6072 explicit ArrayInitIndexExpr(EmptyShell Empty)
6073 : Expr(ArrayInitIndexExprClass, Empty) {}
6074
6075public:
6077 : Expr(ArrayInitIndexExprClass, T, VK_PRValue, OK_Ordinary) {
6078 setDependence(ExprDependence::None);
6079 }
6080
6081 static bool classof(const Stmt *S) {
6082 return S->getStmtClass() == ArrayInitIndexExprClass;
6083 }
6084
6085 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
6086 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
6087
6094
6095 friend class ASTReader;
6096 friend class ASTStmtReader;
6097};
6098
6099/// Represents an implicitly-generated value initialization of
6100/// an object of a given type.
6101///
6102/// Implicit value initializations occur within semantic initializer
6103/// list expressions (InitListExpr) as placeholders for subobject
6104/// initializations not explicitly specified by the user.
6105///
6106/// \see InitListExpr
6108public:
6110 : Expr(ImplicitValueInitExprClass, ty, VK_PRValue, OK_Ordinary) {
6112 }
6113
6114 /// Construct an empty implicit value initialization.
6116 : Expr(ImplicitValueInitExprClass, Empty) { }
6117
6118 static bool classof(const Stmt *T) {
6119 return T->getStmtClass() == ImplicitValueInitExprClass;
6120 }
6121
6122 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
6123 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
6124
6125 // Iterators
6132};
6133
6134class ParenListExpr final
6135 : public Expr,
6136 private llvm::TrailingObjects<ParenListExpr, Stmt *> {
6137 friend class ASTStmtReader;
6138 friend TrailingObjects;
6139
6140 /// The location of the left and right parentheses.
6141 SourceLocation LParenLoc, RParenLoc;
6142
6143 /// Build a paren list.
6144 ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs,
6145 SourceLocation RParenLoc);
6146
6147 /// Build an empty paren list.
6148 ParenListExpr(EmptyShell Empty, unsigned NumExprs);
6149
6150public:
6151 /// Create a paren list.
6152 static ParenListExpr *Create(const ASTContext &Ctx, SourceLocation LParenLoc,
6153 ArrayRef<Expr *> Exprs,
6154 SourceLocation RParenLoc);
6155
6156 /// Create an empty paren list.
6157 static ParenListExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumExprs);
6158
6159 /// Return the number of expressions in this paren list.
6160 unsigned getNumExprs() const { return ParenListExprBits.NumExprs; }
6161
6162 Expr *getExpr(unsigned Init) {
6163 assert(Init < getNumExprs() && "Initializer access out of range!");
6164 return getExprs()[Init];
6165 }
6166
6167 const Expr *getExpr(unsigned Init) const {
6168 return const_cast<ParenListExpr *>(this)->getExpr(Init);
6169 }
6170
6171 Expr **getExprs() { return reinterpret_cast<Expr **>(getTrailingObjects()); }
6172
6173 Expr *const *getExprs() const {
6174 return reinterpret_cast<Expr *const *>(getTrailingObjects());
6175 }
6176
6177 ArrayRef<Expr *> exprs() const { return {getExprs(), getNumExprs()}; }
6178
6179 SourceLocation getLParenLoc() const { return LParenLoc; }
6180 SourceLocation getRParenLoc() const { return RParenLoc; }
6183
6184 static bool classof(const Stmt *T) {
6185 return T->getStmtClass() == ParenListExprClass;
6186 }
6187
6188 // Iterators
6190 return child_range(getTrailingObjects(getNumExprs()));
6191 }
6193 return const_child_range(getTrailingObjects(getNumExprs()));
6194 }
6195};
6196
6197/// Represents a C11 generic selection.
6198///
6199/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
6200/// expression, followed by one or more generic associations. Each generic
6201/// association specifies a type name and an expression, or "default" and an
6202/// expression (in which case it is known as a default generic association).
6203/// The type and value of the generic selection are identical to those of its
6204/// result expression, which is defined as the expression in the generic
6205/// association with a type name that is compatible with the type of the
6206/// controlling expression, or the expression in the default generic association
6207/// if no types are compatible. For example:
6208///
6209/// @code
6210/// _Generic(X, double: 1, float: 2, default: 3)
6211/// @endcode
6212///
6213/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
6214/// or 3 if "hello".
6215///
6216/// As an extension, generic selections are allowed in C++, where the following
6217/// additional semantics apply:
6218///
6219/// Any generic selection whose controlling expression is type-dependent or
6220/// which names a dependent type in its association list is result-dependent,
6221/// which means that the choice of result expression is dependent.
6222/// Result-dependent generic associations are both type- and value-dependent.
6223///
6224/// We also allow an extended form in both C and C++ where the controlling
6225/// predicate for the selection expression is a type rather than an expression.
6226/// This type argument form does not perform any conversions for the
6227/// controlling type, which makes it suitable for use with qualified type
6228/// associations, which is not possible with the expression form.
6229class GenericSelectionExpr final
6230 : public Expr,
6231 private llvm::TrailingObjects<GenericSelectionExpr, Stmt *,
6232 TypeSourceInfo *> {
6233 friend class ASTStmtReader;
6234 friend class ASTStmtWriter;
6235 friend TrailingObjects;
6236
6237 /// The number of association expressions and the index of the result
6238 /// expression in the case where the generic selection expression is not
6239 /// result-dependent. The result index is equal to ResultDependentIndex
6240 /// if and only if the generic selection expression is result-dependent.
6241 unsigned NumAssocs : 15;
6242 unsigned ResultIndex : 15; // NB: ResultDependentIndex is tied to this width.
6243 LLVM_PREFERRED_TYPE(bool)
6244 unsigned IsExprPredicate : 1;
6245 enum : unsigned {
6246 ResultDependentIndex = 0x7FFF
6247 };
6248
6249 unsigned getIndexOfControllingExpression() const {
6250 // If controlled by an expression, the first offset into the Stmt *
6251 // trailing array is the controlling expression, the associated expressions
6252 // follow this.
6253 assert(isExprPredicate() && "Asking for the controlling expression of a "
6254 "selection expr predicated by a type");
6255 return 0;
6256 }
6257
6258 unsigned getIndexOfControllingType() const {
6259 // If controlled by a type, the first offset into the TypeSourceInfo *
6260 // trailing array is the controlling type, the associated types follow this.
6261 assert(isTypePredicate() && "Asking for the controlling type of a "
6262 "selection expr predicated by an expression");
6263 return 0;
6264 }
6265
6266 unsigned getIndexOfStartOfAssociatedExprs() const {
6267 // If the predicate is a type, then the associated expressions are the only
6268 // Stmt * in the trailing array, otherwise we need to offset past the
6269 // predicate expression.
6270 return (int)isExprPredicate();
6271 }
6272
6273 unsigned getIndexOfStartOfAssociatedTypes() const {
6274 // If the predicate is a type, then the associated types follow it in the
6275 // trailing array. Otherwise, the associated types are the only
6276 // TypeSourceInfo * in the trailing array.
6277 return (int)isTypePredicate();
6278 }
6279
6280
6281 /// The location of the "default" and of the right parenthesis.
6282 SourceLocation DefaultLoc, RParenLoc;
6283
6284 // GenericSelectionExpr is followed by several trailing objects.
6285 // They are (in order):
6286 //
6287 // * An array of either
6288 // - getNumAssocs() (if what controls the generic is not an expression), or
6289 // - getNumAssocs() + 1 (if what controls the generic is an expression)
6290 // Stmt * for the association expressions.
6291 // * An array of
6292 // - getNumAssocs() (if what controls the generic is not a type), or
6293 // - getNumAssocs() + 1 (if what controls the generic is a type)
6294 // TypeSourceInfo * for the association types.
6295 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
6296 // Add one to account for the controlling expression; the remainder
6297 // are the associated expressions.
6298 return getNumAssocs() + (int)isExprPredicate();
6299 }
6300
6301 unsigned numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
6302 // Add one to account for the controlling type predicate, the remainder
6303 // are the associated types.
6304 return getNumAssocs() + (int)isTypePredicate();
6305 }
6306
6307 template <bool Const> class AssociationIteratorTy;
6308 /// Bundle together an association expression and its TypeSourceInfo.
6309 /// The Const template parameter is for the const and non-const versions
6310 /// of AssociationTy.
6311 template <bool Const> class AssociationTy {
6312 friend class GenericSelectionExpr;
6313 template <bool OtherConst> friend class AssociationIteratorTy;
6314 using ExprPtrTy = std::conditional_t<Const, const Expr *, Expr *>;
6315 using TSIPtrTy =
6316 std::conditional_t<Const, const TypeSourceInfo *, TypeSourceInfo *>;
6317 ExprPtrTy E;
6318 TSIPtrTy TSI;
6319 bool Selected;
6320 AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
6321 : E(E), TSI(TSI), Selected(Selected) {}
6322
6323 public:
6324 ExprPtrTy getAssociationExpr() const { return E; }
6325 TSIPtrTy getTypeSourceInfo() const { return TSI; }
6326 QualType getType() const { return TSI ? TSI->getType() : QualType(); }
6327 bool isSelected() const { return Selected; }
6328 AssociationTy *operator->() { return this; }
6329 const AssociationTy *operator->() const { return this; }
6330 }; // class AssociationTy
6331
6332 /// Iterator over const and non-const Association objects. The Association
6333 /// objects are created on the fly when the iterator is dereferenced.
6334 /// This abstract over how exactly the association expressions and the
6335 /// corresponding TypeSourceInfo * are stored.
6336 template <bool Const>
6337 class AssociationIteratorTy
6338 : public llvm::iterator_facade_base<
6339 AssociationIteratorTy<Const>, std::input_iterator_tag,
6340 AssociationTy<Const>, std::ptrdiff_t, AssociationTy<Const>,
6341 AssociationTy<Const>> {
6342 friend class GenericSelectionExpr;
6343 // FIXME: This iterator could conceptually be a random access iterator, and
6344 // it would be nice if we could strengthen the iterator category someday.
6345 // However this iterator does not satisfy two requirements of forward
6346 // iterators:
6347 // a) reference = T& or reference = const T&
6348 // b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
6349 // if *It1 and *It2 are bound to the same objects.
6350 // An alternative design approach was discussed during review;
6351 // store an Association object inside the iterator, and return a reference
6352 // to it when dereferenced. This idea was discarded because of nasty
6353 // lifetime issues:
6354 // AssociationIterator It = ...;
6355 // const Association &Assoc = *It++; // Oops, Assoc is dangling.
6356 using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
6357 using StmtPtrPtrTy =
6358 std::conditional_t<Const, const Stmt *const *, Stmt **>;
6359 using TSIPtrPtrTy = std::conditional_t<Const, const TypeSourceInfo *const *,
6360 TypeSourceInfo **>;
6361 StmtPtrPtrTy E = nullptr;
6362 TSIPtrPtrTy TSI; // Kept in sync with E.
6363 unsigned Offset = 0, SelectedOffset = 0;
6364 AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
6365 unsigned SelectedOffset)
6366 : E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
6367
6368 public:
6369 AssociationIteratorTy() : E(nullptr), TSI(nullptr) {}
6370 typename BaseTy::reference operator*() const {
6371 return AssociationTy<Const>(cast<Expr>(*E), *TSI,
6372 Offset == SelectedOffset);
6373 }
6374 typename BaseTy::pointer operator->() const { return **this; }
6375 using BaseTy::operator++;
6376 AssociationIteratorTy &operator++() {
6377 ++E;
6378 ++TSI;
6379 ++Offset;
6380 return *this;
6381 }
6382 bool operator==(AssociationIteratorTy Other) const { return E == Other.E; }
6383 }; // class AssociationIterator
6384
6385 /// Build a non-result-dependent generic selection expression accepting an
6386 /// expression predicate.
6387 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6388 Expr *ControllingExpr,
6389 ArrayRef<TypeSourceInfo *> AssocTypes,
6390 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6391 SourceLocation RParenLoc,
6392 bool ContainsUnexpandedParameterPack,
6393 unsigned ResultIndex);
6394
6395 /// Build a result-dependent generic selection expression accepting an
6396 /// expression predicate.
6397 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6398 Expr *ControllingExpr,
6399 ArrayRef<TypeSourceInfo *> AssocTypes,
6400 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6401 SourceLocation RParenLoc,
6402 bool ContainsUnexpandedParameterPack);
6403
6404 /// Build a non-result-dependent generic selection expression accepting a
6405 /// type predicate.
6406 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6407 TypeSourceInfo *ControllingType,
6408 ArrayRef<TypeSourceInfo *> AssocTypes,
6409 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6410 SourceLocation RParenLoc,
6411 bool ContainsUnexpandedParameterPack,
6412 unsigned ResultIndex);
6413
6414 /// Build a result-dependent generic selection expression accepting a type
6415 /// predicate.
6416 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6417 TypeSourceInfo *ControllingType,
6418 ArrayRef<TypeSourceInfo *> AssocTypes,
6419 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6420 SourceLocation RParenLoc,
6421 bool ContainsUnexpandedParameterPack);
6422
6423 /// Build an empty generic selection expression for deserialization.
6424 explicit GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs);
6425
6426public:
6427 /// Create a non-result-dependent generic selection expression accepting an
6428 /// expression predicate.
6429 static GenericSelectionExpr *
6430 Create(const ASTContext &Context, SourceLocation GenericLoc,
6431 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
6432 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6433 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
6434 unsigned ResultIndex);
6435
6436 /// Create a result-dependent generic selection expression accepting an
6437 /// expression predicate.
6438 static GenericSelectionExpr *
6439 Create(const ASTContext &Context, SourceLocation GenericLoc,
6440 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
6441 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6442 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
6443
6444 /// Create a non-result-dependent generic selection expression accepting a
6445 /// type predicate.
6446 static GenericSelectionExpr *
6447 Create(const ASTContext &Context, SourceLocation GenericLoc,
6448 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
6449 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6450 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
6451 unsigned ResultIndex);
6452
6453 /// Create a result-dependent generic selection expression accepting a type
6454 /// predicate
6455 static GenericSelectionExpr *
6456 Create(const ASTContext &Context, SourceLocation GenericLoc,
6457 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
6458 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6459 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
6460
6461 /// Create an empty generic selection expression for deserialization.
6462 static GenericSelectionExpr *CreateEmpty(const ASTContext &Context,
6463 unsigned NumAssocs);
6464
6465 using Association = AssociationTy<false>;
6466 using ConstAssociation = AssociationTy<true>;
6467 using AssociationIterator = AssociationIteratorTy<false>;
6468 using ConstAssociationIterator = AssociationIteratorTy<true>;
6469 using association_range = llvm::iterator_range<AssociationIterator>;
6471 llvm::iterator_range<ConstAssociationIterator>;
6472
6473 /// The number of association expressions.
6474 unsigned getNumAssocs() const { return NumAssocs; }
6475
6476 /// The zero-based index of the result expression's generic association in
6477 /// the generic selection's association list. Defined only if the
6478 /// generic selection is not result-dependent.
6479 unsigned getResultIndex() const {
6480 assert(!isResultDependent() &&
6481 "Generic selection is result-dependent but getResultIndex called!");
6482 return ResultIndex;
6483 }
6484
6485 /// Whether this generic selection is result-dependent.
6486 bool isResultDependent() const { return ResultIndex == ResultDependentIndex; }
6487
6488 /// Whether this generic selection uses an expression as its controlling
6489 /// argument.
6490 bool isExprPredicate() const { return IsExprPredicate; }
6491 /// Whether this generic selection uses a type as its controlling argument.
6492 bool isTypePredicate() const { return !IsExprPredicate; }
6493
6494 /// Return the controlling expression of this generic selection expression.
6495 /// Only valid to call if the selection expression used an expression as its
6496 /// controlling argument.
6498 return cast<Expr>(
6499 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
6500 }
6501 const Expr *getControllingExpr() const {
6502 return cast<Expr>(
6503 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
6504 }
6505
6506 /// Return the controlling type of this generic selection expression. Only
6507 /// valid to call if the selection expression used a type as its controlling
6508 /// argument.
6510 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
6511 }
6513 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
6514 }
6515
6516 /// Return the result expression of this controlling expression. Defined if
6517 /// and only if the generic selection expression is not result-dependent.
6519 return cast<Expr>(
6520 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6521 getResultIndex()]);
6522 }
6523 const Expr *getResultExpr() const {
6524 return cast<Expr>(
6525 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6526 getResultIndex()]);
6527 }
6528
6530 return {reinterpret_cast<Expr *const *>(getTrailingObjects<Stmt *>() +
6531 getIndexOfStartOfAssociatedExprs()),
6532 NumAssocs};
6533 }
6535 return {getTrailingObjects<TypeSourceInfo *>() +
6536 getIndexOfStartOfAssociatedTypes(),
6537 NumAssocs};
6538 }
6539
6540 /// Return the Ith association expression with its TypeSourceInfo,
6541 /// bundled together in GenericSelectionExpr::(Const)Association.
6543 assert(I < getNumAssocs() &&
6544 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6545 return Association(
6546 cast<Expr>(
6547 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6548 I]),
6549 getTrailingObjects<
6550 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6551 !isResultDependent() && (getResultIndex() == I));
6552 }
6554 assert(I < getNumAssocs() &&
6555 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6556 return ConstAssociation(
6557 cast<Expr>(
6558 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6559 I]),
6560 getTrailingObjects<
6561 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6562 !isResultDependent() && (getResultIndex() == I));
6563 }
6564
6566 AssociationIterator Begin(getTrailingObjects<Stmt *>() +
6567 getIndexOfStartOfAssociatedExprs(),
6568 getTrailingObjects<TypeSourceInfo *>() +
6569 getIndexOfStartOfAssociatedTypes(),
6570 /*Offset=*/0, ResultIndex);
6571 AssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6572 /*Offset=*/NumAssocs, ResultIndex);
6573 return llvm::make_range(Begin, End);
6574 }
6575
6577 ConstAssociationIterator Begin(getTrailingObjects<Stmt *>() +
6578 getIndexOfStartOfAssociatedExprs(),
6579 getTrailingObjects<TypeSourceInfo *>() +
6580 getIndexOfStartOfAssociatedTypes(),
6581 /*Offset=*/0, ResultIndex);
6582 ConstAssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6583 /*Offset=*/NumAssocs, ResultIndex);
6584 return llvm::make_range(Begin, End);
6585 }
6586
6588 return GenericSelectionExprBits.GenericLoc;
6589 }
6590 SourceLocation getDefaultLoc() const { return DefaultLoc; }
6591 SourceLocation getRParenLoc() const { return RParenLoc; }
6594
6595 static bool classof(const Stmt *T) {
6596 return T->getStmtClass() == GenericSelectionExprClass;
6597 }
6598
6600 return child_range(getTrailingObjects<Stmt *>(
6601 numTrailingObjects(OverloadToken<Stmt *>())));
6602 }
6604 return const_child_range(getTrailingObjects<Stmt *>(
6605 numTrailingObjects(OverloadToken<Stmt *>())));
6606 }
6607};
6608
6609//===----------------------------------------------------------------------===//
6610// Clang Extensions
6611//===----------------------------------------------------------------------===//
6612
6613template <class Derived> class ElementAccessExprBase : public Expr {
6614protected:
6618
6621 ExprObjectKind OK)
6622 : Expr(SC, Ty, VK, OK), Base(Base), Accessor(&Accessor),
6623 AccessorLoc(Loc) {
6624 setDependence(computeDependence(static_cast<Derived *>(this)));
6625 }
6626
6629
6630public:
6631 const Expr *getBase() const { return cast<Expr>(Base); }
6632 Expr *getBase() { return cast<Expr>(Base); }
6633 void setBase(Expr *E) { Base = E; }
6634
6637
6640
6641 SourceLocation getBeginLoc() const LLVM_READONLY {
6642 return getBase()->getBeginLoc();
6643 }
6644 SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
6645
6648 return const_child_range(&Base, &Base + 1);
6649 }
6650};
6651
6652/// ExtVectorElementExpr - This represents access to specific elements of a
6653/// vector, and may occur on the left hand side or right hand side. For example
6654/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
6655///
6656/// Note that the base may have either vector or pointer to vector type, just
6657/// like a struct field reference.
6658///
6660 : public ElementAccessExprBase<ExtVectorElementExpr> {
6661public:
6667
6668 /// Build an empty vector element expression.
6670 : ElementAccessExprBase(ExtVectorElementExprClass, Empty) {}
6671
6672 /// getNumElements - Get the number of components being selected.
6673 unsigned getNumElements() const;
6674
6675 /// containsDuplicateElements - Return true if any element access is
6676 /// repeated.
6677 bool containsDuplicateElements() const;
6678
6679 /// getEncodedElementAccess - Encode the elements accessed into an llvm
6680 /// aggregate Constant of ConstantInt(s).
6682
6683 /// isArrow - Return true if the base expression is a pointer to vector,
6684 /// return false if the base expression is a vector.
6685 bool isArrow() const;
6686
6687 static bool classof(const Stmt *T) {
6688 return T->getStmtClass() == ExtVectorElementExprClass;
6689 }
6690};
6691
6692class MatrixElementExpr : public ElementAccessExprBase<MatrixElementExpr> {
6693public:
6697 MatrixElementExprClass, Ty, VK, Base, Accessor, Loc,
6698 OK_Ordinary /*TODO: Should we add a new OK_MatrixComponent?*/) {}
6699
6700 /// Build an empty matrix element expression.
6702 : ElementAccessExprBase(MatrixElementExprClass, Empty) {}
6703
6704 /// getNumElements - Get the number of components being selected.
6705 unsigned getNumElements() const;
6706
6707 /// containsDuplicateElements - Return true if any element access is
6708 /// repeated.
6709 bool containsDuplicateElements() const;
6710
6711 /// getEncodedElementAccess - Encode the elements accessed into an llvm
6712 /// aggregate Constant of ConstantInt(s).
6714
6715 static bool classof(const Stmt *T) {
6716 return T->getStmtClass() == MatrixElementExprClass;
6717 }
6718};
6719
6720/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
6721/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
6722class BlockExpr : public Expr {
6723protected:
6725public:
6726 BlockExpr(BlockDecl *BD, QualType ty, bool ContainsUnexpandedParameterPack)
6727 : Expr(BlockExprClass, ty, VK_PRValue, OK_Ordinary), TheBlock(BD) {
6728 setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
6729 }
6730
6731 /// Build an empty block expression.
6732 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
6733
6734 const BlockDecl *getBlockDecl() const { return TheBlock; }
6736 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
6737
6738 // Convenience functions for probing the underlying BlockDecl.
6740 const Stmt *getBody() const;
6741 Stmt *getBody();
6742
6743 SourceLocation getBeginLoc() const LLVM_READONLY {
6744 return getCaretLocation();
6745 }
6746 SourceLocation getEndLoc() const LLVM_READONLY {
6747 return getBody()->getEndLoc();
6748 }
6749
6750 /// getFunctionType - Return the underlying function type for this block.
6751 const FunctionProtoType *getFunctionType() const;
6752
6753 static bool classof(const Stmt *T) {
6754 return T->getStmtClass() == BlockExprClass;
6755 }
6756
6757 // Iterators
6764};
6765
6766/// Copy initialization expr of a __block variable and a boolean flag that
6767/// indicates whether the expression can throw.
6769 BlockVarCopyInit() = default;
6771 : ExprAndFlag(CopyExpr, CanThrow) {}
6772 void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
6773 ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
6774 }
6775 Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
6776 bool canThrow() const { return ExprAndFlag.getInt(); }
6777 llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag;
6778};
6779
6780/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
6781/// This AST node provides support for reinterpreting a type to another
6782/// type of the same size.
6783class AsTypeExpr : public Expr {
6784private:
6785 Stmt *SrcExpr;
6786 SourceLocation BuiltinLoc, RParenLoc;
6787
6788 friend class ASTReader;
6789 friend class ASTStmtReader;
6790 explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
6791
6792public:
6794 ExprObjectKind OK, SourceLocation BuiltinLoc,
6795 SourceLocation RParenLoc)
6796 : Expr(AsTypeExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
6797 BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
6799 }
6800
6801 /// getSrcExpr - Return the Expr to be converted.
6802 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
6803
6804 /// getBuiltinLoc - Return the location of the __builtin_astype token.
6805 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
6806
6807 /// getRParenLoc - Return the location of final right parenthesis.
6808 SourceLocation getRParenLoc() const { return RParenLoc; }
6809
6810 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
6811 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
6812
6813 static bool classof(const Stmt *T) {
6814 return T->getStmtClass() == AsTypeExprClass;
6815 }
6816
6817 // Iterators
6818 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
6820 return const_child_range(&SrcExpr, &SrcExpr + 1);
6821 }
6822};
6823
6824/// PseudoObjectExpr - An expression which accesses a pseudo-object
6825/// l-value. A pseudo-object is an abstract object, accesses to which
6826/// are translated to calls. The pseudo-object expression has a
6827/// syntactic form, which shows how the expression was actually
6828/// written in the source code, and a semantic form, which is a series
6829/// of expressions to be executed in order which detail how the
6830/// operation is actually evaluated. Optionally, one of the semantic
6831/// forms may also provide a result value for the expression.
6832///
6833/// If any of the semantic-form expressions is an OpaqueValueExpr,
6834/// that OVE is required to have a source expression, and it is bound
6835/// to the result of that source expression. Such OVEs may appear
6836/// only in subsequent semantic-form expressions and as
6837/// sub-expressions of the syntactic form.
6838///
6839/// PseudoObjectExpr should be used only when an operation can be
6840/// usefully described in terms of fairly simple rewrite rules on
6841/// objects and functions that are meant to be used by end-developers.
6842/// For example, under the Itanium ABI, dynamic casts are implemented
6843/// as a call to a runtime function called __dynamic_cast; using this
6844/// class to describe that would be inappropriate because that call is
6845/// not really part of the user-visible semantics, and instead the
6846/// cast is properly reflected in the AST and IR-generation has been
6847/// taught to generate the call as necessary. In contrast, an
6848/// Objective-C property access is semantically defined to be
6849/// equivalent to a particular message send, and this is very much
6850/// part of the user model. The name of this class encourages this
6851/// modelling design.
6852class PseudoObjectExpr final
6853 : public Expr,
6854 private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
6855 // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
6856 // Always at least two, because the first sub-expression is the
6857 // syntactic form.
6858
6859 // PseudoObjectExprBits.ResultIndex - The index of the
6860 // sub-expression holding the result. 0 means the result is void,
6861 // which is unambiguous because it's the index of the syntactic
6862 // form. Note that this is therefore 1 higher than the value passed
6863 // in to Create, which is an index within the semantic forms.
6864 // Note also that ASTStmtWriter assumes this encoding.
6865
6866 PseudoObjectExpr(QualType type, ExprValueKind VK,
6867 Expr *syntactic, ArrayRef<Expr*> semantic,
6868 unsigned resultIndex);
6869
6870 PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
6871
6872 unsigned getNumSubExprs() const {
6873 return PseudoObjectExprBits.NumSubExprs;
6874 }
6875
6876public:
6877 /// NoResult - A value for the result index indicating that there is
6878 /// no semantic result.
6879 enum : unsigned { NoResult = ~0U };
6880
6881 static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
6882 ArrayRef<Expr*> semantic,
6883 unsigned resultIndex);
6884
6885 static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
6886 unsigned numSemanticExprs);
6887
6888 /// Return the syntactic form of this expression, i.e. the
6889 /// expression it actually looks like. Likely to be expressed in
6890 /// terms of OpaqueValueExprs bound in the semantic form.
6891 Expr *getSyntacticForm() { return getTrailingObjects()[0]; }
6892 const Expr *getSyntacticForm() const { return getTrailingObjects()[0]; }
6893
6894 /// Return the index of the result-bearing expression into the semantics
6895 /// expressions, or PseudoObjectExpr::NoResult if there is none.
6896 unsigned getResultExprIndex() const {
6897 if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
6898 return PseudoObjectExprBits.ResultIndex - 1;
6899 }
6900
6901 /// Return the result-bearing expression, or null if there is none.
6903 if (PseudoObjectExprBits.ResultIndex == 0)
6904 return nullptr;
6905 return getTrailingObjects()[PseudoObjectExprBits.ResultIndex];
6906 }
6907 const Expr *getResultExpr() const {
6908 return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
6909 }
6910
6911 unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
6912
6913 typedef Expr * const *semantics_iterator;
6914 typedef const Expr * const *const_semantics_iterator;
6915 semantics_iterator semantics_begin() { return getTrailingObjects() + 1; }
6917 return getTrailingObjects() + 1;
6918 }
6920 return getTrailingObjects() + getNumSubExprs();
6921 }
6923 return getTrailingObjects() + getNumSubExprs();
6924 }
6925
6927 return getTrailingObjects(getNumSubExprs()).drop_front();
6928 }
6930 return getTrailingObjects(getNumSubExprs()).drop_front();
6931 }
6932
6934 return getTrailingObjects(getNumSubExprs())[index + 1];
6935 }
6936 const Expr *getSemanticExpr(unsigned index) const {
6937 return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
6938 }
6939
6940 SourceLocation getExprLoc() const LLVM_READONLY {
6941 return getSyntacticForm()->getExprLoc();
6942 }
6943
6944 SourceLocation getBeginLoc() const LLVM_READONLY {
6945 return getSyntacticForm()->getBeginLoc();
6946 }
6947 SourceLocation getEndLoc() const LLVM_READONLY {
6948 return getSyntacticForm()->getEndLoc();
6949 }
6950
6952 const_child_range CCR =
6953 const_cast<const PseudoObjectExpr *>(this)->children();
6954 return child_range(cast_away_const(CCR.begin()),
6955 cast_away_const(CCR.end()));
6956 }
6958 Stmt *const *cs = const_cast<Stmt *const *>(
6959 reinterpret_cast<const Stmt *const *>(getTrailingObjects()));
6960 return const_child_range(cs, cs + getNumSubExprs());
6961 }
6962
6963 static bool classof(const Stmt *T) {
6964 return T->getStmtClass() == PseudoObjectExprClass;
6965 }
6966
6968 friend class ASTStmtReader;
6969};
6970
6971/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
6972/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
6973/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>,
6974/// and corresponding __opencl_atomic_* for OpenCL 2.0.
6975/// All of these instructions take one primary pointer, at least one memory
6976/// order. The instructions for which getScopeModel returns non-null value
6977/// take one sync scope.
6978class AtomicExpr : public Expr {
6979public:
6981#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
6982#include "clang/Basic/Builtins.inc"
6983 // Avoid trailing comma
6985 };
6986
6987private:
6988 /// Location of sub-expressions.
6989 /// The location of Scope sub-expression is NumSubExprs - 1, which is
6990 /// not fixed, therefore is not defined in enum.
6991 enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
6992 Stmt *SubExprs[END_EXPR + 1];
6993 unsigned NumSubExprs;
6994 SourceLocation BuiltinLoc, RParenLoc;
6995 AtomicOp Op;
6996
6997 friend class ASTStmtReader;
6998public:
7000 AtomicOp op, SourceLocation RP);
7001
7002 /// Determine the number of arguments the specified atomic builtin
7003 /// should have.
7004 static unsigned getNumSubExprs(AtomicOp Op);
7005
7006 /// Build an empty AtomicExpr.
7007 explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
7008
7009 Expr *getPtr() const {
7010 return cast<Expr>(SubExprs[PTR]);
7011 }
7012 Expr *getOrder() const {
7013 return cast<Expr>(SubExprs[ORDER]);
7014 }
7015 Expr *getScope() const {
7016 assert(getScopeModel() && "No scope");
7017 return cast<Expr>(SubExprs[NumSubExprs - 1]);
7018 }
7019 Expr *getVal1() const {
7020 if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init)
7021 return cast<Expr>(SubExprs[ORDER]);
7022 assert(NumSubExprs > VAL1);
7023 return cast<Expr>(SubExprs[VAL1]);
7024 }
7026 assert(NumSubExprs > ORDER_FAIL);
7027 return cast<Expr>(SubExprs[ORDER_FAIL]);
7028 }
7029 Expr *getVal2() const {
7030 if (Op == AO__atomic_exchange || Op == AO__scoped_atomic_exchange)
7031 return cast<Expr>(SubExprs[ORDER_FAIL]);
7032 assert(NumSubExprs > VAL2);
7033 return cast<Expr>(SubExprs[VAL2]);
7034 }
7035 Expr *getWeak() const {
7036 assert(NumSubExprs > WEAK);
7037 return cast<Expr>(SubExprs[WEAK]);
7038 }
7039 QualType getValueType() const;
7040
7041 AtomicOp getOp() const { return Op; }
7042 StringRef getOpAsString() const {
7043 switch (Op) {
7044#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
7045 case AO##ID: \
7046 return #ID;
7047#include "clang/Basic/Builtins.inc"
7048 }
7049 llvm_unreachable("not an atomic operator?");
7050 }
7051 unsigned getNumSubExprs() const { return NumSubExprs; }
7052
7053 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
7054 const Expr * const *getSubExprs() const {
7055 return reinterpret_cast<Expr * const *>(SubExprs);
7056 }
7057
7058 bool isVolatile() const {
7060 }
7061
7062 bool isCmpXChg() const {
7063 return getOp() == AO__c11_atomic_compare_exchange_strong ||
7064 getOp() == AO__c11_atomic_compare_exchange_weak ||
7065 getOp() == AO__hip_atomic_compare_exchange_strong ||
7066 getOp() == AO__opencl_atomic_compare_exchange_strong ||
7067 getOp() == AO__opencl_atomic_compare_exchange_weak ||
7068 getOp() == AO__hip_atomic_compare_exchange_weak ||
7069 getOp() == AO__atomic_compare_exchange ||
7070 getOp() == AO__atomic_compare_exchange_n ||
7071 getOp() == AO__scoped_atomic_compare_exchange ||
7072 getOp() == AO__scoped_atomic_compare_exchange_n;
7073 }
7074
7075 bool hasVal1Operand() const {
7076 switch (getOp()) {
7077 case AO__atomic_load_n:
7078 case AO__scoped_atomic_load_n:
7079 case AO__c11_atomic_load:
7080 case AO__opencl_atomic_load:
7081 case AO__hip_atomic_load:
7082 case AO__atomic_test_and_set:
7083 case AO__atomic_clear:
7084 return false;
7085 default:
7086 return true;
7087 }
7088 }
7089
7090 bool isOpenCL() const {
7091 return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
7092 getOp() <= AO__opencl_atomic_store;
7093 }
7094
7095 bool isHIP() const {
7096 return Op >= AO__hip_atomic_compare_exchange_strong &&
7097 Op <= AO__hip_atomic_store;
7098 }
7099
7100 /// Return true if atomics operations targeting allocations in private memory
7101 /// are undefined.
7103 return isOpenCL() || isHIP();
7104 }
7105
7106 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
7107 SourceLocation getRParenLoc() const { return RParenLoc; }
7108
7109 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
7110 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
7111
7112 static bool classof(const Stmt *T) {
7113 return T->getStmtClass() == AtomicExprClass;
7114 }
7115
7116 // Iterators
7118 return child_range(SubExprs, SubExprs+NumSubExprs);
7119 }
7121 return const_child_range(SubExprs, SubExprs + NumSubExprs);
7122 }
7123
7124 /// Get atomic scope model for the atomic op code.
7125 /// \return empty atomic scope model if the atomic op code does not have
7126 /// scope operand.
7127 static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
7128 // FIXME: Allow grouping of builtins to be able to only check >= and <=
7129 if (Op >= AO__opencl_atomic_compare_exchange_strong &&
7130 Op <= AO__opencl_atomic_store && Op != AO__opencl_atomic_init)
7132 if (Op >= AO__hip_atomic_compare_exchange_strong &&
7133 Op <= AO__hip_atomic_store)
7135 if (Op >= AO__scoped_atomic_add_fetch && Op <= AO__scoped_atomic_xor_fetch)
7138 }
7139
7140 /// Get atomic scope model.
7141 /// \return empty atomic scope model if this atomic expression does not have
7142 /// scope operand.
7143 std::unique_ptr<AtomicScopeModel> getScopeModel() const {
7144 return getScopeModel(getOp());
7145 }
7146};
7147
7148/// This class represents BOTH the OpenMP Array Section and OpenACC 'subarray',
7149/// with a boolean differentiator.
7150/// OpenMP 5.0 [2.1.5, Array Sections].
7151/// To specify an array section in an OpenMP construct, array subscript
7152/// expressions are extended with the following syntax:
7153/// \code
7154/// [ lower-bound : length : stride ]
7155/// [ lower-bound : length : ]
7156/// [ lower-bound : length ]
7157/// [ lower-bound : : stride ]
7158/// [ lower-bound : : ]
7159/// [ lower-bound : ]
7160/// [ : length : stride ]
7161/// [ : length : ]
7162/// [ : length ]
7163/// [ : : stride ]
7164/// [ : : ]
7165/// [ : ]
7166/// \endcode
7167/// The array section must be a subset of the original array.
7168/// Array sections are allowed on multidimensional arrays. Base language array
7169/// subscript expressions can be used to specify length-one dimensions of
7170/// multidimensional array sections.
7171/// Each of the lower-bound, length, and stride expressions if specified must be
7172/// an integral type expressions of the base language. When evaluated
7173/// they represent a set of integer values as follows:
7174/// \code
7175/// { lower-bound, lower-bound + stride, lower-bound + 2 * stride,... ,
7176/// lower-bound + ((length - 1) * stride) }
7177/// \endcode
7178/// The lower-bound and length must evaluate to non-negative integers.
7179/// The stride must evaluate to a positive integer.
7180/// When the size of the array dimension is not known, the length must be
7181/// specified explicitly.
7182/// When the stride is absent it defaults to 1.
7183/// When the length is absent it defaults to ⌈(size − lower-bound)/stride⌉,
7184/// where size is the size of the array dimension. When the lower-bound is
7185/// absent it defaults to 0.
7186///
7187///
7188/// OpenACC 3.3 [2.7.1 Data Specification in Data Clauses]
7189/// In C and C++, a subarray is an array name followed by an extended array
7190/// range specification in brackets, with start and length, such as
7191///
7192/// AA[2:n]
7193///
7194/// If the lower bound is missing, zero is used. If the length is missing and
7195/// the array has known size, the size of the array is used; otherwise the
7196/// length is required. The subarray AA[2:n] means elements AA[2], AA[3], . . .
7197/// , AA[2+n-1]. In C and C++, a two dimensional array may be declared in at
7198/// least four ways:
7199///
7200/// -Statically-sized array: float AA[100][200];
7201/// -Pointer to statically sized rows: typedef float row[200]; row* BB;
7202/// -Statically-sized array of pointers: float* CC[200];
7203/// -Pointer to pointers: float** DD;
7204///
7205/// Each dimension may be statically sized, or a pointer to dynamically
7206/// allocated memory. Each of these may be included in a data clause using
7207/// subarray notation to specify a rectangular array:
7208///
7209/// -AA[2:n][0:200]
7210/// -BB[2:n][0:m]
7211/// -CC[2:n][0:m]
7212/// -DD[2:n][0:m]
7213///
7214/// Multidimensional rectangular subarrays in C and C++ may be specified for any
7215/// array with any combination of statically-sized or dynamically-allocated
7216/// dimensions. For statically sized dimensions, all dimensions except the first
7217/// must specify the whole extent to preserve the contiguous data restriction,
7218/// discussed below. For dynamically allocated dimensions, the implementation
7219/// will allocate pointers in device memory corresponding to the pointers in
7220/// local memory and will fill in those pointers as appropriate.
7221///
7222/// In Fortran, a subarray is an array name followed by a comma-separated list
7223/// of range specifications in parentheses, with lower and upper bound
7224/// subscripts, such as
7225///
7226/// arr(1:high,low:100)
7227///
7228/// If either the lower or upper bounds are missing, the declared or allocated
7229/// bounds of the array, if known, are used. All dimensions except the last must
7230/// specify the whole extent, to preserve the contiguous data restriction,
7231/// discussed below.
7232///
7233/// Restrictions
7234///
7235/// -In Fortran, the upper bound for the last dimension of an assumed-size dummy
7236/// array must be specified.
7237///
7238/// -In C and C++, the length for dynamically allocated dimensions of an array
7239/// must be explicitly specified.
7240///
7241/// -In C and C++, modifying pointers in pointer arrays during the data
7242/// lifetime, either on the host or on the device, may result in undefined
7243/// behavior.
7244///
7245/// -If a subarray appears in a data clause, the implementation may choose to
7246/// allocate memory for only that subarray on the accelerator.
7247///
7248/// -In Fortran, array pointers may appear, but pointer association is not
7249/// preserved in device memory.
7250///
7251/// -Any array or subarray in a data clause, including Fortran array pointers,
7252/// must be a contiguous section of memory, except for dynamic multidimensional
7253/// C arrays.
7254///
7255/// -In C and C++, if a variable or array of composite type appears, all the
7256/// data members of the struct or class are allocated and copied, as
7257/// appropriate. If a composite member is a pointer type, the data addressed by
7258/// that pointer are not implicitly copied.
7259///
7260/// -In Fortran, if a variable or array of composite type appears, all the
7261/// members of that derived type are allocated and copied, as appropriate. If
7262/// any member has the allocatable or pointer attribute, the data accessed
7263/// through that member are not copied.
7264///
7265/// -If an expression is used in a subscript or subarray expression in a clause
7266/// on a data construct, the same value is used when copying data at the end of
7267/// the data region, even if the values of variables in the expression change
7268/// during the data region.
7269class ArraySectionExpr : public Expr {
7270 friend class ASTStmtReader;
7271 friend class ASTStmtWriter;
7272
7273public:
7275
7276private:
7277 enum {
7278 BASE,
7279 LOWER_BOUND,
7280 LENGTH,
7281 STRIDE,
7282 END_EXPR,
7283 OPENACC_END_EXPR = STRIDE
7284 };
7285
7286 ArraySectionType ASType = OMPArraySection;
7287 Stmt *SubExprs[END_EXPR] = {nullptr};
7288 SourceLocation ColonLocFirst;
7289 SourceLocation ColonLocSecond;
7290 SourceLocation RBracketLoc;
7291
7292public:
7293 // Constructor for OMP array sections, which include a 'stride'.
7294 ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, Expr *Stride,
7296 SourceLocation ColonLocFirst, SourceLocation ColonLocSecond,
7297 SourceLocation RBracketLoc)
7298 : Expr(ArraySectionExprClass, Type, VK, OK), ASType(OMPArraySection),
7299 ColonLocFirst(ColonLocFirst), ColonLocSecond(ColonLocSecond),
7300 RBracketLoc(RBracketLoc) {
7301 setBase(Base);
7302 setLowerBound(LowerBound);
7303 setLength(Length);
7304 setStride(Stride);
7306 }
7307
7308 // Constructor for OpenACC sub-arrays, which do not permit a 'stride'.
7311 SourceLocation RBracketLoc)
7312 : Expr(ArraySectionExprClass, Type, VK, OK), ASType(OpenACCArraySection),
7313 ColonLocFirst(ColonLoc), RBracketLoc(RBracketLoc) {
7314 setBase(Base);
7315 setLowerBound(LowerBound);
7316 setLength(Length);
7318 }
7319
7320 /// Create an empty array section expression.
7322 : Expr(ArraySectionExprClass, Shell) {}
7323
7324 /// Return original type of the base expression for array section.
7325 static QualType getBaseOriginalType(const Expr *Base);
7326
7327 /// Return the effective 'element' type of this array section. As the array
7328 /// section itself returns a collection of elements (closer to its `getBase`
7329 /// type), this is only useful for figuring out the effective type of this if
7330 /// it were a normal Array subscript expr.
7331 QualType getElementType() const;
7332
7333 /// Returns the effective 'type' of the base of this array section. This
7334 /// should be the array/pointer type that this operates on. Just
7335 /// getBase->getType isn't sufficient, since it doesn't look through existing
7336 /// Array sections to figure out the actual 'base' of this.
7337 QualType getBaseType() const;
7338
7339 static bool classof(const Stmt *T) {
7340 return T->getStmtClass() == ArraySectionExprClass;
7341 }
7342
7343 bool isOMPArraySection() const { return ASType == OMPArraySection; }
7344 bool isOpenACCArraySection() const { return ASType == OpenACCArraySection; }
7345
7346 /// Get base of the array section.
7347 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
7348 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
7349
7350 /// Get lower bound of array section.
7351 Expr *getLowerBound() { return cast_or_null<Expr>(SubExprs[LOWER_BOUND]); }
7352 const Expr *getLowerBound() const {
7353 return cast_or_null<Expr>(SubExprs[LOWER_BOUND]);
7354 }
7355
7356 /// Get length of array section.
7357 Expr *getLength() { return cast_or_null<Expr>(SubExprs[LENGTH]); }
7358 const Expr *getLength() const { return cast_or_null<Expr>(SubExprs[LENGTH]); }
7359
7360 /// Get stride of array section.
7362 assert(ASType != OpenACCArraySection &&
7363 "Stride not valid in OpenACC subarrays");
7364 return cast_or_null<Expr>(SubExprs[STRIDE]);
7365 }
7366
7367 const Expr *getStride() const {
7368 assert(ASType != OpenACCArraySection &&
7369 "Stride not valid in OpenACC subarrays");
7370 return cast_or_null<Expr>(SubExprs[STRIDE]);
7371 }
7372
7373 SourceLocation getBeginLoc() const LLVM_READONLY {
7374 return getBase()->getBeginLoc();
7375 }
7376 SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
7377
7378 SourceLocation getColonLocFirst() const { return ColonLocFirst; }
7380 assert(ASType != OpenACCArraySection &&
7381 "second colon for stride not valid in OpenACC subarrays");
7382 return ColonLocSecond;
7383 }
7384 SourceLocation getRBracketLoc() const { return RBracketLoc; }
7385
7386 SourceLocation getExprLoc() const LLVM_READONLY {
7387 return getBase()->getExprLoc();
7388 }
7389
7391 return child_range(
7392 &SubExprs[BASE],
7393 &SubExprs[ASType == OMPArraySection ? END_EXPR : OPENACC_END_EXPR]);
7394 }
7395
7397 return const_child_range(
7398 &SubExprs[BASE],
7399 &SubExprs[ASType == OMPArraySection ? END_EXPR : OPENACC_END_EXPR]);
7400 }
7401
7402private:
7403 /// Set base of the array section.
7404 void setBase(Expr *E) { SubExprs[BASE] = E; }
7405
7406 /// Set lower bound of the array section.
7407 void setLowerBound(Expr *E) { SubExprs[LOWER_BOUND] = E; }
7408
7409 /// Set length of the array section.
7410 void setLength(Expr *E) { SubExprs[LENGTH] = E; }
7411
7412 /// Set length of the array section.
7413 void setStride(Expr *E) {
7414 assert(ASType != OpenACCArraySection &&
7415 "Stride not valid in OpenACC subarrays");
7416 SubExprs[STRIDE] = E;
7417 }
7418
7419 void setColonLocFirst(SourceLocation L) { ColonLocFirst = L; }
7420
7421 void setColonLocSecond(SourceLocation L) {
7422 assert(ASType != OpenACCArraySection &&
7423 "second colon for stride not valid in OpenACC subarrays");
7424 ColonLocSecond = L;
7425 }
7426 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
7427};
7428
7429/// This class represents temporary values used to represent inout and out
7430/// arguments in HLSL. From the callee perspective these parameters are more or
7431/// less __restrict__ T&. They are guaranteed to not alias any memory. inout
7432/// parameters are initialized by the caller, and out parameters are references
7433/// to uninitialized memory.
7434///
7435/// In the caller, the argument expression creates a temporary in local memory
7436/// and the address of the temporary is passed into the callee. There may be
7437/// implicit conversion sequences to initialize the temporary, and on expiration
7438/// of the temporary an inverse conversion sequence is applied as a write-back
7439/// conversion to the source l-value.
7440///
7441/// This AST node has three sub-expressions:
7442/// - An OpaqueValueExpr with a source that is the argument lvalue expression.
7443/// - An OpaqueValueExpr with a source that is an implicit conversion
7444/// sequence from the source lvalue to the argument type.
7445/// - An expression that assigns the second expression into the first,
7446/// performing any necessary conversions.
7447class HLSLOutArgExpr : public Expr {
7448 friend class ASTStmtReader;
7449
7450 enum {
7451 BaseLValue,
7452 CastedTemporary,
7453 WritebackCast,
7454 NumSubExprs,
7455 };
7456
7457 Stmt *SubExprs[NumSubExprs];
7458 bool IsInOut;
7459
7461 Expr *WB, bool IsInOut)
7462 : Expr(HLSLOutArgExprClass, Ty, VK_LValue, OK_Ordinary),
7463 IsInOut(IsInOut) {
7464 SubExprs[BaseLValue] = B;
7465 SubExprs[CastedTemporary] = OpV;
7466 SubExprs[WritebackCast] = WB;
7467 assert(!Ty->isDependentType() && "HLSLOutArgExpr given a dependent type!");
7468 }
7469
7470 explicit HLSLOutArgExpr(EmptyShell Shell)
7471 : Expr(HLSLOutArgExprClass, Shell) {}
7472
7473public:
7474 static HLSLOutArgExpr *Create(const ASTContext &C, QualType Ty,
7475 OpaqueValueExpr *Base, OpaqueValueExpr *OpV,
7476 Expr *WB, bool IsInOut);
7477 static HLSLOutArgExpr *CreateEmpty(const ASTContext &Ctx);
7478
7480 return cast<OpaqueValueExpr>(SubExprs[BaseLValue]);
7481 }
7483 return cast<OpaqueValueExpr>(SubExprs[BaseLValue]);
7484 }
7485
7486 /// Return the l-value expression that was written as the argument
7487 /// in source. Everything else here is implicitly generated.
7488 const Expr *getArgLValue() const {
7490 }
7492
7493 const Expr *getWritebackCast() const {
7494 return cast<Expr>(SubExprs[WritebackCast]);
7495 }
7496 Expr *getWritebackCast() { return cast<Expr>(SubExprs[WritebackCast]); }
7497
7499 return cast<OpaqueValueExpr>(SubExprs[CastedTemporary]);
7500 }
7502 return cast<OpaqueValueExpr>(SubExprs[CastedTemporary]);
7503 }
7504
7505 /// returns true if the parameter is inout and false if the parameter is out.
7506 bool isInOut() const { return IsInOut; }
7507
7508 SourceLocation getBeginLoc() const LLVM_READONLY {
7509 return SubExprs[BaseLValue]->getBeginLoc();
7510 }
7511
7512 SourceLocation getEndLoc() const LLVM_READONLY {
7513 return SubExprs[BaseLValue]->getEndLoc();
7514 }
7515
7516 static bool classof(const Stmt *T) {
7517 return T->getStmtClass() == HLSLOutArgExprClass;
7518 }
7519
7520 // Iterators
7522 return child_range(&SubExprs[BaseLValue], &SubExprs[NumSubExprs]);
7523 }
7524};
7525
7526/// Frontend produces RecoveryExprs on semantic errors that prevent creating
7527/// other well-formed expressions. E.g. when type-checking of a binary operator
7528/// fails, we cannot produce a BinaryOperator expression. Instead, we can choose
7529/// to produce a recovery expression storing left and right operands.
7530///
7531/// RecoveryExpr does not have any semantic meaning in C++, it is only useful to
7532/// preserve expressions in AST that would otherwise be dropped. It captures
7533/// subexpressions of some expression that we could not construct and source
7534/// range covered by the expression.
7535///
7536/// By default, RecoveryExpr uses dependence-bits to take advantage of existing
7537/// machinery to deal with dependent code in C++, e.g. RecoveryExpr is preserved
7538/// in `decltype(<broken-expr>)` as part of the `DependentDecltypeType`. In
7539/// addition to that, clang does not report most errors on dependent
7540/// expressions, so we get rid of bogus errors for free. However, note that
7541/// unlike other dependent expressions, RecoveryExpr can be produced in
7542/// non-template contexts.
7543///
7544/// We will preserve the type in RecoveryExpr when the type is known, e.g.
7545/// preserving the return type for a broken non-overloaded function call, a
7546/// overloaded call where all candidates have the same return type. In this
7547/// case, the expression is not type-dependent (unless the known type is itself
7548/// dependent)
7549///
7550/// One can also reliably suppress all bogus errors on expressions containing
7551/// recovery expressions by examining results of Expr::containsErrors().
7552class RecoveryExpr final : public Expr,
7553 private llvm::TrailingObjects<RecoveryExpr, Expr *> {
7554public:
7555 static RecoveryExpr *Create(ASTContext &Ctx, QualType T,
7556 SourceLocation BeginLoc, SourceLocation EndLoc,
7557 ArrayRef<Expr *> SubExprs);
7558 static RecoveryExpr *CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs);
7559
7560 ArrayRef<Expr *> subExpressions() { return getTrailingObjects(NumExprs); }
7561
7563 return const_cast<RecoveryExpr *>(this)->subExpressions();
7564 }
7565
7567 Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects());
7568 return child_range(B, B + NumExprs);
7569 }
7570
7571 SourceLocation getBeginLoc() const { return BeginLoc; }
7572 SourceLocation getEndLoc() const { return EndLoc; }
7573
7574 static bool classof(const Stmt *T) {
7575 return T->getStmtClass() == RecoveryExprClass;
7576 }
7577
7578private:
7580 SourceLocation EndLoc, ArrayRef<Expr *> SubExprs);
7581 RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
7582 : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
7583
7584 size_t numTrailingObjects(OverloadToken<Stmt *>) const { return NumExprs; }
7585
7586 SourceLocation BeginLoc, EndLoc;
7587 unsigned NumExprs;
7588 friend TrailingObjects;
7589 friend class ASTStmtReader;
7590 friend class ASTStmtWriter;
7591};
7592
7593/// Insertion operator for diagnostics. This allows sending
7594/// Expr into a diagnostic with <<.
7596 const Expr *E) {
7597 DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
7598 return DB;
7599}
7600
7601/// Walk @p E through parens, implicit casts, unary &/*, array subscripts and
7602/// comma operators to find the head of a struct-field access -- typically a
7603/// MemberExpr, or an LValueToRValue ImplicitCastExpr over a pointer-typed
7604/// field. Returns nullptr for shapes we don't handle (multiple subscripts,
7605/// non-comma binary ops, or '&fam' on an array lvalue which designates the
7606/// array-as-a-whole rather than an element pointer).
7607///
7608/// If @p OutArrayIndex / @p OutArrayElementTy are non-null, they receive the
7609/// index expression and base array type for forms like '&p->fam[idx]'.
7610///
7611/// Shared by CGBuiltin's __builtin_*_object_size lowering and the AST
7612/// constant evaluator so they recognize the same 'counted_by' access shapes.
7613const Expr *findStructFieldAccess(const Expr *E,
7614 const Expr **OutArrayIndex = nullptr,
7615 QualType *OutArrayElementTy = nullptr);
7616
7617} // end namespace clang
7618
7619#endif // LLVM_CLANG_AST_EXPR_H
#define V(N, I)
#define PTR(CLASS)
Definition AttrVisitor.h:27
Defines enumerations for traits support.
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition CFG.cpp:2852
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition CharUnits.h:225
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Provides definitions for the atomic synchronization scopes.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
a trap message and trap category.
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const
void setValue(const ASTContext &C, const llvm::APFloat &Val)
unsigned getBitWidth() const
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
std::reverse_iterator< iterator > reverse_iterator
Definition ASTVector.h:89
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ASTVector.h:88
const Stmt ** const_iterator
Definition ASTVector.h:86
AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
Definition Expr.h:4407
SourceLocation getColonLoc() const
Definition Expr.h:4425
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4575
static bool classof(const Stmt *T)
Definition Expr.h:4427
AbstractConditionalOperator(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation qloc, SourceLocation cloc)
Definition Expr.h:4402
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition Expr.h:4581
SourceLocation getQuestionLoc() const
Definition Expr.h:4424
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4587
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4609
static bool classof(const Stmt *T)
Definition Expr.h:4620
void setLabel(LabelDecl *L)
Definition Expr.h:4618
child_range children()
Definition Expr.h:4625
void setLabelLoc(SourceLocation L)
Definition Expr.h:4612
AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, QualType t)
Definition Expr.h:4598
void setAmpAmpLoc(SourceLocation L)
Definition Expr.h:4610
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4615
AddrLabelExpr(EmptyShell Empty)
Build an empty address of a label expression.
Definition Expr.h:4606
SourceLocation getLabelLoc() const
Definition Expr.h:4611
const_child_range children() const
Definition Expr.h:4628
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4614
LabelDecl * getLabel() const
Definition Expr.h:4617
const_child_range children() const
Definition Expr.h:6091
ArrayInitIndexExpr(QualType T)
Definition Expr.h:6076
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6085
friend class ASTReader
Definition Expr.h:6095
static bool classof(const Stmt *S)
Definition Expr.h:6081
child_range children()
Definition Expr.h:6088
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6086
friend class ASTStmtReader
Definition Expr.h:6096
child_range children()
Definition Expr.h:6056
ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
Definition Expr.h:6025
const_child_range children() const
Definition Expr.h:6059
llvm::APInt getArraySize() const
Definition Expr.h:6040
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6052
static bool classof(const Stmt *S)
Definition Expr.h:6045
friend class ASTReader
Definition Expr.h:6063
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6049
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6033
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6038
friend class ASTStmtWriter
Definition Expr.h:6065
friend class ASTStmtReader
Definition Expr.h:6064
const Expr * getStride() const
Definition Expr.h:7367
QualType getElementType() const
Return the effective 'element' type of this array section.
Definition Expr.cpp:5457
SourceLocation getRBracketLoc() const
Definition Expr.h:7384
const_child_range children() const
Definition Expr.h:7396
Expr * getBase()
Get base of the array section.
Definition Expr.h:7347
static bool classof(const Stmt *T)
Definition Expr.h:7339
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7376
Expr * getLength()
Get length of array section.
Definition Expr.h:7357
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition Expr.cpp:5429
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:7386
const Expr * getLowerBound() const
Definition Expr.h:7352
bool isOMPArraySection() const
Definition Expr.h:7343
Expr * getStride()
Get stride of array section.
Definition Expr.h:7361
const Expr * getBase() const
Definition Expr.h:7348
ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, QualType Type, ExprValueKind VK, ExprObjectKind OK, SourceLocation ColonLoc, SourceLocation RBracketLoc)
Definition Expr.h:7309
const Expr * getLength() const
Definition Expr.h:7358
ArraySectionExpr(EmptyShell Shell)
Create an empty array section expression.
Definition Expr.h:7321
friend class ASTStmtWriter
Definition Expr.h:7271
ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, Expr *Stride, QualType Type, ExprValueKind VK, ExprObjectKind OK, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, SourceLocation RBracketLoc)
Definition Expr.h:7294
SourceLocation getColonLocSecond() const
Definition Expr.h:7379
Expr * getLowerBound()
Get lower bound of array section.
Definition Expr.h:7351
QualType getBaseType() const
Returns the effective 'type' of the base of this array section.
Definition Expr.cpp:5475
child_range children()
Definition Expr.h:7390
friend class ASTStmtReader
Definition Expr.h:7270
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7373
bool isOpenACCArraySection() const
Definition Expr.h:7344
SourceLocation getColonLocFirst() const
Definition Expr.h:7378
ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation rbracketloc)
Definition Expr.h:2772
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2820
const Expr * getLHS() const
Definition Expr.h:2795
const_child_range children() const
Definition Expr.h:2832
const Expr * getBase() const
Definition Expr.h:2803
SourceLocation getRBracketLoc() const
Definition Expr.h:2813
const Expr * getRHS() const
Definition Expr.h:2799
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2794
void setRHS(Expr *E)
Definition Expr.h:2800
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2808
const Expr * getIdx() const
Definition Expr.h:2806
SourceLocation getEndLoc() const
Definition Expr.h:2811
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2816
child_range children()
Definition Expr.h:2829
static bool classof(const Stmt *T)
Definition Expr.h:2824
void setLHS(Expr *E)
Definition Expr.h:2796
ArraySubscriptExpr(EmptyShell Shell)
Create an empty array subscript expression.
Definition Expr.h:2782
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:6802
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6811
AsTypeExpr(Expr *SrcExpr, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Definition Expr.h:6793
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_astype token.
Definition Expr.h:6805
const_child_range children() const
Definition Expr.h:6819
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6810
friend class ASTReader
Definition Expr.h:6788
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:6808
static bool classof(const Stmt *T)
Definition Expr.h:6813
friend class ASTStmtReader
Definition Expr.h:6789
child_range children()
Definition Expr.h:6818
Expr ** getSubExprs()
Definition Expr.h:7053
static std::unique_ptr< AtomicScopeModel > getScopeModel(AtomicOp Op)
Get atomic scope model for the atomic op code.
Definition Expr.h:7127
Expr * getVal2() const
Definition Expr.h:7029
SourceLocation getRParenLoc() const
Definition Expr.h:7107
Expr * getOrder() const
Definition Expr.h:7012
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7110
QualType getValueType() const
Definition Expr.cpp:5422
Expr * getScope() const
Definition Expr.h:7015
bool isCmpXChg() const
Definition Expr.h:7062
bool isHIP() const
Definition Expr.h:7095
AtomicOp getOp() const
Definition Expr.h:7041
bool isOpenCL() const
Definition Expr.h:7090
AtomicExpr(EmptyShell Empty)
Build an empty AtomicExpr.
Definition Expr.h:7007
Expr * getVal1() const
Definition Expr.h:7019
child_range children()
Definition Expr.h:7117
StringRef getOpAsString() const
Definition Expr.h:7042
bool threadPrivateMemoryAtomicsAreUndefined() const
Return true if atomics operations targeting allocations in private memory are undefined.
Definition Expr.h:7102
const Expr *const * getSubExprs() const
Definition Expr.h:7054
Expr * getPtr() const
Definition Expr.h:7009
std::unique_ptr< AtomicScopeModel > getScopeModel() const
Get atomic scope model.
Definition Expr.h:7143
Expr * getWeak() const
Definition Expr.h:7035
const_child_range children() const
Definition Expr.h:7120
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7109
AtomicExpr(SourceLocation BLoc, ArrayRef< Expr * > args, QualType t, AtomicOp op, SourceLocation RP)
Definition Expr.cpp:5295
friend class ASTStmtReader
Definition Expr.h:6997
SourceLocation getBuiltinLoc() const
Definition Expr.h:7106
Expr * getOrderFail() const
Definition Expr.h:7025
bool hasVal1Operand() const
Definition Expr.h:7075
unsigned getNumSubExprs() const
Definition Expr.h:7051
static bool classof(const Stmt *T)
Definition Expr.h:7112
bool isVolatile() const
Definition Expr.h:7058
static std::unique_ptr< AtomicScopeModel > create(AtomicScopeModelKind K)
Create an atomic scope model by AtomicScopeModelKind.
Definition SyncScope.h:299
static bool classof(const Stmt *T)
Definition Expr.h:4562
BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, Expr *cond, Expr *lhs, Expr *rhs, SourceLocation qloc, SourceLocation cloc, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:4510
const_child_range children() const
Definition Expr.h:4570
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4555
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4551
BinaryConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition Expr.h:4526
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4535
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4558
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4539
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4544
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4532
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4082
static bool isLogicalOp(Opcode Opc)
Definition Expr.h:4215
void setLHS(Expr *E)
Definition Expr.h:4133
Expr * getLHS() const
Definition Expr.h:4132
child_range children()
Definition Expr.h:4257
BinaryOperator(EmptyShell Empty)
Construct an empty binary operator.
Definition Expr.h:4111
static bool isRelationalOp(Opcode Opc)
Definition Expr.h:4176
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2211
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:4098
const_child_range children() const
Definition Expr.h:4260
static bool isComparisonOp(Opcode Opc)
Definition Expr.h:4182
void setHasStoredFPFeatures(bool B)
Set and fetch the bit that shows whether FPFeatures needs to be allocated in Trailing Storage.
Definition Expr.h:4266
void setOperatorLoc(SourceLocation L)
Definition Expr.h:4125
static bool isShiftOp(Opcode Opc)
Definition Expr.h:4170
bool isComparisonOp() const
Definition Expr.h:4183
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4289
StringRef getOpcodeStr() const
Definition Expr.h:4148
static bool isCommaOp(Opcode Opc)
Definition Expr.h:4185
static Opcode getOpForCompoundAssignment(Opcode Opc)
Definition Expr.h:4229
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4137
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.h:4093
bool isRelationalOp() const
Definition Expr.h:4177
void setRHS(Expr *E)
Definition Expr.h:4135
SourceLocation getOperatorLoc() const
Definition Expr.h:4124
bool isPtrMemOp() const
Definition Expr.h:4162
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition Expr.h:4316
bool hasStoredFPFeatures() const
Definition Expr.h:4267
bool isCompoundAssignmentOp() const
Definition Expr.h:4226
static Opcode negateComparisonOp(Opcode Opc)
Definition Expr.h:4188
bool isLogicalOp() const
Definition Expr.h:4216
bool isMultiplicativeOp() const
Definition Expr.h:4167
SourceLocation getExprLoc() const
Definition Expr.h:4123
static Opcode reverseComparisonOp(Opcode Opc)
Definition Expr.h:4201
static bool isShiftAssignOp(Opcode Opc)
Definition Expr.h:4237
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:4310
bool isShiftOp() const
Definition Expr.h:4171
Expr * getRHS() const
Definition Expr.h:4134
static unsigned sizeOfTrailingObjects(bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition Expr.h:4333
bool isEqualityOp() const
Definition Expr.h:4180
BinaryOperator(StmtClass SC, EmptyShell Empty)
Construct an empty BinaryOperator, SC is CompoundAssignOperator.
Definition Expr.h:4327
void setExcludedOverflowPattern(bool B)
Set and get the bit that informs arithmetic overflow sanitizers whether or not they should exclude ce...
Definition Expr.h:4271
bool isBitwiseOp() const
Definition Expr.h:4174
static BinaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5123
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:4279
static bool classof(const Stmt *S)
Definition Expr.h:4251
bool isAdditiveOp() const
Definition Expr.h:4169
static bool isAdditiveOp(Opcode Opc)
Definition Expr.h:4168
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
Definition Expr.h:4159
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4218
static bool isCompoundAssignmentOp(Opcode Opc)
Definition Expr.h:4223
bool isShiftAssignOp() const
Definition Expr.h:4240
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4140
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:4295
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, const Expr *LHS, const Expr *RHS)
Return true if a binary operator using the specified opcode and operands would match the 'p = (i8*)nu...
Definition Expr.cpp:2236
Opcode getOpcode() const
Definition Expr.h:4127
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used only by Serialization.
Definition Expr.h:4284
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4302
bool isCommaOp() const
Definition Expr.h:4186
bool isAssignmentOp() const
Definition Expr.h:4221
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2173
size_t offsetOfTrailingStorage() const
Definition Expr.h:4389
static bool isEqualityOp(Opcode Opc)
Definition Expr.h:4179
bool hasExcludedOverflowPattern() const
Definition Expr.h:4274
void setOpcode(Opcode Opc)
Definition Expr.h:4130
static bool isBitwiseOp(Opcode Opc)
Definition Expr.h:4173
static bool isMultiplicativeOp(Opcode Opc)
Definition Expr.h:4164
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Build a binary operator, assuming that appropriate storage has been allocated for the trailing object...
Definition Expr.cpp:5086
BinaryOperatorKind Opcode
Definition Expr.h:4087
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4807
BlockExpr(EmptyShell Empty)
Build an empty block expression.
Definition Expr.h:6732
SourceLocation getCaretLocation() const
Definition Expr.cpp:2571
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6743
BlockDecl * TheBlock
Definition Expr.h:6724
child_range children()
Definition Expr.h:6758
BlockDecl * getBlockDecl()
Definition Expr.h:6735
const Stmt * getBody() const
Definition Expr.cpp:2574
BlockExpr(BlockDecl *BD, QualType ty, bool ContainsUnexpandedParameterPack)
Definition Expr.h:6726
const_child_range children() const
Definition Expr.h:6761
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6746
void setBlockDecl(BlockDecl *BD)
Definition Expr.h:6736
static bool classof(const Stmt *T)
Definition Expr.h:6753
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition Expr.cpp:2565
const BlockDecl * getBlockDecl() const
Definition Expr.h:6734
This class is used for builtin types like 'int'.
Definition TypeBase.h:3241
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition TypeBase.h:3326
SourceLocation getRParenLoc() const
Definition Expr.h:4048
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition Expr.cpp:2153
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4051
friend class CastExpr
Definition Expr.h:4061
void setRParenLoc(SourceLocation L)
Definition Expr.h:4049
static bool classof(const Stmt *T)
Definition Expr.h:4056
friend TrailingObjects
Definition Expr.h:4060
SourceLocation getLParenLoc() const
Definition Expr.h:4045
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4052
void setLParenLoc(SourceLocation L)
Definition Expr.h:4046
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:85
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2987
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3191
bool hasStoredFPFeatures() const
Definition Expr.h:3146
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:3098
bool usesMemberSyntax() const
Definition Expr.h:3148
std::optional< llvm::APInt > evaluateBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const
Evaluates the total size in bytes allocated by calling a function decorated with alloc_size.
Definition Expr.cpp:3635
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition Expr.h:3070
static constexpr ADLCallKind NotADL
Definition Expr.h:3053
bool usesADL() const
Definition Expr.h:3144
const Stmt * getPreArg(unsigned I) const
Definition Expr.h:3080
SourceLocation getBeginLoc() const
Definition Expr.h:3321
void setRParenLoc(SourceLocation L)
Definition Expr.h:3319
const_arg_iterator arg_begin() const
Definition Expr.h:3249
static bool classof(const Stmt *T)
Definition Expr.h:3384
llvm::iterator_range< const_arg_iterator > const_arg_range
Definition Expr.h:3237
void setCoroElideSafe(bool V=true)
Definition Expr.h:3162
const Expr *const * getArgs() const
Definition Expr.h:3185
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition Expr.h:3204
ConstExprIterator const_arg_iterator
Definition Expr.h:3235
ExprIterator arg_iterator
Definition Expr.h:3234
child_range children()
Definition Expr.h:3390
std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttr(const ASTContext &Ctx) const
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition Expr.h:3309
void setADLCallKind(ADLCallKind V=UsesADL)
Definition Expr.h:3141
const AllocSizeAttr * getCalleeAllocSizeAttr() const
Try to get the alloc_size attribute of the callee. May return null.
Definition Expr.cpp:3626
llvm::iterator_range< arg_iterator > arg_range
Definition Expr.h:3236
const_arg_range arguments() const
Definition Expr.h:3240
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition Expr.cpp:1620
arg_iterator arg_begin()
Definition Expr.h:3244
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:3274
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Expr.h:3263
arg_iterator arg_end()
Definition Expr.h:3247
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3170
static CallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Create an empty call expression, for deserialization.
Definition Expr.cpp:1563
bool isCallToStdMove() const
Definition Expr.cpp:3676
void setUsesMemberSyntax(bool V=true)
Definition Expr.h:3151
void setPreArg(unsigned I, Stmt *PreArg)
Definition Expr.h:3084
ADLCallKind getADLCallKind() const
Definition Expr.h:3138
Expr * getCallee()
Definition Expr.h:3134
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3286
static constexpr unsigned OffsetToTrailingObjects
Definition Expr.h:3024
void markDependentForPostponedNameLookup()
Used by Sema to implement MSVC-compatible delayed name lookup.
Definition Expr.h:3369
const Expr * getCallee() const
Definition Expr.h:3135
const Decl * getCalleeDecl() const
Definition Expr.h:3165
void computeDependence()
Compute and set dependence bits.
Definition Expr.h:3210
void setStoredFPFeatures(FPOptionsOverride F)
Set FPOptionsOverride in trailing storage. Used only by Serialization.
Definition Expr.h:3268
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3178
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:3280
bool isCoroElideSafe() const
Definition Expr.h:3161
Expr ** getArgs()
Retrieve the call arguments.
Definition Expr.h:3181
const_child_range children() const
Definition Expr.h:3395
CallExpr(StmtClass SC, Expr *Fn, ArrayRef< Expr * > PreArgs, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs, ADLCallKind UsesADL)
Build a call expression, assuming that appropriate storage has been allocated for the trailing object...
Definition Expr.cpp:1501
arg_range arguments()
Definition Expr.h:3239
static constexpr unsigned sizeToAllocateForCallExprSubclass(unsigned SizeOfTrailingObjects)
Definition Expr.h:3027
SourceLocation getEndLoc() const
Definition Expr.h:3340
SourceLocation getRParenLoc() const
Definition Expr.h:3318
static constexpr ADLCallKind UsesADL
Definition Expr.h:3054
bool isBuiltinAssumeFalse(const ASTContext &Ctx) const
Return true if this is a call to __assume() or __builtin_assume() with a non-value-dependent constant...
Definition Expr.cpp:3614
const_arg_iterator arg_end() const
Definition Expr.h:3252
const FunctionDecl * getDirectCallee() const
Definition Expr.h:3173
Stmt * getPreArg(unsigned I)
Definition Expr.h:3076
friend class ASTStmtReader
Definition Expr.h:3343
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.h:3092
Decl * getCalleeDecl()
Definition Expr.h:3164
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1631
bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const
Returns true if this is a call to a builtin which does not evaluate side-effects within its arguments...
Definition Expr.cpp:1625
void setNumArgsUnsafe(unsigned NewNumArgs)
Bluntly set a new number of arguments without doing any checks whatsoever.
Definition Expr.h:3232
void setCallee(Expr *F)
Definition Expr.h:3136
unsigned getNumPreArgs() const
Definition Expr.h:3089
ArrayRef< Stmt * > getRawSubExprs() const
This method provides fast access to all the subexpressions of a CallExpr without going through the sl...
Definition Expr.h:3258
bool hasUnusedResultAttr(const ASTContext &Ctx) const
Returns true if this call expression should warn on unused results.
Definition Expr.h:3314
void shrinkNumArgs(unsigned NewNumArgs)
Reduce the number of arguments in this call expression.
Definition Expr.h:3223
const Expr * getArg(unsigned Arg) const
Definition Expr.h:3195
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3720
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.cpp:2083
path_iterator path_begin()
Definition Expr.h:3790
unsigned path_size() const
Definition Expr.h:3789
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes.
Definition Expr.cpp:2032
const Expr * getSubExprAsWritten() const
Definition Expr.h:3778
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:2010
CastKind getCastKind() const
Definition Expr.h:3764
void setCastKind(CastKind K)
Definition Expr.h:3765
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
Definition Expr.h:3807
const FieldDecl * getTargetUnionField() const
Definition Expr.h:3814
CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize, bool HasFPFeatures)
Construct an empty cast.
Definition Expr.h:3746
static bool classof(const Stmt *T)
Definition Expr.h:3864
llvm::iterator_range< path_const_iterator > path() const
Definition Expr.h:3810
bool hasStoredFPFeatures() const
Definition Expr.h:3819
bool changesVolatileQualification() const
Return.
Definition Expr.h:3854
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
Definition Expr.cpp:2064
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Expr.h:3822
CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind, Expr *op, unsigned BasePathSize, bool HasFPFeatures)
Definition Expr.h:3733
const Expr * getSubExpr() const
Definition Expr.h:3771
path_iterator path_end()
Definition Expr.h:3791
const_child_range children() const
Definition Expr.h:3871
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:3759
CXXBaseSpecifier ** path_iterator
Definition Expr.h:3786
path_const_iterator path_end() const
Definition Expr.h:3793
const char * getCastKindName() const
Definition Expr.h:3768
child_range children()
Definition Expr.h:3870
friend class ASTStmtReader
Definition Expr.h:3730
void setSubExpr(Expr *E)
Definition Expr.h:3772
path_const_iterator path_begin() const
Definition Expr.h:3792
const CXXBaseSpecifier *const * path_const_iterator
Definition Expr.h:3787
bool path_empty() const
Definition Expr.h:3788
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3840
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:3828
Expr * getSubExpr()
Definition Expr.h:3770
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operation.
Definition Expr.h:3834
void setValue(unsigned Val)
Definition Expr.h:1655
SourceLocation getLocation() const
Definition Expr.h:1641
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1647
void setLocation(SourceLocation Location)
Definition Expr.h:1651
static bool classof(const Stmt *T)
Definition Expr.h:1657
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition Expr.cpp:1026
unsigned getValue() const
Definition Expr.h:1649
child_range children()
Definition Expr.h:1664
void setKind(CharacterLiteralKind kind)
Definition Expr.h:1652
const_child_range children() const
Definition Expr.h:1667
CharacterLiteralKind getKind() const
Definition Expr.h:1642
CharacterLiteral(EmptyShell Empty)
Construct an empty character literal.
Definition Expr.h:1639
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1646
CharacterLiteral(unsigned value, CharacterLiteralKind kind, QualType type, SourceLocation l)
Definition Expr.h:1630
void setRParenLoc(SourceLocation L)
Definition Expr.h:4943
void setIsConditionTrue(bool isTrue)
Definition Expr.h:4920
SourceLocation getBuiltinLoc() const
Definition Expr.h:4939
Expr * getLHS() const
Definition Expr.h:4934
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4928
bool isConditionDependent() const
Definition Expr.h:4922
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:4940
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4915
ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation RP, bool condIsTrue)
Definition Expr.h:4898
void setRHS(Expr *E)
Definition Expr.h:4937
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4946
child_range children()
Definition Expr.h:4953
Expr * getRHS() const
Definition Expr.h:4936
SourceLocation getRParenLoc() const
Definition Expr.h:4942
ChooseExpr(EmptyShell Empty)
Build an empty __builtin_choose_expr.
Definition Expr.h:4911
const_child_range children() const
Definition Expr.h:4956
Expr * getCond() const
Definition Expr.h:4932
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4945
void setCond(Expr *E)
Definition Expr.h:4933
void setLHS(Expr *E)
Definition Expr.h:4935
static bool classof(const Stmt *T)
Definition Expr.h:4948
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4344
void setComputationResultType(QualType T)
Definition Expr.h:4382
static CompoundAssignOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5145
CompoundAssignOperator(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, ExprValueKind VK, ExprObjectKind OK, SourceLocation OpLoc, FPOptionsOverride FPFeatures, QualType CompLHSType, QualType CompResultType)
Definition Expr.h:4354
QualType getComputationLHSType() const
Definition Expr.h:4378
void setComputationLHSType(QualType T)
Definition Expr.h:4379
static bool classof(const Stmt *S)
Definition Expr.h:4384
QualType getComputationResultType() const
Definition Expr.h:4381
void setFileScope(bool FS)
Definition Expr.h:3682
const_child_range children() const
Definition Expr.h:3711
void setTypeSourceInfo(TypeSourceInfo *tinfo)
Definition Expr.h:3690
bool hasStaticStorage() const
Definition Expr.h:3694
SourceLocation getLParenLoc() const
Definition Expr.h:3684
child_range children()
Definition Expr.h:3710
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:3698
APValue & getStaticValue() const
Definition Expr.cpp:5738
CompoundLiteralExpr(EmptyShell Empty)
Construct an empty compound literal.
Definition Expr.h:3674
void setLParenLoc(SourceLocation L)
Definition Expr.h:3685
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:3703
APValue & getOrCreateStaticValue(ASTContext &Ctx) const
Definition Expr.cpp:5729
bool isFileScope() const
Definition Expr.h:3681
static bool classof(const Stmt *T)
Definition Expr.h:3705
const Expr * getInitializer() const
Definition Expr.h:3677
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3687
void setInitializer(Expr *E)
Definition Expr.h:3679
CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope)
Definition Expr.h:3665
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
ConditionalOperator - The ?
Definition Expr.h:4435
const_child_range children() const
Definition Expr.h:4487
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4467
Expr * getLHS() const
Definition Expr.h:4469
static bool classof(const Stmt *T)
Definition Expr.h:4479
ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, SourceLocation CLoc, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:4441
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4472
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4458
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition Expr.h:4462
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4475
child_range children()
Definition Expr.h:4484
Expr * getRHS() const
Definition Expr.h:4470
friend class ASTStmtReader
Definition Expr.h:4439
ConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition Expr.h:4453
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantResultStorageKind getStorageKind(const APValue &Value)
Definition Expr.cpp:308
child_range children()
Definition Expr.h:1183
void MoveIntoResult(APValue &Value, const ASTContext &Context)
Definition Expr.cpp:384
llvm::APSInt getResultAsAPSInt() const
Definition Expr.cpp:407
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1152
ConstantResultStorageKind getResultStorageKind() const
Definition Expr.h:1171
void SetResult(APValue Value, const ASTContext &Context)
Definition Expr.h:1163
APValue::ValueKind getResultAPValueKind() const
Definition Expr.h:1168
static bool classof(const Stmt *T)
Definition Expr.h:1159
bool hasAPValueResult() const
Definition Expr.h:1177
friend class ASTStmtWriter
Definition Expr.h:1108
const_child_range children() const
Definition Expr.h:1184
friend class ASTStmtReader
Definition Expr.h:1107
bool isImmediateInvocation() const
Definition Expr.h:1174
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1155
static ConstantExpr * CreateEmpty(const ASTContext &Context, ConstantResultStorageKind StorageKind)
Definition Expr.cpp:373
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4763
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4831
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4867
const_child_range children() const
Definition Expr.h:4878
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:4840
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:4816
friend class ASTReader
Definition Expr.h:4770
static ConvertVectorExpr * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5711
static bool classof(const Stmt *T)
Definition Expr.h:4872
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4870
child_range children()
Definition Expr.h:4877
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4869
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4864
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:4826
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4856
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition Expr.h:4836
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:4821
friend class ASTStmtReader
Definition Expr.h:4771
void setTypeSourceInfo(TypeSourceInfo *ti)
Definition Expr.h:4859
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4853
FPOptionsOverride getFPOptionsOverride() const
Definition Expr.h:4846
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition Expr.h:1465
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1401
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1445
NestedNameSpecifier getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
Definition Expr.h:1391
void setIsImmediateEscalating(bool Set)
Definition Expr.h:1502
const_child_range children() const
Definition Expr.h:1525
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1494
void setDecl(ValueDecl *NewD)
Definition Expr.cpp:550
bool hasTemplateKWAndArgsInfo() const
Definition Expr.h:1411
const NamedDecl * getFoundDecl() const
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1407
static DeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Construct an empty declaration reference expression.
Definition Expr.cpp:535
void setLocation(SourceLocation L)
Definition Expr.h:1367
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition Expr.h:1449
DeclarationNameInfo getNameInfo() const
Definition Expr.h:1362
void setHadMultipleCandidates(bool V=true)
Sets the flag telling whether this expression refers to a function that was resolved from an overload...
Definition Expr.h:1483
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1417
bool isCapturedByCopyInLambdaWithExplicitObjectParameter() const
Definition Expr.h:1506
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1425
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
Definition Expr.h:1379
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1383
ValueDecl * getDecl()
Definition Expr.h:1358
child_range children()
Definition Expr.h:1521
const ValueDecl * getDecl() const
Definition Expr.h:1359
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition Expr.h:1457
friend class ASTStmtWriter
Definition Expr.h:1292
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1471
static bool classof(const Stmt *T)
Definition Expr.h:1516
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1488
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:557
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1477
friend class ASTStmtReader
Definition Expr.h:1291
void setCapturedByCopyInLambdaWithExplicitObjectParameter(bool Set, const ASTContext &Context)
Definition Expr.h:1510
SourceLocation getBeginLoc() const
Definition Expr.h:1369
bool hasTemplateKeyword() const
Determines whether the name in this declaration reference was preceded by the template keyword.
Definition Expr.h:1441
SourceLocation getLocation() const
Definition Expr.h:1366
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1433
bool isImmediateEscalating() const
Definition Expr.h:1498
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DeclarationNameLoc - Additional source/type location info for a declaration name.
Represents a single C99 designator.
Definition Expr.h:5644
SourceRange getSourceRange() const LLVM_READONLY
Definition Expr.h:5816
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5806
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5771
struct FieldDesignatorInfo FieldInfo
A field designator, e.g., ".x".
Definition Expr.h:5706
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5725
struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo
An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
Definition Expr.h:5709
void setFieldDecl(FieldDecl *FD)
Definition Expr.h:5742
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5761
FieldDecl * getFieldDecl() const
Definition Expr.h:5735
SourceLocation getFieldLoc() const
Definition Expr.h:5752
SourceLocation getRBracketLoc() const
Definition Expr.h:5800
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5812
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4822
SourceLocation getEllipsisLoc() const
Definition Expr.h:5794
SourceLocation getDotLoc() const
Definition Expr.h:5747
SourceLocation getLBracketLoc() const
Definition Expr.h:5788
Represents a C99 designated initializer expression.
Definition Expr.h:5601
bool isDirectInit() const
Whether this designated initializer should result in direct-initialization of the designated subobjec...
Definition Expr.h:5861
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Definition Expr.cpp:4876
Expr * getArrayRangeEnd(const Designator &D) const
Definition Expr.cpp:4931
void setInit(Expr *init)
Definition Expr.h:5873
const_child_range children() const
Definition Expr.h:5910
const Designator * getDesignator(unsigned Idx) const
Definition Expr.h:5843
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5883
SourceRange getDesignatorsSourceRange() const
Definition Expr.cpp:4892
void setSubExpr(unsigned Idx, Expr *E)
Definition Expr.h:5887
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5865
Expr * getArrayRangeStart(const Designator &D) const
Definition Expr.cpp:4926
void ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last)
Replaces the designator at index Idx with the series of designators in [First, Last).
Definition Expr.cpp:4938
MutableArrayRef< Designator > designators()
Definition Expr.h:5834
void setGNUSyntax(bool GNU)
Definition Expr.h:5866
child_range children()
Definition Expr.h:5906
void setEqualOrColonLoc(SourceLocation L)
Definition Expr.h:5857
Expr * getArrayIndex(const Designator &D) const
Definition Expr.cpp:4921
Designator * getDesignator(unsigned Idx)
Definition Expr.h:5842
ArrayRef< Designator > designators() const
Definition Expr.h:5838
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5869
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5831
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:4900
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
Definition Expr.cpp:4883
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:4917
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5856
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5881
static bool classof(const Stmt *T)
Definition Expr.h:5901
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:4981
DesignatedInitUpdateExpr(EmptyShell Empty)
Definition Expr.h:5973
DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc, Expr *baseExprs, SourceLocation rBraceLoc)
Definition Expr.cpp:4964
static bool classof(const Stmt *T)
Definition Expr.h:5979
void setBase(Expr *Base)
Definition Expr.h:5984
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:4985
const_child_range children() const
Definition Expr.h:5996
void setUpdater(Expr *Updater)
Definition Expr.h:5989
InitListExpr * getUpdater() const
Definition Expr.h:5986
Designator - A designator in a C99 designated initializer.
Definition Designator.h:38
child_range children()
Definition Expr.h:6646
IdentifierInfo & getAccessor() const
Definition Expr.h:6635
void setAccessorLoc(SourceLocation L)
Definition Expr.h:6639
SourceLocation AccessorLoc
Definition Expr.h:6617
void setAccessor(IdentifierInfo *II)
Definition Expr.h:6636
const Expr * getBase() const
Definition Expr.h:6631
const_child_range children() const
Definition Expr.h:6647
SourceLocation getAccessorLoc() const
Definition Expr.h:6638
IdentifierInfo * Accessor
Definition Expr.h:6616
void setBase(Expr *E)
Definition Expr.h:6633
ElementAccessExprBase(StmtClass SC, EmptyShell Empty)
Definition Expr.h:6627
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6644
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6641
ElementAccessExprBase(StmtClass SC, QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc, ExprObjectKind OK)
Definition Expr.h:6619
BaseTy::pointer operator->() const
Definition Expr.h:5240
ChildElementIter & operator++()
Definition Expr.h:5242
BaseTy::reference operator*() const
Definition Expr.h:5228
bool operator==(ChildElementIter Other) const
Definition Expr.h:5253
unsigned getStartingElementPos() const
Definition Expr.h:5200
ChildElementIter< false > begin()
Definition Expr.h:5285
bool doForEachDataElement(Call &&C, unsigned &StartingIndexInArray, Targs &&...Fargs) const
Definition Expr.h:5292
llvm::iterator_range< ChildElementIter< false > > fake_child_range
Definition Expr.h:5259
SourceLocation getEndLoc() const
Definition Expr.h:5194
ChildElementIter< true > begin() const
Definition Expr.h:5287
StringLiteral * getDataStringLiteral() const
Definition Expr.h:5196
const_fake_child_range underlying_data_elements() const
Definition Expr.h:5267
EmbedExpr(EmptyShell Empty)
Definition Expr.h:5190
child_range children()
Definition Expr.h:5273
EmbedDataStorage * getData() const
Definition Expr.h:5198
EmbedExpr(const ASTContext &Ctx, SourceLocation Loc, EmbedDataStorage *Data, unsigned Begin, unsigned NumOfElements)
Definition Expr.cpp:2425
StringRef getFileName() const
Definition Expr.h:5197
fake_child_range underlying_data_elements()
Definition Expr.h:5262
SourceLocation getBeginLoc() const
Definition Expr.h:5193
SourceLocation getLocation() const
Definition Expr.h:5192
static bool classof(const Stmt *T)
Definition Expr.h:5281
llvm::iterator_range< ChildElementIter< true > > const_fake_child_range
Definition Expr.h:5260
friend class ASTStmtReader
Definition Expr.h:5304
const_child_range children() const
Definition Expr.h:5277
size_t getDataElementCount() const
Definition Expr.h:5201
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3558
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3994
ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, CastKind kind, Expr *op, unsigned PathSize, bool HasFPFeatures, TypeSourceInfo *writtenTy)
Definition Expr.h:3978
void setTypeInfoAsWritten(TypeSourceInfo *writtenTy)
Definition Expr.h:3995
static bool classof(const Stmt *T)
Definition Expr.h:4001
ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, bool HasFPFeatures)
Construct an empty explicit cast.
Definition Expr.h:3987
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition Expr.h:3999
The return type of classify().
Definition Expr.h:340
bool isLValue() const
Definition Expr.h:391
bool isPRValue() const
Definition Expr.h:394
bool isXValue() const
Definition Expr.h:392
ModifiableType
The results of modification testing.
Definition Expr.h:359
ModifiableType getModifiable() const
Definition Expr.h:387
bool isGLValue() const
Definition Expr.h:393
Kinds getKind() const
Definition Expr.h:386
Kinds
The various classification results. Most of these mean prvalue.
Definition Expr.h:343
static Classification makeSimpleLValue()
Create a simple, modifiable lvalue.
Definition Expr.h:399
bool isRValue() const
Definition Expr.h:395
bool isModifiable() const
Definition Expr.h:396
This represents one expression.
Definition Expr.h:113
LValueClassification
Definition Expr.h:290
@ LV_DuplicateMatrixComponents
Definition Expr.h:295
@ LV_ArrayTemporary
Definition Expr.h:301
@ LV_DuplicateVectorComponents
Definition Expr.h:294
@ LV_ClassTemporary
Definition Expr.h:300
@ LV_InvalidMessageExpression
Definition Expr.h:297
@ LV_NotObjectType
Definition Expr.h:292
@ LV_MemberFunction
Definition Expr.h:298
@ LV_InvalidExpression
Definition Expr.h:296
@ LV_IncompleteVoidType
Definition Expr.h:293
@ LV_Valid
Definition Expr.h:291
@ LV_SubObjCPropertySetting
Definition Expr.h:299
Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const
ClassifyModifiable - Classify this expression according to the C++11 expression taxonomy,...
Definition Expr.h:428
Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:124
Expr(StmtClass SC, EmptyShell)
Construct an empty expression.
Definition Expr.h:134
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
EnumConstantDecl * getEnumConstantDecl()
If this expression refers to an enum constant, retrieve its declaration.
Definition Expr.cpp:4312
static bool isPotentialConstantExpr(const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExpr - Return true if this function's definition might be usable in a constant exp...
bool isReadIfDiscardedInCPlusPlus11() const
Determine whether an lvalue-to-rvalue conversion should implicitly be applied to this expression if i...
Definition Expr.cpp:2598
bool isXValue() const
Definition Expr.h:287
bool isIntegerConstantExpr(const ASTContext &Ctx) const
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExprUnevaluated - Return true if this expression might be usable in a constant exp...
bool isGLValue() const
Definition Expr.h:288
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Definition Expr.cpp:3150
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, does not have an incomplet...
SideEffectsKind
Definition Expr.h:691
@ SE_AllowSideEffects
Allow any unmodeled side effect.
Definition Expr.h:695
@ SE_NoSideEffects
Strictly evaluate the expression.
Definition Expr.h:692
@ SE_AllowUndefinedBehavior
Allow UB that we can give a value, but not arbitrary unmodeled side effects.
Definition Expr.h:693
static bool classof(const Stmt *T)
Definition Expr.h:1051
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Definition Expr.cpp:3079
Expr & operator=(const Expr &)=delete
static std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType)
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition Expr.cpp:1664
bool EvaluateCharRangeAsString(std::string &Result, const Expr *SizeExpression, const Expr *PtrExpression, ASTContext &Ctx, EvalResult &Status) const
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
Definition Expr.cpp:3328
const Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) const
Definition Expr.h:988
llvm::APSInt EvaluateKnownConstIntCheckOverflow(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition Expr.cpp:3128
void setType(QualType t)
Definition Expr.h:146
bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
isUnusedResultAWarning - Return true if this immediate expression should be warned about if the resul...
Definition Expr.cpp:2664
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:178
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:448
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition Expr.cpp:4319
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:195
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:242
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Skip past any parentheses and lvalue casts which might surround this expression until reaching a fixe...
Definition Expr.cpp:3140
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition Expr.cpp:4025
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
Definition Expr.cpp:70
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition Expr.cpp:3123
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3111
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
Definition Expr.cpp:3132
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Definition Expr.h:247
bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsFloat - Return true if this is a constant which we can fold and convert to a floating point...
bool isObjCSelfExpr() const
Check if this expression is the ObjC 'self' implicit parameter.
Definition Expr.cpp:4247
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3119
bool isFlexibleArrayMemberLike(const ASTContext &Context, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution=false) const
Check whether this array fits the idiom of a flexible array member, depending on the value of -fstric...
Definition Expr.cpp:212
bool hasPlaceholderType(BuiltinType::Kind K) const
Returns whether this expression has a specific placeholder type.
Definition Expr.h:532
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD, EvalResult &Result, bool IsConstantInitializer) const
EvaluateAsInitializer - Evaluate an expression as if it were the initializer of the given declaration...
bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsFixedPoint - Return true if this is a constant which we can fold and convert to a fixed poi...
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
Expr * IgnoreParenBaseCasts() LLVM_READONLY
Skip past any parentheses and derived-to-base casts until reaching a fixed point.
Definition Expr.cpp:3145
bool isConstantInitializer(ASTContext &Ctx, bool ForRef=false, const Expr **Culprit=nullptr) const
Returns true if this expression can be emitted to IR as a constant, and thus can be used as a constan...
Definition Expr.cpp:3380
bool isPRValue() const
Definition Expr.h:286
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition Expr.h:285
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
Definition Expr.cpp:3372
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition Expr.cpp:4265
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
Definition Expr.h:845
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition Expr.h:851
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
Definition Expr.h:847
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
Definition Expr.h:855
Expr * IgnoreUnlessSpelledInSource()
Skip past any invisible AST nodes which might surround this statement, such as ExprWithCleanups or Im...
Definition Expr.cpp:3176
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:455
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
Expr * IgnoreCasts() LLVM_READONLY
Skip past any casts which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3107
Decl * getReferencedDeclOfCallee()
Definition Expr.cpp:1574
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3115
std::optional< uint64_t > tryEvaluateStrLen(const ASTContext &Ctx) const
If the current Expr is a pointer, this will try to statically determine the strlen of the string poin...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition Expr.cpp:3722
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:224
const Expr * getBestDynamicClassTypeExpr() const
Get the inner expression that determines the best dynamic class.
Definition Expr.cpp:45
const Expr * IgnoreUnlessSpelledInSource() const
Definition Expr.h:882
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
std::optional< std::string > tryEvaluateString(ASTContext &Ctx) const
If the current Expr can be evaluated to a pointer to a null-terminated constant string,...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3103
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
Definition Expr.h:822
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
Definition Expr.h:831
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
Definition Expr.h:834
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
Definition Expr.h:837
@ NPCK_GNUNull
Expression is a GNU-style __null constant.
Definition Expr.h:840
@ NPCK_NotNull
Expression is not a Null pointer constant.
Definition Expr.h:824
bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsBooleanCondition - Return true if this is a constant which we can fold and convert to a boo...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
Definition Expr.cpp:3286
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
Definition Expr.cpp:4104
QualType getEnumCoercedType(const ASTContext &Ctx) const
If this expression is an enumeration constant, return the enumeration type under which said constant ...
Definition Expr.cpp:272
bool isBoundMemberFunction(ASTContext &Ctx) const
Returns true if this expression is a bound member function.
Definition Expr.cpp:3073
Expr()=delete
ConstantExprKind
Definition Expr.h:769
@ ClassTemplateArgument
A class template argument. Such a value is used for code generation.
Definition Expr.h:777
@ Normal
An integer constant expression (an array bound, enumerator, case value, bit-field width,...
Definition Expr.h:772
@ ImmediateInvocation
An immediate invocation.
Definition Expr.h:781
@ NonClassTemplateArgument
A non-class template argument.
Definition Expr.h:775
std::optional< uint64_t > tryEvaluateObjectSize(const ASTContext &Ctx, unsigned Type) const
If the current Expr is a pointer, this will try to statically determine the number of bytes available...
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition Expr.h:465
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
const FieldDecl * getSourceBitField() const
Definition Expr.h:498
static bool isSameComparisonOperand(const Expr *E1, const Expr *E2)
Checks that the two Expr's will refer to the same value as a comparison operand.
Definition Expr.cpp:4356
void setObjectKind(ExprObjectKind Cat)
setObjectKind - Set the object kind produced by this expression.
Definition Expr.h:468
friend class ASTImporter
Definition Expr.h:141
bool refersToMatrixElement() const
Returns whether this expression refers to a matrix element.
Definition Expr.h:518
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
Definition Expr.h:480
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3247
isModifiableLvalueResult
Definition Expr.h:306
@ MLV_DuplicateVectorComponents
Definition Expr.h:310
@ MLV_LValueCast
Definition Expr.h:313
@ MLV_InvalidMessageExpression
Definition Expr.h:322
@ MLV_DuplicateMatrixComponents
Definition Expr.h:311
@ MLV_ConstQualifiedField
Definition Expr.h:316
@ MLV_InvalidExpression
Definition Expr.h:312
@ MLV_IncompleteType
Definition Expr.h:314
@ MLV_Valid
Definition Expr.h:307
@ MLV_ConstQualified
Definition Expr.h:315
@ MLV_NoSetterProperty
Definition Expr.h:319
@ MLV_ArrayTemporary
Definition Expr.h:324
@ MLV_SubObjCPropertySetting
Definition Expr.h:321
@ MLV_ConstAddrSpace
Definition Expr.h:317
@ MLV_MemberFunction
Definition Expr.h:320
@ MLV_NotObjectType
Definition Expr.h:308
@ MLV_ArrayType
Definition Expr.h:318
@ MLV_ClassTemporary
Definition Expr.h:323
@ MLV_IncompleteVoidType
Definition Expr.h:309
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
Definition Expr.h:416
QualType getType() const
Definition Expr.h:145
const Decl * getReferencedDeclOfCallee() const
Definition Expr.h:503
bool hasNonTrivialCall(const ASTContext &Ctx) const
Determine whether this expression involves a call to any function that is not trivial.
Definition Expr.cpp:4092
bool isOrdinaryOrBitFieldObject() const
Definition Expr.h:459
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:527
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition Expr.cpp:4344
friend class ASTStmtReader
Definition Expr.h:142
bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const
isCXX98IntegralConstantExpr - Return true if this expression is an integral constant expression in C+...
const ValueDecl * getAsBuiltinConstantDeclRef(const ASTContext &Context) const
If this expression is an unambiguous reference to a single declaration, in the style of __builtin_fun...
Definition Expr.cpp:232
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
Definition Expr.cpp:3034
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:438
bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx, const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This=nullptr) const
EvaluateWithSubstitution - Evaluate an expression as if from the context of a call to the given funct...
const Expr * skipRValueSubobjectAdjustments() const
Definition Expr.h:1040
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Definition Expr.cpp:138
bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result=nullptr, bool AllowRelaxedEval=false) const
isCXX11ConstantExpr - Return true if this expression is a constant expression in C++11.
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Definition Expr.h:138
Expr(const Expr &)=delete
Expr(Expr &&)=delete
void EvaluateForOverflow(const ASTContext &Ctx) const
ExprDependence getDependence() const
Definition Expr.h:165
Expr & operator=(Expr &&)=delete
const EnumConstantDecl * getEnumConstantDecl() const
Definition Expr.h:494
const ObjCPropertyRefExpr * getObjCProperty() const
If this expression is an l-value for an Objective C property, find the underlying property reference ...
Definition Expr.cpp:4228
ExtVectorElementExpr(QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc)
Definition Expr.h:6662
ExtVectorElementExpr(EmptyShell Empty)
Build an empty vector element expression.
Definition Expr.h:6669
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition Expr.cpp:4490
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
Definition Expr.cpp:4472
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition Expr.cpp:4585
static bool classof(const Stmt *T)
Definition Expr.h:6687
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition Expr.cpp:4476
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
bool requiresTrailingStorage() const
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
bool allowFPContractWithinStatement() const
Represents a member of a struct/union/class.
Definition Decl.h:3295
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1601
std::string getValueAsString(unsigned Radix) const
Definition Expr.cpp:1016
unsigned getScale() const
Definition Expr.h:1605
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1597
const_child_range children() const
Definition Expr.h:1618
void setLocation(SourceLocation Location)
Definition Expr.h:1603
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1595
static bool classof(const Stmt *T)
Definition Expr.h:1608
void setScale(unsigned S)
Definition Expr.h:1606
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
Definition Expr.cpp:1003
child_range children()
Definition Expr.h:1615
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1598
SourceLocation getLocation() const
Definition Expr.h:1727
llvm::APFloatBase::Semantics getRawSemantics() const
Get a raw enumeration value representing the floating-point semantics of this literal (32-bit IEEE,...
Definition Expr.h:1696
child_range children()
Definition Expr.h:1738
const llvm::fltSemantics & getSemantics() const
Return the APFloat semantics this literal uses.
Definition Expr.h:1708
void setValue(const ASTContext &C, const llvm::APFloat &Val)
Definition Expr.h:1689
const_child_range children() const
Definition Expr.h:1741
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1730
void setRawSemantics(llvm::APFloatBase::Semantics Sem)
Set the raw enumeration value representing the floating-point semantics of this literal (32-bit IEEE,...
Definition Expr.h:1703
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
Definition Expr.cpp:1095
llvm::APFloat getValue() const
Definition Expr.h:1686
void setExact(bool E)
Definition Expr.h:1720
static bool classof(const Stmt *T)
Definition Expr.h:1733
void setLocation(SourceLocation L)
Definition Expr.h:1728
bool isExact() const
Definition Expr.h:1719
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1731
void setSemantics(const llvm::fltSemantics &Sem)
Set the APFloat semantics this literal uses.
Definition Expr.h:1715
Expr * getSubExpr()
Definition Expr.h:1083
FullExpr(StmtClass SC, EmptyShell Empty)
Definition Expr.h:1079
void setSubExpr(Expr *E)
As with any mutator of the AST, be very careful when modifying an existing AST to preserve its invari...
Definition Expr.h:1087
Stmt * SubExpr
Definition Expr.h:1071
static bool classof(const Stmt *T)
Definition Expr.h:1089
FullExpr(StmtClass SC, Expr *subexpr)
Definition Expr.h:1073
const Expr * getSubExpr() const
Definition Expr.h:1082
Represents a function declaration or definition.
Definition Decl.h:2059
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
SourceLocation getTokenLocation() const
getTokenLocation - The location of the __null token.
Definition Expr.h:4981
static bool classof(const Stmt *T)
Definition Expr.h:4987
child_range children()
Definition Expr.h:4992
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4984
const_child_range children() const
Definition Expr.h:4995
GNUNullExpr(QualType Ty, SourceLocation Loc)
Definition Expr.h:4972
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4985
GNUNullExpr(EmptyShell Empty)
Build an empty GNU __null expression.
Definition Expr.h:4978
void setTokenLocation(SourceLocation L)
Definition Expr.h:4982
SourceLocation getBeginLoc() const
Definition Expr.h:6592
AssociationTy< false > Association
Definition Expr.h:6465
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6509
static bool classof(const Stmt *T)
Definition Expr.h:6595
const Expr * getControllingExpr() const
Definition Expr.h:6501
unsigned getNumAssocs() const
The number of association expressions.
Definition Expr.h:6474
const_association_range associations() const
Definition Expr.h:6576
AssociationIteratorTy< true > ConstAssociationIterator
Definition Expr.h:6468
SourceLocation getEndLoc() const
Definition Expr.h:6593
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6529
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6490
ConstAssociation getAssociation(unsigned I) const
Definition Expr.h:6553
association_range associations()
Definition Expr.h:6565
AssociationTy< true > ConstAssociation
Definition Expr.h:6466
SourceLocation getGenericLoc() const
Definition Expr.h:6587
SourceLocation getRParenLoc() const
Definition Expr.h:6591
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6479
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6518
AssociationIteratorTy< false > AssociationIterator
Definition Expr.h:6467
SourceLocation getDefaultLoc() const
Definition Expr.h:6590
llvm::iterator_range< AssociationIterator > association_range
Definition Expr.h:6469
const Expr * getResultExpr() const
Definition Expr.h:6523
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6486
child_range children()
Definition Expr.h:6599
friend class ASTStmtWriter
Definition Expr.h:6234
const_child_range children() const
Definition Expr.h:6603
Association getAssociation(unsigned I)
Return the Ith association expression with its TypeSourceInfo, bundled together in GenericSelectionEx...
Definition Expr.h:6542
friend class ASTStmtReader
Definition Expr.h:6233
bool isTypePredicate() const
Whether this generic selection uses a type as its controlling argument.
Definition Expr.h:6492
const TypeSourceInfo * getControllingType() const
Definition Expr.h:6512
llvm::iterator_range< ConstAssociationIterator > const_association_range
Definition Expr.h:6470
static GenericSelectionExpr * CreateEmpty(const ASTContext &Context, unsigned NumAssocs)
Create an empty generic selection expression for deserialization.
Definition Expr.cpp:4810
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6497
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6534
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7447
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7512
const OpaqueValueExpr * getCastedTemporary() const
Definition Expr.h:7498
const OpaqueValueExpr * getOpaqueArgLValue() const
Definition Expr.h:7479
Expr * getWritebackCast()
Definition Expr.h:7496
bool isInOut() const
returns true if the parameter is inout and false if the parameter is out.
Definition Expr.h:7506
static HLSLOutArgExpr * CreateEmpty(const ASTContext &Ctx)
Definition Expr.cpp:5697
static bool classof(const Stmt *T)
Definition Expr.h:7516
Expr * getArgLValue()
Definition Expr.h:7491
child_range children()
Definition Expr.h:7521
OpaqueValueExpr * getCastedTemporary()
Definition Expr.h:7501
const Expr * getWritebackCast() const
Definition Expr.h:7493
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7508
const Expr * getArgLValue() const
Return the l-value expression that was written as the argument in source.
Definition Expr.h:7488
OpaqueValueExpr * getOpaqueArgLValue()
Definition Expr.h:7482
friend class ASTStmtReader
Definition Expr.h:7448
One of these records is kept for each identifier that is lexed.
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1770
ImaginaryLiteral(Expr *val, QualType Ty)
Definition Expr.h:1754
const Expr * getSubExpr() const
Definition Expr.h:1763
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1767
ImaginaryLiteral(EmptyShell Empty)
Build an empty imaginary literal.
Definition Expr.h:1760
child_range children()
Definition Expr.h:1777
static bool classof(const Stmt *T)
Definition Expr.h:1772
const_child_range children() const
Definition Expr.h:1778
void setSubExpr(Expr *E)
Definition Expr.h:1765
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3897
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:3944
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:3941
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition Expr.cpp:2126
ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, ExprValueKind VK, FPOptionsOverride FPO)
Definition Expr.h:3920
bool isPartOfExplicitCast() const
Definition Expr.h:3928
friend class CastExpr
Definition Expr.h:3953
static bool classof(const Stmt *T)
Definition Expr.h:3948
void setIsPartOfExplicitCast(bool PartOfExplicitCast)
Definition Expr.h:3929
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6123
static bool classof(const Stmt *T)
Definition Expr.h:6118
child_range children()
Definition Expr.h:6126
ImplicitValueInitExpr(EmptyShell Empty)
Construct an empty implicit value initialization.
Definition Expr.h:6115
const_child_range children() const
Definition Expr.h:6129
ImplicitValueInitExpr(QualType ty)
Definition Expr.h:6109
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6122
Describes an C or C++ initializer list.
Definition Expr.h:5352
const_reverse_iterator rend() const
Definition Expr.h:5573
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5465
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5526
InitExprsTy::reverse_iterator reverse_iterator
Definition Expr.h:5563
InitExprsTy::const_reverse_iterator const_reverse_iterator
Definition Expr.h:5564
void markError()
Mark the semantic form of the InitListExpr as error when the semantic analysis fails.
Definition Expr.h:5427
bool hasDesignatedInit() const
Determine whether this initializer list contains a designated initializer.
Definition Expr.h:5468
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2495
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
Definition Expr.cpp:2455
bool isStringLiteralInit() const
Is this an initializer for an array of characters, initialized by a string literal or an @encode?
Definition Expr.cpp:2481
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5479
unsigned getNumInits() const
Definition Expr.h:5385
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:2529
bool isSemanticForm() const
Definition Expr.h:5515
void setInit(unsigned Init, Expr *expr)
Definition Expr.h:5417
const_iterator begin() const
Definition Expr.h:5567
reverse_iterator rbegin()
Definition Expr.h:5570
const_reverse_iterator rbegin() const
Definition Expr.h:5571
InitExprsTy::const_iterator const_iterator
Definition Expr.h:5562
Expr *const * getInits() const
Retrieve the set of initializers.
Definition Expr.h:5401
SourceLocation getLBraceLoc() const
Definition Expr.h:5510
Expr * updateInit(const ASTContext &C, unsigned Init, Expr *expr)
Updates the initializer at index Init with the new expression expr, and returns the old expression at...
Definition Expr.cpp:2459
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2471
InitListExpr * getSyntacticForm() const
Definition Expr.h:5522
static bool classof(const Stmt *T)
Definition Expr.h:5543
bool hadArrayRangeDesignator() const
Definition Expr.h:5533
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5455
iterator end()
Definition Expr.h:5568
bool isExplicit() const
Definition Expr.h:5495
iterator begin()
Definition Expr.h:5566
unsigned getNumInitsWithEmbedExpanded() const
getNumInits but if the list has an EmbedExpr inside includes full length of embedded data.
Definition Expr.h:5389
SourceLocation getRBraceLoc() const
Definition Expr.h:5512
InitListExpr * getSemanticForm() const
Definition Expr.h:5516
const FieldDecl * getInitializedFieldInUnion() const
Definition Expr.h:5482
InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef< Expr * > initExprs, SourceLocation rbraceloc, bool isExplicit)
Definition Expr.cpp:2437
friend class ASTStmtWriter
Definition Expr.h:5576
const Expr * getInit(unsigned Init) const
Definition Expr.h:5407
InitListExpr(EmptyShell Empty)
Build an empty initializer list.
Definition Expr.h:5380
void setLBraceLoc(SourceLocation Loc)
Definition Expr.h:5511
const Expr * getArrayFiller() const
Definition Expr.h:5458
const_child_range children() const
Definition Expr.h:5554
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
Definition Expr.cpp:2518
reverse_iterator rend()
Definition Expr.h:5572
friend class ASTStmtReader
Definition Expr.h:5575
const_iterator end() const
Definition Expr.h:5569
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:2547
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5485
bool isSyntacticForm() const
Definition Expr.h:5519
void setRBraceLoc(SourceLocation Loc)
Definition Expr.h:5513
ArrayRef< Expr * > inits() const
Definition Expr.h:5405
InitExprsTy::iterator iterator
Definition Expr.h:5561
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5536
Expr ** getInits()
Retrieve the set of initializers.
Definition Expr.h:5398
Expr * getInit(unsigned Init)
Definition Expr.h:5412
child_range children()
Definition Expr.h:5548
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
Definition Expr.cpp:2450
void setLocation(SourceLocation Location)
Definition Expr.h:1558
child_range children()
Definition Expr.h:1565
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1553
static bool classof(const Stmt *T)
Definition Expr.h:1560
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1556
const_child_range children() const
Definition Expr.h:1568
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1552
Represents the declaration of a label.
Definition Decl.h:525
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4973
MatrixElementExpr(QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc)
Definition Expr.h:6694
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition Expr.cpp:4566
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition Expr.cpp:4617
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition Expr.cpp:4482
static bool classof(const Stmt *T)
Definition Expr.h:6715
MatrixElementExpr(EmptyShell Empty)
Build an empty matrix element expression.
Definition Expr.h:6701
MatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, QualType T, SourceLocation RBracketLoc)
matrix[row]
Definition Expr.h:2850
SourceLocation getRBracketLoc() const
Definition Expr.h:2883
const Expr * getRowIdx() const
Definition Expr.h:2870
const_child_range children() const
Definition Expr.h:2898
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2873
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2886
MatrixSingleSubscriptExpr(EmptyShell Shell)
Create an empty matrix single-subscript expression.
Definition Expr.h:2862
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2879
const Expr * getBase() const
Definition Expr.h:2866
static bool classof(const Stmt *T)
Definition Expr.h:2890
SourceLocation getEndLoc() const
Definition Expr.h:2877
void setColumnIdx(Expr *E)
Definition Expr.h:2949
SourceLocation getEndLoc() const
Definition Expr.h:2955
void setBase(Expr *E)
Definition Expr.h:2937
const Expr * getBase() const
Definition Expr.h:2936
const_child_range children() const
Definition Expr.h:2976
SourceLocation getRBracketLoc() const
Definition Expr.h:2961
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2957
MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T, SourceLocation RBracketLoc)
Definition Expr.h:2914
const Expr * getRowIdx() const
Definition Expr.h:2940
void setRowIdx(Expr *E)
Definition Expr.h:2941
bool isIncomplete() const
Definition Expr.h:2929
MatrixSubscriptExpr(EmptyShell Shell)
Create an empty matrix subscript expression.
Definition Expr.h:2926
static bool classof(const Stmt *T)
Definition Expr.h:2968
child_range children()
Definition Expr.h:2973
const Expr * getColumnIdx() const
Definition Expr.h:2944
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2964
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2951
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3408
static MemberExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition Expr.cpp:1802
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3580
void setMemberDecl(ValueDecl *D)
Definition Expr.cpp:1817
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition Expr.h:3597
void setMemberLoc(SourceLocation L)
Definition Expr.h:3598
void setHadMultipleCandidates(bool V=true)
Sets the flag telling whether this expression refers to a method that was resolved from an overloaded...
Definition Expr.h:3618
SourceLocation getOperatorLoc() const
Definition Expr.h:3590
void setArrow(bool A)
Definition Expr.h:3593
child_range children()
Definition Expr.h:3641
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
Definition Expr.h:3519
static bool classof(const Stmt *T)
Definition Expr.h:3636
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3525
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3510
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3491
const_child_range children() const
Definition Expr.h:3642
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3552
friend class ASTReader
Definition Expr.h:3409
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3632
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
Definition Expr.h:3505
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition Expr.h:3556
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
Definition Expr.h:3606
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition Expr.h:3564
bool performsVirtualDispatch(const LangOptions &LO) const
Returns true if virtual dispatch is performed.
Definition Expr.h:3626
Expr * getBase() const
Definition Expr.h:3485
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition Expr.h:3573
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3541
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:1838
void setBase(Expr *E)
Definition Expr.h:3484
friend class ASTStmtWriter
Definition Expr.h:3411
static MemberExpr * CreateImplicit(const ASTContext &C, Expr *Base, bool IsArrow, ValueDecl *MemberDecl, QualType T, ExprValueKind VK, ExprObjectKind OK)
Create an implicit MemberExpr, with no location, qualifier, template arguments, and so on.
Definition Expr.h:3469
bool hadMultipleCandidates() const
Returns true if this member expression refers to a method that was resolved from an overloaded set ha...
Definition Expr.h:3612
bool hasTemplateKeyword() const
Determines whether the member name was preceded by the template keyword.
Definition Expr.h:3548
friend class ASTStmtReader
Definition Expr.h:3410
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:1824
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3533
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3585
bool isArrow() const
Definition Expr.h:3592
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:3603
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3495
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3767
This represents a decl that may have a name.
Definition Decl.h:275
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
static bool classof(const Stmt *T)
Definition Expr.h:5937
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5942
child_range children()
Definition Expr.h:5945
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5941
NoInitExpr(QualType ty)
Definition Expr.h:5929
NoInitExpr(EmptyShell Empty)
Definition Expr.h:5934
const_child_range children() const
Definition Expr.h:5948
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition ExprObjC.h:649
const Expr * getIndexExpr(unsigned Idx) const
Definition Expr.h:2634
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2646
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2605
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
Definition Expr.cpp:1696
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2630
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2647
static bool classof(const Stmt *T)
Definition Expr.h:2649
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2604
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2618
void setIndexExpr(unsigned Idx, Expr *E)
Definition Expr.h:2638
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2611
void setTypeSourceInfo(TypeSourceInfo *tsi)
Definition Expr.h:2614
const_child_range children() const
Definition Expr.h:2658
child_range children()
Definition Expr.h:2654
void setComponent(unsigned Idx, OffsetOfNode ON)
Definition Expr.h:2622
unsigned getNumExpressions() const
Definition Expr.h:2642
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2608
void setRParenLoc(SourceLocation R)
Definition Expr.h:2609
friend TrailingObjects
Definition Expr.h:2663
unsigned getNumComponents() const
Definition Expr.h:2626
Helper class for OffsetOfExpr.
Definition Expr.h:2465
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1718
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2523
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2529
OffsetOfNode(const CXXBaseSpecifier *Base)
Create an offsetof node that refers into a C++ base class.
Definition Expr.h:2515
OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, SourceLocation RBracketLoc)
Create an offsetof node that refers to an array element.
Definition Expr.h:2499
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this offsetof node.
Definition Expr.h:2550
Kind
The kind of offsetof node we have.
Definition Expr.h:2468
@ Array
An index into an array.
Definition Expr.h:2470
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2474
@ Field
A field.
Definition Expr.h:2472
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2477
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2551
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2519
OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
Create an offsetof node that refers to a field.
Definition Expr.h:2504
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2552
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2539
OffsetOfNode(SourceLocation DotLoc, const IdentifierInfo *Name, SourceLocation NameLoc)
Create an offsetof node that refers to an identifier.
Definition Expr.h:2509
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1198
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
Definition Expr.cpp:5200
OpaqueValueExpr(EmptyShell Empty)
Definition Expr.h:1216
OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, ExprObjectKind OK=OK_Ordinary, Expr *SourceExpr=nullptr)
Definition Expr.h:1203
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1222
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1225
static bool classof(const Stmt *T)
Definition Expr.h:1258
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1248
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1220
friend class ASTStmtReader
Definition Expr.h:1199
const_child_range children() const
Definition Expr.h:1236
child_range children()
Definition Expr.h:1232
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:1228
bool isUnique() const
Definition Expr.h:1256
void setIsUnique(bool V)
Definition Expr.h:1250
static OpenACCAsteriskSizeExpr * CreateEmpty(const ASTContext &C)
Definition Expr.cpp:5707
SourceLocation getEndLoc() const
Definition Expr.h:2150
SourceLocation getLocation() const
Definition Expr.h:2151
const_child_range children() const
Definition Expr.h:2161
SourceLocation getBeginLoc() const
Definition Expr.h:2149
static bool classof(const Stmt *T)
Definition Expr.h:2153
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
Definition Expr.h:2231
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2251
Expr * getSubExpr()
Definition Expr.h:2244
static bool classof(const Stmt *T)
Definition Expr.h:2258
ParenExpr(EmptyShell Empty)
Construct an empty parenthesized expression.
Definition Expr.h:2240
void setLParen(SourceLocation Loc)
Definition Expr.h:2252
void setIsProducedByFoldExpansion(bool ProducedByFoldExpansion=true)
Definition Expr.h:2271
const_child_range children() const
Definition Expr.h:2264
void setRParen(SourceLocation Loc)
Definition Expr.h:2256
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2247
child_range children()
Definition Expr.h:2263
const Expr * getSubExpr() const
Definition Expr.h:2243
bool isProducedByFoldExpansion() const
Definition Expr.h:2268
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2255
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2248
void setSubExpr(Expr *E)
Definition Expr.h:2245
Expr *const * getExprs() const
Definition Expr.h:6173
static ParenListExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumExprs)
Create an empty paren list.
Definition Expr.cpp:5012
SourceLocation getBeginLoc() const
Definition Expr.h:6181
Expr * getExpr(unsigned Init)
Definition Expr.h:6162
ArrayRef< Expr * > exprs() const
Definition Expr.h:6177
const Expr * getExpr(unsigned Init) const
Definition Expr.h:6167
const_child_range children() const
Definition Expr.h:6192
Expr ** getExprs()
Definition Expr.h:6171
SourceLocation getEndLoc() const
Definition Expr.h:6182
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6160
SourceLocation getLParenLoc() const
Definition Expr.h:6179
friend class ASTStmtReader
Definition Expr.h:6137
SourceLocation getRParenLoc() const
Definition Expr.h:6180
static bool classof(const Stmt *T)
Definition Expr.h:6184
child_range children()
Definition Expr.h:6189
Represents a parameter to a function.
Definition Decl.h:1820
SourceLocation getBeginLoc() const
Definition Expr.h:2114
void setLocation(SourceLocation L)
Definition Expr.h:2091
static bool classof(const Stmt *T)
Definition Expr.h:2117
SourceLocation getEndLoc() const
Definition Expr.h:2115
const StringLiteral * getFunctionName() const
Definition Expr.h:2099
StringRef getIdentKindName() const
Definition Expr.h:2106
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
Definition Expr.cpp:648
bool isTransparent() const
Definition Expr.h:2088
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
Definition Expr.cpp:679
const_child_range children() const
Definition Expr.h:2126
child_range children()
Definition Expr.h:2122
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2084
SourceLocation getLocation() const
Definition Expr.h:2090
friend class ASTStmtReader
Definition Expr.h:2050
StringLiteral * getFunctionName()
Definition Expr.h:2093
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6854
const Expr * getResultExpr() const
Definition Expr.h:6907
const_semantics_iterator semantics_begin() const
Definition Expr.h:6916
semantics_iterator semantics_end()
Definition Expr.h:6919
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:6940
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6896
semantics_iterator semantics_begin()
Definition Expr.h:6915
const Expr *const * const_semantics_iterator
Definition Expr.h:6914
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6944
Expr *const * semantics_iterator
Definition Expr.h:6913
const_semantics_iterator semantics_end() const
Definition Expr.h:6922
const Expr * getSyntacticForm() const
Definition Expr.h:6892
static bool classof(const Stmt *T)
Definition Expr.h:6963
const Expr * getSemanticExpr(unsigned index) const
Definition Expr.h:6936
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
Definition Expr.h:6902
child_range children()
Definition Expr.h:6951
ArrayRef< Expr * > semantics()
Definition Expr.h:6926
ArrayRef< const Expr * > semantics() const
Definition Expr.h:6929
unsigned getNumSemanticExprs() const
Definition Expr.h:6911
friend class ASTStmtReader
Definition Expr.h:6968
Expr * getSemanticExpr(unsigned index)
Definition Expr.h:6933
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6891
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6947
const_child_range children() const
Definition Expr.h:6957
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8585
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
Represents a struct/union/class.
Definition Decl.h:4460
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7553
ArrayRef< const Expr * > subExpressions() const
Definition Expr.h:7562
ArrayRef< Expr * > subExpressions()
Definition Expr.h:7560
SourceLocation getEndLoc() const
Definition Expr.h:7572
static bool classof(const Stmt *T)
Definition Expr.h:7574
child_range children()
Definition Expr.h:7566
friend class ASTStmtWriter
Definition Expr.h:7590
friend class ASTStmtReader
Definition Expr.h:7589
SourceLocation getBeginLoc() const
Definition Expr.h:7571
static RecoveryExpr * CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs)
Definition Expr.cpp:5506
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3687
static bool classof(const Stmt *T)
Definition Expr.h:2203
const_child_range children() const
Definition Expr.h:2212
SourceLocation getLocation() const
Definition Expr.h:2199
const TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2189
SourceLocation getLParenLocation() const
Definition Expr.h:2200
TypeSourceInfo * getTypeSourceInfo()
Definition Expr.h:2187
std::string ComputeName(ASTContext &Context) const
Definition Expr.cpp:593
SourceLocation getBeginLoc() const
Definition Expr.h:2197
SourceLocation getRParenLocation() const
Definition Expr.h:2201
SourceLocation getEndLoc() const
Definition Expr.h:2198
static SYCLUniqueStableNameExpr * CreateEmpty(const ASTContext &Ctx)
Definition Expr.cpp:588
ShuffleVectorExpr(EmptyShell Empty)
Build an empty vector-shuffle expression.
Definition Expr.h:4701
llvm::APSInt getShuffleMaskIdx(unsigned N) const
Definition Expr.h:4739
void setExprs(const ASTContext &C, ArrayRef< Expr * > Exprs)
Definition Expr.cpp:4640
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4723
const_child_range children() const
Definition Expr.h:4752
child_range children()
Definition Expr.h:4748
ShuffleVectorExpr(const ASTContext &C, ArrayRef< Expr * > args, QualType Type, SourceLocation BLoc, SourceLocation RP)
Definition Expr.cpp:4627
SourceLocation getBuiltinLoc() const
Definition Expr.h:4704
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4711
void setRParenLoc(SourceLocation L)
Definition Expr.h:4708
const Expr * getExpr(unsigned Index) const
Definition Expr.h:4731
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4720
static bool classof(const Stmt *T)
Definition Expr.h:4713
SourceLocation getRParenLoc() const
Definition Expr.h:4707
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4710
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Definition Expr.h:4726
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:4705
SourceLocExpr(EmptyShell Empty)
Build an empty call expression.
Definition Expr.h:5080
SourceLocation getBeginLoc() const
Definition Expr.h:5115
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Definition Expr.cpp:2313
bool isIntType() const
Definition Expr.h:5094
static bool classof(const Stmt *T)
Definition Expr.h:5126
child_range children()
Definition Expr.h:5118
SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Type, QualType ResultTy, SourceLocation BLoc, SourceLocation RParenLoc, DeclContext *Context)
Definition Expr.cpp:2280
SourceLocation getLocation() const
Definition Expr.h:5114
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5111
SourceLocation getEndLoc() const
Definition Expr.h:5116
DeclContext * getParentContext()
Definition Expr.h:5112
StringRef getBuiltinStr() const
Return a string representing the name of the specific builtin function.
Definition Expr.cpp:2293
const_child_range children() const
Definition Expr.h:5122
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5130
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5090
friend class ASTStmtReader
Definition Expr.h:5142
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
const CompoundStmt * getSubStmt() const
Definition Expr.h:4657
void setRParenLoc(SourceLocation L)
Definition Expr.h:4666
const_child_range children() const
Definition Expr.h:4676
child_range children()
Definition Expr.h:4675
CompoundStmt * getSubStmt()
Definition Expr.h:4656
static bool classof(const Stmt *T)
Definition Expr.h:4670
StmtExpr(CompoundStmt *SubStmt, QualType T, SourceLocation LParenLoc, SourceLocation RParenLoc, unsigned TemplateDepth)
Definition Expr.h:4643
StmtExpr(EmptyShell Empty)
Build an empty statement expression.
Definition Expr.h:4654
void setLParenLoc(SourceLocation L)
Definition Expr.h:4664
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4661
unsigned getTemplateDepth() const
Definition Expr.h:4668
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4660
SourceLocation getRParenLoc() const
Definition Expr.h:4665
void setSubStmt(CompoundStmt *S)
Definition Expr.h:4658
SourceLocation getLParenLoc() const
Definition Expr.h:4663
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition Stmt.h:1363
GenericSelectionExprBitfields GenericSelectionExprBits
Definition Stmt.h:1371
InitListExprBitfields InitListExprBits
Definition Stmt.h:1369
ParenListExprBitfields ParenListExprBits
Definition Stmt.h:1370
ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits
Definition Stmt.h:1364
ParenExprBitfields ParenExprBits
Definition Stmt.h:1374
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition Stmt.h:1591
CallExprBitfields CallExprBits
Definition Stmt.h:1365
ShuffleVectorExprBitfields ShuffleVectorExprBits
Definition Stmt.h:1375
FloatingLiteralBitfields FloatingLiteralBits
Definition Stmt.h:1359
child_iterator child_begin()
Definition Stmt.h:1603
StmtClass getStmtClass() const
Definition Stmt.h:1505
CharacterLiteralBitfields CharacterLiteralBits
Definition Stmt.h:1361
UnaryOperatorBitfields UnaryOperatorBits
Definition Stmt.h:1362
ConstCastIterator< Expr > ConstExprIterator
Definition Stmt.h:1479
SourceLocExprBitfields SourceLocExprBits
Definition Stmt.h:1373
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1487
ChooseExprBitfields ChooseExprBits
Definition Stmt.h:1379
ConstantExprBitfields ConstantExprBits
Definition Stmt.h:1356
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1594
StmtExprBitfields StmtExprBits
Definition Stmt.h:1378
StringLiteralBitfields StringLiteralBits
Definition Stmt.h:1360
OpaqueValueExprBitfields OpaqueValueExprBits
Definition Stmt.h:1419
CastExprBitfields CastExprBits
Definition Stmt.h:1367
MemberExprBitfields MemberExprBits
Definition Stmt.h:1366
DeclRefExprBitfields DeclRefExprBits
Definition Stmt.h:1358
ConstStmtIterator const_child_iterator
Definition Stmt.h:1592
PredefinedExprBitfields PredefinedExprBits
Definition Stmt.h:1357
ConvertVectorExprBitfields ConvertVectorExprBits
Definition Stmt.h:1420
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
BinaryOperatorBitfields BinaryOperatorBits
Definition Stmt.h:1368
PseudoObjectExprBitfields PseudoObjectExprBits
Definition Stmt.h:1372
ExprBitfields ExprBits
Definition Stmt.h:1355
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1595
CastIterator< Expr > ExprIterator
Definition Stmt.h:1478
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
const_child_range children() const
Definition Expr.h:2028
UnsignedOrNone findZeroCodeUnit(unsigned StartIndex=0) const
Scan the string literal contents for a code unit with value 0.
Definition Expr.cpp:1410
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
Definition Expr.h:1990
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2017
bool containsNonAscii() const
Scans the string contents for any non-ascii characters.
Definition Expr.h:1964
bool isUTF8() const
Definition Expr.h:1954
bool isWide() const
Definition Expr.h:1953
bool containsNonAsciiOrNull() const
Scans the string contents for any non-ascii or null characters.
Definition Expr.h:1976
bool isPascal() const
Definition Expr.h:1958
unsigned getLength() const
Definition Expr.h:1944
static bool classof(const Stmt *T)
Definition Expr.h:2020
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
Definition Expr.h:1906
tokloc_iterator tokloc_begin() const
Definition Expr.h:2009
tokloc_iterator tokloc_end() const
Definition Expr.h:2013
child_range children()
Definition Expr.h:2025
StringLiteralKind getKind() const
Definition Expr.h:1948
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
Return a source location that points to the specified byte of this string literal.
Definition Expr.cpp:1332
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1895
bool isUnevaluated() const
Definition Expr.h:1957
void outputString(raw_ostream &OS) const
Prints the contents of the string to OS.
Definition Expr.cpp:1215
bool isUTF32() const
Definition Expr.h:1956
int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const
Definition Expr.h:1920
unsigned getByteLength() const
Definition Expr.h:1942
StringRef getString() const
Definition Expr.h:1887
friend class ASTStmtReader
Definition Expr.h:1820
bool isUTF16() const
Definition Expr.h:1955
static StringLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumConcatenated, unsigned Length, unsigned CharByteWidth)
Construct an empty string literal.
Definition Expr.cpp:1204
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2018
const SourceLocation * tokloc_iterator
Definition Expr.h:2007
unsigned getNumConcatenated() const
Get the number of string literal tokens that were concatenated in translation phase #6 to form this s...
Definition Expr.h:1985
bool isOrdinary() const
Definition Expr.h:1952
unsigned getCharByteWidth() const
Definition Expr.h:1946
Exposes information about the current target.
Definition TargetInfo.h:226
A convenient class for passing around template argument information.
Location wrapper for a TemplateArgument.
A container of type source information.
Definition TypeBase.h:8472
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8483
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Definition TypeBase.h:9086
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9154
bool isReferenceType() const
Definition TypeBase.h:8762
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2859
SourceLocation getRParenLoc() const
Definition Expr.h:2745
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2749
void setKind(UnaryExprOrTypeTrait K)
Definition Expr.h:2704
QualType getArgumentType() const
Definition Expr.h:2712
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2743
SourceLocation getOperatorLoc() const
Definition Expr.h:2742
const Expr * getArgumentExpr() const
Definition Expr.h:2723
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2748
void setRParenLoc(SourceLocation L)
Definition Expr.h:2746
static bool classof(const Stmt *T)
Definition Expr.h:2751
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
Definition Expr.h:2738
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
Definition Expr.h:2677
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2715
UnaryExprOrTypeTraitExpr(EmptyShell Empty)
Construct an empty sizeof/alignof expression.
Definition Expr.h:2698
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2701
void setArgument(TypeSourceInfo *TInfo)
Definition Expr.h:2731
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
static bool classof(const Stmt *T)
Definition Expr.h:2414
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition Expr.h:2358
bool isDecrementOp() const
Definition Expr.h:2380
void setSubExpr(Expr *E)
Definition Expr.h:2330
SourceLocation getExprLoc() const
Definition Expr.h:2412
bool isPostfix() const
Definition Expr.h:2368
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition Expr.h:2353
bool isPrefix() const
Definition Expr.h:2367
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2334
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2333
Expr * getSubExpr() const
Definition Expr.h:2329
friend class ASTReader
Definition Expr.h:2457
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2409
bool isArithmeticOp() const
Definition Expr.h:2392
void setCanOverflow(bool C)
Definition Expr.h:2343
UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
Build an empty unary operator.
Definition Expr.h:2310
Opcode getOpcode() const
Definition Expr.h:2324
friend class ASTNodeImporter
Definition Expr.h:2456
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2425
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
Definition Expr.cpp:1458
void setOpcode(Opcode Opc)
Definition Expr.h:2327
child_range children()
Definition Expr.h:2419
static bool isIncrementOp(Opcode Op)
Definition Expr.h:2370
static bool isIncrementDecrementOp(Opcode Op)
Definition Expr.h:2384
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2406
static bool isDecrementOp(Opcode Op)
Definition Expr.h:2377
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:2433
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2428
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:2347
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1443
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:2444
friend class ASTStmtWriter
Definition Expr.h:2459
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition Expr.h:2439
UnaryOperatorKind Opcode
Definition Expr.h:2302
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5174
FPOptionsOverride getFPOptionsOverride() const
Definition Expr.h:2449
friend class ASTStmtReader
Definition Expr.h:2458
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5167
static bool isPrefix(Opcode Op)
isPrefix - Return true if this is a prefix operation, like –x.
Definition Expr.h:2363
friend TrailingObjects
Definition Expr.h:2455
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
Definition Expr.cpp:1434
static bool isArithmeticOp(Opcode Op)
Definition Expr.h:2389
bool isIncrementDecrementOp() const
Definition Expr.h:2385
bool isIncrementOp() const
Definition Expr.h:2373
const_child_range children() const
Definition Expr.h:2420
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2342
void setVarargABI(VarArgKind Kind)
Definition Expr.h:5026
void setRParenLoc(SourceLocation L)
Definition Expr.h:5041
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5034
child_range children()
Definition Expr.h:5051
SourceLocation getBuiltinLoc() const
Definition Expr.h:5037
SourceLocation getRParenLoc() const
Definition Expr.h:5040
bool isZOSABI() const
Returns whether this is really a z/OS ABI va_arg expression.
Definition Expr.h:5032
VAArgExpr(EmptyShell Empty)
Create an empty __builtin_va_arg expression.
Definition Expr.h:5018
Expr * getSubExpr()
Definition Expr.h:5022
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:5029
void setSubExpr(Expr *E)
Definition Expr.h:5023
static bool classof(const Stmt *T)
Definition Expr.h:5046
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5043
VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo, SourceLocation RPLoc, QualType t, VarArgKind VaKind)
Definition Expr.h:5010
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5044
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:5038
VarArgKind getVarargABI() const
Definition Expr.h:5025
void setWrittenTypeInfo(TypeSourceInfo *TI)
Definition Expr.h:5035
const_child_range children() const
Definition Expr.h:5052
const Expr * getSubExpr() const
Definition Expr.h:5021
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
Represents a statement that could possibly have a value and type.
Definition Stmt.h:2139
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1487
Represents a variable declaration or definition.
Definition Decl.h:933
Definition SPIR.cpp:47
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool Const(InterpState &S, const T &Arg)
Definition Interp.h:1588
Top level wrappers for InstallAPI frontend operations.
LLVM_READNONE bool isASCII(char c)
Returns true if a byte is an ASCII character.
Definition CharInfo.h:41
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
Definition Expr.h:1096
bool isa(CodeGen::Address addr)
Definition Address.h:330
const Expr * findStructFieldAccess(const Expr *E, const Expr **OutArrayIndex=nullptr, QualType *OutArrayElementTy=nullptr)
Walk E through parens, implicit casts, unary &/*, array subscripts and comma operators to find the he...
Definition Expr.cpp:5794
ExprDependenceScope::ExprDependence ExprDependence
StmtIterator cast_away_const(const ConstStmtIterator &RHS)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:150
@ OK_VectorComponent
A vector component is an element or range of elements of a vector.
Definition Specifiers.h:158
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:152
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition Specifiers.h:155
@ OK_MatrixComponent
A matrix component is a single element or range of elements of a matrix.
Definition Specifiers.h:170
Expr::ConstantExprKind ConstantExprKind
Definition Expr.h:1062
ExprDependence computeDependence(FullExpr *E)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Result
The result type of a method or function.
Definition TypeBase.h:906
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
@ Type
The name was classified as a type.
Definition Sema.h:558
CastKind
CastKind - The kind of operation required for a conversion.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:133
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:136
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition Specifiers.h:145
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:140
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:147
StringLiteralKind
Definition Expr.h:1783
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
U cast(CodeGen::Address addr)
Definition Address.h:327
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
SourceLocIdentKind
Definition Expr.h:5057
@ Other
Other implicit parameter.
Definition Decl.h:1775
PredefinedIdentKind
Definition Expr.h:2033
@ PrettyFunctionNoVirtual
The same as PrettyFunction, except that the 'virtual' keyword is omitted for virtual member functions...
Definition Expr.h:2043
CharacterLiteralKind
Definition Expr.h:1623
NonOdrUseReason
The reason why a DeclRefExpr does not constitute an odr-use.
Definition Specifiers.h:174
@ NOUR_None
This is an odr-use.
Definition Specifiers.h:176
unsigned long uint64_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
#define true
Definition stdbool.h:25
BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
Definition Expr.h:6770
Expr * getCopyExpr() const
Definition Expr.h:6775
llvm::PointerIntPair< Expr *, 1, bool > ExprAndFlag
Definition Expr.h:6777
bool canThrow() const
Definition Expr.h:6776
void setExprAndFlag(Expr *CopyExpr, bool CanThrow)
Definition Expr.h:6772
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Stores data related to a single embed directive.
Definition Expr.h:5146
StringLiteral * BinaryData
Definition Expr.h:5147
size_t getDataElementCount() const
Definition Expr.h:5151
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:666
APValue Val
Val - This is the value the expression can be folded to.
Definition Expr.h:668
bool isGlobalLValue() const
Return true if the evaluated lvalue expression is global.
bool hasSideEffects() const
Return true if the evaluated expression has side effects.
Definition Expr.h:660
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
Definition Expr.h:650
bool DiagEmitted
Whether any diagnostic has been emitted.
Definition Expr.h:634
bool HasUndefinedBehavior
Whether the evaluation hit undefined behavior.
Definition Expr.h:630
bool HasSideEffects
Whether the evaluated expression has side effects.
Definition Expr.h:625
SmallVectorImpl< PartialDiagnosticAt > * ExtendedDiag
Location where we spot ptr to int cast or null subobject while evaluating constant expression in MS c...
Definition Expr.h:654
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1445
const CastExpr * BasePath
Definition Expr.h:77
const CXXRecordDecl * DerivedClass
Definition Expr.h:78
const MemberPointerType * MPT
Definition Expr.h:82
const FieldDecl * Field
Definition Expr.h:88
SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
Definition Expr.h:103
SubobjectAdjustment(const FieldDecl *Field)
Definition Expr.h:99
SubobjectAdjustment(const CastExpr *BasePath, const CXXRecordDecl *DerivedClass)
Definition Expr.h:92
struct DTB DerivedToBase
Definition Expr.h:87
enum clang::SubobjectAdjustment::@253221166153022235222106274120241151060023135167 Kind