[Bug c/38716] New: Undocumented __attribute__((optimize)) behaviour when the attribute specifies no optimisation level

rsandifo at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sat Jan 3 13:20:00 GMT 2009


If __attribute__((optimize(...))) does not specify an optimisation
level (-Ox), we act as though the prevailing -Ox level had been restated.
So:

  __attribute__((optimize("no-gcse")))

behaves like:

  __attribute__((optimize("Ox", "no-gcse")))

where Ox is the current optimisation level.  This means that if you
compile:

  void bar (int);
  void __attribute__((optimize("no-gcse"))) f1 (void)
  {
    bar (1);
    bar (2);
  }
  void f2 (void)
  {
    bar (1);
    bar (2);
  }

with -O2 -fno-omit-frame-pointer, f1 will be implicitly use:

  __attribute__((optimize("O2", "no-gcse")))

and this implicit -O2 will override the explicit -fno-omit-frame-pointer.
So f1 will be compiled without a frame pointer but f2 will be compiled
with one.

This behaviour isn't mentioned in the current documentation,
so this is either an implementation or a documentation bug.
In RichardG's opinion (and my opinion) it's an implementation
bug, so I'm marking it as "c".


-- 
           Summary: Undocumented __attribute__((optimize)) behaviour when
                    the attribute specifies no optimisation level
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rsandifo at gcc dot gnu dot org
  GCC host triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38716



More information about the Gcc-bugs mailing list