-
Notifications
You must be signed in to change notification settings - Fork 15.4k
release/21.x: [Analysis] Prevent revisiting block when searching for noreturn vars (#150582) #151381
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
|
@erichkeane What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-clang Author: None (llvmbot) ChangesBackport 330b40e Requested by: @pawosm-arm Full diff: https://github.com/llvm/llvm-project/pull/151381.diff 2 Files Affected:
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 5e75c64eb2b9a..85ac3c06ec2c2 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -503,8 +503,12 @@ static bool areAllValuesNoReturn(const VarDecl *VD, const CFGBlock &VarBlk,
TransferFunctions TF(VD);
BackwardDataflowWorklist Worklist(*AC.getCFG(), AC);
+ llvm::DenseSet<const CFGBlock *> Visited;
Worklist.enqueueBlock(&VarBlk);
while (const CFGBlock *B = Worklist.dequeue()) {
+ if (Visited.contains(B))
+ continue;
+ Visited.insert(B);
// First check the current block.
for (CFGBlock::const_reverse_iterator ri = B->rbegin(), re = B->rend();
ri != re; ++ri) {
diff --git a/clang/test/SemaCXX/noreturn-weverything.c b/clang/test/SemaCXX/noreturn-weverything.c
new file mode 100644
index 0000000000000..92a587d395639
--- /dev/null
+++ b/clang/test/SemaCXX/noreturn-weverything.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Weverything
+
+void free(void *);
+typedef void (*set_free_func)(void *);
+struct Method {
+ int nparams;
+ int *param;
+};
+void selelem_free_method(struct Method* method, void* data) {
+ set_free_func free_func = 0;
+ for (int i = 0; i < method->nparams; ++i)
+ free(&method->param[i]);
+ if (data && free_func)
+ free_func(data);
+}
|
erichkeane
left a comment
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.
Yeah, we should merge this, the multiple-visits causes no-turn analysis to infinite loop in some cases, which is obviously not great.
|
@tstellar what needs to be done to make it merged? |
…lvm#150582) When searching for noreturn variable initializations, do not visit CFG blocks that are already visited, it prevents hanging the analysis. It must fix llvm#150336. (cherry picked from commit 330b40e)
|
@pawosm-arm (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. |
Backport 330b40e
Requested by: @pawosm-arm