cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

ProgramMemory: avoid duplicated lookups / removed `at()`

Open firewave opened this issue 4 months ago • 9 comments

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

firewave avatar Aug 25 '25 13:08 firewave

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

firewave avatar Aug 25 '25 13:08 firewave

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 avatar Aug 27 '25 08:08 firewave

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 avatar Aug 27 '25 08:08 firewave

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 avatar Sep 15 '25 05:09 firewave

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 avatar Sep 15 '25 05:09 firewave

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 avatar Sep 15 '25 06:09 firewave

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

I need to reproduce my mistake and add a test which causes this but that will probably take quite a while. Also making it more problematic is that I need to do it on an older commit because another change has also caused this change in the ValueFlow.

firewave avatar Nov 12 '25 12:11 firewave