Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7924,6 +7924,14 @@ static Token* findStartToken(const Variable* var, Token* start, const Library* l
Token* first = uses.front();
if (Token::findmatch(start, "goto|asm|setjmp|longjmp", first))
return start;
if (first != var->nameToken()) {
// if this is lhs in assignment then set first to the first token in LHS expression
Token* temp = first;
while (Token::Match(temp->astParent(), "[&*(]") && precedes(temp->astParent(), temp))
temp = temp->astParent();
if (Token::simpleMatch(temp->astParent(), "=") && precedes(temp, temp->astParent()))
first = temp;
}
// If there is only one usage
if (uses.size() == 1)
return first->previous();
Expand Down
12 changes: 12 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5292,6 +5292,18 @@ class TestValueFlow : public TestFixture {
"}";
ASSERT_EQUALS(0U, tokenValues(code, "x )").size());

// initialization
code = "int foo() {\n"
" int x;\n"
" *((int *)(&x)) = 12;"
" a = x + 1;\n"
"}";
values = tokenValues(code, "x +");
ASSERT_EQUALS(true, values.empty());
// ASSERT_EQUALS(1U, values.size());
// ASSERT(values.front().isIntValue());
// ASSERT_EQUALS(12, values.front().intvalue);

// #8036
code = "void foo() {\n"
" int x;\n"
Expand Down