This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR middle-end/18160
The updated patch addresses the comments I received.
Let me know if it is still OK to commit. I retested the patch. I
will update changes.html in a separate patch.
Adam
2004-10-27 Adam Nemet <anemet@lnxw.com>
PR middle-end/18160
* c-typeck.c (c_mark_addressable): Issue error if address of a
register variable is taken. Use "%qD" to print DECL_NAME.
2004-10-27 Adam Nemet <anemet@lnxw.com>
PR middle-end/18160
* gcc.dg/register-var-1.c: New test.
* gcc.dg/register-var-2.c: New test.
* gcc.dg/asm-7.c: Taking the address of a register variable is an
error now.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.392
diff -c -p -r1.392 c-typeck.c
*** c-typeck.c 17 Oct 2004 22:01:19 -0000 1.392
--- c-typeck.c 27 Oct 2004 19:23:16 -0000
*************** c_mark_addressable (tree exp)
*** 2818,2825 ****
case COMPONENT_REF:
if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
{
! error ("cannot take address of bit-field %qs",
! IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x, 1))));
return false;
}
--- 2818,2825 ----
case COMPONENT_REF:
if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
{
! error
! ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
return false;
}
*************** c_mark_addressable (tree exp)
*** 2846,2869 ****
{
if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
{
! error ("global register variable %qs used in nested function",
! IDENTIFIER_POINTER (DECL_NAME (x)));
return false;
}
! pedwarn ("register variable %qs used in nested function",
! IDENTIFIER_POINTER (DECL_NAME (x)));
}
else if (C_DECL_REGISTER (x))
{
if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
! {
! error ("address of global register variable %qs requested",
! IDENTIFIER_POINTER (DECL_NAME (x)));
! return false;
! }
!
! pedwarn ("address of register variable %qs requested",
! IDENTIFIER_POINTER (DECL_NAME (x)));
}
/* drops in */
--- 2846,2864 ----
{
if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
{
! error
! ("global register variable %qD used in nested function", x);
return false;
}
! pedwarn ("register variable %qD used in nested function", x);
}
else if (C_DECL_REGISTER (x))
{
if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
! error ("address of global register variable %qD requested", x);
! else
! error ("address of register variable %qD requested", x);
! return false;
}
/* drops in */
Index: testsuite/gcc.dg/register-var-1.c
===================================================================
RCS file: testsuite/gcc.dg/register-var-1.c
diff -N testsuite/gcc.dg/register-var-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/register-var-1.c 27 Oct 2004 19:23:16 -0000
***************
*** 0 ****
--- 1,14 ----
+ /* PR/18160 */
+
+ /* { dg-do compile { target i?86-*-* } } */
+
+ /* This should yield an error even without -pedantic. */
+ /* { dg-options "-ansi" } */
+
+ void g(int *);
+
+ void f(void)
+ {
+ register int x __asm ("eax");
+ g(&x); /* { dg-error "error: address of register variable" } */
+ }
Index: testsuite/gcc.dg/register-var-2.c
===================================================================
RCS file: testsuite/gcc.dg/register-var-2.c
diff -N testsuite/gcc.dg/register-var-2.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/register-var-2.c 27 Oct 2004 19:23:16 -0000
***************
*** 0 ****
--- 1,14 ----
+ /* PR/18160 */
+
+ /* { dg-do compile } */
+
+ /* This should yield an error even without -pedantic. */
+ /* { dg-options "-ansi" } */
+
+ void g(int *);
+
+ void f(void)
+ {
+ register int x;
+ g(&x); /* { dg-error "error: address of register variable" } */
+ }
Index: testsuite/gcc.dg/asm-7.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/asm-7.c,v
retrieving revision 1.4
diff -c -p -r1.4 asm-7.c
*** testsuite/gcc.dg/asm-7.c 13 May 2004 06:40:49 -0000 1.4
--- testsuite/gcc.dg/asm-7.c 27 Oct 2004 19:23:16 -0000
*************** void test(void)
*** 9,15 ****
static int m;
int *p;
! __asm__ ("" : : "m"(r)); /* { dg-warning "address of register" } */
__asm__ ("" : : "m"(i));
__asm__ ("" : : "m"(m));
__asm__ ("" : : "m"(0)); /* { dg-error "" } */
--- 9,15 ----
static int m;
int *p;
! __asm__ ("" : : "m"(r)); /* { dg-error "" } */
__asm__ ("" : : "m"(i));
__asm__ ("" : : "m"(m));
__asm__ ("" : : "m"(0)); /* { dg-error "" } */
*************** void test(void)
*** 22,28 ****
__asm__ ("" : : "g"(0));
__asm__ ("" : : "g"(i+1));
! __asm__ ("" : "=m"(r2)); /* { dg-warning "address of register" } */
__asm__ ("" : "=m"(i));
__asm__ ("" : "=m"(m));
}
--- 22,28 ----
__asm__ ("" : : "g"(0));
__asm__ ("" : : "g"(i+1));
! __asm__ ("" : "=m"(r2)); /* { dg-error "" } */
__asm__ ("" : "=m"(i));
__asm__ ("" : "=m"(m));
}