Skip to content

Commit

Permalink
ValueFlow: omit unnecessary location information from `valueFlowBailo…
Browse files Browse the repository at this point in the history
…utIncompleteVar` (danmar#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.
  • Loading branch information
firewave authored Oct 23, 2023
1 parent b58a6b6 commit a765a13
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
5 changes: 3 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error
if (function.find("operator") != std::string::npos)
function = "(valueFlow)";
std::list<ErrorMessage::FileLocation> callstack(1, ErrorMessage::FileLocation(tok, &tokenlist));
const std::string location = Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":";
ErrorMessage errmsg(callstack, tokenlist.getSourceFilePath(), Severity::debug,
Path::stripDirectoryPart(file) + ":" + std::to_string(line) + ":" + function + " bailout: " + what, type, Certainty::normal);
(file.empty() ? "" : location) + function + " bailout: " + what, type, Certainty::normal);
errorLogger->reportErr(errmsg);
}

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

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

#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what)
#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what) bailoutInternal("valueFlowBailoutIncompleteVar", tokenlist, errorLogger, tok, what, "", 0, __func__)

static std::string debugString(const ValueFlow::Value& v)
{
Expand Down
3 changes: 2 additions & 1 deletion test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ class TestSimplifyTokens : public TestFixture {

(void)simplify;

// TODO: should be handled in a better way
// filter out ValueFlow messages..
const std::string debugwarnings = errout.str();
errout.str("");
std::istringstream istr2(debugwarnings);
std::string line;
while (std::getline(istr2,line)) {
if (line.find("valueflow.cpp") == std::string::npos)
if (line.find("bailout") == std::string::npos)
errout << line << "\n";
}

Expand Down
2 changes: 1 addition & 1 deletion test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ class TestSimplifyTypedef : public TestFixture {
"( ( int * * * ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; "
"}";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:3]: (debug) valueflow.cpp:1319:valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable global\n", errout.str());
}

void simplifyTypedef68() { // ticket #2355
Expand Down
4 changes: 2 additions & 2 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3129,8 +3129,8 @@ class TestSymbolDatabase : public TestFixture {
// ticket #2991 - segmentation fault
check("::y(){x}");

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

void symboldatabase20() {
Expand Down
3 changes: 2 additions & 1 deletion test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,14 @@ class TestTokenizer : public TestFixture {
std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);

// TODO: handle in a better way
// filter out ValueFlow messages..
const std::string debugwarnings = errout.str();
errout.str("");
std::istringstream istr2(debugwarnings);
std::string line;
while (std::getline(istr2,line)) {
if (line.find("valueflow.cpp") == std::string::npos)
if (line.find("bailout") == std::string::npos)
errout << line << "\n";
}

Expand Down
26 changes: 13 additions & 13 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,8 @@ class TestValueFlow : public TestFixture {
" x = y;\n"
" if (x == 123) {}\n"
"}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
ASSERT_EQUALS(
"[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
errout.str());
}

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

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

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

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

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

Expand All @@ -1842,7 +1842,7 @@ class TestValueFlow : public TestFixture {
" FREE(x);\n"
"}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
"[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n",
errout.str());
}
Expand All @@ -1856,7 +1856,7 @@ class TestValueFlow : public TestFixture {
" if (x==123){}\n"
"}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS(
"[test.cpp:3]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
"[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable a\n"
"[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n",
errout.str());

Expand Down

0 comments on commit a765a13

Please sign in to comment.