-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] avoid adding consteval condition as the last statement to preserve valid CFG #116513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-analysis @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) ChangesFixes #116485 Full diff: https://github.com/llvm/llvm-project/pull/116513.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a8830a5658c7da..d81085d011b866 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -535,6 +535,8 @@ Improvements to Clang's diagnostics
- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).
+- Clang now diagnoses missing return value in functions containing ``if consteval`` (#GH116485).
+
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..7a6bd8b6f8d070 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -3177,11 +3177,14 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) {
if (!I->isConsteval())
KnownVal = tryEvaluateBool(I->getCond());
- // Add the successors. If we know that specific branches are
+ // Add the successors. If we know that specific branches are
// unreachable, inform addSuccessor() of that knowledge.
addSuccessor(Block, ThenBlock, /* IsReachable = */ !KnownVal.isFalse());
addSuccessor(Block, ElseBlock, /* IsReachable = */ !KnownVal.isTrue());
+ if (I->isConsteval())
+ return Block;
+
// Add the condition as the last statement in the new block. This may
// create new blocks as the condition may contain control-flow. Any newly
// created blocks will be pointed to be "Block".
diff --git a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
index 25d1f8df7f7166..3d993f000e8dda 100644
--- a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
+++ b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
@@ -5,3 +5,9 @@ static_assert(__is_same(decltype([] constexpr -> int { }( )), int)); // expected
consteval int g() { } // expected-warning {{non-void function does not return a value}}
static_assert(__is_same(decltype([] consteval -> int { }( )), int)); // expected-warning {{non-void lambda does not return a value}}
+
+namespace GH116485 {
+int h() {
+ if consteval { }
+} // expected-warning {{non-void function does not return a value}}
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes generally LGTM, but I did have additional tests to try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/8073 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/7766 Here is the relevant piece of the build log for the reference
|
…ow 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.
Fixes #116485