[PATCH] D150036: [Clang] Correctly handle allocation in template arguments
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat May 6 06:46:58 PDT 2023
cor3ntin updated this revision to Diff 520085.
cor3ntin added a comment.
Address @tbaeder feedback
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150036/new/
https://reviews.llvm.org/D150036
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
}
static_assert(h());
}
+
+namespace GH62462 {
+
+class string {
+public:
+ char *mem;
+ constexpr string() {
+ this->mem = new char(1);
+ }
+ constexpr ~string() {
+ delete this->mem;
+ }
+ constexpr unsigned size() const { return 4; }
+};
+
+
+template <unsigned N>
+void test() {};
+
+void f() {
+ test<string().size()>();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,11 @@
LValue LVal;
LVal.set(Base);
- if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects)
- return false;
+ {
+ FullExpressionRAII Scope(Info);
+ if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects || !Scope.destroy())
+ return false;
+ }
if (!Info.discardCleanups())
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -381,6 +381,8 @@
- Fix overly aggressive lifetime checks for parenthesized aggregate
initialization.
(`#61567 <https://github.com/llvm/llvm-project/issues/61567>`_)
+- Fix handling of constexpr dynamic memory allocations in template
+ arguments. (`#62462 <https://github.com/llvm/llvm-project/issues/62462>`)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150036.520085.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230506/a569df75/attachment-0001.bin>
More information about the cfe-commits
mailing list