This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR middle-end/18160
- From: Adam Nemet <anemet at lnxw dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Richard Henderson <rth at redhat dot com>, gcc at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 Oct 2004 23:49:41 -0700
- Subject: Re: PR middle-end/18160
- References: <16766.43717.959860.195034@anemet1.lynx.com><20041026195203.GA15086@redhat.com><16766.46685.198957.191723@anemet1.lynx.com><20041026202657.GA15269@redhat.com><16766.54682.82730.11990@anemet1.lynx.com><20041026224419.GA15592@redhat.com><16766.57917.483995.480374@anemet1.lynx.com><jehdohgh9z.fsf@sykes.suse.de>
Andreas Schwab writes:
> Adam Nemet <anemet@lnxw.com> writes:
>> Should this be turned into an error too?
> It violates a constraint in the standard.
Thanks for all the comments. Here is the patch to turn the testcase
into an error. It was regression tested on i686-pc-linux-gnu.
Is it OK to apply?
Adam
2004-10-26 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.
2004-10-26 Adam Nemet <anemet@lnxw.com>
PR middle-end/18160
* gcc.dg/pr18160.c: New test.
* gcc.dg/pr18160-1.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 06:23:14 -0000
*************** c_mark_addressable (tree exp)
*** 2856,2869 ****
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 */
--- 2856,2867 ----
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)));
! else
! error ("address of register variable %qs requested",
IDENTIFIER_POINTER (DECL_NAME (x)));
+ return false;
}
/* drops in */
Index: testsuite/gcc.dg/pr18160-1.c
===================================================================
RCS file: testsuite/gcc.dg/pr18160-1.c
diff -N testsuite/gcc.dg/pr18160-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/pr18160-1.c 27 Oct 2004 06:23:14 -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 "address of register variable" } */
+ }
Index: testsuite/gcc.dg/pr18160.c
===================================================================
RCS file: testsuite/gcc.dg/pr18160.c
diff -N testsuite/gcc.dg/pr18160.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/pr18160.c 27 Oct 2004 06:23:14 -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 "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 06:23:14 -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));
}