[clang] af67614 - [clang][Interp] Call dtor of Floating values
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 20 06:27:49 PDT 2023
Author: Timm Bäder
Date: 2023-07-20T15:27:16+02:00
New Revision: af67614f79059686399e2808c80658af783f48d3
URL: https://github.com/llvm/llvm-project/commit/af67614f79059686399e2808c80658af783f48d3
DIFF: https://github.com/llvm/llvm-project/commit/af67614f79059686399e2808c80658af783f48d3.diff
LOG: [clang][Interp] Call dtor of Floating values
The APFloat might heap-allocate some memory, so we need to call its
destructor.
Differential Revision: https://reviews.llvm.org/D154928
Added:
Modified:
clang/lib/AST/Interp/Descriptor.cpp
clang/test/AST/Interp/floats.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp
index 565c4b20038472..ccd2a993e9f7d3 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -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);
}
diff --git a/clang/test/AST/Interp/floats.cpp b/clang/test/AST/Interp/floats.cpp
index ab75a537d0ce33..fa1f52317988db 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -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;
+}
More information about the cfe-commits
mailing list