Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,19 +1107,6 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
for (const Token* tok2 : tokens) {
if (const ValueFlow::Value* v = tok2->getKnownValue(ValueFlow::Value::ValueType::INT)) {
values.emplace_back(*v);
} else {
ValueFlow::Value symValue{};
symValue.valueType = ValueFlow::Value::ValueType::SYMBOLIC;
symValue.tokvalue = tok2;
values.push_back(std::move(symValue));
std::copy_if(tok2->values().cbegin(),
tok2->values().cend(),
std::back_inserter(values),
[](const ValueFlow::Value& v) {
if (!v.isKnown())
return false;
return v.isSymbolicValue();
});
}
}
const bool isMin = Token::Match(condTok, "<|<=") ^ flipped;
Expand Down
6 changes: 6 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5222,6 +5222,12 @@ class TestCondition : public TestFixture {
" if (c) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(int a, int b) {\n" // #11437
" a = a < b ? b : a;\n"
" if (a != b) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueInfer() {
Expand Down
62 changes: 0 additions & 62 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class TestValueFlow : public TestFixture {
TEST_CASE(valueFlowSymbolicIdentity);
TEST_CASE(valueFlowSymbolicStrlen);
TEST_CASE(valueFlowSmartPointer);
TEST_CASE(valueFlowImpossibleMinMax);
TEST_CASE(valueFlowImpossibleIncDec);
TEST_CASE(valueFlowImpossibleUnknownConstant);
TEST_CASE(valueFlowContainerEqual);
Expand Down Expand Up @@ -9334,67 +9333,6 @@ class TestValueFlow : public TestFixture {
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
}

void valueFlowImpossibleMinMax()
{
const char* code;

code = "void f(int a, int b) {\n"
" int x = a < b ? a : b;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", 1));
Comment thread
chrchr-github marked this conversation as resolved.
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "b", 1));

code = "void f(int a, int b) {\n"
" int x = a > b ? a : b;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "b", -1));

code = "void f(int a, int b) {\n"
" int x = a > b ? b : a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", 1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "b", 1));

code = "void f(int a, int b) {\n"
" int x = a < b ? b : a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "b", -1));

code = "void f(int a) {\n"
" int x = a < 0 ? a : 0;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", 1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, 1));

code = "void f(int a) {\n"
" int x = a > 0 ? a : 0;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));

code = "void f(int a) {\n"
" int x = a > 0 ? 0 : a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", 1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, 1));

code = "void f(int a) {\n"
" int x = a < 0 ? 0 : a;\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, "a", -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
}

void valueFlowImpossibleIncDec()
{
const char* code;
Expand Down
Loading