Fixed #1169 (improve check: divsion by zero not detected when using the shift (>>) operator)
This commit is contained in:
parent
d738785b61
commit
5835b2665b
|
@ -5010,8 +5010,9 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
|
|
||||||
// Variable is used in calculation..
|
// Variable is used in calculation..
|
||||||
if (Token::Match(tok3, "[=+-*/[] %varid% [?+-*/;]]", varid) ||
|
if (Token::Match(tok3, "[=+-*/[] %varid% [?+-*/;]]", varid) ||
|
||||||
Token::Match(tok3, "[=+-*/[] %varid% <<", varid) ||
|
Token::Match(tok3, "[(=+-*/[] %varid% <<|>>", varid) ||
|
||||||
Token::Match(tok3, "<< %varid% [+-*/;]]", varid))
|
Token::Match(tok3, "<< %varid% [+-*/;])]", varid) ||
|
||||||
|
Token::Match(tok3, ">> %varid% [+-*/])]", varid))
|
||||||
{
|
{
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
|
|
@ -1063,22 +1063,51 @@ private:
|
||||||
void simplifyKnownVariables22()
|
void simplifyKnownVariables22()
|
||||||
{
|
{
|
||||||
// This testcase is related to ticket #1169
|
// This testcase is related to ticket #1169
|
||||||
|
{
|
||||||
const char code[] = "void foo()\n"
|
const char code[] = "void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int n = 10;\n"
|
" int n = 10;\n"
|
||||||
" i = (n >> 1);\n"
|
" i = (n >> 1);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
// Wanted result - Ticket #1169 can probably be closed when this works
|
ASSERT_EQUALS(
|
||||||
TODO_ASSERT_EQUALS(
|
|
||||||
"void foo ( ) { int n ; n = 10 ; i = ( 10 >> 1 ) ; }",
|
"void foo ( ) { int n ; n = 10 ; i = ( 10 >> 1 ) ; }",
|
||||||
simplifyKnownVariables(code));
|
simplifyKnownVariables(code));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char code[] = "void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int n = 10;\n"
|
||||||
|
" i = (n << 1);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
// Current result
|
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"void foo ( ) { int n ; n = 10 ; i = ( n >> 1 ) ; }",
|
"void foo ( ) { int n ; n = 10 ; i = ( 10 << 1 ) ; }",
|
||||||
simplifyKnownVariables(code));
|
simplifyKnownVariables(code));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const char code[] = "void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int n = 10;\n"
|
||||||
|
" i = (1 << n);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(
|
||||||
|
"void foo ( ) { int n ; n = 10 ; i = ( 1 << 10 ) ; }",
|
||||||
|
simplifyKnownVariables(code));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char code[] = "void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int n = 10;\n"
|
||||||
|
" i = (1 >> n);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(
|
||||||
|
"void foo ( ) { int n ; n = 10 ; i = ( 1 >> 10 ) ; }",
|
||||||
|
simplifyKnownVariables(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyKnownVariables23()
|
void simplifyKnownVariables23()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue