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)"
|
||||
//TODO: fix the fails testrunner reports:
|
||||
//1)
|
||||
//test/teststl.cpp:805: Assertion failed.
|
||||
//Expected:
|
||||
//"[test.cpp:7]: (error) Invalid pointer 'first' after push_back / push_front\n".
|
||||
//Actual:
|
||||
//"".
|
||||
/*for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (!Token::Match(tok, "%var%") && !Token::Match(tok, "%num%")
|
||||
std::set<unsigned int> pod;
|
||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (tok->isStandardType()) {
|
||||
while (tok && (tok->str() == "*" || tok->isName())) {
|
||||
if (tok->varId() > 0) {
|
||||
pod.insert(tok->varId());
|
||||
break;
|
||||
}
|
||||
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->next(), "& %var% [ %num% ]") ||
|
||||
Token::Match(tok->next(), "& %var% [ %var% ]"))) {
|
||||
tok = tok->next();
|
||||
|
||||
if (tok->next()->varId()) {
|
||||
if (pod.find(tok->next()->varId()) == pod.end()) {
|
||||
tok = tok->tokAt(5);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// '&' => '('
|
||||
tok->str("(");
|
||||
|
||||
|
@ -3359,7 +3374,9 @@ bool Tokenizer::simplifyTokenList()
|
|||
tok->str(")");
|
||||
Token::createMutualLinks(tok->tokAt(-4), tok);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
removeRedundantAssignment();
|
||||
|
||||
simplifyRealloc();
|
||||
|
||||
|
|
|
@ -421,6 +421,7 @@ private:
|
|||
TEST_CASE(consecutiveBraces);
|
||||
|
||||
TEST_CASE(undefinedSizeArray);
|
||||
TEST_CASE(simplifyCase3304);
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
|
||||
|
@ -6701,7 +6702,6 @@ private:
|
|||
const char expected[] = "void f ( ) "
|
||||
"{"
|
||||
" int a [ 10 ] ;"
|
||||
" int * p ; p = & a [ 0 ] ;"
|
||||
" * a = 0 ; "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
|
@ -7884,6 +7884,17 @@ private:
|
|||
ASSERT_EQUALS("int * * * * x ;", tok("int * * x [][];"));
|
||||
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)
|
||||
|
|
|
@ -5728,8 +5728,8 @@ private:
|
|||
}
|
||||
|
||||
void removeRedundantAssignment() {
|
||||
ASSERT_EQUALS("void f ( ) { int * q ; }", 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, *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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue