c-decl.c (finish_decl): Don't set DECL_C_HARD_REGISTER for non-register variables.
authorMark Mitchell <mark@codesourcery.com>
Mon, 21 May 2001 18:36:57 +0000 (18:36 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 21 May 2001 18:36:57 +0000 (18:36 +0000)
* c-decl.c (finish_decl): Don't set DECL_C_HARD_REGISTER for
non-register variables.
* extend.texi: Document that asm-specifications do not make sense
for non-static local variables.

From-SVN: r42403

gcc/ChangeLog
gcc/c-decl.c
gcc/extend.texi
gcc/testsuite/gcc.dg/20010520-1.c [new file with mode: 0644]

index 861b4ba..5690962 100644 (file)
@@ -1,3 +1,10 @@
+2001-05-21  Mark Mitchell  <mark@codesourcery.com>
+
+       * c-decl.c (finish_decl): Don't set DECL_C_HARD_REGISTER for
+       non-register variables.
+       * extend.texi: Document that asm-specifications do not make sense
+       for non-static local variables.
+
 2001-05-21  Jason Merrill  <jason_merrill@redhat.com>
 
        * dbxout.c (MINIMAL_DEBUG, flag_minimal_debug): Lose.
index 3de4592..0c08662 100644 (file)
@@ -3616,11 +3616,30 @@ finish_decl (decl, init, asmspec_tree)
        }
       else
        {
+         /* This is a local variable.  If there is an ASMSPEC, the
+            user has requested that we handle it specially.  */
          if (asmspec)
            {
-             SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
-             DECL_C_HARD_REGISTER (decl) = 1;
+             /* In conjunction with an ASMSPEC, the `register'
+                keyword indicates that we should place the variable
+                in a particular register.  */
+             if (DECL_REGISTER (decl))
+               DECL_C_HARD_REGISTER (decl) = 1;
+
+             /* If this is not a static variable, issue a warning.
+                It doesn't make any sense to give an ASMSPEC for an
+                ordinary, non-register local variable.  Historically,
+                GCC has accepted -- but ignored -- the ASMSPEC in
+                this case.  */
+             if (TREE_CODE (decl) == VAR_DECL 
+                 && !DECL_REGISTER (decl)
+                 && !TREE_STATIC (decl))
+               warning_with_decl (decl,
+                                  "ignoring asm-specifier for non-static local variable `%s'");
+             else
+               SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
            }
+
          add_decl_stmt (decl);
        }
 
index 0d96b25..48c6ea1 100644 (file)
@@ -3290,6 +3290,13 @@ On systems where an underscore is normally prepended to the name of a C
 function or variable, this feature allows you to define names for the
 linker that do not start with an underscore.
 
+It does not make sense to use this feature with a non-static local
+variable since such variables do not have assembler names.  If you are
+trying to put the variable in a particular register, see @ref{Explicit
+Reg Vars}.  GCC presently accepts such code with a warning, but will
+probably be changed to issue an error, rather than a warning, in the
+future.
+
 You cannot use @code{asm} in this way in a function @emph{definition}; but
 you can get the same effect by writing a declaration for the function
 before its definition and putting @code{asm} there, like this:
diff --git a/gcc/testsuite/gcc.dg/20010520-1.c b/gcc/testsuite/gcc.dg/20010520-1.c
new file mode 100644 (file)
index 0000000..c96dbc4
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-w" } */
+
+void f ()
+{
+  int i __asm__ ("%eax");
+  __asm__ volatile ("" : "=a" (i));
+}
+
+