diff options
Diffstat (limited to 'clang/lib/AST/Interp/EvalEmitter.cpp')
| -rw-r--r-- | clang/lib/AST/Interp/EvalEmitter.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index f22cca90d4f4..9bc42057c5f5 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -7,18 +7,16 @@ //===----------------------------------------------------------------------===// #include "EvalEmitter.h" +#include "ByteCodeGenError.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" -#include "Program.h" #include "clang/AST/DeclCXX.h" using namespace clang; using namespace clang::interp; -using APSInt = llvm::APSInt; -template <typename T> using Expected = llvm::Expected<T>; - EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk, APValue &Result) : Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), Result(Result) { @@ -27,6 +25,14 @@ EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr()); } +EvalEmitter::~EvalEmitter() { + for (auto &[K, V] : Locals) { + Block *B = reinterpret_cast<Block *>(V.get()); + if (B->isInitialized()) + B->invokeDtor(); + } +} + llvm::Expected<bool> EvalEmitter::interpretExpr(const Expr *E) { if (this->visitExpr(E)) return true; @@ -119,10 +125,10 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) { // Method to recursively traverse composites. std::function<bool(QualType, const Pointer &, APValue &)> Composite; Composite = [this, &Composite](QualType Ty, const Pointer &Ptr, APValue &R) { - if (auto *AT = Ty->getAs<AtomicType>()) + if (const auto *AT = Ty->getAs<AtomicType>()) Ty = AT->getValueType(); - if (auto *RT = Ty->getAs<RecordType>()) { + if (const auto *RT = Ty->getAs<RecordType>()) { const auto *Record = Ptr.getRecord(); assert(Record && "Missing record descriptor"); @@ -130,7 +136,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) { if (RT->getDecl()->isUnion()) { const FieldDecl *ActiveField = nullptr; APValue Value; - for (auto &F : Record->fields()) { + for (const auto &F : Record->fields()) { const Pointer &FP = Ptr.atField(F.Offset); QualType FieldTy = F.Decl->getType(); if (FP.isActive()) { @@ -179,7 +185,13 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) { } return Ok; } - if (auto *AT = Ty->getAsArrayTypeUnsafe()) { + + if (Ty->isIncompleteArrayType()) { + R = APValue(APValue::UninitArray(), 0, 0); + return true; + } + + if (const auto *AT = Ty->getAsArrayTypeUnsafe()) { const size_t NumElems = Ptr.getNumElems(); QualType ElemTy = AT->getElementType(); R = APValue(APValue::UninitArray{}, NumElems, NumElems); |
