-
-
Notifications
You must be signed in to change notification settings - Fork 379
[spec/function] Specify null dereference behavior for @safe
code
#4239
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request and interest in making D better, @ntrel! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
Walter from https://forum.dlang.org/post/vv6s8p$lfh$1@digitalmars.com:
That needs to be in the spec, hence this pull. |
Forbid optimizations which assume a null dereference will not occur. `ldc2` does use those optimizations with `-O2` - see: https://forum.dlang.org/post/vv6o31$ac9$1@digitalmars.com. Specify that codegen must detect null dereferences if the system (by default) does not. Specify that codegen must detect when any expression causes a null pointer to be indexed outside the protected first page. Include warning that dmd does not implement this yet - see dlang/dmd#17776.
It's probably no big deal to "bounds check" pointer and class deferences in safe code only. Pointer slicing and indexing is already disallowed, and array slicing/indexing should rightly assume the underlying structure of the array isn't corrupted. |
Timon & Derek Fawcus on the forum found this for LLVM:
From under https://releases.llvm.org/10.0.0/docs/LangRef.html#function-attributes. |
@ibuclaw: Do you explicitly opt out of these null-deref optimizations for GDC? Apparently not just for |
I don't think GCC implements null dereference optimizations. Off the top of my head, infinite loop optimizations are opt-in. As it's part of C++ language to assume all loops are finite. That is to say, if any nul pointer opts do exist its probably opt-in as well. |
Oh I see, it's only clang that 'optimizes' the artificial tiny testcase, not gcc. |
Forbid optimizations which assume a null dereference will not occur.
ldc2
does use those optimizations with-O2
- see:https://forum.dlang.org/post/vv6o31$ac9$1@digitalmars.com. Fixes #4240.
Cc @tgehr @WalterBright.
Specify that the code generated must detect null dereferences if the system (by default) does not.
Specify that the code generated must detect when any expression causes a null pointer to be indexed outside the protected first page. Include warning that
dmd
does not implement this yet - see dlang/dmd#17776.