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