Skip to content

Commit 69689f6

Browse files
committed
[Clang] avoid adding consteval condition as the last statement to preserve valid CFG
1 parent 24c7d97 commit 69689f6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ Improvements to Clang's diagnostics
535535

536536
- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).
537537

538+
- Clang now diagnoses missing return value in functions containing ``if consteval`` (#GH116485).
539+
538540
Improvements to Clang's time-trace
539541
----------------------------------
540542

clang/lib/Analysis/CFG.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3177,11 +3177,14 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) {
31773177
if (!I->isConsteval())
31783178
KnownVal = tryEvaluateBool(I->getCond());
31793179

3180-
// Add the successors. If we know that specific branches are
3180+
// Add the successors. If we know that specific branches are
31813181
// unreachable, inform addSuccessor() of that knowledge.
31823182
addSuccessor(Block, ThenBlock, /* IsReachable = */ !KnownVal.isFalse());
31833183
addSuccessor(Block, ElseBlock, /* IsReachable = */ !KnownVal.isTrue());
31843184

3185+
if (I->isConsteval())
3186+
return Block;
3187+
31853188
// Add the condition as the last statement in the new block. This may
31863189
// create new blocks as the condition may contain control-flow. Any newly
31873190
// created blocks will be pointed to be "Block".

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ static_assert(__is_same(decltype([] constexpr -> int { }( )), int)); // expected
55

66
consteval int g() { } // expected-warning {{non-void function does not return a value}}
77
static_assert(__is_same(decltype([] consteval -> int { }( )), int)); // expected-warning {{non-void lambda does not return a value}}
8+
9+
namespace GH116485 {
10+
int h() {
11+
if consteval { }
12+
} // expected-warning {{non-void function does not return a value}}
13+
}

0 commit comments

Comments
 (0)