C code optimization using #pragma GCC optimize
Solution 1
An ICE (internal compiler error) leading to a segmentation fault is always a bug in the compiler, which is why it asks you to report the bug. You should not be able to crash the compiler with any source code, valid or invalid. (There are all sorts of things that may happen, most often involving a refusal to compile invalid code, but crash isn't one of them.)
Since GCC 4.6.1 is current, why not consider an upgrade to a more recent version of GCC (not that 4.4.3 is all that old).
Before submitting a bug report, you should try to minimize your reproduction. Everything from line 494 onwards is probably immaterial; with luck, you can reduce the material between lines 1 and 493 from almost 500 down to 20 or so. You should certainly aim to reduce it as much as possible while preserving the error. Before you start chopping the code, preserve the version that crashes the compiler. As you successfully remove the code while preserving the crash, check each successive version into your VCS. (You are using a VCS, aren't you? That's a rhetorical question; if you're not, now's a good time to start. You need one to avoid making changes that can't be undone.) Try to eliminate non-standard headers (ones you've written) before eliminating standard headers. Try to get rid of as many headers as possible. Note the request for preprocessed source - the code reduction I'm talking of reduces the size of the preprocessed source.
Solution 2
For the last question: you could put it into a separate compilation unit and use the command line switch: -O3
goldenmean
struct descriptionOf { int elligent_Developer; short list_of_proven_skills; long list_of_ambitions; long long int erest_in_various_technologies; double effort_in_achieving_skills_and_ambitions; float ing_innovator; char of_a_hands_on_doer; }goldenmean; Software Developer with work experience in areas of Video/Image processing and codecs,DSP and multimedia Systems,on DSP/Multicore processor architecures, for devices and applications in Consumer Electronics, Communications industry. Programming languages: C,C++,Matlab/Octave,Python,DSP or RISC assembly languages.
Updated on June 04, 2022Comments
-
goldenmean over 1 year
I am trying to use the GCC pragma optimize to set global optimizations in my C code. GCC version is 4.4.3 on Ubuntu. The basic idea is to use function specific optimization levels.
#pragma GCC optimize ("O3")
I get a compilation error just before my main function in my C code
But when I build it, I get compilation error as below -
passrecovery.c: In function âmainâ: passrecovery.c:493: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions. make: *** [all] Error 1
I checked the README.Bugs file, mentioned in the error, but found no clues regarding this.
Is
#pragma optimize
supported in 4.4.3 GCC or not?If yes, then what is that I am doing incorrectly in using this pragma to optimize the code.
Any other alternative GCC directive for optimizing the code for speed?
EDIT: I even tried
#pragma GCC push_options
then#pragma GCC optimize ("O3")
and at end of file#pragma GCC pop_options
; same error. -
goldenmean over 12 yearsFYI I tried to use this optimize directive on a main(). That seems to be the problem. This directive works fine(Atleast compiled ok) if used on some other function(other than main)
-
goldenmean over 12 years@Would want some more eyeballs to go over the code which is causing this. Only library this code uses is -lcrypt(crypt.h) , string.h, stdio.h, stdlib.h, ctype.h.
-
Jonathan Leffler over 12 years@goldenmean: recommend trying to remove
<crypt.h>
and stuff that depends on it first...well, second. You should look at what's in the first 490 lines and see what can be deleted wholesale while preserving the crash. You can use comments first, then delete them. There's a chance you cannot move any lines of code whatsoever. But that's pretty unlikely. And every line removed is a benefit. That your program is not using any of your own headers simplifies life. -
Hasturkun over 12 yearsI suggest using delta to minimize the (possibly preprocessed) code to the minimal crashing case, it usually works quite nicely