Skip to content

Conversation

firewave
Copy link
Collaborator

all at() calls were proceeded by hasValue() so we can just directly fetch the value instead.

@firewave
Copy link
Collaborator Author

"impossible" lookups with no exprid will be dealt with in a different PR.

@firewave firewave force-pushed the pm-at branch 2 times, most recently from 1cb862f to 7a04197 Compare August 25, 2025 13:32
Comment on lines -1730 to +1743
if (value.tokvalue->exprId() > 0 && !pm->hasValue(value.tokvalue->exprId()))
if (value.tokvalue->exprId() == 0)
continue;
Copy link
Collaborator Author

@firewave firewave Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been separate before since an at() call with no exprid would have failed.

@firewave
Copy link
Collaborator Author

It appears to not have much impact on performance but it gets rid of the at() which has irked me for quite a while.

@firewave
Copy link
Collaborator Author

Should be done but I am seeing slightly less executions when profiling this, which should not be happening since it does not functionally change. So still needs looking into.

@firewave
Copy link
Collaborator Author

Should be done but I am seeing slightly less executions when profiling this, which should not be happening since it does not functionally change. So still needs looking into.

There is indeed a behavior change introduced by this - #7800 surfaced a difference the tests did not catch:

--- selfcheck.exp       2025-09-15 07:19:01.345202904 +0200
+++ selfcheck.res       2025-09-15 07:21:07.006911439 +0200
@@ -13626,6 +13626,8 @@
   tok2 possible symbolic=(tok->next)
 Line 2108
   true always 1
+Line 2109
+  . possible symbolic=(tok2)
 Line 2112
   & {lifetime[Address]=(temp),!0}
 Line 2113

@firewave
Copy link
Collaborator Author

firewave commented Sep 15, 2025

There is indeed a behavior change introduced by this - #7800 surfaced a difference the tests did not catch:

I missed that getValue() does not return impossible values by default where hasValue() and at() do.

@firewave
Copy link
Collaborator Author

I missed that getValue() does not return impossible values by default where hasValue() and at() do.

I consistently added a parameter to the getter (even though they might not be used - can be cleaned up later) and flipped one default.

@firewave firewave marked this pull request as ready for review September 15, 2025 06:25
Copy link

bool getContainerSizeValue(nonneg int exprid, MathLib::bigint& result) const;
bool getContainerEmptyValue(nonneg int exprid, MathLib::bigint& result) const;
bool getContainerSizeValue(nonneg int exprid, MathLib::bigint& result, bool impossible = false) const;
bool getContainerEmptyValue(nonneg int exprid, MathLib::bigint& result, bool impossible = false) const;
Copy link
Collaborator Author

@firewave firewave Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I flipped the default behavior on getContainerEmptyValue() but addressed it via an explicit parameter in its only usage in vf_analyzers.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont add the impossible parameters. They dont make sense at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read my comment. It was to make it clear what they are doing as they were inconsistent. But if we move the impossible logic out of them they will go away.

MathLib::bigint out = 0;
if (pm.getContainerEmptyValue(tok->exprId(), out))
// TODO: do we really went to return an impossible value?
if (pm.getContainerEmptyValue(tok->exprId(), out, true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the correct behaviour, but the parameter and the comment makes it look like its wrong. The getContainerEmptyValue returns true or false if the container is empty or not. It will use impossible values internally to determine this as well(its really an implementation detail though).

This is why the impossible parameter should not be added.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is inconsistent with the other getters. But if we move the impossible logic out of those of them as suggested, things will be clear.

return nullptr;
}

ValueFlow::Value* ProgramMemory::getValue(nonneg int exprid, bool impossible)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return a const ValueFlow::Value*. We dont ever mutate the ValueFlow::Value directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. This was previously done from the non-const at().

copyOnWrite();

const auto it = find(exprid);
const bool found = it != mValues->cend() && (impossible || !it->second.isImpossible());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isImpossible can be checked by the consumers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about doing that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh - it is already handled inside some of the getters. So it was even more inconsistent as it seemed to be. They also return the underlying MathLib::bigint so the impossible handling cannot just be externalized...

@firewave firewave marked this pull request as draft September 17, 2025 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants