Thread: optimized -O3 crashes app

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    optimized -O3 crashes app

    what exactly happens when a build is requested using the O3 switch or other optimisations? my release build crashes, like totally dissapears, on some operations that work when built without the setting. it should be noted this is an fltk app, using codeblocks latest release and gcc
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    When your "release" crashes, you know that there's a bug hidden somewhere. Optimizing operates on code a little different than usual.
    Devoted my life to programming...

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can still do -g (and gdb) with -O3, assuming its a reproducible bug.

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    on reading i found that the o3 option is pretty risky and can indeed cause errors, it also seems overkill for app of 2mb so i am leaving well alone, i am convinced no bug this serious exists in code itself, have been testing for weeks, and the fltk uses lots of inline and static function stuff which i read is potential problem with the option. leaving well alone and keep bug hunting!
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by rogster001 View Post
    on reading i found that the o3 option is pretty risky and can indeed cause errors, it also seems overkill for app of 2mb so i am leaving well alone, i am convinced no bug this serious exists in code itself, have been testing for weeks, and the fltk uses lots of inline and static function stuff which i read is potential problem with the option. leaving well alone and keep bug hunting!
    I'd keep tracking this bug. I've encountered this several times and everytime, soon or later, it turned out to be MY fault, even in the code, which I was sure about and have been using for a very long time. I'm sure you have a bug in your code, especially if you follow the standards.
    Moreover, if it's your fault, it IS a serious bug. It may disappear after changing some code, and then, appear again. If you can't see this error with debugging symbols... you should try to debug it without them.

    EDIT:

    I've just recalled, that one of such problems was an uninitialized variable (I disabled warning because G++ was giving false warnings even in its own STL implementation). Everything worked fine for a very long time, I tried various compiler options including CPU tuning, and it had always been crashing with -o3.
    I think it's a good idea to try different compiler options to find potential bugs.
    Last edited by kmdv; 12-23-2010 at 02:41 PM.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    o3

    ok thanks for the advice, i am in personally in mode CFLAG bury head in sand at this present moment, cans of worms have been opened! bloody filepaths now too with the installed versions, its just so tedious sometimes haha!
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Finding a compiler bug is like winning the lottery. It makes you feel awesome, and it also essentially never happens.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    I'm with kmdv - keep tracking this bug.

    While the -O3 optimisation (I'm assuming g++) is less mature than other optimisation settings, it isn't actually too bad. Some of the optimisations it does actually increase likelihood of coding bugs (most notably pointer molestations) having a visible effect. In other words, -O3 is more likely to break dodgy code than other optimisation settings.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    right its nailed and i feel like i just won that lottery mentioned! thanks 4 advising to stick with it, i will never discount something like this again! found that bug only occurd with my own filetype, .wgn, drove me nuts as still worked on other machine, i was then cleaning registry and all kinds.. problem? simple buffer overflow in sprintf as i had not allowed enough storage for occasions where i loaded additional data found in my native filetype, !
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why are you using sprintf in the first place? Get rid of those dangerous C functions!
    You can use Boost for a safe alternative.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working app crashes on other computers
    By Molokai in forum C Programming
    Replies: 27
    Last Post: 10-19-2009, 12:09 PM
  2. DirectX screenshot via C (app crashes)
    By Delusionz in forum C Programming
    Replies: 6
    Last Post: 01-11-2009, 09:55 AM
  3. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  4. Replies: 3
    Last Post: 08-14-2003, 01:37 PM
  5. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM