Fix 10430: FP knownConditionTrueFalse with bool from unsigned char (#3416)
This commit is contained in:
parent
8ddc5764f8
commit
f7ddd7a35d
|
@ -4716,12 +4716,13 @@ static void valueFlowForwardAssign(Token* const tok,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenlist->isCPP() && vars.size() == 1 && Token::Match(vars.front()->typeStartToken(), "bool|_Bool")) {
|
if (tokenlist->isCPP() && vars.size() == 1 && Token::Match(vars.front()->typeStartToken(), "bool|_Bool")) {
|
||||||
std::list<ValueFlow::Value>::iterator it;
|
for (ValueFlow::Value& value : values) {
|
||||||
for (it = values.begin(); it != values.end(); ++it) {
|
if (value.isImpossible())
|
||||||
if (it->isIntValue())
|
continue;
|
||||||
it->intvalue = (it->intvalue != 0);
|
if (value.isIntValue())
|
||||||
if (it->isTokValue())
|
value.intvalue = (value.intvalue != 0);
|
||||||
it->intvalue = (it->tokvalue != nullptr);
|
if (value.isTokValue())
|
||||||
|
value.intvalue = (value.tokvalue != nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2434,6 +2434,16 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 12U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 12U, 0));
|
||||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 12U, 0));
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 12U, 0));
|
||||||
|
|
||||||
|
code = "bool f(unsigned char uc) {\n"
|
||||||
|
" const bool x = uc;\n"
|
||||||
|
" return x;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 3U, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowAfterCondition() {
|
void valueFlowAfterCondition() {
|
||||||
|
|
Loading…
Reference in New Issue