Skip to content

Commit 29168c0

Browse files
committed
clang import: reject ParmVarDecl without a token between address and type
1 parent c0a3af7 commit 29168c0

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎lib/clangimport.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,9 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
14731473
AstNodePtr child = children[i];
14741474
if (child->nodeType != ParmVarDecl)
14751475
continue;
1476+
// there must be a token between the address and the type
1477+
if (child->mExtTokens.size() < 3)
1478+
throw InternalError(nullptr, "invalid AST node: " + child->nodeType, InternalError::AST);
14761479
if (tokenList.back() != par1)
14771480
addtoken(tokenList, ",");
14781481
const Type *recordType = addTypeTokens(tokenList, child->mExtTokens.back(), nestedIn);

‎test/testclangimport.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,10 @@ class TestClangImport : public TestFixture {
14611461
ASSERT_THROW_INTERNAL_EQUALS(parse("`-CXXConstructorDecl 0x1"), AST, "invalid AST node: CXXConstructorDecl");
14621462
ASSERT_THROW_INTERNAL_EQUALS(parse("`-CXXMethodDecl 0x1"), AST, "invalid AST node: CXXMethodDecl");
14631463
ASSERT_THROW_INTERNAL_EQUALS(parse("`-EnumConstantDecl 0x1"), AST, "invalid AST node: EnumConstantDecl");
1464+
ASSERT_THROW_INTERNAL_EQUALS(parse("`-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()'\n"
1465+
" `-ParmVarDecl 0x2 <col:1>\n"), AST, "invalid AST node: ParmVarDecl");
1466+
ASSERT_THROW_INTERNAL_EQUALS(parse("`-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()'\n"
1467+
" `-ParmVarDecl 0x2 'int'\n"), AST, "invalid AST node: ParmVarDecl");
14641468
}
14651469
};
14661470

0 commit comments

Comments
 (0)