Skip to content
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

Fix 12031: False positive: uninitialized variable #5637

Merged
merged 34 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4ac95fa
Add multicondition evaluation
pfultz2 Oct 28, 2023
b4fab99
Some more fixes
pfultz2 Nov 7, 2023
c6c73fd
Add test
pfultz2 Nov 7, 2023
3b8c2e2
Format
pfultz2 Nov 7, 2023
7c3b391
Remove commented code
pfultz2 Nov 7, 2023
bae046e
Dont make settings optional
pfultz2 Nov 7, 2023
a148c18
Format
pfultz2 Nov 7, 2023
a651569
Fix shadow variable
pfultz2 Nov 7, 2023
315d17e
Remove unused function
pfultz2 Nov 8, 2023
5ee880c
Try to prevent stackoverflow
pfultz2 Nov 17, 2023
3c0525a
Fix null settings
pfultz2 Nov 17, 2023
5282581
Add test case for stack overflow
pfultz2 Nov 18, 2023
c86e159
Format
pfultz2 Nov 18, 2023
08c0c32
Fix stack overflow
pfultz2 Nov 18, 2023
92c8083
Merge branch 'main' into multi-condtion-evaluation
pfultz2 Nov 18, 2023
abfd8aa
Fix compile error
pfultz2 Nov 25, 2023
a0ff7d8
Limit to 4
pfultz2 Nov 25, 2023
815d013
Usa an actual depth
pfultz2 Nov 25, 2023
50c3caa
Avoid complex conditions
pfultz2 Nov 25, 2023
8788eb0
Compare expr ids
pfultz2 Nov 25, 2023
cf9445a
Add functional header
pfultz2 Nov 25, 2023
1284bc7
Format
pfultz2 Nov 25, 2023
e75fa5f
Remove extra condition evaluation
pfultz2 Nov 30, 2023
14c584d
Check the size
pfultz2 Nov 30, 2023
89ba709
Format
pfultz2 Nov 30, 2023
5bdc750
Make function static
pfultz2 Dec 1, 2023
58451d9
Format
pfultz2 Dec 1, 2023
522ea7b
Fix FP
pfultz2 Dec 2, 2023
c2a1803
Merge branch 'main' into multi-condtion-evaluation
pfultz2 Dec 2, 2023
e6b9173
Improve performance by avoiding evaluating conditions multiple times
pfultz2 Dec 2, 2023
31ff79f
Format
pfultz2 Dec 2, 2023
555834c
Fix tidy issue
pfultz2 Dec 10, 2023
f7fe257
Merge branch 'main' into multi-condtion-evaluation
pfultz2 Dec 10, 2023
f5de2e8
Use a function call
pfultz2 Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,17 @@ static int getArgumentPos(const Token* ftok, const Token* tokToFind){
return findArgumentPos(startTok, tokToFind);
}

template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
static void astFlattenRecursive(T* tok, std::vector<T*>& result, const char* op, nonneg int depth = 0)
{
++depth;
if (!tok || depth >= 100)
return;
if (tok->str() == op) {
astFlattenRecursive(tok->astOperand1(), result, op, depth);
astFlattenRecursive(tok->astOperand2(), result, op, depth);
} else {
result.push_back(tok);
}
}

std::vector<const Token*> astFlatten(const Token* tok, const char* op)
{
std::vector<const Token*> result;
astFlattenRecursive(tok, result, op);
astFlattenCopy(tok, op, std::back_inserter(result));
return result;
}

std::vector<Token*> astFlatten(Token* tok, const char* op)
{
std::vector<Token*> result;
astFlattenRecursive(tok, result, op);
astFlattenCopy(tok, op, std::back_inserter(result));
return result;
}

Expand Down Expand Up @@ -163,6 +149,15 @@ bool astHasVar(const Token * tok, nonneg int varid)
return astHasVar(tok->astOperand1(), varid) || astHasVar(tok->astOperand2(), varid);
}

bool astHasExpr(const Token* tok, nonneg int exprid)
{
if (!tok)
return false;
if (tok->exprId() == exprid)
return true;
return astHasExpr(tok->astOperand1(), exprid) || astHasExpr(tok->astOperand2(), exprid);
}

static bool astIsCharWithSign(const Token *tok, ValueType::Sign sign)
{
if (!tok)
Expand Down
16 changes: 16 additions & 0 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,29 @@ const Token* findExpression(const nonneg int exprid,
const std::function<bool(const Token*)>& pred);
const Token* findExpression(const Token* start, const nonneg int exprid);

template<class T, class OuputIterator, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
void astFlattenCopy(T* tok, const char* op, OuputIterator out, nonneg int depth = 100)
{
--depth;
if (!tok || depth < 0)
return;
if (tok->str() == op) {
astFlattenCopy(tok->astOperand1(), op, out, depth);
astFlattenCopy(tok->astOperand2(), op, out, depth);
} else {
*out = tok;
++out;
}
}

std::vector<const Token*> astFlatten(const Token* tok, const char* op);
std::vector<Token*> astFlatten(Token* tok, const char* op);

nonneg int astCount(const Token* tok, const char* op, int depth = 100);

bool astHasToken(const Token* root, const Token * tok);

bool astHasExpr(const Token* tok, nonneg int exprid);
bool astHasVar(const Token * tok, nonneg int varid);

bool astIsPrimitive(const Token* tok);
Expand Down
8 changes: 0 additions & 8 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@
#include <vector>

namespace {
struct OnExit {
std::function<void()> f;

~OnExit() {
f();
}
};

struct ForwardTraversal {
enum class Progress { Continue, Break, Skip };
enum class Terminate { None, Bail, Inconclusive };
Expand Down
Loading
Loading