GCC 4.2.4 optimization bug

Have a question about our Software Developer Kit? Ask them here.
Post Reply
User avatar
samo79
Posts: 572
Joined: Fri Jun 17, 2011 11:13 pm
Location: Italy

GCC 4.2.4 optimization bug

Post by samo79 »

This bug was already reported (and included in a general post) on a topic in "General Developer support"

http://forum.hyperion-entertainment.biz ... 1498#p1498

But as it's a GCC issue i think it's better to report here as well
------------------------------------------------------------
GCC 4.2.4 Bugs
------------------------------------------------------------

The optimizer has bugs. Eg. when using -O1 or -O2 to compile Koules 1.16
for OS4, the resulting executable has a bug: namely, that the P key only
pauses while it is held down. Compiling with -O0 avoids this issue.
If you like to test it, just download Koules from OS4Depot and compile it with -O1 or -O2 with the usual make command, then start the game and press P for pause ;-)
kas1e
Beta Tester
Beta Tester
Posts: 542
Joined: Sat Jun 18, 2011 7:56 am
Contact:

Re: GCC 4.2.4 optimization bug

Post by kas1e »

@samo79

Just to add some stuff which can helps: No one will try to compile Koules and trying to understand what Kolues code do , to reproduce that error (its uninteresting and time consuming job). So, you (or that one who catch the bug) , should create small as possible example, with small as possible code, which will cleary show the difference and problems. And only after that if it will indeed bug, it will be fixed.

But from my expirience, i can tell you, that optimisation "bugs" in most cases are not bugs, but problems with code, and the way, how arguments passing to stack, how optimisator works with stack when you use O1/O2/O3 , and , while with O0 some "wrong" code can works, with O1 or O2 it will just works different. I have the same kind of problems with optimisation, when port some function over mui (DoSuperNew), which use hooks, tags and some stuff. And in end, someone on UtilityBase explain all the stuff (i.e. why compiler produce different code for different optimisation flags), and in end, its just forces to my bad code (which works with O1 and not works with O2).

Expectually when you have disabled optimisation at all in compare with any kind of enabled optimisation: its all will reacts different, if some nasty hacks/hooks/code are done in game itself. But to check all of this, need small example, with reducing all un-necessary for reproduce code.

So, if you and author of that programm still think that its reall bug in optimisation, need to create small as possible example, and then, if it indeed bug it will be fixed. But as it now like "some game have optimisation bug when you press P in game" give you no chance that it will be fixed.
User avatar
samo79
Posts: 572
Joined: Fri Jun 17, 2011 11:13 pm
Location: Italy

Re: GCC 4.2.4 optimization bug

Post by samo79 »

@Roman

Ok received, a small example should be pretty possible i think so at this point i will tell him to do so ;)

All what we know for now is that with -O1 or -O2 optimization Pause will not works correctly while with -O0 works, also would be interesting to know what happen using a more recent GCC, AFAIK latest version is now 4.5.3 altrough not released for the mass yet
kas1e
Beta Tester
Beta Tester
Posts: 542
Joined: Sat Jun 18, 2011 7:56 am
Contact:

Re: GCC 4.2.4 optimization bug

Post by kas1e »

@samo79
"Pause" its too "hi-level" in that case. All depends how code done which handle that "pause" code, and what code do before and after, and how it all handled and so on. Some small piece of only necessary code which cleary show the problem from low-level code-side will help for sure. The smaller example code which show the problem = the higher chances to detect the bug and fix it :)
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: GCC 4.2.4 optimization bug

Post by broadblues »

I agree with kas1e it's quite likely that optimisation is revealing a bug in your code.

Make sure you compile with -Wall and then fix all warnings. And fix them "properly" by that I mean think about them, and why they are happening, sometimes a simple cast is all that it required, other times you need to think much more carefully about what values are being assigned to which variables.

Be especially aware of any warnings related to unassigned variables, the values the variables take might vary with optimisation level.

Also if this code is targeted at more than one compiler, make sure there no assumptions about argument executation order etc in functions calls, this can vary from version to version, and maybe even with optimisation level.
User avatar
Slayer
Beta Tester
Beta Tester
Posts: 851
Joined: Tue Dec 21, 2010 4:19 am
Location: New Zealand

Re: GCC 4.2.4 optimization bug

Post by Slayer »

Yes

I remember Gunther Nikl repeatedly saying the similair on the old gcc list, It's great to look forward to doing all this stuff myself...

Only at my extreme witts end would I admitt defeat and then have to contemplate the possibility I have indeed discovered a genuine gcc generated bug ;)

Of course when I do actually start coding (after I have the X1000) you are to conveniently forget I ever write such stuff as above :D
~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
User avatar
ssolie
Beta Tester
Beta Tester
Posts: 1010
Joined: Mon Dec 20, 2010 8:51 pm
Location: Canada
Contact:

Re: GCC 4.2.4 optimization bug

Post by ssolie »

samo79 wrote:But as it's a GCC issue i think it's better to report here as well
If you really believe this is a GCC optimizer bug then go to GCC bugs and read everything over.

The Amiga build of GCC does not modify anything in the optimizer so any bugs would need to be reported back to the GCC team anyway.

My bet is that the code is broken and has always been broken. More aggressive optimizers tend to expose such subtle bugs which more primitive compilers will gloss over.
ExecSG Team Lead
Post Reply