Clang import

This commit is contained in:
Daniel Marjamäki 2020-01-25 17:01:17 +01:00
parent 6beadd9eb9
commit b6833b525f
9 changed files with 27 additions and 4 deletions

View File

@ -175,6 +175,9 @@ void CheckLeakAutoVar::doubleFreeError(const Token *tok, const Token *prevFreeTo
void CheckLeakAutoVar::check()
{
if (mSettings->clang)
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
// Local variables that are known to be non-zero.

View File

@ -759,6 +759,9 @@ void CheckMemoryLeakInClass::publicAllocationError(const Token *tok, const std::
void CheckMemoryLeakStructMember::check()
{
if (mSettings->clang)
return;
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || !var->isLocal() || var->isStatic() || var->isReference())

View File

@ -866,6 +866,9 @@ void CheckOther::unreachableCodeError(const Token *tok, bool inconclusive)
//---------------------------------------------------------------------------
void CheckOther::checkVariableScope()
{
if (mSettings->clang)
return;
if (!mSettings->isEnabled(Settings::STYLE))
return;

View File

@ -62,6 +62,9 @@ public:
/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) OVERRIDE {
if (settings->clang)
return;
CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger);
checkUninitVar.check();
checkUninitVar.valueFlowUninit();

View File

@ -1091,6 +1091,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (!mSettings->isEnabled(Settings::STYLE))
return;
if (mSettings->clang)
return;
// Parse all executing scopes..
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();

View File

@ -96,6 +96,8 @@ void CheckVaarg::referenceAs_va_start_error(const Token *tok, const std::string&
void CheckVaarg::va_list_usage()
{
if (mSettings->clang)
return;
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || var->isPointer() || var->isReference() || var->isArray() || !var->scope() || var->typeStartToken()->str() != "va_list")

View File

@ -1030,7 +1030,6 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
Scope &scope = symbolDatabase->scopeList.back();
symbolDatabase->functionScopes.push_back(&scope);
nestedIn->functionList.push_back(Function(nameToken));
scope.function = &nestedIn->functionList.back();
scope.type = Scope::ScopeType::eFunction;
@ -1060,6 +1059,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
par2->link(par1);
// Function body
if (mFile == 0 && !children.empty() && children.back()->nodeType == CompoundStmt) {
symbolDatabase->functionScopes.push_back(&scope);
Token *bodyStart = addtoken(tokenList, "{");
bodyStart->scope(&scope);
children.back()->createTokens(tokenList);

View File

@ -890,6 +890,10 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
check->runChecks(&tokenizer, &mSettings, this);
}
if (mSettings.clang)
// TODO: Use CTU for Clang analysis
return;
// Analyse the tokens..
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);

View File

@ -888,8 +888,9 @@ private:
void symbolDatabaseFunction1() {
const char clang[] = "|-FunctionDecl 0x3aea7a0 <1.cpp:2:1, col:22> col:6 used foo 'void (int, int)'\n"
"| |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 x 'int'\n"
"| `-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 y 'int'\n";
" |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 x 'int'\n"
" |-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 y 'int'\n"
" `-CompoundStmt 0x3d45c48 <col:12>\n";
GET_SYMBOL_DB(clang);
@ -907,7 +908,8 @@ private:
void symbolDatabaseFunction2() {
const char clang[] = "|-FunctionDecl 0x3aea7a0 <1.cpp:2:1, col:22> col:6 used foo 'void (int, int)'\n"
"| |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 'int'\n"
"| `-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 'int'\n";
"| |-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 'int'\n"
" `-CompoundStmt 0x3d45c48 <col:12>\n";
GET_SYMBOL_DB(clang);