Skip to content

Conversation

@llvmbot
Copy link
Member

@llvmbot llvmbot commented Jul 30, 2025

Backport 330b40e

Requested by: @pawosm-arm

@llvmbot
Copy link
Member Author

llvmbot commented Jul 30, 2025

@erichkeane What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from erichkeane July 30, 2025 19:20
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 30, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Jul 30, 2025

@llvm/pr-subscribers-clang

Author: None (llvmbot)

Changes

Backport 330b40e

Requested by: @pawosm-arm


Full diff: https://github.com/llvm/llvm-project/pull/151381.diff

2 Files Affected:

  • (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+4)
  • (added) clang/test/SemaCXX/noreturn-weverything.c (+15)
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);
+}

Copy link
Collaborator

@erichkeane erichkeane left a 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.

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Jul 30, 2025
@pawosm-arm pawosm-arm self-requested a review July 30, 2025 23:46
@pawosm-arm pawosm-arm requested a review from tstellar July 30, 2025 23:47
@pawosm-arm
Copy link
Contributor

@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)
@tru tru merged commit f207cb4 into llvm:release/21.x Aug 1, 2025
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 1, 2025
@github-actions
Copy link

github-actions bot commented Aug 1, 2025

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

5 participants