aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcor3ntin <corentinjabot@gmail.com>2024-02-21 20:53:44 +0100
committerTom Stellard <tstellar@redhat.com>2024-02-26 17:03:46 -0800
commita7a74ece1d6b8dc95bf6fb0b7e06b8e0ba9b9559 (patch)
tree6e0c54627cd45c06fdc15c91b55a76dec57adfbd
parent4cc7a75aa6ac272a5774ef7ca3f6b2ad095425e3 (diff)
downloadllvm-a7a74ece1d6b8dc95bf6fb0b7e06b8e0ba9b9559.zip
llvm-a7a74ece1d6b8dc95bf6fb0b7e06b8e0ba9b9559.tar.gz
llvm-a7a74ece1d6b8dc95bf6fb0b7e06b8e0ba9b9559.tar.bz2
[Clang] Fixes to immediate-escalating functions (#82281)
* Consider that immediate escalating function can appear at global scope, fixing a crash * Lambda conversion to function pointer was sometimes not performed in an immediate function context when it should be. Fixes #82258 (cherry picked from commit baf6bd303bd58a521809d456dd9b179636982fc5)
-rw-r--r--clang/docs/ReleaseNotes.rst5
-rw-r--r--clang/include/clang/Sema/Sema.h4
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
-rw-r--r--clang/test/SemaCXX/cxx2b-consteval-propagate.cpp26
4 files changed, 36 insertions, 3 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2411e97..fc27297 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1099,6 +1099,11 @@ Bug Fixes to C++ Support
- Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated.
Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_)
+- Fix crash when using an immediate-escalated function at global scope.
+ (`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
+- Correctly immediate-escalate lambda conversion functions.
+ (`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
+
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd1..6adb8fb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1090,7 +1090,9 @@ public:
if (FD) {
FD->setWillHaveBody(true);
S.ExprEvalContexts.back().InImmediateFunctionContext =
- FD->isImmediateFunction();
+ FD->isImmediateFunction() ||
+ S.ExprEvalContexts[S.ExprEvalContexts.size() - 2]
+ .isConstantEvaluated();
S.ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
} else
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0d9c087..4cce0ab 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18294,7 +18294,6 @@ void Sema::CheckUnusedVolatileAssignment(Expr *E) {
}
void Sema::MarkExpressionAsImmediateEscalating(Expr *E) {
- assert(!FunctionScopes.empty() && "Expected a function scope");
assert(getLangOpts().CPlusPlus20 &&
ExprEvalContexts.back().InImmediateEscalatingFunctionContext &&
"Cannot mark an immediate escalating expression outside of an "
@@ -18311,7 +18310,8 @@ void Sema::MarkExpressionAsImmediateEscalating(Expr *E) {
} else {
assert(false && "expected an immediately escalating expression");
}
- getCurFunction()->FoundImmediateEscalatingExpression = true;
+ if (FunctionScopeInfo *FI = getCurFunction())
+ FI->FoundImmediateEscalatingExpression = true;
}
ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 531a626..4a75392 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -368,3 +368,29 @@ vector<void> v{};
// expected-note@-2 {{in call to 'vector()'}}
}
+
+
+namespace GH82258 {
+
+template <class R, class Pred>
+constexpr auto none_of(R&& r, Pred pred) -> bool { return true; }
+
+struct info { int value; };
+consteval auto is_invalid(info i) -> bool { return false; }
+constexpr info types[] = { {1}, {3}, {5}};
+
+static_assert(none_of(
+ types,
+ +[](info i) consteval {
+ return is_invalid(i);
+ }
+));
+
+static_assert(none_of(
+ types,
+ []{
+ return is_invalid;
+ }()
+));
+
+}