[clang][Interp] Call dtor of Floating values
authorTimm Bäder <tbaeder@redhat.com>
Tue, 11 Jul 2023 07:47:03 +0000 (09:47 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 20 Jul 2023 13:27:16 +0000 (15:27 +0200)
The APFloat might heap-allocate some memory, so we need to call its
destructor.

Differential Revision: https://reviews.llvm.org/D154928

clang/lib/AST/Interp/Descriptor.cpp
clang/test/AST/Interp/floats.cpp

index 565c4b2..ccd2a99 100644 (file)
@@ -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);
 }
 
index ab75a53..fa1f523 100644 (file)
@@ -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;
+}