From 5e1b6aee8cc8eaa65744e17933c95b2d4f5feafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 10 Apr 2017 22:17:34 +0200 Subject: [PATCH] AST: Fix hang for weird VLA code --- lib/tokenlist.cpp | 6 ++++-- test/testtokenize.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0aa0ee7c5..8f6a752d6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2ae5a19b6..b9fa3cc9b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"));