[clang] 32ff209 - [Clang] skip consumed analysis for consteval conditions in control-flow terminators (#117403)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 08:10:21 PST 2024
Author: Oleksandr T.
Date: 2024-11-27T18:10:17+02:00
New Revision: 32ff209b87a84890a1487b4e0bbb4a7645d31645
URL: https://github.com/llvm/llvm-project/commit/32ff209b87a84890a1487b4e0bbb4a7645d31645
DIFF: https://github.com/llvm/llvm-project/commit/32ff209b87a84890a1487b4e0bbb4a7645d31645.diff
LOG: [Clang] skip consumed analysis for consteval conditions in control-flow terminators (#117403)
Fixes #117385
---
These changes extend the work done in #116513. The changes add
additional handling to ensure correct behavior by skipping further
checks when a **CFG** contains a `consteval` condition, where no
_explicit expression_ is present, which is required to proceed with
consumed analyses.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Analysis/Consumed.cpp
clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 356b091c13af4f..b1b8f3bfa33b19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -725,6 +725,7 @@ Bug Fixes to C++ Support
- Clang now uses valid deduced type locations when diagnosing functions with trailing return type
missing placeholder return type. (#GH78694)
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)
+- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Analysis/Consumed.cpp b/clang/lib/Analysis/Consumed.cpp
index 63c59432429447..3eb7e5abff7145 100644
--- a/clang/lib/Analysis/Consumed.cpp
+++ b/clang/lib/Analysis/Consumed.cpp
@@ -1229,6 +1229,9 @@ bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock,
if (const auto *IfNode =
dyn_cast_or_null<IfStmt>(CurrBlock->getTerminator().getStmt())) {
+ if (IfNode->isConsteval())
+ return false;
+
const Expr *Cond = IfNode->getCond();
PInfo = Visitor.getInfo(Cond);
diff --git a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
index 19e7d4976428a7..e3228dddef5f66 100644
--- a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
+++ b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -verify %s
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -Wconsumed -verify %s
constexpr int f() { } // expected-warning {{non-void function does not return a value}}
static_assert(__is_same(decltype([] constexpr -> int { }( )), int)); // expected-warning {{non-void lambda does not return a value}}
@@ -34,3 +34,10 @@ constinit bool l = j(); // expected-error {{variable does not have a constant in
// expected-note {{in call to 'j()'}}
}
+
+namespace GH117385 {
+void f() {
+ if consteval {
+ }
+}
+}
More information about the cfe-commits
mailing list