1 of the many Reasons why GCC really SUUUUUUUCKS!

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Kamjin
DC Developer
DC Developer
Posts: 216
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Dec 17, 2003 5:27 am
Has thanked: 0
Been thanked: 0

1 of the many Reasons why GCC really SUUUUUUUCKS!

Post by Kamjin »

I need to vent.. badly..

For several hours I've been trying to find a bug.. I would change
or add some code.. like adding a printf(), and my program would
crash.. remove the printf() and it works fine...
I finally tracked it to this bit of code in a library I wrote over
10 years ago..
So on all these compilers the code always worked...
Lattice C, SAS C, Mertroworks , Borland, MSC, Watcom

GCC.. enjoys wasting my time!!!
the fix I had to do is on the bottom.. go figure..

Code: Select all

if( data>=192 )
      {
       rollcount=data-192;
      data = fgetc(fp);
      while( rollcount-->0 ) pic->buffer[count++]=data;
       } // end RLE
    else
      {
      // the data is just one pixel, copy it into the buffer
      pic->buffer[count++]=data;
      } // end not RLE
  

Code: Select all

if( data>=192 )
      {
       rollcount = data - 192;
       data = fgetc(fp);
      while( rollcount-->0 ){
	pic->buffer[count++] = data;
      }//end while
      } // end RLE
    else
      {
      // the data is just one pixel, copy it into the buffer
      pic->buffer[count++] = data;
      } // end not RLE
   
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

That's very very odd. Is this GCC targetted at SH4 that we're talking about? Which version of GCC are you using?

I have seen some weird things myself as well. Such as crashes that can be prevented by adding a printf(), or even an if (0) statement in exactly the right place. Those things usually indicate an optimization bug. All the problem I've seen happened with GCC 3.1 and up, GCC 3.0.4 has performed well for me so far.

But what you said is very weird, because those two pieces of code should produce the exact same output.
"Nothing works" - Catweazle
q_006
Mental DCEmu
Mental DCEmu
Posts: 415
Joined: Thu Oct 10, 2002 7:18 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by q_006 »

so you had to put bracket around the while statements for your code to work??

what version of GCC are you using?

...i've never had that problem before.
Kamjin
DC Developer
DC Developer
Posts: 216
Joined: Wed Dec 17, 2003 5:27 am
Has thanked: 0
Been thanked: 0

Post by Kamjin »

I belive it was V3.04, and I've never has this problem before either :nut:

It just got more confusing..
I can leave the brackets out, but remove a typecast just above the code
area and it starts to work.. from what I finally managed to catch it looks
like some constants are getting trashed during compile.. I've nabbed it
in several spots.. the dump is below.
It compiles on the system I'm on now without a flaw.. it's an older build
of gcc.. might just be some whacky bug.. or more like somethings gone corrupt
on my system.. might be the demon lord of GCC has a thing for me :chair:
I think he's telling me to grab a new build and reinstall!

.loc 29 87 0
mov r8,r3
cmp/pz r3
bf.s .L25
add #-1,r8
mov.w .L52,r3
mov #-1,r7
mov.l @r15,r4
add r4,r3
.L32:

.loc 29 87 0
mov r8,r3
cmp/pl r3
bf.s .L25
add #-1,r8
mov.w .L52,r3
mov.l @r15,r4
add r4,r3
.L32:
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Has thanked: 0
Been thanked: 0
Contact:

Post by GPF »

I have seen problems with using the increment operator within an array index.

When I was help port Neo Geo CD emulator, there was many instances of that. I had to move the count++ out of the array index and just use

Code: Select all

     while( rollcount-->0 ){
         pic->buffer[count]=data;
         count++;
    } //end while 
      } // end RLE 
Your are probably running into a similiar bug in GCC 3.0.4, or there might be a workaround compiler switch.

Troy
Vorrtexx
Insane DCEmu
Insane DCEmu
Posts: 138
Joined: Sun Apr 06, 2003 5:29 am
Has thanked: 0
Been thanked: 0
Contact:

Post by Vorrtexx »

I've had problems like this before also.
It hadn't to do with not using braces on a single line while loop, but it would compile fine if I had put in a printf() statement, and if I removed it, it would break. other cases were if I moved independent code around in a function, that it would make it compile again. I spent hours trying to fix them.
Very frustrating indeed.
Kamjin
DC Developer
DC Developer
Posts: 216
Joined: Wed Dec 17, 2003 5:27 am
Has thanked: 0
Been thanked: 0

Post by Kamjin »

I had sent the complete dump, to a few coders I used to work
with serious 'nix nerds.. they were saying the same thing that
this kinda bug pops up all the time, and not to bother looking
for it, everytime you change your code and it happens again,
the bug will have moved, They said when it starts happeing to
them they usually move functions around, or change the linking
order.

At least it good to know I'm not the only cursed one!
Ex-Cyber
DCEmu User with No Life
DCEmu User with No Life
Posts: 3641
Joined: Sat Feb 16, 2002 1:55 pm
Has thanked: 0
Been thanked: 0

Post by Ex-Cyber »

I think Dan Potter wrote, in the original libdream distribution, a document entitled something to the effect of: "GCC IS NOT YOUR FRIEND", and it showed how GCC managed to optimize an addition right out of existence. That being said, on x86 GCC an optimization screwing up often means that you are doing something to confuse the compiler (depending on the order of resolution of side effects, type punning, etc.). You might want to try adding flags like -fno-strict-aliasing and see if your problem magically goes away. This is becoming more common with GCC 3.4, so it looks like the GCC guys have few qualms about being strict about standards compliance and/or taking every liberty that the standard allows.
"You know, I have a great, wonderful, really original method of teaching antitrust law, and it kept 80 percent of the students awake. They learned things. It was fabulous." -- Justice Stephen Breyer
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

Kamjin wrote:I had sent the complete dump, to a few coders I used to work
with serious 'nix nerds.. they were saying the same thing that
this kinda bug pops up all the time, and not to bother looking
for it, everytime you change your code and it happens again,
the bug will have moved, They said when it starts happeing to
them they usually move functions around, or change the linking
order.

At least it good to know I'm not the only cursed one!

Happens to me all the time got problems like this in neogeo cd all the time even when adding SFX back i had to move the input function ot it crashed removed a printf it worked . Controls breaking put the input some were else it would not be broken. Change the link line order completly breaks etc.

GCC does suck glad you have vented it out as this type of crap happens to me in the simplest bits of code even menus and simple arrays. Just think most dreamcast games were compiled with GCC version 2.1
Dreamcast forever!!!
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

It's unfortuntate that SH4 support is not a priority for the GCC team. On the other hand, where would we be without GCC...
"Nothing works" - Catweazle
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

Prolly using wince.
Dreamcast forever!!!
Kamjin
DC Developer
DC Developer
Posts: 216
Joined: Wed Dec 17, 2003 5:27 am
Has thanked: 0
Been thanked: 0

Post by Kamjin »

GCC does suck glad you have vented it out as this type of crap happens to me in the simplest bits of code even menus and simple arrays. Just think most dreamcast games were compiled with GCC version 2.1
That's exactly it!! and I fall into that trap every time.
add a real simple bit of code.. then I get a crash.. go back
start playing with the code.. I'm always assuming a trashed
pointer.. faulty logic etc.. by the end of it I've managed to destroy most
of the code I wrote that day..
It's unfortuntate that SH4 support is not a priority for the GCC team. On the other hand, where would we be without GCC...
I used to use a Hitachi (renesas) compiler a while back for a sh2 based
datalogging device we built, it didnt have any of these problems,
after that we had switched to GNU toolchain from KPIT (i think that
was the name). It also had an IDE.. but it would probably quite a
bit of work to get KOS, and the ARM-ELF to work with it..
Ian Micheal
Soul Sold for DCEmu
Soul Sold for DCEmu
Posts: 4865
Joined: Fri Jul 11, 2003 9:56 pm
Has thanked: 2 times
Been thanked: 4 times

Post by Ian Micheal »

Ex-Cyber wrote:I think Dan Potter wrote, in the original libdream distribution, a document entitled something to the effect of: "GCC IS NOT YOUR FRIEND", and it showed how GCC managed to optimize an addition right out of existence. That being said, on x86 GCC an optimization screwing up often means that you are doing something to confuse the compiler (depending on the order of resolution of side effects, type punning, etc.). You might want to try adding flags like -fno-strict-aliasing and see if your problem magically goes away. This is becoming more common with GCC 3.4, so it looks like the GCC guys have few qualms about being strict about standards compliance and/or taking every liberty that the standard allows.

fno-strict-aliasing this fixed a few of the problems i was geting magical like as you said.
Dreamcast forever!!!
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

Kamjin wrote:I used to use a Hitachi (renesas) compiler a while back for a sh2 based
datalogging device we built, it didnt have any of these problems,
Yeah, but that compiler is windows-only and it's not free. Correct me if I'm wrong. The package that you can download from Renesas for free does not include the toolchain (IIRC).
"Nothing works" - Catweazle
Ex-Cyber
DCEmu User with No Life
DCEmu User with No Life
Posts: 3641
Joined: Sat Feb 16, 2002 1:55 pm
Has thanked: 0
Been thanked: 0

Post by Ex-Cyber »

fno-strict-aliasing this fixed a few of the problems i was geting magical like as you said.
Yeah, anything that works too-deep magic with pointers apparently runs the risk of getting on the wrathful side of the optimizer if -fstrict-aliasing is on, and it's a component of -O2 and -Os. I wouldn't even know this if GCC 3.4 hadn't raised (lowered?) the bar ever farther and started generating warnings for type punning and breaking various programs that compiled fine on previous versions.
"You know, I have a great, wonderful, really original method of teaching antitrust law, and it kept 80 percent of the students awake. They learned things. It was fabulous." -- Justice Stephen Breyer
Post Reply