Fixed #8858 (FP: identicalConditionAfterEarlyExit when there is #if)
This commit is contained in:
parent
ddd21a260f
commit
f56a17bf3d
|
@ -702,22 +702,19 @@ void CheckCondition::multiCondition2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::stack<const Token *> tokens2;
|
visitAstNodes(cond2, [&](const Token *secondCondition) {
|
||||||
tokens2.push(cond2);
|
if (secondCondition->str() == "||" || secondCondition->str() == "&&")
|
||||||
while (!tokens2.empty()) {
|
return ChildrenToVisit::op1_and_op2;
|
||||||
const Token *secondCondition = tokens2.top();
|
|
||||||
tokens2.pop();
|
if ((!cond1->hasKnownIntValue() || !secondCondition->hasKnownIntValue()) &&
|
||||||
if (!secondCondition)
|
isSameExpression(mTokenizer->isCPP(), true, cond1, secondCondition, mSettings->library, true, true, &errorPath)) {
|
||||||
continue;
|
if (!isAliased(vars) && !mTokenizer->hasIfdef(cond1, secondCondition)) {
|
||||||
if (secondCondition->str() == "||" || secondCondition->str() == "&&") {
|
|
||||||
tokens2.push(secondCondition->astOperand1());
|
|
||||||
tokens2.push(secondCondition->astOperand2());
|
|
||||||
} else if ((!cond1->hasKnownIntValue() || !secondCondition->hasKnownIntValue()) &&
|
|
||||||
isSameExpression(mTokenizer->isCPP(), true, cond1, secondCondition, mSettings->library, true, true, &errorPath)) {
|
|
||||||
if (!isAliased(vars))
|
|
||||||
identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath);
|
identicalConditionAfterEarlyExitError(cond1, secondCondition, errorPath);
|
||||||
|
return ChildrenToVisit::done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return ChildrenToVisit::none;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "%name% (") && isVariablesChanged(tok, tok->linkAt(1), true, varsInCond, mSettings, mTokenizer->isCPP())) {
|
if (Token::Match(tok, "%name% (") && isVariablesChanged(tok, tok->linkAt(1), true, varsInCond, mSettings, mTokenizer->isCPP())) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "checkcondition.h"
|
#include "checkcondition.h"
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
#include "preprocessor.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "testsuite.h"
|
#include "testsuite.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
|
@ -136,10 +137,14 @@ private:
|
||||||
std::map<std::string, simplecpp::TokenList*> filedata;
|
std::map<std::string, simplecpp::TokenList*> filedata;
|
||||||
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
|
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
|
||||||
|
|
||||||
|
Preprocessor preprocessor(settings0, nullptr);
|
||||||
|
preprocessor.setDirectives(tokens1);
|
||||||
|
|
||||||
// Tokenizer..
|
// Tokenizer..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
tokenizer.createTokens(std::move(tokens2));
|
tokenizer.createTokens(std::move(tokens2));
|
||||||
tokenizer.simplifyTokens1("");
|
tokenizer.simplifyTokens1("");
|
||||||
|
tokenizer.setPreprocessor(&preprocessor);
|
||||||
|
|
||||||
// Run checks..
|
// Run checks..
|
||||||
CheckCondition checkCondition;
|
CheckCondition checkCondition;
|
||||||
|
@ -2570,6 +2575,18 @@ private:
|
||||||
" int FileIndex; \n"
|
" int FileIndex; \n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #8858 - #if
|
||||||
|
check("short Do() {\n"
|
||||||
|
" short ret = bar1();\n"
|
||||||
|
" if ( ret )\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"#ifdef FEATURE\n"
|
||||||
|
" ret = bar2();\n"
|
||||||
|
"#endif\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void innerConditionModified() {
|
void innerConditionModified() {
|
||||||
|
|
Loading…
Reference in New Issue