Skip to content

Commit 330b40e

Browse files
authored
[Analysis] Prevent revisiting block when searching for noreturn vars (#150582)
When searching for noreturn variable initializations, do not visit CFG blocks that are already visited, it prevents hanging the analysis. It must fix #150336.
1 parent fcbbcff commit 330b40e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,12 @@ static bool areAllValuesNoReturn(const VarDecl *VD, const CFGBlock &VarBlk,
503503

504504
TransferFunctions TF(VD);
505505
BackwardDataflowWorklist Worklist(*AC.getCFG(), AC);
506+
llvm::DenseSet<const CFGBlock *> Visited;
506507
Worklist.enqueueBlock(&VarBlk);
507508
while (const CFGBlock *B = Worklist.dequeue()) {
509+
if (Visited.contains(B))
510+
continue;
511+
Visited.insert(B);
508512
// First check the current block.
509513
for (CFGBlock::const_reverse_iterator ri = B->rbegin(), re = B->rend();
510514
ri != re; ++ri) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -fsyntax-only %s -Weverything
2+
3+
void free(void *);
4+
typedef void (*set_free_func)(void *);
5+
struct Method {
6+
int nparams;
7+
int *param;
8+
};
9+
void selelem_free_method(struct Method* method, void* data) {
10+
set_free_func free_func = 0;
11+
for (int i = 0; i < method->nparams; ++i)
12+
free(&method->param[i]);
13+
if (data && free_func)
14+
free_func(data);
15+
}

0 commit comments

Comments
 (0)