Skip to content

Commit a338be4

Browse files
authored
Add source traces when using LifetimeStore (#4678)
1 parent 4c1c506 commit a338be4

1 file changed

Lines changed: 70 additions & 14 deletions

File tree

lib/valueflow.cpp

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,7 +3925,13 @@ struct LifetimeStore {
39253925
}
39263926

39273927
template<class Predicate>
3928-
bool byRef(Token* tok, TokenList* tokenlist, ErrorLogger* errorLogger, const Settings* settings, Predicate pred) const {
3928+
bool byRef(Token* tok,
3929+
TokenList* tokenlist,
3930+
ErrorLogger* errorLogger,
3931+
const Settings* settings,
3932+
Predicate pred,
3933+
SourceLocation loc = SourceLocation::current()) const
3934+
{
39293935
if (!argtok)
39303936
return false;
39313937
bool update = false;
@@ -3950,6 +3956,8 @@ struct LifetimeStore {
39503956
// Don't add the value a second time
39513957
if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
39523958
return false;
3959+
if (settings->debugnormal)
3960+
setSourceLocation(value, loc, tok);
39533961
setTokenValue(tok, value, tokenlist->getSettings());
39543962
update = true;
39553963
}
@@ -3958,14 +3966,31 @@ struct LifetimeStore {
39583966
return update;
39593967
}
39603968

3961-
bool byRef(Token* tok, TokenList* tokenlist, ErrorLogger* errorLogger, const Settings* settings) const {
3962-
return byRef(tok, tokenlist, errorLogger, settings, [](const Token*) {
3969+
bool byRef(Token* tok,
3970+
TokenList* tokenlist,
3971+
ErrorLogger* errorLogger,
3972+
const Settings* settings,
3973+
SourceLocation loc = SourceLocation::current()) const
3974+
{
3975+
return byRef(
3976+
tok,
3977+
tokenlist,
3978+
errorLogger,
3979+
settings,
3980+
[](const Token*) {
39633981
return true;
3964-
});
3982+
},
3983+
loc);
39653984
}
39663985

39673986
template<class Predicate>
3968-
bool byVal(Token* tok, TokenList* tokenlist, ErrorLogger* errorLogger, const Settings* settings, Predicate pred) const {
3987+
bool byVal(Token* tok,
3988+
TokenList* tokenlist,
3989+
ErrorLogger* errorLogger,
3990+
const Settings* settings,
3991+
Predicate pred,
3992+
SourceLocation loc = SourceLocation::current()) const
3993+
{
39693994
if (!argtok)
39703995
return false;
39713996
bool update = false;
@@ -3991,7 +4016,8 @@ struct LifetimeStore {
39914016
// Don't add the value a second time
39924017
if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
39934018
continue;
3994-
4019+
if (settings->debugnormal)
4020+
setSourceLocation(value, loc, tok);
39954021
setTokenValue(tok, value, tokenlist->getSettings());
39964022
update = true;
39974023
}
@@ -4024,6 +4050,8 @@ struct LifetimeStore {
40244050
// Don't add the value a second time
40254051
if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
40264052
continue;
4053+
if (settings->debugnormal)
4054+
setSourceLocation(value, loc, tok);
40274055
setTokenValue(tok, value, tokenlist->getSettings());
40284056
update = true;
40294057
}
@@ -4033,14 +4061,31 @@ struct LifetimeStore {
40334061
return update;
40344062
}
40354063

4036-
bool byVal(Token* tok, TokenList* tokenlist, ErrorLogger* errorLogger, const Settings* settings) const {
4037-
return byVal(tok, tokenlist, errorLogger, settings, [](const Token*) {
4064+
bool byVal(Token* tok,
4065+
TokenList* tokenlist,
4066+
ErrorLogger* errorLogger,
4067+
const Settings* settings,
4068+
SourceLocation loc = SourceLocation::current()) const
4069+
{
4070+
return byVal(
4071+
tok,
4072+
tokenlist,
4073+
errorLogger,
4074+
settings,
4075+
[](const Token*) {
40384076
return true;
4039-
});
4077+
},
4078+
loc);
40404079
}
40414080

40424081
template<class Predicate>
4043-
void byDerefCopy(Token *tok, TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings, Predicate pred) const {
4082+
void byDerefCopy(Token* tok,
4083+
TokenList* tokenlist,
4084+
ErrorLogger* errorLogger,
4085+
const Settings* settings,
4086+
Predicate pred,
4087+
SourceLocation loc = SourceLocation::current()) const
4088+
{
40444089
if (!settings->certainty.isEnabled(Certainty::inconclusive) && inconclusive)
40454090
return;
40464091
if (!argtok)
@@ -4060,17 +4105,28 @@ struct LifetimeStore {
40604105
const Token * const varDeclEndToken = var->declEndToken();
40614106
for (const Token *tok3 = tok; tok3 && tok3 != varDeclEndToken; tok3 = tok3->previous()) {
40624107
if (tok3->varId() == var->declarationId()) {
4063-
LifetimeStore{tok3, message, type, inconclusive}.byVal(tok, tokenlist, errorLogger, settings, pred);
4108+
LifetimeStore{tok3, message, type, inconclusive}.byVal(tok, tokenlist, errorLogger, settings, pred, loc);
40644109
break;
40654110
}
40664111
}
40674112
}
40684113
}
40694114

4070-
void byDerefCopy(Token *tok, TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings) const {
4071-
byDerefCopy(tok, tokenlist, errorLogger, settings, [](const Token *) {
4115+
void byDerefCopy(Token* tok,
4116+
TokenList* tokenlist,
4117+
ErrorLogger* errorLogger,
4118+
const Settings* settings,
4119+
SourceLocation loc = SourceLocation::current()) const
4120+
{
4121+
byDerefCopy(
4122+
tok,
4123+
tokenlist,
4124+
errorLogger,
4125+
settings,
4126+
[](const Token*) {
40724127
return true;
4073-
});
4128+
},
4129+
loc);
40744130
}
40754131

40764132
private:

0 commit comments

Comments
 (0)