[cfe-dev] Feature Request: __builtin_undefined()
Ryan Nicholl via cfe-dev
cfe-dev at lists.llvm.org
Sat Oct 7 10:10:44 PDT 2017
I would like to request a feature, __builtin_undefined()
This would serve multiple purposes, it would be similar to __builtin_unreachable, but can be used to specify that the behavior upon reaching it it undefined (not necessarily that it can't be reached.)
For example, in pseudo code "T my_array<T>::operator[](size_t n) { if (n >= this->internal_size) __builtin_undefined(); ... }"
So this would indicate that a user has invoked undefined behavior, and -fsanitize=undefined would trap this behavior, and additionally, when debugging is disabled, the compiler could use __builtin_undefined() as an optimization hint.
I like to distinguish my proposed __builtin_undefined() from __builtin_unreachable() in that __builtin_unreachable() should really be unreachable. (Even if the user e.g. uses an invalid input index?) (i.e., it should indicate a bug in the code that uses __builtin_unreachable() rather than in the calling code)
I recognize that the distinction is probably not substantial, but being able to explicitly specify certain behavior as undefined might prove useful when developing libraries as compilers develop more advanced optimizations.
--
Ryan Nicholl
(678)-358-7765
Sent with [ProtonMail](https://protonmail.com) Secure Email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171007/c2ef6697/attachment.html>
More information about the cfe-dev
mailing list