https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100685

            Bug ID: 100685
           Summary: #pragma GCC push_options ineffective for optimize
                    options
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The #pragma GCC push_options in the program below should prevent the folding of
the strlen() call in g() but doesn't.  This has changed in GCC 11 (GCC 10
behaves as expected).  The dump shows that the optimize attribute has both
optimization options, -O1 as well as -O2.  That also seems unexpected but it
has not changed between 10 and 11.

$ cat a.c && gcc -O0 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
#pragma GCC optimize ("2")

int f (void)
{
  const char s[] = "12";
  return __builtin_strlen (s);   // folded to 1 (good)
}

#pragma GCC push_options
#pragma GCC optimize ("1")

int g (void)
{
  const char s[] = "1";
  return __builtin_strlen (s);   // also folded but shouldn't be
}

;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)

__attribute__((optimize ("2")))
int f ()
{
  <bb 2> [local count: 1073741824]:
  return 2;

}



;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)

__attribute__((optimize ("2", "1")))
int g ()
{
  <bb 2> [local count: 1073741824]:
  return 1;

}

Reply via email to