clang: include/clang/Analysis/ConstructionContext.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
17#define LLVM_CLANG_ANALYSIS_CONSTRUCTIONCONTEXT_H
18
22
24
25
26
27
29public:
48
50 switch (K) {
51 case VariableKind: return "construct into local variable";
53 case ReturnKind: return "construct into return address";
58 case ArgumentKind: return "construct into argument";
60 return "construct into lambda captured variable";
61 case InitializerKind: return "construct into member variable";
62 };
63 llvm_unreachable("Unknown ItemKind");
64 }
65
66private:
67 const void *const Data;
69 const unsigned Index = 0;
70
71 bool hasStatement() const {
74 }
75
76 bool hasIndex() const {
79 }
80
81 bool hasInitializer() const {
84 }
85
86public:
87
88
89
92
95
98
101
103 bool IsElided = false)
104 : Data(BTE),
106
109
112
115
118
121
122
129
132
135
137
141
142
143
144
145
147 assert(hasStatement());
148 return static_cast<const Stmt *>(Data);
149 }
150
152 return hasStatement() ? getStmt() : nullptr;
153 }
154
155
156
157
159 assert(hasInitializer());
161 }
162
163
164
165
166
168
169
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
181
182
183
184 return std::make_tuple(Data, Kind, Index) ==
186 }
187
189 return std::make_tuple(Data, Kind, Index) <
191 }
192};
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213class ConstructionContextLayer {
214 const ConstructionContextLayer *Parent = nullptr;
216
218 const ConstructionContextLayer *Parent)
219 : Parent(Parent), Item(Item) {}
220
221public:
222 static const ConstructionContextLayer *
224 const ConstructionContextLayer *Parent = nullptr);
225
227 const ConstructionContextLayer *getParent() const { return Parent; }
228 bool isLast() const { return !Parent; }
229
230
231
232
233
234
236};
237
238
239
240
241
242
244public:
266
267protected:
269
270
271
273
274private:
275
276 template <typename T, typename... ArgTypes>
278 auto *CC = C.getAllocator().Allocate<T>();
279 return new (CC) T(Args...);
280 }
281
282
283
284
286 BumpVectorContext &C, const MaterializeTemporaryExpr *MTE,
287 const CXXBindTemporaryExpr *BTE,
288 const ConstructionContextLayer *ParentLayer);
289
290
291
292
293
295 createBoundTemporaryFromLayers(
296 BumpVectorContext &C, const CXXBindTemporaryExpr *BTE,
297 const ConstructionContextLayer *ParentLayer);
298
299public:
300
301
302
305 const ConstructionContextLayer *TopLayer);
306
308
310
311
313};
314
315
318
319protected:
325
326public:
328
330 const auto *Var = cast(DS->getSingleDecl());
331
332 return dyn_cast(Var->getInit());
333 }
334
339};
340
341
342
343
344
347
348 explicit SimpleVariableConstructionContext(const DeclStmt *DS)
350 DS) {}
351
352public:
356};
357
358
359
360
361
362
363
364
365
366
367class CXX17ElidedCopyVariableConstructionContext
370
372
373 explicit CXX17ElidedCopyVariableConstructionContext(
376 assert(BTE);
377 }
378
379public:
381
385};
386
387
390
391protected:
398
399public:
401
403 return dyn_cast(I->getInit());
404 }
405
410};
411
412
413
414class SimpleConstructorInitializerConstructionContext
417
418 explicit SimpleConstructorInitializerConstructionContext(
422
423public:
427};
428
429
430
431
432
433
434
435
436
437
438
439class CXX17ElidedCopyConstructorInitializerConstructionContext
442
444
445 explicit CXX17ElidedCopyConstructorInitializerConstructionContext(
449 BTE(BTE) {
450 assert(BTE);
451 }
452
453public:
455
459};
460
461
462
465
467
468 explicit NewAllocatedObjectConstructionContext(const CXXNewExpr *NE)
470 NE(NE) {
471 assert(NE);
472 }
473
474public:
476
480};
481
482
483
484
485
489
490protected:
500
501public:
502
503
507
508
509
510
511
512
516
520};
521
522
523
524
525
526class SimpleTemporaryObjectConstructionContext
529
530 explicit SimpleTemporaryObjectConstructionContext(
534
535public:
539};
540
541
542
543
544
545
546
547
548
549class ElidedTemporaryObjectConstructionContext
553
555
556 explicit ElidedTemporaryObjectConstructionContext(
561 ElidedCE(ElidedCE), ElidedCC(ElidedCC) {
562
563
564
565 assert(ElidedCE && ElidedCE->isElidable() && ElidedCC);
566 }
567
568public:
570 return ElidedCE;
571 }
572
574 return ElidedCC;
575 }
576
580};
581
584
585protected:
592
593public:
595
600};
601
602
603
604
605
606
607class SimpleReturnedValueConstructionContext
610
611 explicit SimpleReturnedValueConstructionContext(const ReturnStmt *RS)
614
615public:
619};
620
621
622
623
624
625
626
627
628
629class CXX17ElidedCopyReturnedValueConstructionContext
632
634
635 explicit CXX17ElidedCopyReturnedValueConstructionContext(
639 BTE(BTE) {
640 assert(BTE);
641 }
642
643public:
645
649};
650
652
653 const Expr *CE;
654
655
656
657
658 unsigned Index;
659
660
662
664
665 explicit ArgumentConstructionContext(const Expr *CE, unsigned Index,
668 Index(Index), BTE(BTE) {
671
672 }
673
674public:
676 unsigned getIndex() const { return Index; }
678
682};
683
685
687
688
689 unsigned Index;
690
692
693 explicit LambdaCaptureConstructionContext(const LambdaExpr *LE,
694 unsigned Index)
696
697public:
699 unsigned getIndex() const { return Index; }
700
702 return *(LE->capture_init_begin() + Index);
703 }
704
706 auto It = LE->getLambdaClass()->field_begin();
707 std::advance(It, Index);
708 return *It;
709 }
710
712 return dyn_cast_or_null(getInitializer());
713 }
714
718};
719
720}
721
722#endif
Defines the clang::Expr interface and subclasses for C++ expressions.
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:679
friend class ConstructionContext
Definition ConstructionContext.h:663
const Expr * getCallLikeExpr() const
Definition ConstructionContext.h:675
unsigned getIndex() const
Definition ConstructionContext.h:676
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition ConstructionContext.h:677
Represents a loop initializing the elements of an array.
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition ConstructionContext.h:454
friend class ConstructionContext
Definition ConstructionContext.h:443
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:456
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:646
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition ConstructionContext.h:644
friend class ConstructionContext
Definition ConstructionContext.h:633
friend class ConstructionContext
Definition ConstructionContext.h:371
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:382
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
Definition ConstructionContext.h:380
Represents binding an expression to a temporary.
Represents a call to a C++ constructor.
Represents a C++ base or member initializer.
Represents a call to an inherited base class constructor from an inheriting constructor.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Represents a single point (AST node) in the program that requires attention during construction of an...
Definition ConstructionContext.h:28
ConstructionContextItem(const ReturnStmt *RS)
Definition ConstructionContext.h:96
ConstructionContextItem(const CXXInheritedCtorInitExpr *CE, unsigned Index)
Definition ConstructionContext.h:116
ConstructionContextItem(const CallExpr *CE, unsigned Index)
Definition ConstructionContext.h:110
ConstructionContextItem(const CXXCtorInitializer *Init)
Definition ConstructionContext.h:130
ConstructionContextItem(const LambdaExpr *LE, unsigned Index)
Definition ConstructionContext.h:133
unsigned getIndex() const
If a single trigger statement triggers multiple constructors, they are usually being enumerated.
Definition ConstructionContext.h:167
bool operator==(const ConstructionContextItem &Other) const
Definition ConstructionContext.h:180
bool operator<(const ConstructionContextItem &Other) const
Definition ConstructionContext.h:188
const CXXCtorInitializer * getCXXCtorInitializer() const
The construction site is not necessarily a statement.
Definition ConstructionContext.h:158
void Profile(llvm::FoldingSetNodeID &ID) const
Definition ConstructionContext.h:174
ConstructionContextItem(const MaterializeTemporaryExpr *MTE)
Definition ConstructionContext.h:99
ConstructionContextItem(const CXXConstructExpr *CE, unsigned Index)
Definition ConstructionContext.h:113
ConstructionContextItem(const ObjCMessageExpr *ME, unsigned Index)
Definition ConstructionContext.h:119
ConstructionContextItem(const CXXConstructExpr *CE)
Definition ConstructionContext.h:107
ConstructionContextItem(const DeclStmt *DS)
Definition ConstructionContext.h:90
ConstructionContextItem(const CXXNewExpr *NE)
Definition ConstructionContext.h:93
ItemKind
Definition ConstructionContext.h:30
@ InitializerKind
Definition ConstructionContext.h:44
@ ElidedDestructorKind
Definition ConstructionContext.h:36
@ STATEMENT_WITH_INDEX_KIND_END
Definition ConstructionContext.h:41
@ NewAllocatorKind
Definition ConstructionContext.h:32
@ LambdaCaptureKind
Definition ConstructionContext.h:39
@ STATEMENT_KIND_BEGIN
Definition ConstructionContext.h:42
@ ReturnKind
Definition ConstructionContext.h:33
@ STATEMENT_WITH_INDEX_KIND_BEGIN
Definition ConstructionContext.h:40
@ INITIALIZER_KIND_END
Definition ConstructionContext.h:46
@ MaterializationKind
Definition ConstructionContext.h:34
@ TemporaryDestructorKind
Definition ConstructionContext.h:35
@ ElidableConstructorKind
Definition ConstructionContext.h:37
@ ArgumentKind
Definition ConstructionContext.h:38
@ STATEMENT_KIND_END
Definition ConstructionContext.h:43
@ INITIALIZER_KIND_BEGIN
Definition ConstructionContext.h:45
@ VariableKind
Definition ConstructionContext.h:31
ItemKind getKind() const
Definition ConstructionContext.h:136
LLVM_DUMP_METHOD StringRef getKindAsString() const
Definition ConstructionContext.h:138
const Stmt * getStmtOrNull() const
Definition ConstructionContext.h:151
static LLVM_DUMP_METHOD StringRef getKindAsString(ItemKind K)
Definition ConstructionContext.h:49
ConstructionContextItem(const Expr *E, unsigned Index)
Definition ConstructionContext.h:123
ConstructionContextItem(const CXXBindTemporaryExpr *BTE, bool IsElided=false)
Definition ConstructionContext.h:102
const Stmt * getStmt() const
The construction site - the statement that triggered the construction for one of its parts.
Definition ConstructionContext.h:146
Construction context can be seen as a linked list of multiple layers.
Definition ConstructionContext.h:213
static const ConstructionContextLayer * create(BumpVectorContext &C, const ConstructionContextItem &Item, const ConstructionContextLayer *Parent=nullptr)
const ConstructionContextItem & getItem() const
Definition ConstructionContext.h:226
const ConstructionContextLayer * getParent() const
Definition ConstructionContext.h:227
bool isLast() const
Definition ConstructionContext.h:228
bool isStrictlyMoreSpecificThan(const ConstructionContextLayer *Other) const
See if Other is a proper initial segment of this construction context in terms of the parent chain - ...
Kind K
Definition ConstructionContext.h:268
virtual const ArrayInitLoopExpr * getArrayInitLoop() const
Definition ConstructionContext.h:309
virtual ~ConstructionContext()=default
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...
ConstructionContext(Kind K)
Definition ConstructionContext.h:272
Kind getKind() const
Definition ConstructionContext.h:307
Kind
Definition ConstructionContext.h:245
@ SimpleVariableKind
Definition ConstructionContext.h:246
@ INITIALIZER_END
Definition ConstructionContext.h:253
@ LambdaCaptureKind
Definition ConstructionContext.h:264
@ CXX17ElidedCopyVariableKind
Definition ConstructionContext.h:247
@ INITIALIZER_BEGIN
Definition ConstructionContext.h:252
@ ArgumentKind
Definition ConstructionContext.h:263
@ TEMPORARY_END
Definition ConstructionContext.h:258
@ NewAllocatedObjectKind
Definition ConstructionContext.h:254
@ TEMPORARY_BEGIN
Definition ConstructionContext.h:257
@ ElidedTemporaryObjectKind
Definition ConstructionContext.h:256
@ SimpleTemporaryObjectKind
Definition ConstructionContext.h:255
@ CXX17ElidedCopyConstructorInitializerKind
Definition ConstructionContext.h:251
@ SimpleConstructorInitializerKind
Definition ConstructionContext.h:250
@ RETURNED_VALUE_BEGIN
Definition ConstructionContext.h:261
@ VARIABLE_END
Definition ConstructionContext.h:249
@ RETURNED_VALUE_END
Definition ConstructionContext.h:262
@ SimpleReturnedValueKind
Definition ConstructionContext.h:259
@ VARIABLE_BEGIN
Definition ConstructionContext.h:248
@ CXX17ElidedCopyReturnedValueKind
Definition ConstructionContext.h:260
const CXXCtorInitializer * getCXXCtorInitializer() const
Definition ConstructionContext.h:400
ConstructorInitializerConstructionContext(ConstructionContext::Kind K, const CXXCtorInitializer *I)
Definition ConstructionContext.h:392
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition ConstructionContext.h:402
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:406
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:577
const ConstructionContext * getConstructionContextAfterElision() const
Definition ConstructionContext.h:573
friend class ConstructionContext
Definition ConstructionContext.h:554
const CXXConstructExpr * getConstructorAfterElision() const
Definition ConstructionContext.h:569
This represents one expression.
Represents a member of a struct/union/class.
const Expr * getInitializer() const
Definition ConstructionContext.h:701
const LambdaExpr * getLambdaExpr() const
Definition ConstructionContext.h:698
unsigned getIndex() const
Definition ConstructionContext.h:699
friend class ConstructionContext
Definition ConstructionContext.h:691
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition ConstructionContext.h:711
const FieldDecl * getFieldDecl() const
Definition ConstructionContext.h:705
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:715
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
friend class ConstructionContext
Definition ConstructionContext.h:466
const CXXNewExpr * getCXXNewExpr() const
Definition ConstructionContext.h:475
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:477
An expression that sends a message to the given Objective-C object or class.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
ReturnedValueConstructionContext(ConstructionContext::Kind K, const ReturnStmt *RS)
Definition ConstructionContext.h:586
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:596
const ReturnStmt * getReturnStmt() const
Definition ConstructionContext.h:594
friend class ConstructionContext
Definition ConstructionContext.h:416
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:424
friend class ConstructionContext
Definition ConstructionContext.h:609
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:616
friend class ConstructionContext
Definition ConstructionContext.h:528
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:536
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:353
friend class ConstructionContext
Definition ConstructionContext.h:346
Stmt - This represents one statement.
const CXXBindTemporaryExpr * getCXXBindTemporaryExpr() const
CXXBindTemporaryExpr here is non-null as long as the temporary has a non-trivial destructor.
Definition ConstructionContext.h:504
const MaterializeTemporaryExpr * getMaterializedTemporaryExpr() const
MaterializeTemporaryExpr is non-null as long as the temporary is actually used after construction,...
Definition ConstructionContext.h:513
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:517
TemporaryObjectConstructionContext(ConstructionContext::Kind K, const CXXBindTemporaryExpr *BTE, const MaterializeTemporaryExpr *MTE)
Definition ConstructionContext.h:491
static bool classof(const ConstructionContext *CC)
Definition ConstructionContext.h:335
const ArrayInitLoopExpr * getArrayInitLoop() const override
Definition ConstructionContext.h:329
VariableConstructionContext(ConstructionContext::Kind K, const DeclStmt *DS)
Definition ConstructionContext.h:320
const DeclStmt * getDeclStmt() const
Definition ConstructionContext.h:327
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
const FunctionProtoType * T
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.