Fixed #10276 (FP: (style) Variable '((uint8_t*)(uint16_t)0x1000)[0]' is assigned a value that is never used.)

This commit is contained in:
Daniel Marjamäki 2021-05-18 20:35:00 +02:00
parent 0aebc32ae0
commit 216918756b
2 changed files with 15 additions and 2 deletions

View File

@ -2405,8 +2405,11 @@ bool isNullOperand(const Token *expr)
bool isGlobalData(const Token *expr, bool cpp)
{
bool globalData = false;
bool var = false;
visitAstNodes(expr,
[&](const Token *tok) {
[expr, cpp, &globalData, &var](const Token *tok) {
if (tok->varId())
var = true;
if (tok->varId() && !tok->variable()) {
// Bailout, this is probably global
globalData = true;
@ -2467,7 +2470,7 @@ bool isGlobalData(const Token *expr, bool cpp)
return ChildrenToVisit::op1;
return ChildrenToVisit::op1_and_op2;
});
return globalData;
return globalData || !var;
}
struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *startToken, const Token *endToken, const std::set<nonneg int> &exprVarIds, bool local, bool inInnerClass, int depth)

View File

@ -220,6 +220,7 @@ private:
TEST_CASE(argumentClass);
TEST_CASE(escapeAlias); // #9150
TEST_CASE(volatileData); // #9280
TEST_CASE(globalData);
}
void checkStructMemberUsage(const char code[], const std::list<Directive> *directives=nullptr) {
@ -5809,6 +5810,15 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
}
void globalData() {
// #10276
functionVariableUsage(
"void f(void) {\n"
" ((uint8_t *) (uint16_t)0x1000)[0] = 0x42;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestUnusedVar)