:: Re: [DNG] Gcc issue?
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Adam Borowski
Datum:  
To: dng
Betreff: Re: [DNG] Gcc issue?
On Fri, Apr 22, 2016 at 10:27:16AM +0200, parazyd wrote:
> On Thu, 21 Apr 2016, Steven W. Scott wrote:
> >    Just curious, anyone else getting segfaults after compiling with gcc -O3
> >    optimization flag on alpha 4? Same system, same code, same flags work ok
> >    on Wheezy. If I back down to -O2 no problems.

> >
> >    I'm blaming gcc, but I was interested if anyone else had a similar
> >    experience or insight as to what might be the issue.

>
> Do you actually understand how optimization works? The bigger the level,
> the more unsafe code you get, like you just got segfaults. Depending on
> the program, one will take some max. level of optimization, but any
> higher and it will break, like yours did.


While GCC is not totally bug-free and thus optimization errors do happen, in
99.9% cases it's a bug in the code you're compiling.

Using any of canned optimization levels other than -Ofast, does not change
the behaviour of any standards-compliant program. Unless you do something
that won't be kept on a different architecture/different compiler, such as
converting a pointer to int and using it as a non-opaque value, you will get
the same result, just (hopefully) faster.

So sorry, your program is likely bogus. There's a lot of tools that can
help finding such errors, such as valgrind or -fsanitize=*.

> Note how many more warnings you get on compilation as you get higher in
> optimization level.


That's a good thing -- the compiler analyzes the code deeper and thus is
able to spot more suspicious things.

--
A tit a day keeps the vet away.