[PATCH] D147531: [clang] Reset track of immediate function context when entering new function
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 6 03:39:33 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55bbcbf511b4: [clang] Reset track of immediate function context when entering new function (authored by Fznamznon).
Changed prior to commit:
https://reviews.llvm.org/D147531?vs=510843&id=511357#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147531/new/
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,27 @@
}
} // namespace GH60166
+
+namespace GH61142 {
+
+template <typename T>
+struct Test {
+ constexpr static void bar() {
+ foo();
+ }
+ consteval static void foo() {};
+};
+
+consteval void a() {
+ Test<int>::bar();
+}
+
+void b() {
+ Test<int>::bar();
+}
+
+// Make sure consteval function is not emitted.
+// CHECK-NOT: call {{.*}}foo{{.*}}()
+// CHECK-NOT: define {{.*}}foo{{.*}}()
+
+} // namespace GH61142
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15180,6 +15180,15 @@
FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext
: ExprEvalContexts.back().Context);
+ // Each ExpressionEvaluationContextRecord also keeps track of whether the
+ // context is nested in an immediate function context, so smaller contexts
+ // that appear inside immediate functions (like variable initializers) are
+ // considered to be inside an immediate function context even though by
+ // themselves they are not immediate function contexts. But when a new
+ // function is entered, we need to reset this tracking, since the entered
+ // function might be not an immediate function.
+ ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval();
+
// Check for defining attributes before the check for redefinition.
if (const auto *Attr = FD->getAttr<AliasAttr>()) {
Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -279,6 +279,9 @@
- Fix crash when generating code coverage information for `PseudoObjectExpr` in
Clang AST.
(`#45481 <https://github.com/llvm/llvm-project/issues/45481>`_)
+- Fix the assertion hit when a template consteval function appears in a nested
+ consteval/constexpr call chain.
+ (`#61142 <https://github.com/llvm/llvm-project/issues/61142>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147531.511357.patch
Type: text/x-patch
Size: 2394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230406/072dbb81/attachment-0001.bin>
More information about the cfe-commits
mailing list