I am trying to use the GCC pragma optimize to set global optimizations in my C code. GCC version is 4.4.3 on 开发者_C百科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.
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.
For the last question: you could put it into a separate compilation unit and use the command line switch: -O3
精彩评论