Skip to content

Commit 272c4d0

Browse files
committed
refs #10765 - Token: introduced cache for isMutableExpression() calls
1 parent 8dee2e4 commit 272c4d0

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

lib/astutils.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,13 +2482,6 @@ static bool isArray(const Token* tok)
24822482
return false;
24832483
}
24842484

2485-
static inline
2486-
// limit it to CLang as compiling with GCC might fail with
2487-
// error: inlining failed in call to always_inline 'bool isMutableExpression(const Token*)': function not considered for inlining
2488-
// error: inlining failed in call to ‘always_inline’ ‘bool isMutableExpression(const Token*)’: recursive inlining
2489-
#if defined(__clang__)
2490-
__attribute__((always_inline))
2491-
#endif
24922485
bool isMutableExpression(const Token* tok)
24932486
{
24942487
if (!tok)
@@ -2632,7 +2625,7 @@ static bool hasOverloadedMemberAccess(const Token* tok)
26322625

26332626
bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, int depth)
26342627
{
2635-
if (!isMutableExpression(tok))
2628+
if (!tok->isMutableExpr())
26362629
return false;
26372630

26382631
if (indirect == 0 && isConstVarExpression(tok))
@@ -2924,7 +2917,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
29242917
{
29252918
if (depth < 0)
29262919
return true;
2927-
if (!isMutableExpression(tok))
2920+
if (!tok->isMutableExpr())
29282921
return false;
29292922
if (tok->exprId() != exprid || (!tok->varId() && !tok->isName())) {
29302923
if (globalvar && Token::Match(tok, "%name% (") &&

lib/astutils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ Token* getTokenArgumentFunction(Token* tok, int& argn);
319319

320320
std::vector<const Variable*> getArgumentVars(const Token* tok, int argnr);
321321

322+
bool isMutableExpression(const Token* tok);
323+
322324
/** Is variable changed by function call?
323325
* In case the answer of the question is inconclusive, e.g. because the function declaration is not known
324326
* the return value is false and the output parameter inconclusive is set to true

lib/token.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,3 +2769,10 @@ bool Token::isAliasOf(const Token* expr, int* indirect) const
27692769
*indirect = i;
27702770
return b;
27712771
}
2772+
2773+
bool Token::isMutableExpr() const
2774+
{
2775+
if (mImpl->mMutableExpr == -1)
2776+
mImpl->mMutableExpr = isMutableExpression(this);
2777+
return !!mImpl->mMutableExpr;
2778+
}

lib/token.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class CPPCHECKLIB Token {
176176

177177
std::unordered_map<const Token*, std::pair<bool, int>> mAliases;
178178

179+
std::int8_t mMutableExpr{-1};
180+
179181
void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value);
180182
bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const;
181183

@@ -1369,6 +1371,8 @@ class CPPCHECKLIB Token {
13691371

13701372
bool isAliasOf(const Token* expr, int* indirect) const;
13711373

1374+
bool isMutableExpr() const;
1375+
13721376
/**
13731377
* Sets the original name.
13741378
*/

0 commit comments

Comments
 (0)