This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Fix PR2164
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Fix PR2164
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Mon, 21 May 2001 11:18:41 -0700
- Organization: CodeSourcery, LLC
I was amused to find out, in the course of fixing this bug, that GCC
has long accepted:
void f () {
int i __asm__ ("%ebx");
}
but totally ignored the `asm'. In other words, this doesn't put `i'
in register %ebx; for that, you need to explicitly say `register'.
That's fine, but we should warn on the above, since it's meaningless.
We were marking `i' as DECL_C_HARD_REGISTER, but not putting it a
register, which caused the regression from GCC 2.95.2, because that
confused us elsewhere.
Bootstrapped and tested on i686-pc-linux-gnu, installed on the
mainline and on the branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
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.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.207.2.9
diff -c -p -r1.207.2.9 c-decl.c
*** c-decl.c 2001/05/13 07:09:51 1.207.2.9
--- c-decl.c 2001/05/21 17:47:39
*************** finish_decl (decl, init, asmspec_tree)
*** 3616,3626 ****
|| TREE_ASM_WRITTEN (decl)), 0);
else
{
if (asmspec)
{
! SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
! DECL_C_HARD_REGISTER (decl) = 1;
}
add_decl_stmt (decl);
}
--- 3616,3645 ----
|| TREE_ASM_WRITTEN (decl)), 0);
else
{
+ /* This is a local variable. If there is an ASMSPEC, the
+ user has requested that we handle it specially. */
if (asmspec)
{
! /* 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: extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/extend.texi,v
retrieving revision 1.92.2.11
diff -c -p -r1.92.2.11 extend.texi
*** extend.texi 2001/05/21 15:43:54 1.92.2.11
--- extend.texi 2001/05/21 17:47:40
*************** On systems where an underscore is normal
*** 3290,3295 ****
--- 3290,3302 ----
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:
Index: testsuite/gcc.dg/20010520-1.c
===================================================================
RCS file: 20010520-1.c
diff -N 20010520-1.c
*** /dev/null Tue May 5 13:32:27 1998
--- 20010520-1.c Mon May 21 10:47:45 2001
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile { target i?86-*-* } } */
+ /* { dg-options "-w" } */
+
+ void f ()
+ {
+ int i __asm__ ("%eax");
+ __asm__ volatile ("" : "=a" (i));
+ }
+
+