From a765a1310d8a6f7a95f0267326253d071c8715c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 23 Oct 2023 10:13:10 +0200 Subject: [PATCH] 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. --- lib/valueflow.cpp | 5 +++-- test/testsimplifytokens.cpp | 3 ++- test/testsimplifytypedef.cpp | 2 +- test/testsymboldatabase.cpp | 4 ++-- test/testtokenize.cpp | 3 ++- test/testvalueflow.cpp | 26 +++++++++++++------------- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ff8279d99d9..2848c0e870d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -132,8 +132,9 @@ static void bailoutInternal(const std::string& type, TokenList &tokenlist, Error if (function.find("operator") != std::string::npos) function = "(valueFlow)"; std::list 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); } @@ -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 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) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 184575784b1..d4d79f4124a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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"; } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 1239ddbda31..bebdd30b3f1 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -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 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 5fffaec3957..d6b8c13b7a0 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 801897163cc..ab4ab531dd6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 542691618cb..ce8c25b3e52 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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()); } @@ -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" @@ -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" @@ -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" @@ -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()); } @@ -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()); @@ -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()); } @@ -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());