Tokenizer: Avoid constant folding

This commit is contained in:
Daniel Marjamäki 2018-10-20 10:51:50 +02:00
parent d265a0d6ab
commit 29feaa5a51
5 changed files with 16 additions and 22 deletions

View File

@ -1716,14 +1716,17 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
void CheckOther::checkNanInArithmeticExpression()
{
if (!mSettings->isEnabled(Settings::STYLE))
return;
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "inf.0 +|-") ||
Token::Match(tok, "+|- inf.0") ||
Token::Match(tok, "+|- %num% / 0.0")) {
if (tok->str() != "/")
continue;
if (!Token::Match(tok->astParent(), "[+-]"))
continue;
if (Token::simpleMatch(tok->astOperand2(), "0.0"))
nanInArithmeticExpressionError(tok);
}
}
}
void CheckOther::nanInArithmeticExpressionError(const Token *tok)
{

View File

@ -3831,11 +3831,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
simplifyRedundantParentheses();
if (!isC()) {
// TODO: Only simplify template parameters
for (Token *tok = list.front(); tok; tok = tok->next())
while (mTemplateSimplifier->simplifyNumericCalculations(tok))
;
// Handle templates..
simplifyTemplates();

View File

@ -1193,8 +1193,7 @@ private:
" else\n"
" return;\n"
"}");
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (warning) Logical conjunction always evaluates to false: neg < -1.0 && neg > -1.0.\n", errout.str());
ASSERT_EQUALS("", errout.str());
}
void incorrectLogicOperator8() { // opposite expressions

View File

@ -641,7 +641,7 @@ private:
void nanInArithmeticExpression() {
check("void f()\n"
"{\n"
" double x = 3.0 / 0.0 + 1.0\n"
" double x = 3.0 / 0.0 + 1.0;\n"
" printf(\"%f\", x);\n"
"}");
ASSERT_EQUALS(
@ -649,7 +649,7 @@ private:
check("void f()\n"
"{\n"
" double x = 3.0 / 0.0 - 1.0\n"
" double x = 3.0 / 0.0 - 1.0;\n"
" printf(\"%f\", x);\n"
"}");
ASSERT_EQUALS(
@ -657,7 +657,7 @@ private:
check("void f()\n"
"{\n"
" double x = 1.0 + 3.0 / 0.0\n"
" double x = 1.0 + 3.0 / 0.0;\n"
" printf(\"%f\", x);\n"
"}");
ASSERT_EQUALS(
@ -665,7 +665,7 @@ private:
check("void f()\n"
"{\n"
" double x = 1.0 - 3.0 / 0.0\n"
" double x = 1.0 - 3.0 / 0.0;\n"
" printf(\"%f\", x);\n"
"}");
ASSERT_EQUALS(
@ -673,7 +673,7 @@ private:
check("void f()\n"
"{\n"
" double x = 3.0 / 0.0\n"
" double x = 3.0 / 0.0;\n"
" printf(\"%f\", x);\n"
"}");
ASSERT_EQUALS("", errout.str());

View File

@ -3305,7 +3305,7 @@ private:
void removeParentheses15() {
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
ASSERT_EQUALS("a = b ? c : ( 579 ) ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
ASSERT_EQUALS("a = b ? c : ( 123 + 456 ) ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;", false));
// #4316
@ -3402,7 +3402,7 @@ private:
"float b ; b = 4.2f ;\n"
"double c ; c = 4.2e+10 ;\n"
"double d ; d = 4.2e-10 ;\n"
"int e ; e = 6 ;\n"
"int e ; e = 4 + 2 ;\n"
"}", tokenizeAndStringify(code));
}
@ -3722,7 +3722,7 @@ private:
// Ticket #4450
const char code[] = "static int large_eeprom_type = (13 | (5)), "
"default_flash_type = 42;";
ASSERT_EQUALS("static int large_eeprom_type = 13 ; static int default_flash_type = 42 ;",
ASSERT_EQUALS("static int large_eeprom_type = 13 | 5 ; static int default_flash_type = 42 ;",
tokenizeAndStringify(code));
}
@ -6012,9 +6012,6 @@ private:
ASSERT_EQUALS("( 0 ) ;",
tokenizeAndStringify("( 0 && a[123] );", true));
// ticket #3964 - simplify numeric calculations in tokenization
ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];"));
// ticket #4931
ASSERT_EQUALS("dostuff ( 1 ) ;", tokenizeAndStringify("dostuff(9&&8);", true));
}