clang  17.0.0git
ConstructionContext.h
Go to the documentation of this file.
1 //===- ConstructionContext.h - CFG constructor information ------*- 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 ConstructionContext class and its sub-classes,
10 // which represent various different ways of constructing C++ objects
11 // with the additional information the users may want to know about
12 // the constructor.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
17 #define LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
18 
20 #include "clang/AST/ExprCXX.h"
21 #include "clang/AST/ExprObjC.h"
22 
23 namespace clang {
24 
25 /// Represents a single point (AST node) in the program that requires attention
26 /// during construction of an object. ConstructionContext would be represented
27 /// as a list of such items.
29 public:
30  enum ItemKind {
47  };
48 
49  LLVM_DUMP_METHOD static StringRef getKindAsString(ItemKind K) {
50  switch (K) {
51  case VariableKind: return "construct into local variable";
52  case NewAllocatorKind: return "construct into new-allocator";
53  case ReturnKind: return "construct into return address";
54  case MaterializationKind: return "materialize temporary";
55  case TemporaryDestructorKind: return "destroy temporary";
56  case ElidedDestructorKind: return "elide destructor";
57  case ElidableConstructorKind: return "elide constructor";
58  case ArgumentKind: return "construct into argument";
59  case LambdaCaptureKind:
60  return "construct into lambda captured variable";
61  case InitializerKind: return "construct into member variable";
62  };
63  llvm_unreachable("Unknown ItemKind");
64  }
65 
66 private:
67  const void *const Data;
68  const ItemKind Kind;
69  const unsigned Index = 0;
70 
71  bool hasStatement() const {
72  return Kind >= STATEMENT_KIND_BEGIN &&
73  Kind <= STATEMENT_KIND_END;
74  }
75 
76  bool hasIndex() const {
77  return Kind >= STATEMENT_WITH_INDEX_KIND_BEGIN &&
79  }
80 
81  bool hasInitializer() const {
82  return Kind >= INITIALIZER_KIND_BEGIN &&
84  }
85 
86 public:
87  // ConstructionContextItem should be simple enough so that it was easy to
88  // re-construct it from the AST node it captures. For that reason we provide
89  // simple implicit conversions from all sorts of supported AST nodes.
91  : Data(DS), Kind(VariableKind) {}
92 
94  : Data(NE), Kind(NewAllocatorKind) {}
95 
97  : Data(RS), Kind(ReturnKind) {}
98 
100  : Data(MTE), Kind(MaterializationKind) {}
101 
103  bool IsElided = false)
104  : Data(BTE),
105  Kind(IsElided ? ElidedDestructorKind : TemporaryDestructorKind) {}
106 
108  : Data(CE), Kind(ElidableConstructorKind) {}
109 
110  ConstructionContextItem(const CallExpr *CE, unsigned Index)
111  : Data(CE), Kind(ArgumentKind), Index(Index) {}
112 
113  ConstructionContextItem(const CXXConstructExpr *CE, unsigned Index)
114  : Data(CE), Kind(ArgumentKind), Index(Index) {}
115 
117  : Data(CE), Kind(ArgumentKind), Index(Index) {}
118 
119  ConstructionContextItem(const ObjCMessageExpr *ME, unsigned Index)
120  : Data(ME), Kind(ArgumentKind), Index(Index) {}
121 
122  // A polymorphic version of the previous calls with dynamic type check.
123  ConstructionContextItem(const Expr *E, unsigned Index)
124  : Data(E), Kind(ArgumentKind), Index(Index) {
125  assert(isa<CallExpr>(E) || isa<CXXConstructExpr>(E) ||
126  isa<CXXDeleteExpr>(E) || isa<CXXInheritedCtorInitExpr>(E) ||
127  isa<ObjCMessageExpr>(E));
128  }
129 
131  : Data(Init), Kind(InitializerKind), Index(0) {}
132 
133  ConstructionContextItem(const LambdaExpr *LE, unsigned Index)
134  : Data(LE), Kind(LambdaCaptureKind), Index(Index) {}
135 
136  ItemKind getKind() const { return Kind; }
137 
138  LLVM_DUMP_METHOD StringRef getKindAsString() const {
139  return getKindAsString(getKind());
140  }
141 
142  /// The construction site - the statement that triggered the construction
143  /// for one of its parts. For instance, stack variable declaration statement
144  /// triggers construction of itself or its elements if it's an array,
145  /// new-expression triggers construction of the newly allocated object(s).
146  const Stmt *getStmt() const {
147  assert(hasStatement());
148  return static_cast<const Stmt *>(Data);
149  }
150 
151  const Stmt *getStmtOrNull() const {
152  return hasStatement() ? getStmt() : nullptr;
153  }
154 
155  /// The construction site is not necessarily a statement. It may also be a
156  /// CXXCtorInitializer, which means that a member variable is being
157  /// constructed during initialization of the object that contains it.
159  assert(hasInitializer());
160  return static_cast<const CXXCtorInitializer *>(Data);
161  }
162 
163  /// If a single trigger statement triggers multiple constructors, they are
164  /// usually being enumerated. This covers function argument constructors
165  /// triggered by a call-expression and items in an initializer list triggered
166  /// by an init-list-expression.
167  unsigned getIndex() const {
168  // This is a fairly specific request. Let's make sure the user knows
169  // what he's doing.
170  assert(hasIndex());
171  return Index;
172  }
173 
174  void Profile(llvm::FoldingSetNodeID &ID) const {
175  ID.AddPointer(Data);
176  ID.AddInteger(Kind);
177  ID.AddInteger(Index);
178  }
179 
180  bool operator==(const ConstructionContextItem &Other) const {
181  // For most kinds the Index comparison is trivially true, but
182  // checking kind separately doesn't seem to be less expensive
183  // than checking Index. Same in operator<().
184  return std::make_tuple(Data, Kind, Index) ==
185  std::make_tuple(Other.Data, Other.Kind, Other.Index);
186  }
187 
188  bool operator<(const ConstructionContextItem &Other) const {
189  return std::make_tuple(Data, Kind, Index) <
190  std::make_tuple(Other.Data, Other.Kind, Other.Index);
191  }
192 };
193 
194 /// Construction context can be seen as a linked list of multiple layers.
195 /// Sometimes a single trigger is not enough to describe the construction
196 /// site. That's what causing us to have a chain of "partial" construction
197 /// context layers. Some examples:
198 /// - A constructor within in an aggregate initializer list within a variable
199 /// would have a construction context of the initializer list with
200 /// the parent construction context of a variable.
201 /// - A constructor for a temporary that needs to be both destroyed
202 /// and materialized into an elidable copy constructor would have a
203 /// construction context of a CXXBindTemporaryExpr with the parent
204 /// construction context of a MaterializeTemproraryExpr.
205 /// Not all of these are currently supported.
206 /// Layers are created gradually while traversing the AST, and layers that
207 /// represent the outmost AST nodes are built first, while the node that
208 /// immediately contains the constructor would be built last and capture the
209 /// previous layers as its parents. Construction context captures the last layer
210 /// (which has links to the previous layers) and classifies the seemingly
211 /// arbitrary chain of layers into one of the possible ways of constructing
212 /// an object in C++ for user-friendly experience.
214  const ConstructionContextLayer *Parent = nullptr;
216 
219  : Parent(Parent), Item(Item) {}
220 
221 public:
222  static const ConstructionContextLayer *
224  const ConstructionContextLayer *Parent = nullptr);
225 
226  const ConstructionContextItem &getItem() const { return Item; }
227  const ConstructionContextLayer *getParent() const { return Parent; }
228  bool isLast() const { return !Parent; }
229 
230  /// See if Other is a proper initial segment of this construction context
231  /// in terms of the parent chain - i.e. a few first parents coincide and
232  /// then the other context terminates but our context goes further - i.e.,
233  /// we are providing the same context that the other context provides,
234  /// and a bit more above that.
235  bool isStrictlyMoreSpecificThan(const ConstructionContextLayer *Other) const;
236 };
237 
238 
239 /// ConstructionContext's subclasses describe different ways of constructing
240 /// an object in C++. The context re-captures the essential parent AST nodes
241 /// of the CXXConstructExpr it is assigned to and presents these nodes
242 /// through easy-to-understand accessor methods.
244 public:
245  enum Kind {
265  };
266 
267 protected:
269 
270  // Do not make public! These need to only be constructed
271  // via createFromLayers().
272  explicit ConstructionContext(Kind K) : K(K) {}
273 
274 private:
275  // A helper function for constructing an instance into a bump vector context.
276  template <typename T, typename... ArgTypes>
277  static T *create(BumpVectorContext &C, ArgTypes... Args) {
278  auto *CC = C.getAllocator().Allocate<T>();
279  return new (CC) T(Args...);
280  }
281 
282  // A sub-routine of createFromLayers() that deals with temporary objects
283  // that need to be materialized. The BTE argument is for the situation when
284  // the object also needs to be bound for destruction.
285  static const ConstructionContext *createMaterializedTemporaryFromLayers(
286  BumpVectorContext &C, const MaterializeTemporaryExpr *MTE,
287  const CXXBindTemporaryExpr *BTE,
288  const ConstructionContextLayer *ParentLayer);
289 
290  // A sub-routine of createFromLayers() that deals with temporary objects
291  // that need to be bound for destruction. Automatically finds out if the
292  // object also needs to be materialized and delegates to
293  // createMaterializedTemporaryFromLayers() if necessary.
294  static const ConstructionContext *
295  createBoundTemporaryFromLayers(
296  BumpVectorContext &C, const CXXBindTemporaryExpr *BTE,
297  const ConstructionContextLayer *ParentLayer);
298 
299 public:
300  /// Consume the construction context layer, together with its parent layers,
301  /// and wrap it up into a complete construction context. May return null
302  /// if layers do not form any supported construction context.
303  static const ConstructionContext *
304  createFromLayers(BumpVectorContext &C,
305  const ConstructionContextLayer *TopLayer);
306 
307  Kind getKind() const { return K; }
308 
309  virtual const ArrayInitLoopExpr *getArrayInitLoop() const { return nullptr; }
310 
311  // Only declared to silence -Wnon-virtual-dtor warnings.
312  virtual ~ConstructionContext() = default;
313 };
314 
315 /// An abstract base class for local variable constructors.
317  const DeclStmt *DS;
318 
319 protected:
321  : ConstructionContext(K), DS(DS) {
322  assert(classof(this));
323  assert(DS);
324  }
325 
326 public:
327  const DeclStmt *getDeclStmt() const { return DS; }
328 
329  const ArrayInitLoopExpr *getArrayInitLoop() const override {
330  const auto *Var = cast<VarDecl>(DS->getSingleDecl());
331 
332  return dyn_cast<ArrayInitLoopExpr>(Var->getInit());
333  }
334 
335  static bool classof(const ConstructionContext *CC) {
336  return CC->getKind() >= VARIABLE_BEGIN &&
337  CC->getKind() <= VARIABLE_END;
338  }
339 };
340 
341 /// Represents construction into a simple local variable, eg. T var(123);.
342 /// If a variable has an initializer, eg. T var = makeT();, then the final
343 /// elidable copy-constructor from makeT() into var would also be a simple
344 /// variable constructor handled by this class.
346  friend class ConstructionContext; // Allows to create<>() itself.
347 
348  explicit SimpleVariableConstructionContext(const DeclStmt *DS)
350  DS) {}
351 
352 public:
353  static bool classof(const ConstructionContext *CC) {
354  return CC->getKind() == SimpleVariableKind;
355  }
356 };
357 
358 /// Represents construction into a simple variable with an initializer syntax,
359 /// with a single constructor, eg. T var = makeT();. Such construction context
360 /// may only appear in C++17 because previously it was split into a temporary
361 /// object constructor and an elidable simple variable copy-constructor and
362 /// we were producing separate construction contexts for these constructors.
363 /// In C++17 we have a single construction context that combines both.
364 /// Note that if the object has trivial destructor, then this code is
365 /// indistinguishable from a simple variable constructor on the AST level;
366 /// in this case we provide a simple variable construction context.
368  : public VariableConstructionContext {
369  const CXXBindTemporaryExpr *BTE;
370 
371  friend class ConstructionContext; // Allows to create<>() itself.
372 
374  const DeclStmt *DS, const CXXBindTemporaryExpr *BTE)
376  assert(BTE);
377  }
378 
379 public:
380  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
381 
382  static bool classof(const ConstructionContext *CC) {
383  return CC->getKind() == CXX17ElidedCopyVariableKind;
384  }
385 };
386 
387 // An abstract base class for constructor-initializer-based constructors.
389  const CXXCtorInitializer *I;
390 
391 protected:
394  : ConstructionContext(K), I(I) {
395  assert(classof(this));
396  assert(I);
397  }
398 
399 public:
400  const CXXCtorInitializer *getCXXCtorInitializer() const { return I; }
401 
402  const ArrayInitLoopExpr *getArrayInitLoop() const override {
403  return dyn_cast<ArrayInitLoopExpr>(I->getInit());
404  }
405 
406  static bool classof(const ConstructionContext *CC) {
407  return CC->getKind() >= INITIALIZER_BEGIN &&
408  CC->getKind() <= INITIALIZER_END;
409  }
410 };
411 
412 /// Represents construction into a field or a base class within a bigger object
413 /// via a constructor initializer, eg. T(): field(123) { ... }.
416  friend class ConstructionContext; // Allows to create<>() itself.
417 
419  const CXXCtorInitializer *I)
422 
423 public:
424  static bool classof(const ConstructionContext *CC) {
426  }
427 };
428 
429 /// Represents construction into a field or a base class within a bigger object
430 /// via a constructor initializer, with a single constructor, eg.
431 /// T(): field(Field(123)) { ... }. Such construction context may only appear
432 /// in C++17 because previously it was split into a temporary object constructor
433 /// and an elidable simple constructor-initializer copy-constructor and we were
434 /// producing separate construction contexts for these constructors. In C++17
435 /// we have a single construction context that combines both. Note that if the
436 /// object has trivial destructor, then this code is indistinguishable from
437 /// a simple constructor-initializer constructor on the AST level; in this case
438 /// we provide a simple constructor-initializer construction context.
441  const CXXBindTemporaryExpr *BTE;
442 
443  friend class ConstructionContext; // Allows to create<>() itself.
444 
446  const CXXCtorInitializer *I, const CXXBindTemporaryExpr *BTE)
449  BTE(BTE) {
450  assert(BTE);
451  }
452 
453 public:
454  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
455 
456  static bool classof(const ConstructionContext *CC) {
458  }
459 };
460 
461 /// Represents immediate initialization of memory allocated by operator new,
462 /// eg. new T(123);.
464  const CXXNewExpr *NE;
465 
466  friend class ConstructionContext; // Allows to create<>() itself.
467 
470  NE(NE) {
471  assert(NE);
472  }
473 
474 public:
475  const CXXNewExpr *getCXXNewExpr() const { return NE; }
476 
477  static bool classof(const ConstructionContext *CC) {
478  return CC->getKind() == NewAllocatedObjectKind;
479  }
480 };
481 
482 /// Represents a temporary object, eg. T(123), that does not immediately cross
483 /// function boundaries "by value"; constructors that construct function
484 /// value-type arguments or values that are immediately returned from the
485 /// function that returns a value receive separate construction context kinds.
487  const CXXBindTemporaryExpr *BTE;
488  const MaterializeTemporaryExpr *MTE;
489 
490 protected:
493  const MaterializeTemporaryExpr *MTE)
494  : ConstructionContext(K), BTE(BTE), MTE(MTE) {
495  // Both BTE and MTE can be null here, all combinations possible.
496  // Even though for now at least one should be non-null, we simply haven't
497  // implemented the other case yet (this would be a temporary in the middle
498  // of nowhere that doesn't have a non-trivial destructor).
499  }
500 
501 public:
502  /// CXXBindTemporaryExpr here is non-null as long as the temporary has
503  /// a non-trivial destructor.
505  return BTE;
506  }
507 
508  /// MaterializeTemporaryExpr is non-null as long as the temporary is actually
509  /// used after construction, eg. by binding to a reference (lifetime
510  /// extension), accessing a field, calling a method, or passing it into
511  /// a function (an elidable copy or move constructor would be a common
512  /// example) by reference.
514  return MTE;
515  }
516 
517  static bool classof(const ConstructionContext *CC) {
518  return CC->getKind() >= TEMPORARY_BEGIN && CC->getKind() <= TEMPORARY_END;
519  }
520 };
521 
522 /// Represents a temporary object that is not constructed for the purpose of
523 /// being immediately copied/moved by an elidable copy/move-constructor.
524 /// This includes temporary objects "in the middle of nowhere" like T(123) and
525 /// lifetime-extended temporaries.
528  friend class ConstructionContext; // Allows to create<>() itself.
529 
531  const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
534 
535 public:
536  static bool classof(const ConstructionContext *CC) {
537  return CC->getKind() == SimpleTemporaryObjectKind;
538  }
539 };
540 
541 /// Represents a temporary object that is constructed for the sole purpose
542 /// of being immediately copied by an elidable copy/move constructor.
543 /// For example, T t = T(123); includes a temporary T(123) that is immediately
544 /// copied to variable t. In such cases the elidable copy can (but not
545 /// necessarily should) be omitted ("elided") according to the rules of the
546 /// language; the constructor would then construct variable t directly.
547 /// This construction context contains information of the elidable constructor
548 /// and its respective construction context.
551  const CXXConstructExpr *ElidedCE;
552  const ConstructionContext *ElidedCC;
553 
554  friend class ConstructionContext; // Allows to create<>() itself.
555 
557  const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE,
558  const CXXConstructExpr *ElidedCE, const ConstructionContext *ElidedCC)
561  ElidedCE(ElidedCE), ElidedCC(ElidedCC) {
562  // Elided constructor and its context should be either both specified
563  // or both unspecified. In the former case, the constructor must be
564  // elidable.
565  assert(ElidedCE && ElidedCE->isElidable() && ElidedCC);
566  }
567 
568 public:
570  return ElidedCE;
571  }
572 
574  return ElidedCC;
575  }
576 
577  static bool classof(const ConstructionContext *CC) {
578  return CC->getKind() == ElidedTemporaryObjectKind;
579  }
580 };
581 
583  const ReturnStmt *RS;
584 
585 protected:
587  const ReturnStmt *RS)
588  : ConstructionContext(K), RS(RS) {
589  assert(classof(this));
590  assert(RS);
591  }
592 
593 public:
594  const ReturnStmt *getReturnStmt() const { return RS; }
595 
596  static bool classof(const ConstructionContext *CC) {
597  return CC->getKind() >= RETURNED_VALUE_BEGIN &&
598  CC->getKind() <= RETURNED_VALUE_END;
599  }
600 };
601 
602 /// Represents a temporary object that is being immediately returned from a
603 /// function by value, eg. return t; or return T(123);. In this case there is
604 /// always going to be a constructor at the return site. However, the usual
605 /// temporary-related bureaucracy (CXXBindTemporaryExpr,
606 /// MaterializeTemporaryExpr) is normally located in the caller function's AST.
609  friend class ConstructionContext; // Allows to create<>() itself.
610 
614 
615 public:
616  static bool classof(const ConstructionContext *CC) {
617  return CC->getKind() == SimpleReturnedValueKind;
618  }
619 };
620 
621 /// Represents a temporary object that is being immediately returned from a
622 /// function by value, eg. return t; or return T(123); in C++17.
623 /// In C++17 there is not going to be an elidable copy constructor at the
624 /// return site. However, the usual temporary-related bureaucracy (CXXBindTemporaryExpr,
625 /// MaterializeTemporaryExpr) is normally located in the caller function's AST.
626 /// Note that if the object has trivial destructor, then this code is
627 /// indistinguishable from a simple returned value constructor on the AST level;
628 /// in this case we provide a simple returned value construction context.
631  const CXXBindTemporaryExpr *BTE;
632 
633  friend class ConstructionContext; // Allows to create<>() itself.
634 
636  const ReturnStmt *RS, const CXXBindTemporaryExpr *BTE)
639  BTE(BTE) {
640  assert(BTE);
641  }
642 
643 public:
644  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
645 
646  static bool classof(const ConstructionContext *CC) {
648  }
649 };
650 
652  // The call of which the context is an argument.
653  const Expr *CE;
654 
655  // Which argument we're constructing. Note that when numbering between
656  // arguments and parameters is inconsistent (eg., operator calls),
657  // this is the index of the argument, not of the parameter.
658  unsigned Index;
659 
660  // Whether the object needs to be destroyed.
661  const CXXBindTemporaryExpr *BTE;
662 
663  friend class ConstructionContext; // Allows to create<>() itself.
664 
665  explicit ArgumentConstructionContext(const Expr *CE, unsigned Index,
666  const CXXBindTemporaryExpr *BTE)
668  Index(Index), BTE(BTE) {
669  assert(isa<CallExpr>(CE) || isa<CXXConstructExpr>(CE) ||
670  isa<ObjCMessageExpr>(CE));
671  // BTE is optional.
672  }
673 
674 public:
675  const Expr *getCallLikeExpr() const { return CE; }
676  unsigned getIndex() const { return Index; }
677  const CXXBindTemporaryExpr *getCXXBindTemporaryExpr() const { return BTE; }
678 
679  static bool classof(const ConstructionContext *CC) {
680  return CC->getKind() == ArgumentKind;
681  }
682 };
683 
685  // The lambda of which the initializer we capture.
686  const LambdaExpr *LE;
687 
688  // Index of the captured element in the captured list.
689  unsigned Index;
690 
691  friend class ConstructionContext; // Allows to create<>() itself.
692 
694  unsigned Index)
695  : ConstructionContext(LambdaCaptureKind), LE(LE), Index(Index) {}
696 
697 public:
698  const LambdaExpr *getLambdaExpr() const { return LE; }
699  unsigned getIndex() const { return Index; }
700 
701  const Expr *getInitializer() const {
702  return *(LE->capture_init_begin() + Index);
703  }
704 
705  const FieldDecl *getFieldDecl() const {
706  auto It = LE->getLambdaClass()->field_begin();
707  std::advance(It, Index);
708  return *It;
709  }
710 
711  const ArrayInitLoopExpr *getArrayInitLoop() const override {
712  return dyn_cast_or_null<ArrayInitLoopExpr>(getInitializer());
713  }
714 
715  static bool classof(const ConstructionContext *CC) {
716  return CC->getKind() == LambdaCaptureKind;
717  }
718 };
719 
720 } // end namespace clang
721 
722 #endif // LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
clang::ConstructionContext::TEMPORARY_BEGIN
@ TEMPORARY_BEGIN
Definition: ConstructionContext.h:257
clang::ConstructorInitializerConstructionContext::getCXXCtorInitializer
const CXXCtorInitializer * getCXXCtorInitializer() const
Definition: ConstructionContext.h:400
clang::TemporaryObjectConstructionContext::TemporaryObjectConstructionContext
TemporaryObjectConstructionContext(ConstructionContext::Kind K, const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
Definition: ConstructionContext.h:491
clang::ConstructionContext::INITIALIZER_BEGIN
@ INITIALIZER_BEGIN
Definition: ConstructionContext.h:252
clang::ConstructionContext::NewAllocatedObjectKind
@ NewAllocatedObjectKind
Definition: ConstructionContext.h:254
clang::ElidedTemporaryObjectConstructionContext::getConstructionContextAfterElision
const ConstructionContext * getConstructionContextAfterElision() const
Definition: ConstructionContext.h:573
clang::SimpleTemporaryObjectConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:536
clang::ConstructionContextItem::getKind
ItemKind getKind() const
Definition: ConstructionContext.h:136
clang::ConstructionContextLayer::isLast
bool isLast() const
Definition: ConstructionContext.h:228
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const DeclStmt *DS)
Definition: ConstructionContext.h:90
clang::ConstructionContextItem::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: ConstructionContext.h:174
clang::SimpleVariableConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:353
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXInheritedCtorInitExpr *CE, unsigned Index)
Definition: ConstructionContext.h:116
clang::TemporaryObjectConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:517
advance
static ParseState advance(ParseState S, size_t N)
Definition: Parsing.cpp:144
clang::ConstructionContextItem::STATEMENT_KIND_END
@ STATEMENT_KIND_END
Definition: ConstructionContext.h:43
clang::ReturnedValueConstructionContext::ReturnedValueConstructionContext
ReturnedValueConstructionContext(ConstructionContext::Kind K, const ReturnStmt *RS)
Definition: ConstructionContext.h:586
clang::ArgumentConstructionContext::getCXXBindTemporaryExpr
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition: ConstructionContext.h:677
clang::ConstructionContextItem::TemporaryDestructorKind
@ TemporaryDestructorKind
Definition: ConstructionContext.h:35
clang::LambdaCaptureConstructionContext::getIndex
unsigned getIndex() const
Definition: ConstructionContext.h:699
clang::ConstructionContextItem::getCXXCtorInitializer
const CXXCtorInitializer * getCXXCtorInitializer() const
The construction site is not necessarily a statement.
Definition: ConstructionContext.h:158
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXConstructExpr *CE)
Definition: ConstructionContext.h:107
clang::ConstructionContext::CXX17ElidedCopyConstructorInitializerKind
@ CXX17ElidedCopyConstructorInitializerKind
Definition: ConstructionContext.h:251
clang::ConstructionContext
ConstructionContext's subclasses describe different ways of constructing an object in C++.
Definition: ConstructionContext.h:243
clang::ConstructionContextItem::getStmtOrNull
const Stmt * getStmtOrNull() const
Definition: ConstructionContext.h:151
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2943
clang::VariableConstructionContext::getArrayInitLoop
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition: ConstructionContext.h:329
clang::CXXNewExpr
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2197
clang::ConstructionContext::SimpleReturnedValueKind
@ SimpleReturnedValueKind
Definition: ConstructionContext.h:259
clang::ConstructorInitializerConstructionContext::ConstructorInitializerConstructionContext
ConstructorInitializerConstructionContext(ConstructionContext::Kind K, const CXXCtorInitializer *I)
Definition: ConstructionContext.h:392
clang::ConstructionContext::CXX17ElidedCopyVariableKind
@ CXX17ElidedCopyVariableKind
Definition: ConstructionContext.h:247
clang::LambdaCaptureConstructionContext::getFieldDecl
const FieldDecl * getFieldDecl() const
Definition: ConstructionContext.h:705
clang::ConstructionContext::INITIALIZER_END
@ INITIALIZER_END
Definition: ConstructionContext.h:253
clang::VariableConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:335
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXConstructExpr *CE, unsigned Index)
Definition: ConstructionContext.h:113
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXNewExpr *NE)
Definition: ConstructionContext.h:93
clang::VariableConstructionContext::getDeclStmt
const DeclStmt * getDeclStmt() const
Definition: ConstructionContext.h:327
clang::SimpleConstructorInitializerConstructionContext
Represents construction into a field or a base class within a bigger object via a constructor initial...
Definition: ConstructionContext.h:414
clang::ArrayInitLoopExpr
Represents a loop initializing the elements of an array.
Definition: Expr.h:5426
clang::ConstructionContextLayer::getItem
const ConstructionContextItem & getItem() const
Definition: ConstructionContext.h:226
clang::ConstructionContextItem::INITIALIZER_KIND_BEGIN
@ INITIALIZER_KIND_BEGIN
Definition: ConstructionContext.h:45
clang::ArgumentConstructionContext
Definition: ConstructionContext.h:651
clang::ConstructionContextItem::ItemKind
ItemKind
Definition: ConstructionContext.h:30
clang::ConstructionContextItem::getKindAsString
LLVM_DUMP_METHOD StringRef getKindAsString() const
Definition: ConstructionContext.h:138
clang::ConstructionContextItem
Represents a single point (AST node) in the program that requires attention during construction of an...
Definition: ConstructionContext.h:28
clang::ConstructionContextLayer::create
static const ConstructionContextLayer * create(BumpVectorContext &C, const ConstructionContextItem &Item, const ConstructionContextLayer *Parent=nullptr)
Definition: ConstructionContext.cpp:22
clang::CXX17ElidedCopyConstructorInitializerConstructionContext
Represents construction into a field or a base class within a bigger object via a constructor initial...
Definition: ConstructionContext.h:439
clang::CXX17ElidedCopyReturnedValueConstructionContext
Represents a temporary object that is being immediately returned from a function by value,...
Definition: ConstructionContext.h:629
clang::ConstructionContext::TEMPORARY_END
@ TEMPORARY_END
Definition: ConstructionContext.h:258
clang::ConstructionContext::Kind
Kind
Definition: ConstructionContext.h:245
clang::ConstructionContextItem::INITIALIZER_KIND_END
@ INITIALIZER_KIND_END
Definition: ConstructionContext.h:46
clang::SimpleConstructorInitializerConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:424
clang::TemporaryObjectConstructionContext::getMaterializedTemporaryExpr
const MaterializeTemporaryExpr * getMaterializedTemporaryExpr() const
MaterializeTemporaryExpr is non-null as long as the temporary is actually used after construction,...
Definition: ConstructionContext.h:513
clang::ConstructionContextItem::getIndex
unsigned getIndex() const
If a single trigger statement triggers multiple constructors, they are usually being enumerated.
Definition: ConstructionContext.h:167
clang::TemporaryObjectConstructionContext::getCXXBindTemporaryExpr
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
CXXBindTemporaryExpr here is non-null as long as the temporary has a non-trivial destructor.
Definition: ConstructionContext.h:504
clang::ArgumentConstructionContext::getIndex
unsigned getIndex() const
Definition: ConstructionContext.h:676
clang::ConstructionContextItem::STATEMENT_KIND_BEGIN
@ STATEMENT_KIND_BEGIN
Definition: ConstructionContext.h:42
clang::ConstructionContext::VARIABLE_BEGIN
@ VARIABLE_BEGIN
Definition: ConstructionContext.h:248
clang::ConstructionContextItem::ElidedDestructorKind
@ ElidedDestructorKind
Definition: ConstructionContext.h:36
clang::ConstructionContextItem::operator==
bool operator==(const ConstructionContextItem &Other) const
Definition: ConstructionContext.h:180
clang::NewAllocatedObjectConstructionContext::getCXXNewExpr
const CXXNewExpr * getCXXNewExpr() const
Definition: ConstructionContext.h:475
clang::ReturnedValueConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:596
clang::ConstructorInitializerConstructionContext
Definition: ConstructionContext.h:388
clang::ConstructionContextItem::NewAllocatorKind
@ NewAllocatorKind
Definition: ConstructionContext.h:32
clang::ConstructionContextItem::ReturnKind
@ ReturnKind
Definition: ConstructionContext.h:33
clang::CXXBindTemporaryExpr
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1470
clang::ConstructionContext::LambdaCaptureKind
@ LambdaCaptureKind
Definition: ConstructionContext.h:264
clang::NewAllocatedObjectConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:477
clang::CXXCtorInitializer::getInit
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2418
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1923
clang::interp::LE
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:628
clang::LambdaCaptureConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:715
clang::MaterializeTemporaryExpr
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4562
clang::ConstructionContextItem::getKindAsString
static LLVM_DUMP_METHOD StringRef getKindAsString(ItemKind K)
Definition: ConstructionContext.h:49
clang::LambdaCaptureConstructionContext::getLambdaExpr
const LambdaExpr * getLambdaExpr() const
Definition: ConstructionContext.h:698
clang::CXX17ElidedCopyReturnedValueConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:646
clang::ElidedTemporaryObjectConstructionContext
Represents a temporary object that is constructed for the sole purpose of being immediately copied by...
Definition: ConstructionContext.h:549
clang::CXX17ElidedCopyConstructorInitializerConstructionContext::getCXXBindTemporaryExpr
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition: ConstructionContext.h:454
clang::ConstructionContext::SimpleConstructorInitializerKind
@ SimpleConstructorInitializerKind
Definition: ConstructionContext.h:250
clang::ReturnedValueConstructionContext
Definition: ConstructionContext.h:582
clang::ConstructionContextItem::InitializerKind
@ InitializerKind
Definition: ConstructionContext.h:44
clang::CXX17ElidedCopyVariableConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:382
clang::ConstructorInitializerConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:406
BumpVector.h
ExprObjC.h
ExprCXX.h
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXCtorInitializer *Init)
Definition: ConstructionContext.h:130
clang::CXXInheritedCtorInitExpr
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1709
clang::ReturnedValueConstructionContext::getReturnStmt
const ReturnStmt * getReturnStmt() const
Definition: ConstructionContext.h:594
clang::SimpleReturnedValueConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:616
clang::VariableConstructionContext
An abstract base class for local variable constructors.
Definition: ConstructionContext.h:316
clang::LambdaCaptureConstructionContext::getInitializer
const Expr * getInitializer() const
Definition: ConstructionContext.h:701
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
clang::ConstructionContext::ConstructionContext
ConstructionContext(Kind K)
Definition: ConstructionContext.h:272
clang::ConstructionContextItem::getStmt
const Stmt * getStmt() const
The construction site - the statement that triggered the construction for one of its parts.
Definition: ConstructionContext.h:146
clang::DeclStmt::getSingleDecl
const Decl * getSingleDecl() const
Definition: Stmt.h:1326
clang::ElidedTemporaryObjectConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:577
clang::LambdaCaptureKind
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
clang::ConstructionContext::SimpleVariableKind
@ SimpleVariableKind
Definition: ConstructionContext.h:246
clang::ArgumentConstructionContext::getCallLikeExpr
const Expr * getCallLikeExpr() const
Definition: ConstructionContext.h:675
clang::ConstructionContextItem::STATEMENT_WITH_INDEX_KIND_BEGIN
@ STATEMENT_WITH_INDEX_KIND_BEGIN
Definition: ConstructionContext.h:40
clang::SimpleTemporaryObjectConstructionContext
Represents a temporary object that is not constructed for the purpose of being immediately copied/mov...
Definition: ConstructionContext.h:526
clang::NewAllocatedObjectConstructionContext
Represents immediate initialization of memory allocated by operator new, eg.
Definition: ConstructionContext.h:463
clang::ConstructionContextItem::VariableKind
@ VariableKind
Definition: ConstructionContext.h:31
clang::ConstructionContext::getArrayInitLoop
virtual const ArrayInitLoopExpr * getArrayInitLoop() const
Definition: ConstructionContext.h:309
clang::LambdaCaptureConstructionContext::getArrayInitLoop
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition: ConstructionContext.h:711
clang::ConstructionContextLayer
Construction context can be seen as a linked list of multiple layers.
Definition: ConstructionContext.h:213
clang::ConstructionContextItem::ArgumentKind
@ ArgumentKind
Definition: ConstructionContext.h:38
clang::ConstructionContextItem::ElidableConstructorKind
@ ElidableConstructorKind
Definition: ConstructionContext.h:37
clang::ConstructionContextLayer::isStrictlyMoreSpecificThan
bool isStrictlyMoreSpecificThan(const ConstructionContextLayer *Other) const
See if Other is a proper initial segment of this construction context in terms of the parent chain - ...
Definition: ConstructionContext.cpp:30
clang::ConstructionContextItem::MaterializationKind
@ MaterializationKind
Definition: ConstructionContext.h:34
clang::SimpleVariableConstructionContext
Represents construction into a simple local variable, eg.
Definition: ConstructionContext.h:345
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1311
clang::ConstructionContext::K
Kind K
Definition: ConstructionContext.h:268
clang::interp::NE
bool NE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:614
clang::Builtin::ID
ID
Definition: Builtins.h:64
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const Expr *E, unsigned Index)
Definition: ConstructionContext.h:123
clang::ConstructionContext::RETURNED_VALUE_BEGIN
@ RETURNED_VALUE_BEGIN
Definition: ConstructionContext.h:261
clang
Definition: CalledOnceCheck.h:17
clang::ConstructionContext::SimpleTemporaryObjectKind
@ SimpleTemporaryObjectKind
Definition: ConstructionContext.h:255
clang::ConstructionContextItem::LambdaCaptureKind
@ LambdaCaptureKind
Definition: ConstructionContext.h:39
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const LambdaExpr *LE, unsigned Index)
Definition: ConstructionContext.h:133
clang::ConstructorInitializerConstructionContext::getArrayInitLoop
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition: ConstructionContext.h:402
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:72
clang::SimpleReturnedValueConstructionContext
Represents a temporary object that is being immediately returned from a function by value,...
Definition: ConstructionContext.h:607
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const ObjCMessageExpr *ME, unsigned Index)
Definition: ConstructionContext.h:119
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CallExpr *CE, unsigned Index)
Definition: ConstructionContext.h:110
clang::ArgumentConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:679
clang::ConstructionContext::~ConstructionContext
virtual ~ConstructionContext()=default
clang::ConstructionContext::getKind
Kind getKind() const
Definition: ConstructionContext.h:307
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const ReturnStmt *RS)
Definition: ConstructionContext.h:96
clang::ConstructionContextItem::STATEMENT_WITH_INDEX_KIND_END
@ STATEMENT_WITH_INDEX_KIND_END
Definition: ConstructionContext.h:41
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const CXXBindTemporaryExpr *BTE, bool IsElided=false)
Definition: ConstructionContext.h:102
clang::ConstructionContext::ElidedTemporaryObjectKind
@ ElidedTemporaryObjectKind
Definition: ConstructionContext.h:256
clang::ConstructionContext::RETURNED_VALUE_END
@ RETURNED_VALUE_END
Definition: ConstructionContext.h:262
Parent
NodeId Parent
Definition: ASTDiff.cpp:191
clang::TemporaryObjectConstructionContext
Represents a temporary object, eg.
Definition: ConstructionContext.h:486
clang::CXX17ElidedCopyVariableConstructionContext::getCXXBindTemporaryExpr
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition: ConstructionContext.h:380
clang::CXX17ElidedCopyReturnedValueConstructionContext::getCXXBindTemporaryExpr
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition: ConstructionContext.h:644
clang::BumpVectorContext
Definition: BumpVector.h:32
clang::ConstructionContext::CXX17ElidedCopyReturnedValueKind
@ CXX17ElidedCopyReturnedValueKind
Definition: ConstructionContext.h:260
clang::Expr
This represents one expression.
Definition: Expr.h:110
clang::VariableConstructionContext::VariableConstructionContext
VariableConstructionContext(ConstructionContext::Kind K, const DeclStmt *DS)
Definition: ConstructionContext.h:320
clang::ConstructionContextLayer::getParent
const ConstructionContextLayer * getParent() const
Definition: ConstructionContext.h:227
clang::ConstructionContext::ArgumentKind
@ ArgumentKind
Definition: ConstructionContext.h:263
clang::ElidedTemporaryObjectConstructionContext::getConstructorAfterElision
const CXXConstructExpr * getConstructorAfterElision() const
Definition: ConstructionContext.h:569
clang::CXXCtorInitializer
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2219
clang::ConstructionContext::createFromLayers
static const ConstructionContext * createFromLayers(BumpVectorContext &C, const ConstructionContextLayer *TopLayer)
Consume the construction context layer, together with its parent layers, and wrap it up into a comple...
Definition: ConstructionContext.cpp:170
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2812
clang::ConstructionContextItem::ConstructionContextItem
ConstructionContextItem(const MaterializeTemporaryExpr *MTE)
Definition: ConstructionContext.h:99
clang::LambdaCaptureConstructionContext
Definition: ConstructionContext.h:684
clang::CXXConstructExpr
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1518
clang::CXX17ElidedCopyConstructorInitializerConstructionContext::classof
static bool classof(const ConstructionContext *CC)
Definition: ConstructionContext.h:456
clang::ConstructionContextItem::operator<
bool operator<(const ConstructionContextItem &Other) const
Definition: ConstructionContext.h:188
clang::CXXConstructExpr::isElidable
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1596
clang::ConstructionContext::VARIABLE_END
@ VARIABLE_END
Definition: ConstructionContext.h:249
clang::CXX17ElidedCopyVariableConstructionContext
Represents construction into a simple variable with an initializer syntax, with a single constructor,...
Definition: ConstructionContext.h:367
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:2804