-
-
Notifications
You must be signed in to change notification settings - Fork 706
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 20426 - doesPointTo with void[N] fails #7458
Conversation
|
Thanks for your pull request and interest in making D better, @MoonlightSentinel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7458" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
sourceis or contains a union, then there may be either false positives or false negatives
This PR should update the documentation to specify that false positives / false negatives are also possible if source is or contains a static array whose element type is void.
std/exception.d
Outdated
| static if (is(S == void[n], size_t n)) | ||
| { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do more than this in mayPointTo. Minimally return S.sizeof >= typeof(void*).sizeof as we know that a data chunk smaller than a pointer cannot contain a pointer. Maximally we could interpret every properly-aligned pointer-sized chunk of the static array as if it were a pointer, which is safe since we never actually dereference the pointer but merely compare it to other pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented the latter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch for CTFE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a __ctfe branch which pessimistically returns true because I didn't find a way to implement the actual logic without using a reinterpreting cast.
73a41d6 to
7d3e916
Compare
7d3e916 to
54af8ab
Compare
std/exception.d
Outdated
| (cast(void*[]) voidArr[])[] = null; // Ensure no false pointers | ||
|
|
||
| *cast(void**) &voidArr[16] = &a; // Pointers should be found | ||
| *cast(void**) &voidArr[3] = &b; // But only if they are properly aligned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if misaligned writes are guaranteed to work with LDC. I guess if some supported platform actually ignores the lowest few bits of a destination address that it "knows" is aligned on a word boundary, the automated test suite will tell us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would writing individual bytes using slice assignment work for all platforms? E.g.:
void*[1] tmp = [&b];
(cast(ubyte[]) voidArr[3 .. 3 + (void*).sizeof])[] = cast(ubyte[]) tmp[];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely.
Accept a false positive/negative for may/doesPointTo
54af8ab to
bf7bde1
Compare
| { | ||
| // Reinterpreting cast is impossible during ctfe | ||
| if (__ctfe) | ||
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make this work, you should be able to cast to some form of ubyte[], but the compiler refuses to see anything but a void[N]. I tried slicing, slicing a pointer, and using a helper function.
|
Unfortunately there's a problem with the IDK if it's worth checking this. It might be better to change |
|
Hm... I think it's worth revising, the use case that prompted this is TaggedAlgebraic, which uses a |
|
We could still implement checks like if the |
…d[N] can contain a slice.
… hold a slice, unless the entire thing is zero
… hold a slice, unless the entire thing is zero
… hold a slice, unless the entire thing is zero
… hold a slice, unless the entire thing is zero
… hold a slice, unless the entire thing is zero
… hold a slice, unless the entire thing is zero
Followup to #7458 - Always return true for mayPointTo if the void[N] … merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
… hold a slice, unless the entire thing is zero
Accept a false positive/negative for may/doesPointTo