Skip to content

Commit a765a13

Browse files
authored
ValueFlow: omit unnecessary location information from valueFlowBailoutIncompleteVar (#5583)
This is unnecessary since we only issue it from a single location. It also leads to a lot of unnecessary noise in the daca diff reports.
1 parent b58a6b6 commit a765a13

6 files changed

Lines changed: 23 additions & 20 deletions

File tree

lib/valueflow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,17 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error
132132
if (function.find("operator") != std::string::npos)
133133
function = "(valueFlow)";
134134
std::list<ErrorMessage::FileLocation> callstack(1, ErrorMessage::FileLocation(tok, &tokenlist));
135+
const std::string location = Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":";
135136
ErrorMessage errmsg(callstack, tokenlist.getSourceFilePath(), Severity::debug,
136-
Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":" + function + " bailout: " + what, type, Certainty::normal);
137+
(file.empty() ? "" : location) + function + " bailout: " + what, type, Certainty::normal);
137138
errorLogger->reportErr(errmsg);
138139
}
139140

140141
#define bailout2(type, tokenlist, errorLogger, tok, what) bailoutInternal(type, tokenlist, errorLogger, tok, what, __FILE__, __LINE__, __func__)
141142

142143
#define bailout(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailout", tokenlist, errorLogger, tok, what)
143144

144-
#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what)
145+
#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailoutInternal("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what, "", 0, __func__)
145146

146147
static std::string debugString(const ValueFlow::Value& v)
147148
{

test/testsimplifytokens.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,14 @@ class TestSimplifyTokens : public TestFixture {
201201

202202
(void)simplify;
203203

204+
// TODO: should be handled in a better way
204205
// filter out ValueFlow messages..
205206
const std::string debugwarnings = errout.str();
206207
errout.str("");
207208
std::istringstream istr2(debugwarnings);
208209
std::string line;
209210
while (std::getline(istr2,line)) {
210-
if (line.find("valueflow.cpp") == std::string::npos)
211+
if (line.find("bailout") == std::string::npos)
211212
errout << line << "\n";
212213
}
213214

test/testsimplifytypedef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ class TestSimplifyTypedef : public TestFixture {
19491949
"( ( int * * * ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; "
19501950
"}";
19511951
ASSERT_EQUALS(expected, tok(code));
1952-
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:3]: (debug) valueflow.cpp:1319:valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str());
1952+
ASSERT_EQUALS("[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str());
19531953
}
19541954

19551955
void simplifyTypedef68() { // ticket #2355

test/testsymboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,8 +3129,8 @@ class TestSymbolDatabase : public TestFixture {
31293129
// ticket #2991 - segmentation fault
31303130
check("::y(){x}");
31313131

3132-
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n"
3133-
"[test.cpp:1]: (debug) valueflow.cpp:1321:valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str());
3132+
ASSERT_EQUALS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n"
3133+
"[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str());
31343134
}
31353135

31363136
void symboldatabase20() {

test/testtokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,14 @@ class TestTokenizer : public TestFixture {
459459
std::istringstream istr(code);
460460
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
461461

462+
// TODO: handle in a better way
462463
// filter out ValueFlow messages..
463464
const std::string debugwarnings = errout.str();
464465
errout.str("");
465466
std::istringstream istr2(debugwarnings);
466467
std::string line;
467468
while (std::getline(istr2,line)) {
468-
if (line.find("valueflow.cpp") == std::string::npos)
469+
if (line.find("bailout") == std::string::npos)
469470
errout << line << "\n";
470471
}
471472

test/testvalueflow.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ class TestValueFlow : public TestFixture {
15711571
" x = y;\n"
15721572
" if (x == 123) {}\n"
15731573
"}");
1574-
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1575-
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
1574+
ASSERT_EQUALS(
1575+
"[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
15761576
errout.str());
15771577
}
15781578

@@ -1695,8 +1695,8 @@ class TestValueFlow : public TestFixture {
16951695
bailout("void f(int x) {\n"
16961696
" y = ((x<0) ? x : ((x==2)?3:4));\n"
16971697
"}");
1698-
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1699-
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
1698+
ASSERT_EQUALS(
1699+
"[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
17001700
errout.str());
17011701

17021702
bailout("int f(int x) {\n"
@@ -1760,8 +1760,8 @@ class TestValueFlow : public TestFixture {
17601760
" if (x != 123) { b = x; }\n"
17611761
" if (x == 123) {}\n"
17621762
"}");
1763-
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1764-
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n",
1763+
ASSERT_EQUALS(
1764+
"[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n",
17651765
errout.str());
17661766

17671767
code = "void f(int x, bool abc) {\n"
@@ -1809,8 +1809,8 @@ class TestValueFlow : public TestFixture {
18091809
" case 2: if (x==5) {} break;\n"
18101810
" };\n"
18111811
"}");
1812-
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1813-
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n",
1812+
ASSERT_EQUALS(
1813+
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n",
18141814
errout.str());
18151815

18161816
bailout("void f(int x, int y) {\n"
@@ -1819,8 +1819,8 @@ class TestValueFlow : public TestFixture {
18191819
" case 2: if (x==5) {} break;\n"
18201820
" };\n"
18211821
"}");
1822-
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1823-
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n",
1822+
ASSERT_EQUALS(
1823+
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n",
18241824
errout.str());
18251825
}
18261826

@@ -1832,7 +1832,7 @@ class TestValueFlow : public TestFixture {
18321832
" M;\n"
18331833
"}");
18341834
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1835-
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
1835+
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
18361836
"[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n",
18371837
errout.str());
18381838

@@ -1842,7 +1842,7 @@ class TestValueFlow : public TestFixture {
18421842
" FREE(x);\n"
18431843
"}");
18441844
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1845-
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
1845+
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
18461846
"[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n",
18471847
errout.str());
18481848
}
@@ -1856,7 +1856,7 @@ class TestValueFlow : public TestFixture {
18561856
" if (x==123){}\n"
18571857
"}");
18581858
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
1859-
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
1859+
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
18601860
"[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n",
18611861
errout.str());
18621862

0 commit comments

Comments
 (0)