diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 0bb1037b9..b6d207b27 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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. diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f2ac9a1a0..acb4e14c3 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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()) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index dde37dcde..0fad60ee0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index cefd07500..d10dd9a14 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -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(); diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 9f4ea36d8..12a75b452 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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(); diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 527d68802..650b85fcc 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -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") diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 1e94e36b4..318df2cd5 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -1030,7 +1030,6 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList) Scope *nestedIn = const_cast(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); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index bf491cf7c..c62d75929 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index c08c93a7f..ba994465e 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -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:14 x 'int'\n" - "| `-ParmVarDecl 0x3aea6c8 col:21 y 'int'\n"; + " |-ParmVarDecl 0x3aea650 col:14 x 'int'\n" + " |-ParmVarDecl 0x3aea6c8 col:21 y 'int'\n" + " `-CompoundStmt 0x3d45c48 \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:14 'int'\n" - "| `-ParmVarDecl 0x3aea6c8 col:21 'int'\n"; + "| |-ParmVarDecl 0x3aea6c8 col:21 'int'\n" + " `-CompoundStmt 0x3d45c48 \n"; GET_SYMBOL_DB(clang);