Fixed #7573 (Tokenizer: FP caused by constant folding)

This commit is contained in:
Daniel Marjamäki 2016-08-28 19:11:05 +02:00
parent fee0e4edfa
commit 254e5675ff
2 changed files with 22 additions and 6 deletions

View File

@ -3364,12 +3364,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Combine tokens..
combineOperators();
// simplify simple calculations
for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) {
if (tok->isNumber())
TemplateSimplifier::simplifyNumericCalculations(tok->previous());
}
// remove extern "C" and extern "C" {}
if (isCPP())
simplifyExternC();
@ -3405,6 +3399,25 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Remove "volatile", "inline", "register", and "restrict"
simplifyKeyword();
// simplify simple calculations inside <..>
if (isCPP()) {
Token *lt = nullptr;
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}]"))
lt = nullptr;
else if (Token::Match(tok, "%type <"))
lt = tok->next();
else if (lt && Token::Match(tok, ">|>> %name%|::|(")) {
const Token * const end = tok;
for (tok = lt; tok != end; tok = tok->next()) {
if (tok->isNumber())
TemplateSimplifier::simplifyNumericCalculations(tok->previous());
}
lt = tok->next();
}
}
}
// Convert K&R function declarations to modern C
simplifyVarDecl(true);
simplifyFunctionParameters();

View File

@ -765,6 +765,9 @@ static void valueFlowBitAnd(TokenList *tokenlist)
if (tok->str() != "&")
continue;
if (tok->values.size() == 1U && tok->values.front().isKnown())
continue;
if (!tok->astOperand1() || !tok->astOperand2())
continue;