Skip to content

Commit

Permalink
[clang][Interp] Call dtor of Floating values
Browse files Browse the repository at this point in the history
The APFloat might heap-allocate some memory, so we need to call its
destructor.

Differential Revision: https://reviews.llvm.org/D154928
  • Loading branch information
tbaederr committed Jul 20, 2023
1 parent f8a36d8 commit af67614
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/AST/Interp/Descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
}

static BlockDtorFn getDtorPrim(PrimType Type) {
// Floating types are special. They are primitives, but need their
// destructor called, since they might allocate memory.
if (Type == PT_Float)
return dtorTy<PrimConv<PT_Float>::T>;

COMPOSITE_TYPE_SWITCH(Type, return dtorTy<T>, return nullptr);
}

Expand Down
4 changes: 4 additions & 0 deletions clang/test/AST/Interp/floats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ namespace ZeroInit {
constexpr A<double> b{12};
static_assert(a.f == 0.0, "");
};

namespace LongDouble {
constexpr long double ld = 3.1425926539;
}

0 comments on commit af67614

Please sign in to comment.