__attribute__((optimize("-O2"))) doesn't work

Oleg Endo oleg.endo@t-online.de
Mon Dec 22 21:39:00 GMT 2014


On Mon, 2014-12-22 at 15:33 -0600, Chaoran Yang wrote:
> Hi all, 
> 
> I’m trying to use the __attribute__((optimize(“-O2”))) to mark a
> function that should always be optimized. But it doesn’t seem to work.
> I’ve tested both GCC 4.9.2 and 4.8.3, they both silently ignored the
> attribute. I’m wondering if I’m something super stupid that I’m not
> aware of.

Try __attribute__((optimize("O2"))

i.e. remove the leading '-'.

See also:
https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes

"Strings that begin with O are assumed to be an optimization option,
while other options are assumed to be used with a -f prefix. "

Cheers,
Oleg



More information about the Gcc-help mailing list