Fznamznon created this revision. Herald added a project: All. Fznamznon requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Due not resetting that, clang still thinks that it is in immediate function context even if it is already entered non-consteval function. It caused consteval functions reaching codegen in some cases. Fixes https://github.com/llvm/llvm-project/issues/61142 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147531 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDecl.cpp clang/test/CodeGenCXX/cxx20-consteval-crash.cpp Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp =================================================================== --- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp +++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp @@ -116,3 +116,23 @@ } } // namespace GH60166 + +namespace GH61142 { + +template <typename T> +struct Test { + constexpr static void g() { + f(); + } + consteval static void f() {}; +}; + +consteval void a() { + Test<int>::g(); +} + +void b() { + Test<int>::g(); +} + +} // namespace GH61142 Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -15174,6 +15174,7 @@ PushExpressionEvaluationContext( FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext : ExprEvalContexts.back().Context); + ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval(); // Check for defining attributes before the check for redefinition. if (const auto *Attr = FD->getAttr<AliasAttr>()) { Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -271,6 +271,9 @@ (`#60887 <https://github.com/llvm/llvm-project/issues/60887>`_) - Fix incorrect merging of lambdas across modules. (`#60985 <https://github.com/llvm/llvm-project/issues/60985>`_) +- Fix assertion hit when template consteval function appears in nested + consteval/constexpr call chain. + (`#61142 <https://github.com/llvm/llvm-project/issues/61142>`_) Bug Fixes to Compiler Builtins
Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp =================================================================== --- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp +++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp @@ -116,3 +116,23 @@ } } // namespace GH60166 + +namespace GH61142 { + +template <typename T> +struct Test { + constexpr static void g() { + f(); + } + consteval static void f() {}; +}; + +consteval void a() { + Test<int>::g(); +} + +void b() { + Test<int>::g(); +} + +} // namespace GH61142 Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -15174,6 +15174,7 @@ PushExpressionEvaluationContext( FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext : ExprEvalContexts.back().Context); + ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval(); // Check for defining attributes before the check for redefinition. if (const auto *Attr = FD->getAttr<AliasAttr>()) { Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -271,6 +271,9 @@ (`#60887 <https://github.com/llvm/llvm-project/issues/60887>`_) - Fix incorrect merging of lambdas across modules. (`#60985 <https://github.com/llvm/llvm-project/issues/60985>`_) +- Fix assertion hit when template consteval function appears in nested + consteval/constexpr call chain. + (`#61142 <https://github.com/llvm/llvm-project/issues/61142>`_) Bug Fixes to Compiler Builtins
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits