Skip to content
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

fix Issue 10948 - BitArray.opEquals is invalid #2204

Merged
merged 1 commit into from May 31, 2014
Merged

fix Issue 10948 - BitArray.opEquals is invalid #2204

merged 1 commit into from May 31, 2014

Conversation

jblume
Copy link
Contributor

@jblume jblume commented May 26, 2014

https://issues.dlang.org/show_bug.cgi?id=10948

Implemented the fix as proposed by nbelov on Bugzilla. Included are unit tests which would have triggered this bug and also fixed it in opCmp.

The issue was that the 32 bit expression "(1 << n)" was treated as being of size_t, which lead to incorrect bit patterns on 64 bit environments.

@Safety0ff
Copy link
Contributor

This is a reboot of #1551 , there is likely relevant comments there.

@jblume
Copy link
Contributor Author

jblume commented May 26, 2014

Sorry, I didn't notice that @nbelov made a pull request before.

From what I could gather, the very thorough unit test in that PR triggered a test failure of unclear cause. It didn't seem to be connected to the fix of this bug, so unless the failure appears again this fix should probably go in.

I will try that expensive test @nbelov wrote and try to trigger that failure again. If I find something, I will open another bug report.

@Safety0ff
Copy link
Contributor

There's already a bug report for it and I've been trying to narrow down the cause in: #1551

By coincidence, at the moment I'm creating a Freebsd 32bit VM to try and solve this once and for all.
Though if you can reproduce the bug locally and provide more information, that would be great.

@monarchdodra
Copy link
Collaborator

Well, if this doesn't break anything, I'm pulling it. The code is obviously more correct than the old code.

@@ -884,7 +884,7 @@ struct BitArray
}

n = this.length & (bitsPerSizeT-1);
size_t mask = (1 << n) - 1;
size_t mask = (cast(size_t)1 << n) - 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: uniform initialization now allows:

size_t mask = (size_t(1) << n) - 1;

I think it reads better.

@Safety0ff
Copy link
Contributor

@monarchdodra BTW, I tracked down the source of the failure: https://issues.dlang.org/show_bug.cgi?id=11435#c5

@jblume
Copy link
Contributor Author

jblume commented May 27, 2014

Sorry, there was more in that commit than I wanted. I'll fix it and squash the commits.

https://issues.dlang.org/show_bug.cgi?id=10948

Implemented the fix as proposed by nbelov on Bugzilla. Included are unit tests which would have triggered this bug and also fixed it in opCmp.

The issue was that the 32 bit expression "(1 << n)" was treated as being of size_t, which lead to incorrect bit patterns on 64 bit environments.
@jblume
Copy link
Contributor Author

jblume commented May 27, 2014

I have changed the casts to uniform initialization and squashed the commits into one. This should be good to go now.

@DmitryOlshansky
Copy link
Member

Won't hurt to pull I guess.

DmitryOlshansky added a commit that referenced this pull request May 31, 2014
fix Issue 10948 - BitArray.opEquals is invalid
@DmitryOlshansky DmitryOlshansky merged commit 48afca0 into dlang:master May 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants