/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/Block.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Block.cpp - Allocated blocks for the interpreter -------*- 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 | | // Defines the classes describing allocated blocks. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "Block.h" |
14 | | #include "Pointer.h" |
15 | | |
16 | | using namespace clang; |
17 | | using namespace clang::interp; |
18 | | |
19 | | |
20 | | |
21 | 0 | void Block::addPointer(Pointer *P) { |
22 | 0 | if (IsStatic) |
23 | 0 | return; |
24 | 0 | if (Pointers) |
25 | 0 | Pointers->Prev = P; |
26 | 0 | P->Next = Pointers; |
27 | 0 | P->Prev = nullptr; |
28 | 0 | Pointers = P; |
29 | 0 | } |
30 | | |
31 | 0 | void Block::removePointer(Pointer *P) { |
32 | 0 | if (IsStatic) |
33 | 0 | return; |
34 | 0 | if (Pointers == P) |
35 | 0 | Pointers = P->Next; |
36 | 0 | if (P->Prev) |
37 | 0 | P->Prev->Next = P->Next; |
38 | 0 | if (P->Next) |
39 | 0 | P->Next->Prev = P->Prev; |
40 | 0 | } |
41 | | |
42 | 0 | void Block::cleanup() { |
43 | 0 | if (Pointers == nullptr && IsDead) |
44 | 0 | (reinterpret_cast<DeadBlock *>(this + 1) - 1)->free(); |
45 | 0 | } |
46 | | |
47 | 0 | void Block::movePointer(Pointer *From, Pointer *To) { |
48 | 0 | if (IsStatic) |
49 | 0 | return; |
50 | 0 | To->Prev = From->Prev; |
51 | 0 | if (To->Prev) |
52 | 0 | To->Prev->Next = To; |
53 | 0 | To->Next = From->Next; |
54 | 0 | if (To->Next) |
55 | 0 | To->Next->Prev = To; |
56 | 0 | if (Pointers == From) |
57 | 0 | Pointers = To; |
58 | 0 |
|
59 | 0 | From->Prev = nullptr; |
60 | 0 | From->Next = nullptr; |
61 | 0 | } |
62 | | |
63 | | DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk) |
64 | 0 | : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) { |
65 | 0 | // Add the block to the chain of dead blocks. |
66 | 0 | if (Root) |
67 | 0 | Root->Prev = this; |
68 | 0 |
|
69 | 0 | Next = Root; |
70 | 0 | Prev = nullptr; |
71 | 0 | Root = this; |
72 | 0 |
|
73 | 0 | // Transfer pointers. |
74 | 0 | B.Pointers = Blk->Pointers; |
75 | 0 | for (Pointer *P = Blk->Pointers; P; P = P->Next) |
76 | 0 | P->Pointee = &B; |
77 | 0 | } |
78 | | |
79 | 0 | void DeadBlock::free() { |
80 | 0 | if (Prev) |
81 | 0 | Prev->Next = Next; |
82 | 0 | if (Next) |
83 | 0 | Next->Prev = Prev; |
84 | 0 | if (Root == this) |
85 | 0 | Root = Next; |
86 | 0 | ::free(this); |
87 | 0 | } |