This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimisations and undefined behaviour
- From: Vincent Lefevre <vincent+gcc at vinc17 dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 9 Nov 2015 23:21:36 +0100
- Subject: Re: Optimisations and undefined behaviour
- Authentication-results: sourceware.org; auth=none
- References: <563C9DD3 dot 9030407 at hesbynett dot no> <563F9E4C dot 5000504 at redhat dot com> <20151108193430 dot GA28206 at gate dot crashing dot org> <56407162 dot 7050106 at redhat dot com> <56408D14 dot 2090101 at redhat dot com> <5640A8D3 dot 8060706 at redhat dot com> <5640AAC5 dot 9090509 at redhat dot com> <5640ADC5 dot 4090604 at redhat dot com> <20151109215934 dot GA18853 at zira dot vinc17 dot org> <56411A0F dot 2010705 at redhat dot com>
On 2015-11-09 15:11:27 -0700, Jeff Law wrote:
> I feel it's best to err on the side of safety here -- given a function call,
> loops and the like, we have to consider the possibility that the statement
> which exhibits UB may not be executed. And until that statement is
> executed, we have no license to do anything weird.
BTW, the C standard says that a function may be interrupted by a
signal at any time. So, if some code that has a visible side effect
appears before an UB, the program may be interrupted between this
code and the UB so that the UB will not occur. Thus a compiler does
not have the license to remove such code with side effect.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)