Refactoring fix for #7816

This commit is contained in:
Daniel Marjamäki 2016-11-21 13:54:59 +01:00
parent 933815ee54
commit 21364b4401
3 changed files with 13 additions and 50 deletions

View File

@ -8037,7 +8037,8 @@ const Token * Tokenizer::findGarbageCode() const
return list.back();
if (list.back()->str() == ")" && !Token::Match(list.back()->link()->previous(), "%name% ("))
return list.back();
if (Token::Match(list.back(), "void|char|short|int|long|float|double|const|volatile|static|inline|struct|class|enum|union|template|sizeof|break|continue|typedef"))
return list.back();
return nullptr;
}
@ -8445,12 +8446,9 @@ void Tokenizer::simplifyAttribute()
if (!tok->next()->link()->next())
syntaxError(tok);
if (tok->next()->link()->next()->str() == "void") {
// __attribute__((destructor)) void func() {}
if (!tok->next()->link()->next()->next())
syntaxError(tok);
if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {}
tok->next()->link()->next()->next()->isAttributeDestructor(true);
} else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((destructor));
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((destructor));
tok->previous()->link()->previous()->isAttributeDestructor(true);
else // void __attribute__((destructor)) func() {}
tok->next()->link()->next()->isAttributeDestructor(true);

View File

@ -66,7 +66,6 @@ private:
TEST_CASE(garbageCode16);
TEST_CASE(garbageCode17);
TEST_CASE(garbageCode18);
TEST_CASE(garbageCode19);
TEST_CASE(garbageCode20);
TEST_CASE(garbageCode21);
TEST_CASE(garbageCode22);
@ -80,7 +79,7 @@ private:
TEST_CASE(garbageCode31); // #6539
TEST_CASE(garbageCode33); // #6613
TEST_CASE(garbageCode34); // #6626
TEST_CASE(garbageCode35); // #2599, #2604
TEST_CASE(garbageCode35); // #2604
TEST_CASE(garbageCode36); // #6334
TEST_CASE(garbageCode37); // #5166
TEST_CASE(garbageCode38); // #6666
@ -94,7 +93,6 @@ private:
TEST_CASE(garbageCode47); // #6706
TEST_CASE(garbageCode48); // #6712
TEST_CASE(garbageCode49); // #6715
TEST_CASE(garbageCode50); // #6718
TEST_CASE(garbageCode51); // #6719
TEST_CASE(garbageCode53); // #6721
TEST_CASE(garbageCode54); // #6722
@ -211,13 +209,10 @@ private:
TEST_CASE(garbageCode174); // #7356
TEST_CASE(garbageCode175);
TEST_CASE(garbageCode176); // #7527
TEST_CASE(garbageCode177); // #7321
TEST_CASE(garbageCode180);
TEST_CASE(garbageCode181);
TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageCode185); // #7816
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -452,11 +447,6 @@ private:
ASSERT_THROW(checkCode("switch(){case}"), InternalError);
}
void garbageCode19() {
// ticket #3512 - Don't crash on garbage code
ASSERT_EQUALS("p = const", checkCode("1 *p = const"));
}
void garbageCode20() {
// #3953 (valgrind errors on garbage code)
ASSERT_EQUALS("void f ( 0 * ) ;", checkCode("void f ( 0 * ) ;"));
@ -560,9 +550,6 @@ private:
}
void garbageCode35() {
// ticket #2599 segmentation fault
checkCode("sizeof");
// ticket #2604 segmentation fault
checkCode("sizeof <= A");
}
@ -626,10 +613,6 @@ private:
checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }");
}
void garbageCode50() { // #6718
checkCode(" enum struct");
}
void garbageCode51() { // #6719
checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }");
}
@ -1404,14 +1387,6 @@ private:
checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;");
}
void garbageCode177() { // #7321
checkCode("{(){(())}}r&const");
}
void garbageCode180() {
checkCode("int");
}
void garbageCode181() {
checkCode("int test() { int +; }");
}
@ -1432,10 +1407,6 @@ private:
"}");
}
void garbageCode185() { // #7816
checkCode("__attribute__((destructor)) void");
}
void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858
@ -1476,6 +1447,14 @@ private:
ASSERT_THROW(checkCode(" ( * const ( size_t ) ; foo )"), InternalError); // #6135
ASSERT_THROW(checkCode("({ (); strcat(strcat(() ()) ()) })"), InternalError); // #6686
ASSERT_THROW(checkCode("%: return ; ()"), InternalError); // #3441
ASSERT_THROW(checkCode("__attribute__((destructor)) void"), InternalError); // #7816
ASSERT_THROW(checkCode("1 *p = const"), InternalError); // #3512
ASSERT_THROW(checkCode("sizeof"), InternalError); // #2599
ASSERT_THROW(checkCode(" enum struct"), InternalError); // #6718
ASSERT_THROW(checkCode("{(){(())}}r&const"), InternalError); // #7321
ASSERT_THROW(checkCode("int"), InternalError);
ASSERT_THROW(checkCode("struct A :\n"), InternalError); // #2591
ASSERT_THROW(checkCode("{} const const\n"), InternalError); // #2637
// ASSERT_THROW( , InternalError)
}

View File

@ -214,8 +214,6 @@ private:
TEST_CASE(symboldatabase12); // ticket #2547
TEST_CASE(symboldatabase13); // ticket #2577
TEST_CASE(symboldatabase14); // ticket #2589
TEST_CASE(symboldatabase15); // ticket #2591
TEST_CASE(symboldatabase16); // ticket #2637
TEST_CASE(symboldatabase17); // ticket #2657
TEST_CASE(symboldatabase19); // ticket #2991 (segmentation fault)
TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault)
@ -2164,18 +2162,6 @@ private:
ASSERT_THROW(check("struct B : A\n"), InternalError);
}
void symboldatabase15() {
// ticket #2591 - segmentation fault
ASSERT_THROW(check("struct A :\n"), InternalError);
}
void symboldatabase16() {
// ticket #2637 - segmentation fault
check("{} const const\n");
ASSERT_EQUALS("", errout.str());
}
void symboldatabase17() {
// ticket #2657 - segmentation fault
check("return f(){}");