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