Skip to content

Commit 32ff209

Browse files
authored
[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.
1 parent 38049dc commit 32ff209

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ Bug Fixes to C++ Support
725725
- Clang now uses valid deduced type locations when diagnosing functions with trailing return type
726726
missing placeholder return type. (#GH78694)
727727
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)
728+
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
728729

729730
Bug Fixes to AST Handling
730731
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Analysis/Consumed.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock,
12291229

12301230
if (const auto *IfNode =
12311231
dyn_cast_or_null<IfStmt>(CurrBlock->getTerminator().getStmt())) {
1232+
if (IfNode->isConsteval())
1233+
return false;
1234+
12321235
const Expr *Cond = IfNode->getCond();
12331236

12341237
PInfo = Visitor.getInfo(Cond);

clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -verify %s
1+
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -Wconsumed -verify %s
22

33
constexpr int f() { } // expected-warning {{non-void function does not return a value}}
44
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
3434
// expected-note {{in call to 'j()'}}
3535

3636
}
37+
38+
namespace GH117385 {
39+
void f() {
40+
if consteval {
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)