Fixes for sanitizer errors from SPEC CPU testing#7697
Fixes for sanitizer errors from SPEC CPU testing#7697heshpdx wants to merge 5 commits intocppcheck-opensource:mainfrom
Conversation
lib/vf_common.cpp:115:96: runtime error: shift exponent 18446744073709550144 is too large for 64-bit type 'long long unsigned int' lib/vf_common.cpp:116:47: runtime error: shift exponent 1919 is too large for 64-bit type 'long long unsigned int'
lib/token.cpp:1949:20: runtime error: signed integer overflow: -9223372036854775808 - 9223372032559808511 cannot be represented in type 'long long int'
lib/infer.cpp:131:39: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int' lib/infer.cpp:141:39: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long long int' lib/infer.cpp:322:65: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int'
|
In addition, there are some final errors that I don't know how to fix. I tried the following to cap the value at the limits, but this led to regressions and failures in testrunner. If someone has a better idea, please share. Thank you. |
| if (std::numeric_limits<long long>::max() == minValue->intvalue) | ||
| result.setMinValue(minValue->intvalue, minValue); | ||
| else | ||
| result.setMinValue(minValue->intvalue + 1, minValue); |
There was a problem hiding this comment.
I wonder if not doing the addition still leads to a useful value, or if we should bail out somehow for LLONG_MAX.
|
|
|
| return value; | ||
|
|
||
| // sizeof(long long) = 8 | ||
| value_size = std::min(sizeof(MathLib::bigint), value_size); |
There was a problem hiding this comment.
I have the feeling we want to be able to truncate according to sizeof(int) here. I.e. the result of ~0U + 2U should be 1.
|
Also see #2922. |
|
We need to add tests which trigger these warnings instead of "blindly" fixing them. |
|
See also https://trac.cppcheck.net/ticket/13446. |



We're doing some sanitizer testing on the source code here at SPEC, and I was able to offer some patches to correct the overflow issues. These are corner cases so maybe the cppcheck community may not be so keen to accept these, but I figured I would share.