Related discussion:
http://gcc.gnu.org/ml/gcc/2005-03/msg00181.html

Given the following,

static char const rcsid[] =
"$Id: f.c,v 5.4 1993/11/09 17:40:15 eggert Exp $";
int main() {}

When compiled with GCC 3.4.3, at -O2, the ident string above will _not_
appear in the executable.  This is apparently expected behavior.

However,
  gcc -fkeep-static-consts -O2 t.c
did not retain the ident string, rcsid, defined above.  Shouldn't
-fkepp-static-consts have ensured that this static constant would appear
in the executable?

The logic in wrapup_global_declarations (toplev.c) doesn't look quite right:

              else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
                       && (optimize || !flag_keep_static_consts 
                           || DECL_ARTIFICIAL (decl))) 
                needed = 0; 

If 'optimize' is asserted above then flag_keep_static_consts will
not be tested.  Perhaps it should read as follows?

                       && ((optimize && !flag_keep_static_consts)

Alternatively, I wonder if flag_keep_static_consts should be tested earlier at a
higher level, for example:

   if (flag_keep_static_consts)
      /* needed */;

but I'm not sure about which of the earlier tests which assert needed = 0;
are mandatory and which are optional.

-- 
           Summary: -fkeep-static-consts with -O asserted doesn't keep
                    consts
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gary at intrepid dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to