Skip to content

Commit b6833b5

Browse files
committed
Clang import
1 parent 6beadd9 commit b6833b5

File tree

9 files changed

+27
-4
lines changed

9 files changed

+27
-4
lines changed

lib/checkleakautovar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ void CheckLeakAutoVar::doubleFreeError(const Token *tok, const Token *prevFreeTo
175175

176176
void CheckLeakAutoVar::check()
177177
{
178+
if (mSettings->clang)
179+
return;
180+
178181
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
179182

180183
// Local variables that are known to be non-zero.

lib/checkmemoryleak.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ void CheckMemoryLeakInClass::publicAllocationError(const Token *tok, const std::
759759

760760
void CheckMemoryLeakStructMember::check()
761761
{
762+
if (mSettings->clang)
763+
return;
764+
762765
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
763766
for (const Variable* var : symbolDatabase->variableList()) {
764767
if (!var || !var->isLocal() || var->isStatic() || var->isReference())

lib/checkother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,9 @@ void CheckOther::unreachableCodeError(const Token *tok, bool inconclusive)
866866
//---------------------------------------------------------------------------
867867
void CheckOther::checkVariableScope()
868868
{
869+
if (mSettings->clang)
870+
return;
871+
869872
if (!mSettings->isEnabled(Settings::STYLE))
870873
return;
871874

lib/checkuninitvar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class CPPCHECKLIB CheckUninitVar : public Check {
6262

6363
/** @brief Run checks against the normal token list */
6464
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) OVERRIDE {
65+
if (settings->clang)
66+
return;
67+
6568
CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger);
6669
checkUninitVar.check();
6770
checkUninitVar.valueFlowUninit();

lib/checkunusedvar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
10911091
if (!mSettings->isEnabled(Settings::STYLE))
10921092
return;
10931093

1094+
if (mSettings->clang)
1095+
return;
1096+
10941097
// Parse all executing scopes..
10951098
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
10961099

lib/checkvaarg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ void CheckVaarg::referenceAs_va_start_error(const Token *tok, const std::string&
9696

9797
void CheckVaarg::va_list_usage()
9898
{
99+
if (mSettings->clang)
100+
return;
99101
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
100102
for (const Variable* var : symbolDatabase->variableList()) {
101103
if (!var || var->isPointer() || var->isReference() || var->isArray() || !var->scope() || var->typeStartToken()->str() != "va_list")

lib/clangimport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
10301030
Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
10311031
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
10321032
Scope &scope = symbolDatabase->scopeList.back();
1033-
symbolDatabase->functionScopes.push_back(&scope);
10341033
nestedIn->functionList.push_back(Function(nameToken));
10351034
scope.function = &nestedIn->functionList.back();
10361035
scope.type = Scope::ScopeType::eFunction;
@@ -1060,6 +1059,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
10601059
par2->link(par1);
10611060
// Function body
10621061
if (mFile == 0 && !children.empty() && children.back()->nodeType == CompoundStmt) {
1062+
symbolDatabase->functionScopes.push_back(&scope);
10631063
Token *bodyStart = addtoken(tokenList, "{");
10641064
bodyStart->scope(&scope);
10651065
children.back()->createTokens(tokenList);

lib/cppcheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
890890
check->runChecks(&tokenizer, &mSettings, this);
891891
}
892892

893+
if (mSettings.clang)
894+
// TODO: Use CTU for Clang analysis
895+
return;
896+
893897
// Analyse the tokens..
894898

895899
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);

test/testclangimport.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,9 @@ class TestClangImport: public TestFixture {
888888

889889
void symbolDatabaseFunction1() {
890890
const char clang[] = "|-FunctionDecl 0x3aea7a0 <1.cpp:2:1, col:22> col:6 used foo 'void (int, int)'\n"
891-
"| |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 x 'int'\n"
892-
"| `-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 y 'int'\n";
891+
" |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 x 'int'\n"
892+
" |-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 y 'int'\n"
893+
" `-CompoundStmt 0x3d45c48 <col:12>\n";
893894

894895
GET_SYMBOL_DB(clang);
895896

@@ -907,7 +908,8 @@ class TestClangImport: public TestFixture {
907908
void symbolDatabaseFunction2() {
908909
const char clang[] = "|-FunctionDecl 0x3aea7a0 <1.cpp:2:1, col:22> col:6 used foo 'void (int, int)'\n"
909910
"| |-ParmVarDecl 0x3aea650 <col:10, col:14> col:14 'int'\n"
910-
"| `-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 'int'\n";
911+
"| |-ParmVarDecl 0x3aea6c8 <col:17, col:21> col:21 'int'\n"
912+
" `-CompoundStmt 0x3d45c48 <col:12>\n";
911913

912914
GET_SYMBOL_DB(clang);
913915

0 commit comments

Comments
 (0)