Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jun 2017 15:24:01 -0700
From:      Patrick Mahan <mahan@mahan.org>
To:        FreeBSD Mailing List <freebsd-questions@freebsd.org>, serpent7776@gmail.com
Subject:   Re: -O2 flag
Message-ID:  <dbe711db-2090-6e61-9306-4e451317098f@mahan.org>
In-Reply-To: <20170610230928.581e3cf9@DaemONX>
References:  <593C4679.5010104@gmail.com> <20170610230928.581e3cf9@DaemONX>

next in thread | previous in thread | raw e-mail | index | archive | help
On 6/10/17 2:09 PM, Serpent7776 wrote:
> On Sat, 10 Jun 2017 16:20:25 -0300
> Friedrich Locke <friedrich.locke@gmail.com> wrote:
> 
>> Hi folks,
>>
>> i am trying compile a program with cc on freebsd 11.
>> When i use -O2 compilation flag, the compiled code is giving error on 
>> execution, but with i omit -O2 everything works ok.
>>
>> Have anybody already faced such problem ?
> Yes, a few times in the past. Your code may have hidden bug which is triggered
> only with optimizations enabled. It might be relying on some kind of undefined
> behaviour.
> Unfortunately, I don't have any helpful advices on how to find this error -
> try enabling all compiler warnings flags.
> I'd suspect a bug in your code rather than a bug in compiler, but the latter is
> not impossible.
> 

This is especially noticeable when you use uninitialized stack variables in a
function.  Non-optimized generally gets you a cleaner stack.  But I've seen
code that assumes a stack variable always has a certain value.

Patrick



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?dbe711db-2090-6e61-9306-4e451317098f>