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]

[PATCH] C++ implications of PR 18160


Hi,

It turns out that C++ also fails with an ICE when trying to expand an
address expression for an explicit register variable.

The difference is that for C++ we cannot issue a hard error for the
basic case as taking the address of a register variable is allowed in
C++ (7.1.1 paragraph #3 in the standard).

If this patch is approved I will summarize the modified behavior in
changes.html.

The patch was regression-tested on i686-pc-linux-gnu.

Is it OK to commit?

Adam

        PR middle-end/18160   
        * cp/typeck.c (cxx_mark_addressable): Issue an error if address of 
        an explicit register variable is requested. 

        PR middle-end/18160   
        * g++.dg/warn/register-var-1.C: New test. 
        * g++.dg/warn/register-var-2.C: New test. 

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.588
diff -c -p -r1.588 typeck.c
*** cp/typeck.c	21 Oct 2004 21:23:41 -0000	1.588
--- cp/typeck.c	31 Oct 2004 02:06:07 -0000
*************** cxx_mark_addressable (tree exp)
*** 4339,4347 ****
        case CONST_DECL:
        case RESULT_DECL:
  	if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
! 	    && !DECL_ARTIFICIAL (x) && extra_warnings)
! 	  warning ("address requested for %qD, which is declared `register'",
!                    x);
  	TREE_ADDRESSABLE (x) = 1;
  	return true;
  
--- 4339,4354 ----
        case CONST_DECL:
        case RESULT_DECL:
  	if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
! 	    && !DECL_ARTIFICIAL (x))
! 	  if (DECL_HARD_REGISTER (x) != 0)
! 	    {
! 	      error
! 		("address of explicit register variable %qD requested", x);
! 	      return false;
! 	    }
! 	  else if (extra_warnings)
! 	    warning
! 	      ("address requested for %qD, which is declared `register'", x);
  	TREE_ADDRESSABLE (x) = 1;
  	return true;
  
Index: testsuite/g++.dg/warn/register-var-1.C
===================================================================
RCS file: testsuite/g++.dg/warn/register-var-1.C
diff -N testsuite/g++.dg/warn/register-var-1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/register-var-1.C	31 Oct 2004 02:06:07 -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 explicit register variable" } */
+ } 
Index: testsuite/g++.dg/warn/register-var-2.C
===================================================================
RCS file: testsuite/g++.dg/warn/register-var-2.C
diff -N testsuite/g++.dg/warn/register-var-2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/register-var-2.C	31 Oct 2004 02:06:07 -0000
***************
*** 0 ****
--- 1,14 ----
+ /* PR/18160 */
+ 
+ /* { dg-do compile } */
+ 
+ /* This should yield an error even without -pedantic.  */
+ /* { dg-options "-Wall -W" } */
+ 
+ void g(int *);
+ 
+ void f(void) 
+ { 
+   register int x;
+   g(&x); /* { dg-warning "address requested for 'x', which is declared `register'" } */
+ } 


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