-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined behavior shift in CompileHelper.cpp #3376
Comments
I can't reproduce any of these errors with GCC. I tried to set a comparison of the value to 32, it never hits in the entire regression. sudo apt-get install clang The following packages have unmet dependencies: |
Is this a real error? |
If you shift a 32 bit number by 1023 bits, it sounds like a real error. |
The code in question is something like values[valIndex] = (v & (1ULL << (csize - 1 - i))) ? 1 : 0; so is csize some very large value ? then the code might not do what one expect it to do. |
I can't find any testcase that has that kind of shift. |
Can you reproduce the error with GCC, if yes, please tell me which test and eventual code change to create an assert. |
With the recent changes, this location now moved to In my address sanitizer set-up I get the some tests that create an issue, e.g.:
The error message from asan is something like
You can instrument is by adding something like this: --- a/src/DesignCompile/CompileHelper.cpp
+++ b/src/DesignCompile/CompileHelper.cpp
@@ -4614,6 +4614,13 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps,
if (valIndex > (int32_t)(size - 1)) {
break;
}
+ {
+ int shift = (csize - 1 - i);
+ if (shift < 0 || shift >= 64) {
+ fprintf(stderr, "%s: shifting by %d\n", __FILE__, shift);
+ abort();
+ }
+ }
values[valIndex] = (v & (1ULL << (csize - 1 - i))) ? 1 : 0;
valIndex++;
}
|
@hzeller, @hs-apotell , can you tell me how you compile Surelog with clang? I get the GNU linker and it errors out (rightfully) |
I haven't tried with v12. I have v13 installed. It might be a version issue.
|
Thanks! I think I also got my settings incorrect, it should be: |
A first order fix is done in #3641. |
Testing with undefined behavior sanitizer finds that in CompileHelper.cpp:4044 an invalid shift is used. Shifting outside the width of an integer is UB
This can be seen with
ArianeElab
,ArianeElab2
,HierPathOverride
andLargeHexCast
Besides fixing this: it would probably make sense to set up
asan
,msan
andubsan
tests in the CI.The text was updated successfully, but these errors were encountered: