From 80055d42ffb1f6c32d2b4f759a83b21ba91694bb Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 24 Jul 2018 13:53:32 +0200 Subject: [PATCH] logic: fixed infinite iteration in cxx signature recording --- .../cxx/CxxAstVisitorComponentIndexer.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp index 177e36db..2ba0cf67 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp @@ -769,14 +769,7 @@ ParseLocation CxxAstVisitorComponentIndexer::getSignatureLocation(clang::Functio if (d->doesThisDeclarationHaveABody()) { - const clang::TypeSourceInfo *TSI = d->getTypeSourceInfo(); - if (!TSI) - { - return ParseLocation(); - } - - clang::FunctionTypeLoc FTL = TSI->getTypeLoc().IgnoreParens().getAs(); - if (FTL.isNull()) + if (!d->getTypeSourceInfo()) { return ParseLocation(); } @@ -784,7 +777,13 @@ ParseLocation CxxAstVisitorComponentIndexer::getSignatureLocation(clang::Functio const clang::SourceManager& sm = m_astContext->getSourceManager(); const clang::LangOptions& opts = m_astContext->getLangOpts(); - clang::SourceLocation endLoc = FTL.getSourceRange().getEnd(); + clang::SourceLocation endLoc = signatureRange.getBegin(); + + if (d->getNumParams() > 0) + { + endLoc = d->getParamDecl(d->getNumParams() - 1)->getLocEnd(); + } + while (sm.isBeforeInTranslationUnit(endLoc, signatureRange.getEnd())) { llvm::Optional token = clang::Lexer::findNextToken(endLoc, sm, opts); @@ -794,15 +793,23 @@ ParseLocation CxxAstVisitorComponentIndexer::getSignatureLocation(clang::Functio if (tokenKind == clang::tok::l_brace || tokenKind == clang::tok::colon) { signatureRange.setEnd(endLoc); - break; + return getParseLocation(signatureRange); } - endLoc = token.getValue().getLocation(); + + clang::SourceLocation nextEndLoc = token.getValue().getLocation(); + if (nextEndLoc == endLoc) + { + return ParseLocation(); + } + + endLoc = nextEndLoc; } else { return ParseLocation(); } } + return ParseLocation(); } return getParseLocation(signatureRange);