Fixed #9344 (FP redundantAssignment related to increasing index variable for vector)
This commit is contained in:
parent
5426138786
commit
99ef64459b
|
@ -1818,6 +1818,8 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
|||
} else if (mWhat == What::Reassign && parent->valueType() && parent->valueType()->pointer && Token::Match(parent->astParent(), "%assign%") && parent == parent->astParent()->astOperand1()) {
|
||||
return Result(Result::Type::READ);
|
||||
} else if (Token::Match(parent->astParent(), "%assign%") && !parent->astParent()->astParent() && parent == parent->astParent()->astOperand1()) {
|
||||
if (mWhat == What::Reassign)
|
||||
return Result(Result::Type::BAILOUT, parent->astParent());
|
||||
continue;
|
||||
} else {
|
||||
// TODO: this is a quick bailout
|
||||
|
|
|
@ -173,6 +173,7 @@ private:
|
|||
TEST_CASE(redundantVarAssignment_after_switch);
|
||||
TEST_CASE(redundantVarAssignment_pointer);
|
||||
TEST_CASE(redundantVarAssignment_pointer_parameter);
|
||||
TEST_CASE(redundantVarAssignment_array);
|
||||
TEST_CASE(redundantInitialization);
|
||||
TEST_CASE(redundantMemWrite);
|
||||
|
||||
|
@ -6627,6 +6628,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void redundantVarAssignment_array() {
|
||||
check("void f() {\n"
|
||||
" int arr[10];\n"
|
||||
" int i = 0;\n"
|
||||
" arr[i] = 1;\n"
|
||||
" i += 2;\n"
|
||||
" arr[i] = 3;\n"
|
||||
" dostuff(arr);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void redundantInitialization() {
|
||||
setMultiline();
|
||||
|
||||
|
|
Loading…
Reference in New Issue