Code Required Compiler Options

View: New views
2 Messages — Rating Filter:   Alert me  

Code Required Compiler Options

by carnellr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have some code that requires the command line option -fno-strict-aliasing to be set when using -O2 optimization or the optimizer will silently cause the code to return unexpected results.

Because other people may compile these functions into their code, I would like to be sure that they use the correct command line options when compiling.

Is there a way to require that -fno-strict-aliasing be set when compiling through the use of pragmas?  I would like an error to be thrown at compile time if it is not set.  Something like #pragam require -fno-strict-aliasing would be nice.

Thanks for your help,
Rob

Re: Code Required Compiler Options

by tom fogal-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

carnellr <carnellr@...> writes:
[snip]
> Is there a way to require that -fno-strict-aliasing be set when
> compiling through the use of pragmas?  I would like an error to be
> thrown at compile time if it is not set.  Something like #pragam
> require -fno-strict-aliasing would be nice.

Perhaps you can just force it off.  Does

  #pragma GCC optimize ("no-strict-aliasing")

do what you want? and/or

  __attribute__ ((optimize("no-strict-aliasing")))

on particular functions?

I haven't tested this, but

  http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Function-Specific-Option-Pragmas.html#Function-Specific-Option-Pragmas
  http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Function-Attributes.html

implies it might work.

HTH,

-tom