This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimisations and undefined behaviour
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: David Brown <david dot brown at hesbynett dot no>
- Cc: "[gcc-help]" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 5 Nov 2015 22:23:01 +0100
- Subject: Re: Optimisations and undefined behaviour
- Authentication-results: sourceware.org; auth=none
- References: <563BC190 dot 7080406 at hesbynett dot no>
On 2015.11.05 at 21:52 +0100, David Brown wrote:
> There has been some discussions going on in the comp.lang.c newsgroup
> about how far compilers are allowed to go regarding optimisation using
> their knowledge of undefined behaviour (i.e., if a piece of code has
> undefined behaviour, the compiler can assume that the user does not care
> about the result in that case, and can therefore do whatever it wants in
> order to generate faster code).
The compiler just assumes that undefined behavior will not happen and
optimizes accordingly.
Now that -fsanitize=undefined is available this shouldn't be a big issue
anymore.
For more details I recommend John Regehr's excellent blog entries on
this topic, e.g.: http://blog.regehr.org/archives/1234
--
Markus