Menu

TDM-GCC generates faulty code?

Compiling
LEOcab
2014-07-30
2014-08-04
  • LEOcab

    LEOcab - 2014-07-30

    This isn't necessarily a Dev-C++ question but I bet a lot of Dev-C++ users are using TDM-GCC so I'm gonna ask here just in case.

    I just switched from an older version of Dev-C++ (with MinGW) to the latest version (with TDM-GCC). My code compiles, but it crashes instantly when ran. I started doing trial-and-error, lucky for me the new debugger is much more useful than in the old version (less stupid "??" stack frames, yay!).

    The first bug I found was a simple integer addition involving an array with a static array index, it is so simple that there is no way that code is faulty. So I decided to recompile the faulty file without optimizations, and to my surprise my program actually got to the start screen. It crashed shortly after, however. This new bug is very similar to the first: an addition involving an array. I found three more identical bugs in unrelated parts of my code, all fixed by recompiling the file without optimization. To summarize:

    a) the problem is caused by using optimizations (-Ofast, to be specific)
    b) the problem is caused by operations with arrays
    c) according to the debugging screen, the problem is caused by the movdqa instruction dealing with the xmm0 register

    A quick google search pointed out that adding the -mstackrealign compiler flag would fix movdqa issues, and fortunately it did. However, I'm worried about two things:
    a) the -mstackrealign option is pointed out to reduce performance.
    b) why isn't this issue more known? Arrays aren't really an advanced concept, neither are compiler optimizations, so you'd think more people would notice their code crashing all the time like this.

     
  • M.Trifon

    M.Trifon - 2014-08-04

    Very interesting (...and, yes, it doesn't seem a Dev-C++ issue )
    I've seen your explanation and I would suggest you tell us more.
    As a minimum: are you using 32 or 64 bit pointers, was the linkage static or dynamic, have you optimised for your CPU or left option blank, plus whatever you believe may shed the light.
    (Also, have you switched from Win 7 to 8.1 ?)

     
  • ralph engels

    ralph engels - 2017-06-24

    Latest version of tdm seems to have some strange bugs, i also had it produce faulty code where another mingw compiler worked just fine. Later versions of gcc seems to work better with his patchset.atleast i havent run into any bugs besides some sources getting rather pissy about statically linked libgcc and one that bitched about pthreads because it thought it needed the dll. Unfortunatly TDM's version has not been updated since gcc-5.0.1 which is a shame since 5.3.0 works just fine.

     

Log in to post a comment.