This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG9857caf9d14f: [Clang] Correctly handle allocation in template arguments (authored by cor3ntin).
Changed prior to commit: https://reviews.llvm.org/D150036?vs=520356&id=520369#toc 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,16 @@ LValue LVal; LVal.set(Base); - if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects) - return false; + { + // C++23 [intro.execution]/p5 + // A full-expression is [...] a constant-expression + // So we need to make sure temporary objects are destroyed after having + // evaluating the expression (per C++23 [class.temporary]/p4). + 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 @@ -370,7 +370,7 @@ (`#62192 <https://github.com/llvm/llvm-project/issues/62192>`_) - Fix crash when attempting to pass a non-pointer type as first argument of ``__builtin_assume_aligned``. - (`#62305 <https://github.com/llvm/llvm-project/issues/62305>`_) + (`#62305 <https://github.com/llvm/llvm-project/issues/62305>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -416,6 +416,8 @@ initialization. (`#61567 <https://github.com/llvm/llvm-project/issues/61567>`_) - Fix a crash when expanding a pack as the index of a subscript expression. +- Fix handling of constexpr dynamic memory allocations in template + arguments. (`#62462 <https://github.com/llvm/llvm-project/issues/62462>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^
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,16 @@ LValue LVal; LVal.set(Base); - if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects) - return false; + { + // C++23 [intro.execution]/p5 + // A full-expression is [...] a constant-expression + // So we need to make sure temporary objects are destroyed after having + // evaluating the expression (per C++23 [class.temporary]/p4). + 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 @@ -370,7 +370,7 @@ (`#62192 <https://github.com/llvm/llvm-project/issues/62192>`_) - Fix crash when attempting to pass a non-pointer type as first argument of ``__builtin_assume_aligned``. - (`#62305 <https://github.com/llvm/llvm-project/issues/62305>`_) + (`#62305 <https://github.com/llvm/llvm-project/issues/62305>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -416,6 +416,8 @@ initialization. (`#61567 <https://github.com/llvm/llvm-project/issues/61567>`_) - Fix a crash when expanding a pack as the index of a subscript expression. +- Fix handling of constexpr dynamic memory allocations in template + arguments. (`#62462 <https://github.com/llvm/llvm-project/issues/62462>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits