[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / lib / AST / Interp / InterpState.cpp
blob2cb87ef07fe5882c5fcb275d5c68c0e3a2e52f05
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 //===----------------------------------------------------------------------===//
9 #include "InterpState.h"
10 #include "InterpFrame.h"
11 #include "InterpStack.h"
12 #include "Program.h"
13 #include "State.h"
15 using namespace clang;
16 using namespace clang::interp;
18 InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
19 Context &Ctx, SourceMapper *M)
20 : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr) {}
22 InterpState::~InterpState() {
23 while (Current) {
24 InterpFrame *Next = Current->Caller;
25 delete Current;
26 Current = Next;
29 while (DeadBlocks) {
30 DeadBlock *Next = DeadBlocks->Next;
31 std::free(DeadBlocks);
32 DeadBlocks = Next;
36 Frame *InterpState::getCurrentFrame() {
37 if (Current && Current->Caller)
38 return Current;
39 return Parent.getCurrentFrame();
42 bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
43 QualType Type = E->getType();
44 CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
45 return noteUndefinedBehavior();
48 void InterpState::deallocate(Block *B) {
49 assert(B);
50 const Descriptor *Desc = B->getDescriptor();
51 assert(Desc);
53 if (B->hasPointers()) {
54 size_t Size = B->getSize();
56 // Allocate a new block, transferring over pointers.
57 char *Memory =
58 reinterpret_cast<char *>(std::malloc(sizeof(DeadBlock) + Size));
59 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
61 // Move data and metadata from the old block to the new (dead)block.
62 if (Desc->MoveFn) {
63 Desc->MoveFn(B, B->data(), D->data(), Desc);
64 if (Desc->getMetadataSize() > 0)
65 std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
68 // We moved the contents over to the DeadBlock.
69 B->IsInitialized = false;
70 } else {
71 B->invokeDtor();