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.
This commit is contained in:
Oliver Stöneberg 2023-10-23 10:13:10 +02:00 committed by GitHub
parent b58a6b6911
commit a765a1310d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 20 deletions

View File

@ -132,8 +132,9 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error
if (function.find("operator") != std::string::npos) if (function.find("operator") != std::string::npos)
function = "(valueFlow)"; function = "(valueFlow)";
std::list<ErrorMessage::FileLocation> callstack(1, ErrorMessage::FileLocation(tok, &tokenlist)); 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, 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); errorLogger->reportErr(errmsg);
} }
@ -141,7 +142,7 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error
#define bailout(tokenlist, errorLogger, tok, what) bailout2("valueFlowBailout", tokenlist, errorLogger, tok, what) #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) static std::string debugString(const ValueFlow::Value& v)
{ {

View File

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

View File

@ -1949,7 +1949,7 @@ private:
"( ( int * * * ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; " "( ( int * * * ) global [ 6 ] ) ( \"assoc\" , \"eggdrop\" , 106 , 0 ) ; "
"}"; "}";
ASSERT_EQUALS(expected, tok(code)); 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 void simplifyTypedef68() { // ticket #2355

View File

@ -3129,8 +3129,8 @@ private:
// ticket #2991 - segmentation fault // ticket #2991 - segmentation fault
check("::y(){x}"); check("::y(){x}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:1]: (debug) Executable scope 'y' with unknown function.\n" ASSERT_EQUALS("[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()); "[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout.str());
} }
void symboldatabase20() { void symboldatabase20() {

View File

@ -459,13 +459,14 @@ private:
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr); ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
// TODO: handle in a better way
// filter out ValueFlow messages.. // filter out ValueFlow messages..
const std::string debugwarnings = errout.str(); const std::string debugwarnings = errout.str();
errout.str(""); errout.str("");
std::istringstream istr2(debugwarnings); std::istringstream istr2(debugwarnings);
std::string line; std::string line;
while (std::getline(istr2,line)) { while (std::getline(istr2,line)) {
if (line.find("valueflow.cpp") == std::string::npos) if (line.find("bailout") == std::string::npos)
errout << line << "\n"; errout << line << "\n";
} }

View File

@ -1571,8 +1571,8 @@ private:
" x = y;\n" " x = y;\n"
" if (x == 123) {}\n" " if (x == 123) {}\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS(
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
errout.str()); errout.str());
} }
@ -1695,8 +1695,8 @@ private:
bailout("void f(int x) {\n" bailout("void f(int x) {\n"
" y = ((x<0) ? x : ((x==2)?3:4));\n" " y = ((x<0) ? x : ((x==2)?3:4));\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS(
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n", "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable y\n",
errout.str()); errout.str());
bailout("int f(int x) {\n" bailout("int f(int x) {\n"
@ -1760,8 +1760,8 @@ private:
" if (x != 123) { b = x; }\n" " if (x != 123) { b = x; }\n"
" if (x == 123) {}\n" " if (x == 123) {}\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS(
"[test.cpp:2]: (debug) valueflow.cpp::valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n", "[test.cpp:2]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable b\n",
errout.str()); errout.str());
code = "void f(int x, bool abc) {\n" code = "void f(int x, bool abc) {\n"
@ -1809,8 +1809,8 @@ private:
" case 2: if (x==5) {} break;\n" " case 2: if (x==5) {} break;\n"
" };\n" " };\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS(
"[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",
errout.str()); errout.str());
bailout("void f(int x, int y) {\n" bailout("void f(int x, int y) {\n"
@ -1819,8 +1819,8 @@ private:
" case 2: if (x==5) {} break;\n" " case 2: if (x==5) {} break;\n"
" };\n" " };\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS(
"[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",
errout.str()); errout.str());
} }
@ -1832,7 +1832,7 @@ private:
" M;\n" " M;\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( 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", "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n",
errout.str()); errout.str());
@ -1842,7 +1842,7 @@ private:
" FREE(x);\n" " FREE(x);\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( 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", "[test.cpp:4]: (debug) valueflow.cpp:1260:(valueFlow) bailout: variable 'x', condition is defined in macro\n",
errout.str()); errout.str());
} }
@ -1856,7 +1856,7 @@ private:
" if (x==123){}\n" " if (x==123){}\n"
"}"); "}");
ASSERT_EQUALS_WITHOUT_LINENUMBERS( 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", "[test.cpp:2]: (debug) valueflow.cpp::(valueFlow) bailout: valueFlowAfterCondition: bailing in conditional block\n",
errout.str()); errout.str());