Dont traverse conditions multiple times (#2574)
This commit is contained in:
parent
f2527f5340
commit
7fd3580f21
|
@ -2,6 +2,7 @@
|
||||||
#include "astutils.h"
|
#include "astutils.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
@ -70,8 +71,6 @@ struct ForwardTraversal {
|
||||||
Progress traverseConditional(T* tok, F f, bool traverseUnknown) {
|
Progress traverseConditional(T* tok, F f, bool traverseUnknown) {
|
||||||
if (Token::Match(tok, "?|&&|%oror%")) {
|
if (Token::Match(tok, "?|&&|%oror%")) {
|
||||||
T* condTok = tok->astOperand1();
|
T* condTok = tok->astOperand1();
|
||||||
if (traverseRecursive(condTok, f, traverseUnknown) == Progress::Break)
|
|
||||||
return Progress::Break;
|
|
||||||
T* childTok = tok->astOperand2();
|
T* childTok = tok->astOperand2();
|
||||||
bool checkThen, checkElse;
|
bool checkThen, checkElse;
|
||||||
std::tie(checkThen, checkElse) = evalCond(condTok);
|
std::tie(checkThen, checkElse) = evalCond(condTok);
|
||||||
|
|
|
@ -132,6 +132,7 @@ private:
|
||||||
TEST_CASE(valueFlowCrashIncompleteCode);
|
TEST_CASE(valueFlowCrashIncompleteCode);
|
||||||
|
|
||||||
TEST_CASE(valueFlowCrash);
|
TEST_CASE(valueFlowCrash);
|
||||||
|
TEST_CASE(valueFlowHang);
|
||||||
TEST_CASE(valueFlowCrashConstructorInitialization);
|
TEST_CASE(valueFlowCrashConstructorInitialization);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4454,6 +4455,49 @@ private:
|
||||||
valueOfTok(code, "x");
|
valueOfTok(code, "x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void valueFlowHang() {
|
||||||
|
const char* code;
|
||||||
|
// #9659
|
||||||
|
code = "float arr1[4][4] = {0.0};\n"
|
||||||
|
"float arr2[4][4] = {0.0};\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" if(arr1[0][0] == 0.0 &&\n"
|
||||||
|
" arr1[0][1] == 0.0 &&\n"
|
||||||
|
" arr1[0][2] == 0.0 &&\n"
|
||||||
|
" arr1[0][3] == 0.0 &&\n"
|
||||||
|
" arr1[1][0] == 0.0 &&\n"
|
||||||
|
" arr1[1][1] == 0.0 &&\n"
|
||||||
|
" arr1[1][2] == 0.0 &&\n"
|
||||||
|
" arr1[1][3] == 0.0 &&\n"
|
||||||
|
" arr1[2][0] == 0.0 &&\n"
|
||||||
|
" arr1[2][1] == 0.0 &&\n"
|
||||||
|
" arr1[2][2] == 0.0 &&\n"
|
||||||
|
" arr1[2][3] == 0.0 &&\n"
|
||||||
|
" arr1[3][0] == 0.0 &&\n"
|
||||||
|
" arr1[3][1] == 0.0 &&\n"
|
||||||
|
" arr1[3][2] == 0.0 &&\n"
|
||||||
|
" arr1[3][3] == 0.0 &&\n"
|
||||||
|
" arr2[0][0] == 0.0 &&\n"
|
||||||
|
" arr2[0][1] == 0.0 &&\n"
|
||||||
|
" arr2[0][2] == 0.0 &&\n"
|
||||||
|
" arr2[0][3] == 0.0 &&\n"
|
||||||
|
" arr2[1][0] == 0.0 &&\n"
|
||||||
|
" arr2[1][1] == 0.0 &&\n"
|
||||||
|
" arr2[1][2] == 0.0 &&\n"
|
||||||
|
" arr2[1][3] == 0.0 &&\n"
|
||||||
|
" arr2[2][0] == 0.0 &&\n"
|
||||||
|
" arr2[2][1] == 0.0 &&\n"
|
||||||
|
" arr2[2][2] == 0.0 &&\n"
|
||||||
|
" arr2[2][3] == 0.0 &&\n"
|
||||||
|
" arr2[3][0] == 0.0 &&\n"
|
||||||
|
" arr2[3][1] == 0.0 &&\n"
|
||||||
|
" arr2[3][2] == 0.0 &&\n"
|
||||||
|
" arr2[3][3] == 0.0\n"
|
||||||
|
" ) {}\n"
|
||||||
|
"}\n";
|
||||||
|
valueOfTok(code, "x");
|
||||||
|
}
|
||||||
|
|
||||||
void valueFlowCrashConstructorInitialization() { // #9577
|
void valueFlowCrashConstructorInitialization() { // #9577
|
||||||
const char* code;
|
const char* code;
|
||||||
code = "void Error()\n"
|
code = "void Error()\n"
|
||||||
|
|
Loading…
Reference in New Issue