This commit is contained in:
parent
082331c210
commit
38b2c5ee3f
|
@ -7852,14 +7852,14 @@ bool findTokenSkipDeadCodeImpl(const Library* library, Token* start, const Token
|
||||||
tok = thenStart->link();
|
tok = thenStart->link();
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok->astParent(), "&&|?|%oror%") && astIsLHS(tok) && tok->hasKnownIntValue()) {
|
} else if (Token::Match(tok->astParent(), "&&|?|%oror%") && astIsLHS(tok) && tok->hasKnownIntValue()) {
|
||||||
int r = tok->values().front().intvalue;
|
const bool cond = tok->values().front().intvalue != 0;
|
||||||
Token* next = nullptr;
|
Token* next = nullptr;
|
||||||
if ((r == 0 && Token::simpleMatch(tok->astParent(), "||")) ||
|
if ((cond && Token::simpleMatch(tok->astParent(), "||")) ||
|
||||||
(r != 0 && Token::simpleMatch(tok->astParent(), "&&"))) {
|
(!cond && Token::simpleMatch(tok->astParent(), "&&"))) {
|
||||||
next = nextAfterAstRightmostLeaf(tok->astParent());
|
next = nextAfterAstRightmostLeaf(tok->astParent());
|
||||||
} else if (Token::simpleMatch(tok->astParent(), "?")) {
|
} else if (Token::simpleMatch(tok->astParent(), "?")) {
|
||||||
Token* colon = tok->astParent()->astOperand2();
|
Token* colon = tok->astParent()->astOperand2();
|
||||||
if (r == 0) {
|
if (!cond) {
|
||||||
next = colon;
|
next = colon;
|
||||||
} else {
|
} else {
|
||||||
if (findTokenSkipDeadCodeImpl(library, tok->astParent()->next(), colon, pred, found))
|
if (findTokenSkipDeadCodeImpl(library, tok->astParent()->next(), colon, pred, found))
|
||||||
|
|
|
@ -5554,6 +5554,17 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
values = tokenValues(code, ". id", ValueFlow::Value::ValueType::UNINIT);
|
values = tokenValues(code, ". id", ValueFlow::Value::ValueType::UNINIT);
|
||||||
ASSERT_EQUALS(0, values.size());
|
ASSERT_EQUALS(0, values.size());
|
||||||
|
|
||||||
|
// #11777 - false || ...
|
||||||
|
code = "bool init(int *p);\n"
|
||||||
|
"\n"
|
||||||
|
"void uninitvar_FP9() {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" if (false || init(&x)) {}\n"
|
||||||
|
" int b = x+1;\n"
|
||||||
|
"}";
|
||||||
|
values = tokenValues(code, "x + 1", ValueFlow::Value::ValueType::UNINIT);
|
||||||
|
ASSERT_EQUALS(0, values.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowConditionExpressions() {
|
void valueFlowConditionExpressions() {
|
||||||
|
|
Loading…
Reference in New Issue