Skip to content

Commit 254e567

Browse files
committed
Fixed danmar#7573 (Tokenizer: FP caused by constant folding)
1 parent fee0e4e commit 254e567

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lib/tokenize.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,12 +3364,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
33643364
// Combine tokens..
33653365
combineOperators();
33663366

3367-
// simplify simple calculations
3368-
for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) {
3369-
if (tok->isNumber())
3370-
TemplateSimplifier::simplifyNumericCalculations(tok->previous());
3371-
}
3372-
33733367
// remove extern "C" and extern "C" {}
33743368
if (isCPP())
33753369
simplifyExternC();
@@ -3405,6 +3399,25 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
34053399
// Remove "volatile", "inline", "register", and "restrict"
34063400
simplifyKeyword();
34073401

3402+
// simplify simple calculations inside <..>
3403+
if (isCPP()) {
3404+
Token *lt = nullptr;
3405+
for (Token *tok = list.front(); tok; tok = tok->next()) {
3406+
if (Token::Match(tok, "[;{}]"))
3407+
lt = nullptr;
3408+
else if (Token::Match(tok, "%type <"))
3409+
lt = tok->next();
3410+
else if (lt && Token::Match(tok, ">|>> %name%|::|(")) {
3411+
const Token * const end = tok;
3412+
for (tok = lt; tok != end; tok = tok->next()) {
3413+
if (tok->isNumber())
3414+
TemplateSimplifier::simplifyNumericCalculations(tok->previous());
3415+
}
3416+
lt = tok->next();
3417+
}
3418+
}
3419+
}
3420+
34083421
// Convert K&R function declarations to modern C
34093422
simplifyVarDecl(true);
34103423
simplifyFunctionParameters();

lib/valueflow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,9 @@ static void valueFlowBitAnd(TokenList *tokenlist)
765765
if (tok->str() != "&")
766766
continue;
767767

768+
if (tok->values.size() == 1U && tok->values.front().isKnown())
769+
continue;
770+
768771
if (!tok->astOperand1() || !tok->astOperand2())
769772
continue;
770773

0 commit comments

Comments
 (0)