[clang] baf6bd3 - [Clang] Fixes to immediate-escalating functions (#82281)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 21 11:53:47 PST 2024
Author: cor3ntin
Date: 2024-02-21T20:53:44+01:00
New Revision: baf6bd303bd58a521809d456dd9b179636982fc5
URL: https://github.com/llvm/llvm-project/commit/baf6bd303bd58a521809d456dd9b179636982fc5
DIFF: https://github.com/llvm/llvm-project/commit/baf6bd303bd58a521809d456dd9b179636982fc5.diff
LOG: [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
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 15905e08955097..dd217e16f1f1ae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -297,6 +297,10 @@ Bug Fixes to C++ Support
was only accepted at namespace scope but not at local function scope.
- Clang no longer tries to call consteval constructors at runtime when they appear in a member initializer.
(`#782154 <https://github.com/llvm/llvm-project/issues/82154>`_`)
+- 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
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 89215bf3d1c69a..fcccac10f4733a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1158,7 +1158,9 @@ class Sema final {
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 37a7db889a6eac..816ee9e281359a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18311,7 +18311,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 "
@@ -18328,7 +18327,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 531a6262287335..4a75392045d05a 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 at -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;
+ }()
+));
+
+}
More information about the cfe-commits
mailing list