From c050a92bae7255e1ecc960aca2e7da3f797ab306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Feb 2014 17:37:39 +0100 Subject: [PATCH] Fixed #5468 (crash: freebsd: llvm/RegionPrinter.cpp - AST failure) --- lib/tokenlist.cpp | 3 +++ test/testtokenize.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 73f2d5bde..3acb0b9d0 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -758,6 +758,9 @@ static Token * createAstAtToken(Token *tok) if (Token::simpleMatch(tok, "( {")) return tok; + if (Token::Match(tok, "%type% <") && Token::Match(tok->linkAt(1), "> !!(")) + return tok->linkAt(1); + if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%var% %op%|(|[|.|=|::") || Token::Match(tok->previous(), "[;{}] %cop%|( !!{")) { std::stack operands; Token * const tok1 = tok; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1f936d0c3..4ecad6f02 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -10077,6 +10077,8 @@ private: links.pop(); } else if (Token::Match(tok, "< %type% >")) { Token::createMutualLinks(tok, tok->tokAt(2)); + } else if (Token::Match(tok, "< %type% * >")) { + Token::createMutualLinks(tok, tok->tokAt(3)); } } @@ -10194,13 +10196,14 @@ private: testAst("extern int for_each_commit_graft(int (*)(int*), void *);"); // don't crash testAst("for (;;) {}"); // don't crash ASSERT_EQUALS("xsizeofvoid(=", testAst("x=sizeof(void*)")); - - ASSERT_EQUALS("publica::b::", testAst("class C : public ::a::b { };")); } void asttemplate() const { // uninstantiated templates will have <,>,etc.. ASSERT_EQUALS("a(3==", testAst("a()==3")); ASSERT_EQUALS("ab(== f(", testAst("a == b(); f();")); + + ASSERT_EQUALS("publica::b::", testAst("class C : public ::a::b { };")); + ASSERT_EQUALS("f( abc+=", testAst("struct A : public B { void f() { a=b+c; } };")); } };