Fixed #3304 (simple cases)
This commit is contained in:
parent
be716e81d3
commit
913670d254
|
@ -3333,19 +3333,34 @@ bool Tokenizer::simplifyTokenList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace "&str[num]" => "(str + num)"
|
// Replace "&str[num]" => "(str + num)"
|
||||||
//TODO: fix the fails testrunner reports:
|
std::set<unsigned int> pod;
|
||||||
//1)
|
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
//test/teststl.cpp:805: Assertion failed.
|
if (tok->isStandardType()) {
|
||||||
//Expected:
|
while (tok && (tok->str() == "*" || tok->isName())) {
|
||||||
//"[test.cpp:7]: (error) Invalid pointer 'first' after push_back / push_front\n".
|
if (tok->varId() > 0) {
|
||||||
//Actual:
|
pod.insert(tok->varId());
|
||||||
//"".
|
break;
|
||||||
/*for (Token *tok = list.front(); tok; tok = tok->next()) {
|
}
|
||||||
if (!Token::Match(tok, "%var%") && !Token::Match(tok, "%num%")
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
if (!Token::Match(tok, "%var%")
|
||||||
|
&& !Token::Match(tok, "%num%")
|
||||||
&& !Token::Match(tok, "]|)")
|
&& !Token::Match(tok, "]|)")
|
||||||
&& (Token::Match(tok->next(), "& %var% [ %num% ]") ||
|
&& (Token::Match(tok->next(), "& %var% [ %num% ]") ||
|
||||||
Token::Match(tok->next(), "& %var% [ %var% ]"))) {
|
Token::Match(tok->next(), "& %var% [ %var% ]"))) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
if (tok->next()->varId()) {
|
||||||
|
if (pod.find(tok->next()->varId()) == pod.end()) {
|
||||||
|
tok = tok->tokAt(5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// '&' => '('
|
// '&' => '('
|
||||||
tok->str("(");
|
tok->str("(");
|
||||||
|
|
||||||
|
@ -3359,7 +3374,9 @@ bool Tokenizer::simplifyTokenList()
|
||||||
tok->str(")");
|
tok->str(")");
|
||||||
Token::createMutualLinks(tok->tokAt(-4), tok);
|
Token::createMutualLinks(tok->tokAt(-4), tok);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
removeRedundantAssignment();
|
||||||
|
|
||||||
simplifyRealloc();
|
simplifyRealloc();
|
||||||
|
|
||||||
|
|
|
@ -421,6 +421,7 @@ private:
|
||||||
TEST_CASE(consecutiveBraces);
|
TEST_CASE(consecutiveBraces);
|
||||||
|
|
||||||
TEST_CASE(undefinedSizeArray);
|
TEST_CASE(undefinedSizeArray);
|
||||||
|
TEST_CASE(simplifyCase3304);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
|
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
|
||||||
|
@ -6701,7 +6702,6 @@ private:
|
||||||
const char expected[] = "void f ( ) "
|
const char expected[] = "void f ( ) "
|
||||||
"{"
|
"{"
|
||||||
" int a [ 10 ] ;"
|
" int a [ 10 ] ;"
|
||||||
" int * p ; p = & a [ 0 ] ;"
|
|
||||||
" * a = 0 ; "
|
" * a = 0 ; "
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
|
@ -7884,6 +7884,17 @@ private:
|
||||||
ASSERT_EQUALS("int * * * * x ;", tok("int * * x [][];"));
|
ASSERT_EQUALS("int * * * * x ;", tok("int * * x [][];"));
|
||||||
ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }"));
|
ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyCase3304() { // ticket #3304
|
||||||
|
const char code[] = "void foo() {\n"
|
||||||
|
" int a[10];\n"
|
||||||
|
" memset(&a[4], 0, 20*sizeof(int));\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS("void foo ( ) {"
|
||||||
|
" int a [ 10 ] ;"
|
||||||
|
" memset ( a + 4 , 0 , 80 ) ;"
|
||||||
|
" }", tok(code, true));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestSimplifyTokens)
|
REGISTER_TEST(TestSimplifyTokens)
|
||||||
|
|
|
@ -5728,8 +5728,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeRedundantAssignment() {
|
void removeRedundantAssignment() {
|
||||||
ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
|
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
|
||||||
ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));
|
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));
|
||||||
ASSERT_EQUALS("int f ( int * x ) { return * x ; }", tokenizeAndStringify("int f(int *x) { return *x; }", true));
|
ASSERT_EQUALS("int f ( int * x ) { return * x ; }", tokenizeAndStringify("int f(int *x) { return *x; }", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue