AST: Fix hang for weird VLA code

This commit is contained in:
Daniel Marjamäki 2017-04-10 22:17:34 +02:00
parent ffeadbdde4
commit 5e1b6aee8c
2 changed files with 5 additions and 2 deletions

View File

@ -488,7 +488,7 @@ static bool iscast(const Token *tok)
if (!Token::Match(tok2, "%name%|*|&|::"))
return false;
if (tok2->isStandardType() && tok2->next()->str() != "(")
if (tok2->isStandardType() && (tok2->next()->str() != "(" || Token::Match(tok2->next(), "( * |* )")))
type = true;
}
@ -617,7 +617,9 @@ static void compileTerm(Token *&tok, AST_state& state)
}
}
} else if (tok->str() == "{") {
if (tok->previous() && tok->previous()->isName()) {
if (Token::simpleMatch(tok->link(),"} [")) {
tok = tok->next();
} else if (tok->previous() && tok->previous()->isName()) {
compileBinOp(tok, state, compileExpression);
} else if (!state.inArrayAssignment && tok->strAt(-1) != "=") {
state.op.push(tok);

View File

@ -8046,6 +8046,7 @@ private:
ASSERT_EQUALS("a1(2+=",testAst("a=(t&)1+2;"));
ASSERT_EQUALS("ab::r&c(=", testAst("a::b& r = (a::b&)c;")); // #5261
ASSERT_EQUALS("ab10:?=", testAst("a=(b)?1:0;"));
ASSERT_EQUALS("a&(", testAst("(int (**)[i]){&a}[0][1][5] = 0;")); // TODO: This AST is incomplete however it's very weird syntax (taken from clang/test/CodeGen/vla.c)
// ({..})
ASSERT_EQUALS("a{+d+ bc+", testAst("a+({b+c;})+d"));