Fixed #6110 (TemplateSimplifier::simplifyCalculations: wrong simplification of 'if (VG_(strlen)(s)>=3)')
This commit is contained in:
parent
86cdc8e7a6
commit
925f077b8a
|
@ -997,14 +997,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
|
||||||
(Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) &&
|
(Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) &&
|
||||||
!tok->isName() &&
|
!tok->isName() &&
|
||||||
tok->str() != ">" &&
|
tok->str() != ">" &&
|
||||||
tok->str() != "]" &&
|
tok->str() != ")" &&
|
||||||
tok->strAt(-1) != "operator" &&
|
tok->str() != "]") {
|
||||||
!Token::simpleMatch(tok->previous(), "* )") &&
|
|
||||||
!Token::simpleMatch(tok->previous(), ") )") &&
|
|
||||||
!Token::Match(tok->tokAt(-2), "* %name% )") &&
|
|
||||||
!Token::Match(tok->tokAt(-2), "%type% ( ) ( %name%") &&
|
|
||||||
!Token::Match(tok, ") ( %name% ) ;")
|
|
||||||
) {
|
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
|
|
@ -97,6 +97,7 @@ private:
|
||||||
TEST_CASE(removeCast14);
|
TEST_CASE(removeCast14);
|
||||||
TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast<int>(b?60:0)'
|
TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast<int>(b?60:0)'
|
||||||
TEST_CASE(removeCast16); // #6278
|
TEST_CASE(removeCast16); // #6278
|
||||||
|
TEST_CASE(removeCast17); // #6110 - don't remove any parentheses in 'a(b)(c)'
|
||||||
|
|
||||||
TEST_CASE(simplifyFloatCasts); // float casting a integer
|
TEST_CASE(simplifyFloatCasts); // float casting a integer
|
||||||
|
|
||||||
|
@ -960,7 +961,7 @@ private:
|
||||||
void removeCast4() {
|
void removeCast4() {
|
||||||
// ticket #970
|
// ticket #970
|
||||||
const char code[] = "if (a >= (unsigned)(b)) {}";
|
const char code[] = "if (a >= (unsigned)(b)) {}";
|
||||||
const char expected[] = "if ( a >= ( unsigned int ) b ) { }";
|
const char expected[] = "if ( a >= ( unsigned int ) ( b ) ) { }";
|
||||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -984,7 +985,7 @@ private:
|
||||||
|
|
||||||
void removeCast9() {
|
void removeCast9() {
|
||||||
ASSERT_EQUALS("f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true));
|
ASSERT_EQUALS("f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true));
|
||||||
ASSERT_EQUALS("int v1 ; f ( ( double ) v1 * v2 )", tokenizeAndStringify("int v1; f((double)(v1)*v2)", true));
|
ASSERT_EQUALS("int v1 ; f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("int v1; f((double)(v1)*v2)", true));
|
||||||
ASSERT_EQUALS("f ( ( A ) ( B ) & x )", tokenizeAndStringify("f((A)(B)&x)", true)); // #4439
|
ASSERT_EQUALS("f ( ( A ) ( B ) & x )", tokenizeAndStringify("f((A)(B)&x)", true)); // #4439
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1039,6 +1040,11 @@ private:
|
||||||
tokenizeAndStringify("Get((CObject*&)pArray);", true));
|
tokenizeAndStringify("Get((CObject*&)pArray);", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeCast17() { // #6110 - don't remove any parentheses in 'a(b)(c)'
|
||||||
|
ASSERT_EQUALS("if ( a ( b ) ( c ) >= 3 )",
|
||||||
|
tokenizeAndStringify("if (a(b)(c) >= 3)", true));
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyFloatCasts() { // float casting integers
|
void simplifyFloatCasts() { // float casting integers
|
||||||
// C-style casts
|
// C-style casts
|
||||||
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
|
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
|
||||||
|
|
Loading…
Reference in New Issue