Skip to content

Commit d7febf6

Browse files
fwdanalysis: Remove unused What::ValueFlow mode
The What::ValueFlow mode and its state (mValueFlow, mValueFlowKnown, KnownAndToken) are not used since commit 921887a, which switched to valueFlowForwardExpression instead of FwdAnalysis::valueFlow().
1 parent 21de4fa commit d7febf6

2 files changed

Lines changed: 5 additions & 86 deletions

File tree

lib/fwdanalysis.cpp

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <list>
3131
#include <string>
3232
#include <utility>
33+
#include <vector>
3334

3435
static bool isUnchanged(const Token *startToken, const Token *endToken, const std::set<nonneg int> &exprVarIds, bool local)
3536
{
@@ -155,10 +156,6 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
155156
}
156157

157158
if (tok->str() == "}") {
158-
// Known value => possible value
159-
if (tok->scope() == expr->scope())
160-
mValueFlowKnown = false;
161-
162159
if (tok->scope()->isLoopScope()) {
163160
// check condition
164161
const Token *conditionStart = nullptr;
@@ -195,65 +192,6 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
195192
if (Token::simpleMatch(tok, "asm ("))
196193
return Result(Result::Type::BAILOUT);
197194

198-
if (mWhat == What::ValueFlow && (Token::Match(tok, "while|for (") || Token::simpleMatch(tok, "do {"))) {
199-
const Token *bodyStart = nullptr;
200-
const Token *conditionStart = nullptr;
201-
if (Token::simpleMatch(tok, "do {")) {
202-
bodyStart = tok->next();
203-
if (Token::simpleMatch(bodyStart->link(), "} while ("))
204-
conditionStart = bodyStart->link()->tokAt(2);
205-
} else {
206-
conditionStart = tok->next();
207-
if (Token::simpleMatch(conditionStart->link(), ") {"))
208-
bodyStart = conditionStart->link()->next();
209-
}
210-
211-
if (!bodyStart || !conditionStart)
212-
return Result(Result::Type::BAILOUT);
213-
214-
// Is expr changed in condition?
215-
if (!isUnchanged(conditionStart, conditionStart->link(), exprVarIds, local))
216-
return Result(Result::Type::BAILOUT);
217-
218-
// Is expr changed in loop body?
219-
if (!isUnchanged(bodyStart, bodyStart->link(), exprVarIds, local))
220-
return Result(Result::Type::BAILOUT);
221-
}
222-
223-
if (mWhat == What::ValueFlow && Token::simpleMatch(tok, "if (") && Token::simpleMatch(tok->linkAt(1), ") {")) {
224-
const Token *bodyStart = tok->linkAt(1)->next();
225-
const Token *conditionStart = tok->next();
226-
const Token *condTok = conditionStart->astOperand2();
227-
if (const ValueFlow::Value* v = condTok->getKnownValue(ValueFlow::Value::ValueType::INT)) {
228-
const bool cond = !!v->intvalue;
229-
if (cond) {
230-
FwdAnalysis::Result result = checkRecursive(expr, bodyStart, bodyStart->link(), exprVarIds, local, true, depth);
231-
if (result.type != Result::Type::NONE)
232-
return result;
233-
} else if (Token::simpleMatch(bodyStart->link(), "} else {")) {
234-
bodyStart = bodyStart->link()->tokAt(2);
235-
FwdAnalysis::Result result = checkRecursive(expr, bodyStart, bodyStart->link(), exprVarIds, local, true, depth);
236-
if (result.type != Result::Type::NONE)
237-
return result;
238-
}
239-
}
240-
tok = bodyStart->link();
241-
if (isReturnScope(tok, mSettings.library))
242-
return Result(Result::Type::BAILOUT);
243-
if (Token::simpleMatch(tok, "} else {"))
244-
tok = tok->linkAt(2);
245-
if (!tok)
246-
return Result(Result::Type::BAILOUT);
247-
248-
// Is expr changed in condition?
249-
if (!isUnchanged(conditionStart, conditionStart->link(), exprVarIds, local))
250-
return Result(Result::Type::BAILOUT);
251-
252-
// Is expr changed in condition body?
253-
if (!isUnchanged(bodyStart, bodyStart->link(), exprVarIds, local))
254-
return Result(Result::Type::BAILOUT);
255-
}
256-
257195
if (!local && Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) {
258196
// TODO: this is a quick bailout
259197
return Result(Result::Type::BAILOUT);
@@ -279,22 +217,15 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
279217
parent = parent->astParent();
280218
if (parent->str() == "(" && !parent->isCast())
281219
break;
282-
if (isSameExpression(false, expr, parent, mSettings, true, false, nullptr)) {
220+
if (isSameExpression(false, expr, parent, mSettings, true, false, nullptr))
283221
same = true;
284-
if (mWhat == What::ValueFlow) {
285-
KnownAndToken v;
286-
v.known = mValueFlowKnown;
287-
v.token = parent;
288-
mValueFlow.push_back(v);
289-
}
290-
}
291222
if (Token::Match(parent, ". %var%") && parent->next()->varId() && exprVarIds.find(parent->next()->varId()) == exprVarIds.end() &&
292223
isSameExpression(false, expr->astOperand1(), parent->astOperand1(), mSettings, true, false, nullptr)) {
293224
other = true;
294225
break;
295226
}
296227
}
297-
if (mWhat != What::ValueFlow && same && Token::simpleMatch(parent->astParent(), "[") && parent == parent->astParent()->astOperand2()) {
228+
if (same && Token::simpleMatch(parent->astParent(), "[") && parent == parent->astParent()->astOperand2()) {
298229
return Result(Result::Type::READ);
299230
}
300231
if (other)
@@ -381,8 +312,6 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
381312
return result1;
382313
if (mWhat == What::UnusedValue && result1.type == Result::Type::WRITE && expr->variable() && expr->variable()->isReference())
383314
return result1;
384-
if (mWhat == What::ValueFlow && result1.type == Result::Type::WRITE)
385-
mValueFlowKnown = false;
386315
if (mWhat == What::Reassign && result1.type == Result::Type::BREAK) {
387316
const Token *scopeEndToken = findNextTokenFromBreak(result1.token);
388317
if (scopeEndToken) {
@@ -394,8 +323,6 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
394323
if (Token::simpleMatch(tok->linkAt(1), "} else {")) {
395324
const Token *elseStart = tok->linkAt(1)->tokAt(2);
396325
const Result &result2 = checkRecursive(expr, elseStart, elseStart->link(), exprVarIds, local, inInnerClass, depth);
397-
if (mWhat == What::ValueFlow && result2.type == Result::Type::WRITE)
398-
mValueFlowKnown = false;
399326
if (result2.type == Result::Type::READ || result2.type == Result::Type::BAILOUT)
400327
return result2;
401328
if (result1.type == Result::Type::WRITE && result2.type == Result::Type::WRITE)
@@ -475,7 +402,7 @@ FwdAnalysis::Result FwdAnalysis::check(const Token* expr, const Token* startToke
475402
Result result = checkRecursive(expr, startToken, endToken, exprVarIds, local, false);
476403

477404
// Break => continue checking in outer scope
478-
while (mWhat!=What::ValueFlow && result.type == FwdAnalysis::Result::Type::BREAK) {
405+
while (result.type == FwdAnalysis::Result::Type::BREAK) {
479406
const Token *scopeEndToken = findNextTokenFromBreak(result.token);
480407
if (!scopeEndToken)
481408
break;

lib/fwdanalysis.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <cstdint>
2727
#include <set>
28-
#include <vector>
2928

3029
class Token;
3130
class Settings;
@@ -60,11 +59,6 @@ class FwdAnalysis {
6059
*/
6160
bool unusedValue(const Token *expr, const Token *startToken, const Token *endToken);
6261

63-
struct KnownAndToken {
64-
bool known{};
65-
const Token* token{};
66-
};
67-
6862
/** Is there some possible alias for given expression */
6963
bool possiblyAliased(const Token *expr, const Token *startToken) const;
7064

@@ -84,9 +78,7 @@ class FwdAnalysis {
8478
Result checkRecursive(const Token *expr, const Token *startToken, const Token *endToken, const std::set<nonneg int> &exprVarIds, bool local, bool inInnerClass, int depth=0);
8579

8680
const Settings &mSettings;
87-
enum class What : std::uint8_t { Reassign, UnusedValue, ValueFlow } mWhat = What::Reassign;
88-
std::vector<KnownAndToken> mValueFlow;
89-
bool mValueFlowKnown = true;
81+
enum class What : std::uint8_t { Reassign, UnusedValue } mWhat = What::Reassign;
9082
};
9183

9284
#endif // fwdanalysisH

0 commit comments

Comments
 (0)