This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR middle-end/18160


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));
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]