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