/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Interp/InterpState.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- InterpState.cpp - Interpreter for the constexpr VM -----*- 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 | | #include "InterpState.h" |
10 | | #include <limits> |
11 | | #include "Function.h" |
12 | | #include "InterpFrame.h" |
13 | | #include "InterpStack.h" |
14 | | #include "Opcode.h" |
15 | | #include "PrimType.h" |
16 | | #include "Program.h" |
17 | | #include "State.h" |
18 | | |
19 | | using namespace clang; |
20 | | using namespace clang::interp; |
21 | | |
22 | | using APSInt = llvm::APSInt; |
23 | | |
24 | | InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk, |
25 | | Context &Ctx, SourceMapper *M) |
26 | | : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr), |
27 | 14 | CallStackDepth(Parent.getCallStackDepth() + 1) {} |
28 | | |
29 | 14 | InterpState::~InterpState() { |
30 | 28 | while (Current) { |
31 | 14 | InterpFrame *Next = Current->Caller; |
32 | 14 | delete Current; |
33 | 14 | Current = Next; |
34 | 14 | } |
35 | | |
36 | 14 | while (DeadBlocks) { |
37 | 0 | DeadBlock *Next = DeadBlocks->Next; |
38 | 0 | free(DeadBlocks); |
39 | 0 | DeadBlocks = Next; |
40 | 0 | } |
41 | 14 | } |
42 | | |
43 | 0 | Frame *InterpState::getCurrentFrame() { |
44 | 0 | if (Current && Current->Caller) { |
45 | 0 | return Current; |
46 | 0 | } else { |
47 | 0 | return Parent.getCurrentFrame(); |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | 0 | bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) { |
52 | 0 | QualType Type = E->getType(); |
53 | 0 | CCEDiag(E, diag::note_constexpr_overflow) << Value << Type; |
54 | 0 | return noteUndefinedBehavior(); |
55 | 0 | } |
56 | | |
57 | 0 | void InterpState::deallocate(Block *B) { |
58 | 0 | Descriptor *Desc = B->getDescriptor(); |
59 | 0 | if (B->hasPointers()) { |
60 | 0 | size_t Size = B->getSize(); |
61 | | |
62 | | // Allocate a new block, transferring over pointers. |
63 | 0 | char *Memory = reinterpret_cast<char *>(malloc(sizeof(DeadBlock) + Size)); |
64 | 0 | auto *D = new (Memory) DeadBlock(DeadBlocks, B); |
65 | | |
66 | | // Move data from one block to another. |
67 | 0 | if (Desc->MoveFn) |
68 | 0 | Desc->MoveFn(B, B->data(), D->data(), Desc); |
69 | 0 | } else { |
70 | | // Free storage, if necessary. |
71 | 0 | if (Desc->DtorFn) |
72 | 0 | Desc->DtorFn(B, B->data(), Desc); |
73 | 0 | } |
74 | 0 | } |