[cfe-dev] [LLVMdev] proposal for exploiting undefined behavior much more aggressively
Florian Weimer
fweimer at redhat.com
Fri Jul 27 02:58:43 PDT 2012
On 07/27/2012 11:45 AM, David Chisnall wrote:
> On 27 Jul 2012, at 09:35, annulen at yandex.ru wrote:
>
>> if someone has checked the code and found it UB-free he could allow aggressive UB exploiting.
>
> Surely code that contains no undefined behaviour will gain no benefits from optimisations that exploit undefined behaviour?
Relying undefined behavior, the compiler can infer conditions which must
necessarily hold, and use this information in subsequent optimizations.
For instance, adding positive values to a signed integer which is zero
initially will never yield a negative value. If this value is later fed
to code which can cope with negatives values through an explicit check,
that check can be optimized away. So obviously, you need some code
reuse/abstraction (calling a more general routine from very specialized
code) to trigger optimizations, but there are hypothetical wins even for
programs which never actually trigger undefined behavior at run time.
However, I would prefer if programmers could provide the compiler with
the necessary information in more obvious ways. This way, similar
properties could be specified for values of unsigned integer type as well.
--
Florian Weimer / Red Hat Product Security Team
More information about the cfe-dev
mailing list