PATCH for global register error message

Andrew Haley aph@pasanda.cygnus.co.uk
Wed Nov 10 04:09:00 GMT 1999


Hi,

This is a resend of a message from a couple of weeks ago.  I think my
explanation is reasonable.  My patch moves the check for global
register vars into regclass.c, which IMO is a logical place for it to
be.

Andrew.


------- Start of forwarded message -------
Date: 28 Oct 1999 10:53:42 -0000
From: Andrew Haley <aph@cygnus.co.uk>
To: law@cygnus.com
CC: gcc-patches@sourceware.cygnus.com
Subject: Re: PATCH for global register error message

> Date: Thu, 28 Oct 1999 02:38:19 -0600
> From: Jeffrey A Law <law@cygnus.com>
> 
>   In message <199910271230.NAA26358@viagra.cygnus.co.uk>you write:
>   > Sure.  C++'s init_decl_processing calls c_common_nodes_and_builtins,
>   > which in turn defines a bunch of functions such as __builtin_constant_p.
>   > A file which only contains a global register declaration is rejected
>   > by the C++ compiler.
> But C does precisely the same thing.
> 
> init_decl_processing calls c_common_nodes_and_builtins.  

c_common_nodes_and_builtins calls builtin_function, which is different
in C and C++.  C++'s builtin_function is just a wrapper around
define_function (which eventually calls make_function_rtl,) whereas
C's builtin_function does not call make_function_rtl.  Instead, it
calls make_decl_rtl, so the variable function_defined doesn't get set
until a user's function is defined.

>   > In any case, I would have thought that we should leave the prohibition
>   > of global register variables until as late as possible.
> I agree.  What I'm trying to find out is whether or not the C++ front-end is
> behaving in a sensible manner.  I'm still not sure if C++ is doing something
> wrong or not.

Hard to say.  It seems that C and C++ have diverged in the way that
they do this, but I don't think that you could say that C++ is wrong.

Andrew.
------- End of forwarded message -------

Fri Oct 22 14:30:30 1999  Andrew Haley  <aph@cygnus.com>

        * varasm.c (function_defined): Remove.
        (make_function_rtl): Don't set function_defined.
        (make_decl_rtl): Remove global register warning.
        * regclass.c (no_global_reg_vars): New variable.
        (globalize_reg): Warn if function has already been defined.
        (regclass_init): Set no_global_reg_vars.

Index: varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.84
diff -p -r1.84 varasm.c
*** varasm.c    1999/10/03 16:47:52     1.84
--- varasm.c    1999/10/22 13:23:58
*************** int size_directive_output;
*** 149,158 ****

  tree last_assemble_variable_decl;

- /* Nonzero if at least one function definition has been seen.  */
-
- static int function_defined;
-
  static const char *strip_reg_name     PROTO((const char *));
  static int contains_pointers_p                PROTO((tree));
  static void decode_addr_const         PROTO((tree, struct addr_const *));
--- 149,154 ----
*************** make_function_rtl (decl)
*** 579,587 ****
        ENCODE_SECTION_INFO (decl);
  #endif
      }
-
-   /* Record at least one function has been defined.  */
-   function_defined = 1;
  }

  /* Given NAME, a putative register name, discard any customary prefixes.  */
--- 575,580 ----
*************** make_decl_rtl (decl, asmspec, top_level)
*** 729,737 ****
              DECL_INITIAL (decl) = 0;
              error ("global register variable has initial value");
            }
-         if (fixed_regs[reg_number] == 0
-             && function_defined && top_level)
-           error ("global register variable follows a function definition");
          if (TREE_THIS_VOLATILE (decl))
            warning ("volatile register variables don't work as you might wish");

--- 722,727 ----
Index: regclass.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/regclass.c,v
retrieving revision 1.63
diff -p -r1.63 regclass.c
*** regclass.c  1999/10/01 10:00:25     1.63
--- regclass.c  1999/10/22 13:23:59
*************** struct reg_info_data {
*** 213,219 ****
--- 213,224 ----

  static struct reg_info_data *reg_info_head;

+ /* No more global register vairiables may be declared; true once
+    regclass has been initialized. */

+ static int no_global_reg_vars = 0;
+
+
  /* Function called only once to initialize the above data on reg usage.
     Once this is done, various switches may override.  */

*************** void
*** 615,620 ****
--- 620,628 ----
  globalize_reg (i)
       int i;
  {
+   if (no_global_reg_vars)
+     error ("global register variable follows a function definition");
+
    if (global_regs[i])
      {
        warning ("register used for two global register variables");
*************** regclass_init ()
*** 743,748 ****
--- 751,759 ----
    /* This prevents dump_flow_info from losing if called
       before regclass is run.  */
    prefclass = 0;
+
+   /* No more global register vairiables may be declared. */
+   no_global_reg_vars = 1;
  }
  ^L


More information about the Gcc-patches mailing list