fix garbage code handling

This commit is contained in:
Daniel Marjamäki 2016-07-26 08:50:00 +02:00
parent 2b31afe2ab
commit fd19ab4ed1
3 changed files with 7 additions and 6 deletions

View File

@ -8087,7 +8087,7 @@ const Token * Tokenizer::findGarbageCode() const
{
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "if|while|for|switch")) { // switch (EXPR) { ... }
if (!Token::Match(tok->previous(), ";|{|}|(|)|,|else"))
if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|(|)|,|else|do"))
return tok;
if (!Token::Match(tok->next(), "( !!)"))
return tok;

View File

@ -1229,7 +1229,7 @@ private:
}
void garbageCode151() { // #4175
checkCode(">{ x while (y) z int = }");
ASSERT_THROW(checkCode(">{ x while (y) z int = }"), InternalError);
checkCode("void f() {\n" // #4911 - bad simplification => don't crash
" int a;\n"
" do { a=do_something() } while (a);\n"
@ -1317,9 +1317,9 @@ private:
void garbageAST() {
checkCode("--"); // don't crash
checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n"
ASSERT_THROW(checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n"
"int #define for (i = avx_test i < c[i]; i++)\n"
"b[i + 3] = a[i] * {}"); // Don't hang (#5787)
"b[i + 3] = a[i] * {}"), InternalError); // Don't hang (#5787)
checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991)
}

View File

@ -1148,7 +1148,8 @@ private:
void ifAddBraces15() {
// ticket #2616 - unknown macro before if
ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false));
// TODO: Move to TestGarbage
ASSERT_THROW(tokenizeAndStringify("{A if(x)y();}", false), InternalError);
}
void ifAddBraces16() {